Changeset 1677 for branches/alma/python
- Timestamp:
- 01/27/10 18:29:48 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma/python/scantable.py
r1676 r1677 1868 1868 return s 1869 1869 1870 def scale(self, factor, tsys=True, insitu=None):1870 def scale(self, factor, tsys=True, mode='channel', insitu=None): 1871 1871 """ 1872 1872 Return a scan where all spectra are scaled by the give 'factor' 1873 1873 Parameters: 1874 factor: the scaling factor 1874 factor: the scaling factor (float or 1D float list) 1875 1875 insitu: if False a new scantable is returned. 1876 1876 Otherwise, the scaling is done in-situ … … 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. Possible 1881 values are 'channel' (channel-by-channel) or 1882 'row' (row-by-row). 1880 1883 """ 1881 1884 if insitu is None: insitu = rcParams['insitu'] 1882 1885 self._math._setinsitu(insitu) 1883 1886 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)) 1885 1899 s._add_history("scale", varlist) 1886 1900 print_log() … … 2027 2041 s = None 2028 2042 if isinstance(other, scantable): 2029 s = scantable(self._math._binaryop(self , other, "ADD"))2043 s = scantable(self._math._binaryop(self.copy(), other, "ADD")) 2030 2044 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") 2034 2055 s._add_history("operator +", varlist) 2035 2056 print_log() … … 2043 2064 s = None 2044 2065 if isinstance(other, scantable): 2045 s = scantable(self._math._binaryop(self , other, "SUB"))2066 s = scantable(self._math._binaryop(self.copy(), other, "SUB")) 2046 2067 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") 2050 2078 s._add_history("operator -", varlist) 2051 2079 print_log() … … 2059 2087 s = None 2060 2088 if isinstance(other, scantable): 2061 s = scantable(self._math._binaryop(self , other, "MUL"))2089 s = scantable(self._math._binaryop(self.copy(), other, "MUL")) 2062 2090 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") 2066 2101 s._add_history("operator *", varlist) 2067 2102 print_log() 2068 2103 return s 2069 2070 2104 2071 2105 def __div__(self, other): … … 2076 2110 s = None 2077 2111 if isinstance(other, scantable): 2078 s = scantable(self._math._binaryop(self , other, "DIV"))2112 s = scantable(self._math._binaryop(self.copy(), other, "DIV")) 2079 2113 elif isinstance(other, float): 2080 2114 if other == 0.0: 2081 2115 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") 2085 2126 s._add_history("operator /", varlist) 2086 2127 print_log()
Note:
See TracChangeset
for help on using the changeset viewer.