- Timestamp:
- 01/21/05 22:31:17 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapmath.py
r246 r258 1 1 from scantable import scantable 2 from asap import rcParams 2 3 3 4 def average_time(*args, **kwargs): … … 23 24 if kwargs.has_key('scanav'): 24 25 scanAv = kwargs.get('scanav') 25 # 26 26 27 weight = 'none' 27 28 if kwargs.has_key('weight'): 28 29 weight = kwargs.get('weight') 29 # 30 30 31 mask = () 31 32 if kwargs.has_key('mask'): 32 33 mask = kwargs.get('mask') 33 # 34 34 35 lst = tuple(args) 35 36 from asap._asap import average as _av … … 56 57 return scantable(_quot(source, reference, preserve)) 57 58 58 def b_operate(left, right, op='add'):59 def simple_math(left, right, op='add'): 59 60 """ 60 61 Apply simple mathematical binary operations to two … … 66 67 op: the operation: 'add' (default), 'sub', 'mul', 'div' 67 68 """ 69 if not isinstance(left,scantable) and not isinstance(right,scantable): 70 print "Please provide two scantables as input" 71 return 68 72 from asap._asap import b_operate as _bop 69 73 return scantable(_bop(left, right, op)) 70 74 71 def scale(scan, factor, insitu= False, all=True):75 def scale(scan, factor, insitu=None, allaxes=None): 72 76 """ 73 77 Return a scan where all spectra are scaled by the give 'factor' … … 75 79 scan: a scantable 76 80 factor: the scaling factor 77 insitu: if False (default) a new scantable is returned. 78 Otherwise, the scaling is done in-situ 79 all: if True (default) apply to all spectra. Otherwise 81 insitu: if False a new scantable is returned. 82 Otherwise, the scaling is done in-situ 83 The default is taken from .asaprc (False) 84 allaxes: if True apply to all spectra. Otherwise 85 apply only to the selected (beam/pol/if)spectra only. 86 The default is taken from .asaprc (True) 87 """ 88 if allaxes is None: allaxes = rcParams['scantable.allaxes'] 89 if insitu is None: insitu = rcParams['insitu'] 90 if not insitu: 91 from asap._asap import scale as _scale 92 return scantable(_scale(scan, factor, allaxes)) 93 else: 94 from asap._asap import scale_insitu as _scale 95 _scale(scan, factor, allaxes) 96 return 97 98 99 def add(scan, offset, insitu=None, allaxes=None): 100 """ 101 Return a scan where all spectra have the offset added 102 Parameters: 103 scan: a scantable 104 offset: the offset 105 insitu: if False a new scantable is returned. 106 Otherwise, the scaling is done in-situ 107 The default is taken from .asaprc (False) 108 allaxes: if True apply to all spectra. Otherwise 80 109 apply only to the selected (beam/pol/if)spectra only 81 """ 82 if not insitu: 83 from asap._asap import scale as _scale 84 return scantable(_scale(scan, factor, all)) 85 else: 86 from asap._asap import scale_insitu as _scale 87 _scale(scan, factor, all) 110 The default is taken from .asaprc (True) 111 """ 112 if allaxes is None: allaxes = rcParams['scantable.allaxes'] 113 if insitu is None: insitu = rcParams['insitu'] 114 if not insitu: 115 from asap._asap import add as _add 116 return scantable(_add(scan, offset, allaxes)) 117 else: 118 from asap._asap import add_insitu as _add 119 _add(scan, offset, allaxes) 88 120 return 89 121 90 91 def add(scan, offset, insitu=False, all=True): 92 """ 93 Return a scan where all spectra have the offset added 94 Parameters: 95 scan: a scantable 96 offset: the offset 97 insitu: if False (default) a new scantable is returned. 98 Otherwise, the addition is done in-situ 99 all: if True (default) apply to all spectra. Otherwise 100 apply only to the selected (beam/pol/if)spectra only 101 """ 102 if not insitu: 103 from asap._asap import add as _add 104 return scantable(_add(scan, offset, all)) 105 else: 106 from asap._asap import add_insitu as _add 107 _add(scan, offset, all) 108 return 109 110 def convert_flux(scan, area, eta=1.0, insitu=False, all=True): 122 def convert_flux(scan, area, eta=1.0, insitu=None, allaxes=None): 111 123 """ 112 124 Return a scan where all spectra are converted to either Jansky or Kelvin … … 116 128 area: the illuminated area of the telescope (m**2) 117 129 eta: The efficiency of the telescope (default 1.0) 118 insitu: if False (default) a new scantable is returned. 119 Otherwise, the conversion is done in-situ 120 all: if True (default) apply to all spectra. Otherwise 130 insitu: if False a new scantable is returned. 131 Otherwise, the scaling is done in-situ 132 The default is taken from .asaprc (False) 133 allaxes: if True apply to all spectra. Otherwise 121 134 apply only to the selected (beam/pol/if)spectra only 122 """ 135 The default is taken from .asaprc (True) 136 """ 137 if allaxes is None: allaxes = rcParams['scantable.allaxes'] 138 if insitu is None: insitu = rcParams['insitu'] 123 139 if not insitu: 124 140 from asap._asap import convertflux as _convert 125 return scantable(_convert(scan, area, eta, all ))141 return scantable(_convert(scan, area, eta, allaxes)) 126 142 else: 127 143 from asap._asap import convertflux_insitu as _convert 128 _convert(scan, area, eta, all )129 return 130 131 def gain_el(scan, poly=None, filename="", method="linear", insitu= False, all=True):144 _convert(scan, area, eta, allaxes) 145 return 146 147 def gain_el(scan, poly=None, filename="", method="linear", insitu=None, allaxes=None): 132 148 """ 133 149 Return a scan after applying a gain-elevation correction. The correction … … 140 156 Parameters: 141 157 scan: a scantable 142 poly: Polynomial coefficients (default None) to compute a gain-elevation 143 correction as a function of elevation (in degrees). 158 poly: Polynomial coefficients (default None) to compute a 159 gain-elevation correction as a function of 160 elevation (in degrees). 144 161 filename: The name of an ascii file holding correction factors. 145 162 The first row of the ascii file must give the column 146 163 names and these MUST include columns 147 "ELEVATION" (degrees) and "FACTOR" (multiply data by this) somewhere. 148 The second row must give the data type of the column. Use 'R' for 149 Real and 'I' for Integer. An example file would be: 164 "ELEVATION" (degrees) and "FACTOR" (multiply data by this) 165 somewhere. 166 The second row must give the data type of the column. Use 167 'R' for Real and 'I' for Integer. An example file 168 would be: 150 169 151 170 TIME ELEVATION FACTOR … … 159 178 method: Interpolation method when correcting from a table. Values 160 179 are "nearest", "linear" (default), "cubic" and "spline" 161 insitu: if False (default) a new scantable is returned. 162 Otherwise, the conversion is done in-situ 163 all: if True (default) apply to all spectra. Otherwise 164 apply only to the selected (beam/pol/if)spectra only 165 """ 180 insitu: if False a new scantable is returned. 181 Otherwise, the scaling is done in-situ 182 The default is taken from .asaprc (False) 183 allaxes: if True apply to all spectra. Otherwise 184 apply only to the selected (beam/pol/if) spectra only 185 The default is taken from .asaprc (True) 186 """ 187 if allaxes is None: allaxes = rcParams['scantable.allaxes'] 166 188 if poly is None: 167 189 poly = () 190 if insitu is None: insitu = rcParams['insitu'] 168 191 if not insitu: 169 192 from asap._asap import gainel as _gainEl 170 return scantable(_gainEl(scan, poly, filename, method, all ))193 return scantable(_gainEl(scan, poly, filename, method, allaxes)) 171 194 else: 172 195 from asap._asap import gainel_insitu as _gainEl 173 _gainEl(scan, poly, filename, method, all )196 _gainEl(scan, poly, filename, method, allaxes) 174 197 return 175 198 176 def opacity(scan, tau, insitu= False, all=True):199 def opacity(scan, tau, insitu=None, allaxes=None): 177 200 """ 178 201 Return a scan after applying an opacity correction. … … 181 204 tau: Opacity from which the correction factor is exp(tau*ZD) 182 205 where ZD is the zenith-distance 183 insitu: if False (default) a new scantable is returned. 184 Otherwise, the conversion is done in-situ 185 all: if True (default) apply to all spectra. Otherwise 206 insitu: if False a new scantable is returned. 207 Otherwise, the scaling is done in-situ 208 The default is taken from .asaprc (False) 209 allaxes: if True apply to all spectra. Otherwise 186 210 apply only to the selected (beam/pol/if)spectra only 187 """ 211 The default is taken from .asaprc (True) 212 """ 213 if allaxes is None: allaxes = rcParams['scantable.allaxes'] 214 if insitu is None: insitu = rcParams['insitu'] 188 215 if not insitu: 189 216 from asap._asap import opacity as _opacity 190 return scantable(_opacity(scan, tau, all ))217 return scantable(_opacity(scan, tau, allaxes)) 191 218 else: 192 219 from asap._asap import opacity_insitu as _opacity 193 _opacity(scan, tau, all )220 _opacity(scan, tau, allaxes) 194 221 return 195 222 196 def bin(scan, width=5, insitu= False):223 def bin(scan, width=5, insitu=None): 197 224 """ 198 225 Return a scan where all spectra have been binned up 199 226 width: The bin width (default=5) in pixels 200 insitu: if False (default) a new scantable is returned. 201 Otherwise, the addition is done in-situ 202 """ 227 insitu: if False a new scantable is returned. 228 Otherwise, the scaling is done in-situ 229 The default is taken from .asaprc (False) 230 """ 231 if insitu is None: insitu = rcParams['insitu'] 203 232 if not insitu: 204 233 from asap._asap import bin as _bin … … 209 238 return 210 239 211 def average_pol(scan, mask=None, insitu= False):240 def average_pol(scan, mask=None, insitu=None): 212 241 """ 213 242 Average the Polarisations together. … … 217 246 averaging will be applied. The output will have all 218 247 specified points masked. 219 insitu: If False (default) a new scantable is returned. 220 Otherwise, the averaging is done in-situ 248 insitu: if False a new scantable is returned. 249 Otherwise, the scaling is done in-situ 250 The default is taken from .asaprc (False) 221 251 Example: 222 252 polav = average_pols(myscan) … … 224 254 if mask is None: 225 255 mask = () 256 if insitu is None: insitu = rcParams['insitu'] 226 257 if not insitu: 227 258 from asap._asap import averagepol as _avpol … … 232 263 return 233 264 234 def smooth(scan, kernel="hanning", width=5.0, insitu= False, all=True):265 def smooth(scan, kernel="hanning", width=5.0, insitu=None, allaxes=None): 235 266 """ 236 267 Smooth the spectrum by the specified kernel (conserving flux). … … 244 275 For 'gaussian' it is the Full Width Half 245 276 Maximum. For 'boxcar' it is the full width. 246 insitu: If False (default)a new scantable is returned.277 insitu: if False a new scantable is returned. 247 278 Otherwise, the scaling is done in-situ 248 all: If True (default) apply to all spectra. Otherwise 279 The default is taken from .asaprc (False) 280 allaxes: If True (default) apply to all spectra. Otherwise 249 281 apply only to the selected (beam/pol/if)spectra only 282 The default is taken from .asaprc (True) 250 283 Example: 251 284 none 252 285 """ 286 if allaxes is None: allaxes = rcParams['scantable.allaxes'] 287 if insitu is None: insitu = rcParams['insitu'] 253 288 if not insitu: 254 289 from asap._asap import smooth as _smooth 255 return scantable(_smooth(scan,kernel,width,all ))290 return scantable(_smooth(scan,kernel,width,allaxes)) 256 291 else: 257 292 from asap._asap import smooth_insitu as _smooth 258 _smooth(scan,kernel,width,all )293 _smooth(scan,kernel,width,allaxes) 259 294 return 260 295 261 def poly_baseline(scan, mask=None, order=0 ):296 def poly_baseline(scan, mask=None, order=0, insitu=None): 262 297 """ 263 298 Return a scan which has been baselined (all rows) by a polynomial. … … 266 301 mask: an optional mask 267 302 order: the order of the polynomial (default is 0) 303 insitu: if False a new scantable is returned. 304 Otherwise, the scaling is done in-situ 305 The default is taken from .asaprc (False) 268 306 Example: 269 307 # return a scan baselined by a third order polynomial, … … 279 317 f.set_scan(scan, mask) 280 318 f.set_function(poly=order) 281 sf = f.auto_fit( )319 sf = f.auto_fit(insitu) 282 320 return sf
Note:
See TracChangeset
for help on using the changeset viewer.