Changeset 1680
- Timestamp:
- 01/29/10 14:07:38 (15 years ago)
- Location:
- branches/alma
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma/python/scantable.py
r1678 r1680 41 41 varlist = vars() 42 42 from asap._asap import stmath 43 self._math = stmath( )43 self._math = stmath( rcParams['insitu'] ) 44 44 if isinstance(filename, Scantable): 45 45 Scantable.__init__(self, filename) … … 1868 1868 return s 1869 1869 1870 def scale(self, factor, tsys=True, mode='channel',insitu=None):1870 def scale(self, factor, tsys=True, insitu=None): 1871 1871 """ 1872 1872 Return a scan where all spectra are scaled by the give 'factor' … … 1878 1878 tsys: if True (default) then apply the operation to Tsys 1879 1879 as well as the data 1880 mode: operation mode for list scaling factor. Possible1881 values are 'channel' (channel-by-channel) or1882 'row' (row-by-row).1883 1880 """ 1884 1881 if insitu is None: insitu = rcParams['insitu'] 1885 1882 self._math._setinsitu(insitu) 1886 1883 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 ) 1893 1891 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' ) 1897 1894 else: 1898 1895 s = scantable(self._math._unaryop(self.copy(), factor, "MUL", tsys)) … … 2042 2039 if isinstance(other, scantable): 2043 2040 s = scantable(self._math._binaryop(self.copy(), other, "ADD")) 2044 elif isinstance(other, float) :2041 elif isinstance(other, float) or isinstance(other, int): 2045 2042 s = scantable(self._math._unaryop(self.copy(), other, "ADD", False)) 2046 2043 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 ) 2051 2049 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") 2054 2051 else: 2055 2052 raise TypeError("Other input is not a scantable or float value or float list") … … 2066 2063 if isinstance(other, scantable): 2067 2064 s = scantable(self._math._binaryop(self.copy(), other, "SUB")) 2068 elif isinstance(other, float) :2065 elif isinstance(other, float) or isinstance(other, int): 2069 2066 s = scantable(self._math._unaryop(self.copy(), other, "SUB", False)) 2070 2067 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 ) 2075 2073 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") 2078 2075 else: 2079 2076 raise TypeError("Other input is not a scantable or float value or float list") … … 2090 2087 if isinstance(other, scantable): 2091 2088 s = scantable(self._math._binaryop(self.copy(), other, "MUL")) 2092 elif isinstance(other, float) :2089 elif isinstance(other, float) or isinstance(other, int): 2093 2090 s = scantable(self._math._unaryop(self.copy(), other, "MUL", False)) 2094 2091 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 ) 2099 2097 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") 2102 2099 else: 2103 2100 raise TypeError("Other input is not a scantable or float value or float list") … … 2114 2111 if isinstance(other, scantable): 2115 2112 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: 2118 2115 raise ZeroDivisionError("Dividing by zero is not recommended") 2119 2116 s = scantable(self._math._unaryop(self.copy(), other, "DIV", False)) 2120 2117 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 ) 2125 2123 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") 2128 2125 else: 2129 2126 raise TypeError("Other input is not a scantable or float value or float list") -
branches/alma/src/STMath.cpp
r1677 r1680 507 507 const std::vector<float> val, 508 508 const std::string& mode, 509 bool tsys,510 const std::string& op)509 const std::string& opmode, 510 bool tsys ) 511 511 { 512 512 CountedPtr< Scantable > out ; 513 if ( op == "channel" ) {513 if ( opmode == "channel" ) { 514 514 out = arrayOperateChannel( in, val, mode, tsys ) ; 515 515 } 516 else if ( op == "row" ) {516 else if ( opmode == "row" ) { 517 517 out = arrayOperateRow( in, val, mode, tsys ) ; 518 518 } -
branches/alma/src/STMath.h
r1677 r1680 123 123 arrayOperate( const casa::CountedPtr<Scantable>& in, 124 124 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 ); 127 128 128 129 // channel operation -
branches/alma/src/STMathWrapper.h
r1677 r1680 75 75 ScantableWrapper arrayOperate( const ScantableWrapper& in, 76 76 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)); } 80 80 81 81 ScantableWrapper array2dOperate( const ScantableWrapper& in,
Note:
See TracChangeset
for help on using the changeset viewer.