Changeset 1680 for branches/alma


Ignore:
Timestamp:
01/29/10 14:07:38 (14 years ago)
Author:
Takeshi Nakazato
Message:

New Development: No

JIRA Issue: Yes CAS-1823

Ready to Release: Yes

Interface Changes: No

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes/No?

Module(s): Module Names change impacts.

Description: Describe your changes here...

  1. Bug fix

In scantable.py, self._math = stmath() should be
self._math = stmath( rcParamsinsitu? ).

  1. Delete operation mode

I have deleted operation mode parameter which is used for a function
to do an operation of scantable with 1D list, since I have implemented
the operation of scantable with 2D list.

  1. Extend operation of scantable

Now, operation of scantable with 2D list is available.

  1. Accept integer input for operation

Operation of scantable with int as well as int list is working
in addition to operation with float or float list.


Location:
branches/alma
Files:
4 edited

Legend:

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

    r1678 r1680  
    4141        varlist = vars()
    4242        from asap._asap import stmath
    43         self._math = stmath()
     43        self._math = stmath( rcParams['insitu'] )
    4444        if isinstance(filename, Scantable):
    4545            Scantable.__init__(self, filename)
     
    18681868            return s
    18691869
    1870     def scale(self, factor, tsys=True, mode='channel', insitu=None):
     1870    def scale(self, factor, tsys=True, insitu=None):
    18711871        """
    18721872        Return a scan where all spectra are scaled by the give 'factor'
     
    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).
    18831880        """
    18841881        if insitu is None: insitu = rcParams['insitu']
    18851882        self._math._setinsitu(insitu)
    18861883        varlist = vars()
    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' ) )
     1884        s = None
     1885        if isinstance(factor, list):
     1886            if isinstance(factor[0], float) or isinstance(factor[0], int):
     1887                s = scantable( self._math._arrayop( self.copy(), factor, "MUL", tsys ) )
     1888            elif isinstance(factor[0], list):
     1889                from asapmath import _array2dOp
     1890                s = _array2dOp( self.copy(), factor, "MUL", tsys )
    18931891            else:
    1894                 asaplog.push( 'scantable.scale(): Unknown operation mode. No scaling.' )
    1895                 print_log()
    1896                 s = self.copy()
     1892                asaplog.push( 'Unexpected type of scaling factor.' )
     1893                print_log( 'ERROR' )
    18971894        else:
    18981895            s = scantable(self._math._unaryop(self.copy(), factor, "MUL", tsys))
     
    20422039        if isinstance(other, scantable):
    20432040            s = scantable(self._math._binaryop(self.copy(), other, "ADD"))
    2044         elif isinstance(other, float):
     2041        elif isinstance(other, float) or isinstance(other, int):
    20452042            s = scantable(self._math._unaryop(self.copy(), other, "ADD", False))
    20462043        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(self.getifnos()[0]):
    2050                 s = scantable(self._math._arrayop(self.copy(), other, "ADD", False, 'channel'))
     2044            if isinstance(other[0], float) or isinstance(other[0], int):
     2045                s = scantable(self._math._arrayop(self.copy(), other, "ADD", False))
     2046            elif isinstance(other[0], list):
     2047                from asapmath import _array2dOp
     2048                s = _array2dOp( self.copy(), other, "ADD", False )
    20512049            else:
    2052                 asaplog.push( 'Length of list operand should equal to either scantable.nchan() or scantable.nrow().' )
    2053                 print_log( 'ERROR' )
     2050                raise TypeError("Other input is not a scantable or float value or float list")
    20542051        else:
    20552052            raise TypeError("Other input is not a scantable or float value or float list")
     
    20662063        if isinstance(other, scantable):
    20672064            s = scantable(self._math._binaryop(self.copy(), other, "SUB"))
    2068         elif isinstance(other, float):
     2065        elif isinstance(other, float) or isinstance(other, int):
    20692066            s = scantable(self._math._unaryop(self.copy(), other, "SUB", False))
    20702067        elif isinstance(other, list):
    2071             if len(other) == self.nrow():
    2072                 s = scantable(self._math._arrayop(self.copy(), other, "SUB", False, 'row'))
    2073             elif len(other) == self.nchan(self.getifnos()[0]):
    2074                 s = scantable(self._math._arrayop(self.copy(), other, "SUB", False, 'channel'))
     2068            if isinstance(other[0], float) or isinstance(other[0], int):
     2069                s = scantable(self._math._arrayop(self.copy(), other, "SUB", False))
     2070            elif isinstance(other[0], list):
     2071                from asapmath import _array2dOp
     2072                s = _array2dOp( self.copy(), other, "SUB", False )
    20752073            else:
    2076                 asaplog.push( 'Length of list operand should equal to either scantable.nchan() or scantable.nrow().' )
    2077                 print_log( 'ERROR' )
     2074                raise TypeError("Other input is not a scantable or float value or float list")
    20782075        else:
    20792076            raise TypeError("Other input is not a scantable or float value or float list")
     
    20902087        if isinstance(other, scantable):
    20912088            s = scantable(self._math._binaryop(self.copy(), other, "MUL"))
    2092         elif isinstance(other, float):
     2089        elif isinstance(other, float) or isinstance(other, int):
    20932090            s = scantable(self._math._unaryop(self.copy(), other, "MUL", False))
    20942091        elif isinstance(other, list):
    2095             if len(other) == self.nrow():
    2096                 s = scantable(self._math._arrayop(self.copy(), other, "MUL", False, 'row'))
    2097             elif len(other) == self.nchan(self.getifnos()[0]):
    2098                 s = scantable(self._math._arrayop(self.copy(), other, "MUL", False, 'channel'))
     2092            if isinstance(other[0], float) or isinstance(other[0], int):
     2093                s = scantable(self._math._arrayop(self.copy(), other, "MUL", False))
     2094            elif isinstance(other[0], list):
     2095                from asapmath import _array2dOp
     2096                s = _array2dOp( self.copy(), other, "MUL", False )
    20992097            else:
    2100                 asaplog.push( 'Length of list operand should equal to either scantable.nchan() or scantable.nrow().' )
    2101                 print_log( 'ERROR' )
     2098                raise TypeError("Other input is not a scantable or float value or float list")
    21022099        else:
    21032100            raise TypeError("Other input is not a scantable or float value or float list")
     
    21142111        if isinstance(other, scantable):
    21152112            s = scantable(self._math._binaryop(self.copy(), other, "DIV"))
    2116         elif isinstance(other, float):
    2117             if other == 0.0:
     2113        elif isinstance(other, float) or isinstance(other, int):
     2114            if float(other) == 0.0:
    21182115                raise ZeroDivisionError("Dividing by zero is not recommended")
    21192116            s = scantable(self._math._unaryop(self.copy(), other, "DIV", False))
    21202117        elif isinstance(other, list):
    2121             if len(other) == self.nrow():
    2122                 s = scantable(self._math._array2dop(self.copy(), other, "DIV", False, 'row'))
    2123             elif len(other) == self.nchan(self.getifnos()[0]):
    2124                 s = scantable(self._math._arrayop(self.copy(), other, "DIV", False, 'channel'))
     2118            if isinstance(other[0], float) or isinstance(other[0], int):
     2119                s = scantable(self._math._arrayop(self.copy(), other, "DIV", False))
     2120            elif isinstance(other[0], list):
     2121                from asapmath import _array2dOp
     2122                s = _array2dOp( self.copy(), other, "DIV", False )
    21252123            else:
    2126                 asaplog.push( 'Length of list operand should equal to either scantable.nchan() or scantable.nrow().' )
    2127                 print_log( 'ERROR' )
     2124                raise TypeError("Other input is not a scantable or float value or float list")
    21282125        else:
    21292126            raise TypeError("Other input is not a scantable or float value or float list")
  • branches/alma/src/STMath.cpp

    r1677 r1680  
    507507                                              const std::vector<float> val,
    508508                                              const std::string& mode,
    509                                               bool tsys,
    510                                               const std::string& op )
     509                                              const std::string& opmode,
     510                                              bool tsys )
    511511{
    512512  CountedPtr< Scantable > out ;
    513   if ( op == "channel" ) {
     513  if ( opmode == "channel" ) {
    514514    out = arrayOperateChannel( in, val, mode, tsys ) ;
    515515  }
    516   else if ( op == "row" ) {
     516  else if ( opmode == "row" ) {
    517517    out = arrayOperateRow( in, val, mode, tsys ) ;
    518518  }
  • branches/alma/src/STMath.h

    r1677 r1680  
    123123    arrayOperate( const casa::CountedPtr<Scantable>& in,
    124124                  const std::vector<float> val,
    125                   const std::string& mode, bool tsys=false,
    126                   const std::string& op="channel" );
     125                  const std::string& mode,
     126                  const std::string& opmode="channel", 
     127                  bool tsys=false );
    127128
    128129  // channel operation
  • branches/alma/src/STMathWrapper.h

    r1677 r1680  
    7575  ScantableWrapper arrayOperate( const ScantableWrapper& in,
    7676                                 const std::vector<float> val,
    77                                  const std::string& mode, bool tsys=false,
    78                                  const std::string& op="channel" )
    79   { return ScantableWrapper(STMath::arrayOperate(in.getCP(), val, mode, tsys, op)); }
     77                                 const std::string& mode,
     78                                 bool tsys=false )
     79  { return ScantableWrapper(STMath::arrayOperateChannel(in.getCP(), val, mode, tsys)); }
    8080
    8181  ScantableWrapper array2dOperate( const ScantableWrapper& in,
Note: See TracChangeset for help on using the changeset viewer.