Changeset 1677 for branches/alma/python


Ignore:
Timestamp:
01/27/10 18:29:48 (15 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-1823

Ready to Release: Yes

Interface Changes: Yes

What Interface Changed: The mode parameter is added to scantable.scale() method.

Test Programs: s = sd.scantable('yourfile',False)

factor = []
for i in range(s.nrow()):

factor.append(i)

s2 = s + factor

Put in Release Notes: Yes

Module(s): -

Description: Describe your changes here...

Basic operations (addition, subtraction, multiplication, division)
of scantable with one dimensional list are implemented.
Size of list operand should be equal to either number of spectral channel
or number of row. In the former case, the list is operated as
channel-by-channel manner, while it is operated as row-by-row manner
in the latter case.
If number of spectral channel is equal to number of row, row-by-row
operation will be done.

The user is able to select operation mode (channel-by-channel or row-by-row)
manually by using lower level function, stmath.arrayop().

The scantable.scale() method is updated to allow list scaling factor.
Scaling is done in channel-by-channel manner if mode is set to 'channel',
while in row-by-row manner if mode is set to 'row'.


File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/alma/python/scantable.py

    r1676 r1677  
    18681868            return s
    18691869
    1870     def scale(self, factor, tsys=True, insitu=None):
     1870    def scale(self, factor, tsys=True, mode='channel', insitu=None):
    18711871        """
    18721872        Return a scan where all spectra are scaled by the give 'factor'
    18731873        Parameters:
    1874             factor:      the scaling factor
     1874            factor:      the scaling factor (float or 1D float list)
    18751875            insitu:      if False a new scantable is returned.
    18761876                         Otherwise, the scaling is done in-situ
     
    18781878            tsys:        if True (default) then apply the operation to Tsys
    18791879                         as well as the data
     1880            mode:        operation mode for list scaling factor. Possible
     1881                         values are 'channel' (channel-by-channel) or
     1882                         'row' (row-by-row).
    18801883        """
    18811884        if insitu is None: insitu = rcParams['insitu']
    18821885        self._math._setinsitu(insitu)
    18831886        varlist = vars()
    1884         s = scantable(self._math._unaryop(self, factor, "MUL", tsys))
     1887        import numpy
     1888        if type(factor) == list:
     1889            if mode == 'row':
     1890                s = scantable( self._math._arrayop( self.copy(), factor, "MUL", tsys, 'row' ) )
     1891            elif mode == 'channel':
     1892                s = scantable( self._math._arrayop( self.copy(), factor, "MUL", tsys, 'channel' ) )
     1893            else:
     1894                asaplog.push( 'scantable.scale(): Unknown operation mode. No scaling.' )
     1895                print_log()
     1896                s = self.copy()
     1897        else:
     1898            s = scantable(self._math._unaryop(self.copy(), factor, "MUL", tsys))
    18851899        s._add_history("scale", varlist)
    18861900        print_log()
     
    20272041        s = None
    20282042        if isinstance(other, scantable):
    2029             s = scantable(self._math._binaryop(self, other, "ADD"))
     2043            s = scantable(self._math._binaryop(self.copy(), other, "ADD"))
    20302044        elif isinstance(other, float):
    2031             s = scantable(self._math._unaryop(self, other, "ADD", False))
    2032         else:
    2033             raise TypeError("Other input is not a scantable or float value")
     2045            s = scantable(self._math._unaryop(self.copy(), other, "ADD", False))
     2046        elif isinstance(other, list):
     2047            if len(other) == self.nrow():
     2048                s = scantable(self._math._arrayop(self.copy(), other, "ADD", False, 'row'))
     2049            elif len(other) == self.nchan(0):
     2050                s = scantable(self._math._arrayop(self.copy(), other, "ADD", False, 'channel'))
     2051            else:
     2052                casalog.post( 'Length of list operand should equal to either scantable.nchan() or scantable.nrow().', 'ERROR' )
     2053        else:
     2054            raise TypeError("Other input is not a scantable or float value or float list")
    20342055        s._add_history("operator +", varlist)
    20352056        print_log()
     
    20432064        s = None
    20442065        if isinstance(other, scantable):
    2045             s = scantable(self._math._binaryop(self, other, "SUB"))
     2066            s = scantable(self._math._binaryop(self.copy(), other, "SUB"))
    20462067        elif isinstance(other, float):
    2047             s = scantable(self._math._unaryop(self, other, "SUB", False))
    2048         else:
    2049             raise TypeError("Other input is not a scantable or float value")
     2068            s = scantable(self._math._unaryop(self.copy(), other, "SUB", False))
     2069        elif isinstance(other, list):
     2070            if len(other) == self.nrow():
     2071                s = scantable(self._math._arrayop(self.copy(), other, "SUB", False, 'row'))
     2072            elif len(other) == self.nchan(0):
     2073                s = scantable(self._math._arrayop(self.copy(), other, "SUB", False, 'channel'))
     2074            else:
     2075                casalog.post( 'Length of list operand should equal to either scantable.nchan() or scantable.nrow().', 'ERROR' )
     2076        else:
     2077            raise TypeError("Other input is not a scantable or float value or float list")
    20502078        s._add_history("operator -", varlist)
    20512079        print_log()
     
    20592087        s = None
    20602088        if isinstance(other, scantable):
    2061             s = scantable(self._math._binaryop(self, other, "MUL"))
     2089            s = scantable(self._math._binaryop(self.copy(), other, "MUL"))
    20622090        elif isinstance(other, float):
    2063             s = scantable(self._math._unaryop(self, other, "MUL", False))
    2064         else:
    2065             raise TypeError("Other input is not a scantable or float value")
     2091            s = scantable(self._math._unaryop(self.copy(), other, "MUL", False))
     2092        elif isinstance(other, list):
     2093            if len(other) == self.nrow():
     2094                s = scantable(self._math._arrayop(self.copy(), other, "MUL", False, 'row'))
     2095            elif len(other) == self.nchan(0):
     2096                s = scantable(self._math._arrayop(self.copy(), other, "MUL", False, 'channel'))
     2097            else:
     2098                casalog.post( 'Length of list operand should equal to either scantable.nchan() or scantable.nrow().', 'ERROR' )
     2099        else:
     2100            raise TypeError("Other input is not a scantable or float value or float list")
    20662101        s._add_history("operator *", varlist)
    20672102        print_log()
    20682103        return s
    2069 
    20702104
    20712105    def __div__(self, other):
     
    20762110        s = None
    20772111        if isinstance(other, scantable):
    2078             s = scantable(self._math._binaryop(self, other, "DIV"))
     2112            s = scantable(self._math._binaryop(self.copy(), other, "DIV"))
    20792113        elif isinstance(other, float):
    20802114            if other == 0.0:
    20812115                raise ZeroDivisionError("Dividing by zero is not recommended")
    2082             s = scantable(self._math._unaryop(self, other, "DIV", False))
    2083         else:
    2084             raise TypeError("Other input is not a scantable or float value")
     2116            s = scantable(self._math._unaryop(self.copy(), other, "DIV", False))
     2117        elif isinstance(other, list):
     2118            if len(other) == self.nrow():
     2119                s = scantable(self._math._array2dop(self.copy(), other, "DIV", False, 'row'))
     2120            elif len(other) == self.nchan(0):
     2121                s = scantable(self._math._arrayop(self.copy(), other, "DIV", False, 'channel'))
     2122            else:
     2123                casalog.post( 'Length of list operand should equal to either scantable.nchan() or scantable.nrow().', 'ERROR' )
     2124        else:
     2125            raise TypeError("Other input is not a scantable or float value or float list")
    20852126        s._add_history("operator /", varlist)
    20862127        print_log()
Note: See TracChangeset for help on using the changeset viewer.