Changeset 1681 for branches/alma
- Timestamp:
- 01/29/10 18:14:51 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma/python/scantable.py
r1680 r1681 1883 1883 varlist = vars() 1884 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): 1885 import numpy 1886 if isinstance(factor, list) or isinstance(factor, numpy.ndarray): 1887 if isinstance(factor[0], list) or isinstance(factor[0], numpy.ndarray): 1889 1888 from asapmath import _array2dOp 1890 1889 s = _array2dOp( self.copy(), factor, "MUL", tsys ) 1891 1890 else: 1892 asaplog.push( 'Unexpected type of scaling factor.' ) 1893 print_log( 'ERROR' ) 1891 s = scantable( self._math._arrayop( self.copy(), factor, "MUL", tsys ) ) 1894 1892 else: 1895 1893 s = scantable(self._math._unaryop(self.copy(), factor, "MUL", tsys)) … … 2035 2033 2036 2034 def __add__(self, other): 2037 varlist = vars() 2038 s = None 2039 if isinstance(other, scantable): 2040 s = scantable(self._math._binaryop(self.copy(), other, "ADD")) 2041 elif isinstance(other, float) or isinstance(other, int): 2042 s = scantable(self._math._unaryop(self.copy(), other, "ADD", False)) 2043 elif isinstance(other, list): 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 ) 2049 else: 2050 raise TypeError("Other input is not a scantable or float value or float list") 2051 else: 2052 raise TypeError("Other input is not a scantable or float value or float list") 2053 s._add_history("operator +", varlist) 2054 print_log() 2055 return s 2035 """ 2036 implicit on all axes and on Tsys 2037 """ 2038 return self._operation( other, "ADD" ) 2056 2039 2057 2040 def __sub__(self, other): … … 2059 2042 implicit on all axes and on Tsys 2060 2043 """ 2061 varlist = vars() 2062 s = None 2063 if isinstance(other, scantable): 2064 s = scantable(self._math._binaryop(self.copy(), other, "SUB")) 2065 elif isinstance(other, float) or isinstance(other, int): 2066 s = scantable(self._math._unaryop(self.copy(), other, "SUB", False)) 2067 elif isinstance(other, list): 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 ) 2073 else: 2074 raise TypeError("Other input is not a scantable or float value or float list") 2075 else: 2076 raise TypeError("Other input is not a scantable or float value or float list") 2077 s._add_history("operator -", varlist) 2078 print_log() 2079 return s 2044 return self._operation( other, 'SUB' ) 2080 2045 2081 2046 def __mul__(self, other): … … 2083 2048 implicit on all axes and on Tsys 2084 2049 """ 2085 varlist = vars() 2086 s = None 2087 if isinstance(other, scantable): 2088 s = scantable(self._math._binaryop(self.copy(), other, "MUL")) 2089 elif isinstance(other, float) or isinstance(other, int): 2090 s = scantable(self._math._unaryop(self.copy(), other, "MUL", False)) 2091 elif isinstance(other, list): 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 ) 2097 else: 2098 raise TypeError("Other input is not a scantable or float value or float list") 2099 else: 2100 raise TypeError("Other input is not a scantable or float value or float list") 2101 s._add_history("operator *", varlist) 2102 print_log() 2103 return s 2050 return self._operation( other, 'MUL' ) 2104 2051 2105 2052 def __div__(self, other): … … 2107 2054 implicit on all axes and on Tsys 2108 2055 """ 2109 varlist = vars() 2110 s = None 2111 if isinstance(other, scantable): 2112 s = scantable(self._math._binaryop(self.copy(), other, "DIV")) 2113 elif isinstance(other, float) or isinstance(other, int): 2114 if float(other) == 0.0: 2115 raise ZeroDivisionError("Dividing by zero is not recommended") 2116 s = scantable(self._math._unaryop(self.copy(), other, "DIV", False)) 2117 elif isinstance(other, list): 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 ) 2123 else: 2124 raise TypeError("Other input is not a scantable or float value or float list") 2125 else: 2126 raise TypeError("Other input is not a scantable or float value or float list") 2127 s._add_history("operator /", varlist) 2128 print_log() 2129 return s 2056 return self._operation( other, 'DIV' ) 2130 2057 2131 2058 def get_fit(self, row=0): … … 2302 2229 for i in range(len(self)): 2303 2230 yield self[i] 2231 2232 def _operation(self, other, opmode): 2233 varlist = vars() 2234 s = None 2235 import numpy 2236 if isinstance(other, scantable): 2237 s = scantable(self._math._binaryop(self.copy(), other, opmode)) 2238 elif isinstance(other, float) or isinstance(other, int): 2239 if opmode == 'DIV' and float(other) == 0.0: 2240 raise ZeroDivisionError("Dividing by zero is not recommended") 2241 s = scantable(self._math._unaryop(self.copy(), other, opmode, False)) 2242 elif isinstance(other, list) or isinstance(other, numpy.ndarray): 2243 if isinstance(other[0], list) or isinstance(other[0], numpy.ndarray): 2244 from asapmath import _array2dOp 2245 s = _array2dOp( self.copy(), other, opmode, False ) 2246 else: 2247 s = scantable(self._math._arrayop(self.copy(), other, opmode, False)) 2248 else: 2249 raise TypeError("Other input is not a scantable or float value or float list") 2250 opdic = {} 2251 opdic['ADD'] = '+' 2252 opdic['SUB'] = '-' 2253 opdic['MUL'] = '*' 2254 opdic['DIV'] = '/' 2255 s._add_history("operator %s" % opdic[opmode], varlist) 2256 print_log() 2257 return s 2258 2259
Note:
See TracChangeset
for help on using the changeset viewer.