Changeset 513 for trunk/python/asapmath.py
- Timestamp:
- 02/28/05 15:28:33 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapmath.py
r509 r513 60 60 remove - Output = Tref * (sig/ref) - Tsig 61 61 """ 62 varlist = vars() 62 63 from asap._asap import quotient as _quot 63 return scantable(_quot(source, reference, preserve)) 64 s = scantable(_quot(source, reference, preserve)) 65 s._add_history("quotient",varlist) 66 return s 64 67 65 68 def simple_math(left, right, op='add', tsys=True): … … 84 87 s._add_history("simple_math", varlist) 85 88 return s 86 87 def scale(scan, factor, insitu=None, allaxes=None, tsys=True):88 """89 Return a scan where all spectra are scaled by the give 'factor'90 Parameters:91 scan: a scantable92 factor: the scaling factor93 insitu: if False a new scantable is returned.94 Otherwise, the scaling is done in-situ95 The default is taken from .asaprc (False)96 allaxes: if True apply to all spectra. Otherwise97 apply only to the selected (beam/pol/if)spectra only.98 The default is taken from .asaprc (True if none)99 tsys: if True (default) then apply the operation to Tsys100 as well as the data101 """102 if allaxes is None: allaxes = rcParams['scantable.allaxes']103 if insitu is None: insitu = rcParams['insitu']104 varlist = vars()105 if not insitu:106 from asap._asap import scale as _scale107 s = scantable(_scale(scan, factor, allaxes, tsys))108 s._add_history("scale",varlist)109 return s110 else:111 from asap._asap import scale_insitu as _scale112 _scale(scan, factor, allaxes, tsys)113 scan._add_history("scale",varlist)114 return115 116 def add(scan, offset, insitu=None, allaxes=None):117 """118 Return a scan where all spectra have the offset added119 Parameters:120 scan: a scantable121 offset: the offset122 insitu: if False a new scantable is returned.123 Otherwise, the scaling is done in-situ124 The default is taken from .asaprc (False)125 allaxes: if True apply to all spectra. Otherwise126 apply only to the selected (beam/pol/if)spectra only127 The default is taken from .asaprc (True if none)128 """129 if allaxes is None: allaxes = rcParams['scantable.allaxes']130 if insitu is None: insitu = rcParams['insitu']131 if not insitu:132 from asap._asap import add as _add133 return scantable(_add(scan, offset, allaxes))134 else:135 from asap._asap import add_insitu as _add136 _add(scan, offset, allaxes)137 return138 139 def convert_flux(scan, jyperk=None, eta=None, d=None, insitu=None,140 allaxes=None):141 """142 Return a scan where all spectra are converted to either Jansky or Kelvin143 depending upon the flux units of the scan table. By default the144 function tries to look the values up internally. If it can't find145 them (or if you want to over-ride), you must specify EITHER jyperk146 OR eta (and D which it will try to look up also if you don't147 set it). jyperk takes precedence if you set both.148 Parameters:149 scan: a scantable150 jyperk: the Jy / K conversion factor151 eta: the aperture efficiency152 d: the geomtric diameter (metres)153 insitu: if False a new scantable is returned.154 Otherwise, the scaling is done in-situ155 The default is taken from .asaprc (False)156 allaxes: if True apply to all spectra. Otherwise157 apply only to the selected (beam/pol/if)spectra only158 The default is taken from .asaprc (True if none)159 """160 if allaxes is None: allaxes = rcParams['scantable.allaxes']161 if insitu is None: insitu = rcParams['insitu']162 varlist = vars()163 if jyperk is None: jyperk = -1.0164 if d is None: d = -1.0165 if eta is None: eta = -1.0166 if not insitu:167 from asap._asap import convertflux as _convert168 s = scantable(_convert(scan, d, eta, jyperk, allaxes))169 s._add_history("convert_flux", varlist)170 return s171 else:172 from asap._asap import convertflux_insitu as _convert173 _convert(scan, d, eta, jyperk, allaxes)174 scan._add_history("convert_flux", varlist)175 return176 177 def gain_el(scan, poly=None, filename="", method="linear",178 insitu=None, allaxes=None):179 """180 Return a scan after applying a gain-elevation correction. The correction181 can be made via either a polynomial or a table-based interpolation182 (and extrapolation if necessary).183 You specify polynomial coefficients, an ascii table or neither.184 If you specify neither, then a polynomial correction will be made185 with built in coefficients known for certain telescopes (an error will186 occur if the instrument is not known). The data and Tsys are *divided*187 by the scaling factors.188 Parameters:189 scan: a scantable190 poly: Polynomial coefficients (default None) to compute a191 gain-elevation correction as a function of192 elevation (in degrees).193 filename: The name of an ascii file holding correction factors.194 The first row of the ascii file must give the column195 names and these MUST include columns196 "ELEVATION" (degrees) and "FACTOR" (multiply data by this)197 somewhere.198 The second row must give the data type of the column. Use199 'R' for Real and 'I' for Integer. An example file200 would be (actual factors are arbitrary) :201 202 TIME ELEVATION FACTOR203 R R R204 0.1 0 0.8205 0.2 20 0.85206 0.3 40 0.9207 0.4 60 0.85208 0.5 80 0.8209 0.6 90 0.75210 method: Interpolation method when correcting from a table. Values211 are "nearest", "linear" (default), "cubic" and "spline"212 insitu: if False a new scantable is returned.213 Otherwise, the scaling is done in-situ214 The default is taken from .asaprc (False)215 allaxes: if True apply to all spectra. Otherwise216 apply only to the selected (beam/pol/if) spectra only217 The default is taken from .asaprc (True if none)218 """219 if allaxes is None: allaxes = rcParams['scantable.allaxes']220 if insitu is None: insitu = rcParams['insitu']221 varlist = vars()222 if poly is None:223 poly = ()224 from os.path import expandvars225 filename = expandvars(filename)226 if not insitu:227 from asap._asap import gainel as _gainEl228 s = scantable(_gainEl(scan, poly, filename, method, allaxes))229 s._add_history("gain_el", varlist)230 return s231 else:232 from asap._asap import gainel_insitu as _gainEl233 _gainEl(scan, poly, filename, method, allaxes)234 scan._add_history("gain_el", varlist)235 return236 237 def freq_align(scan, reftime=None, method='cubic', perif=False, insitu=None):238 """239 Return a scan where all rows have been aligned in frequency/velocity.240 The alignment frequency frame (e.g. LSRK) is that set by function241 set_freqframe.242 scan: a scantable243 reftime: reference time to align at. By default, the time of244 the first row of data is used.245 method: Interpolation method for regridding the spectra. Choose246 from "nearest", "linear", "cubic" (default) and "spline"247 perif: Generate aligners per freqID (no doppler tracking) or248 per IF (scan-based doppler tracking)249 insitu: if False a new scantable is returned.250 Otherwise, the scaling is done in-situ251 The default is taken from .asaprc (False)252 """253 if insitu is None: insitu = rcParams['insitu']254 varlist = vars()255 if reftime is None: reftime = ''256 perfreqid = not perif257 if not insitu:258 from asap._asap import freq_align as _align259 s = scantable(_align(scan, reftime, method, perfreqid))260 s._add_history("freq_align", varlist)261 return s262 else:263 from asap._asap import freq_align_insitu as _align264 _align(scan, reftime, method, perfreqid)265 scan._add_history("freq_align", varlist)266 return267 268 def opacity(scan, tau, insitu=None, allaxes=None):269 """270 Return a scan after applying an opacity correction. The data271 and Tsys are multiplied by the correction factor.272 Parameters:273 scan: a scantable274 tau: Opacity from which the correction factor is exp(tau*ZD)275 where ZD is the zenith-distance276 insitu: if False a new scantable is returned.277 Otherwise, the scaling is done in-situ278 The default is taken from .asaprc (False)279 allaxes: if True apply to all spectra. Otherwise280 apply only to the selected (beam/pol/if)spectra only281 The default is taken from .asaprc (True if none)282 """283 if allaxes is None: allaxes = rcParams['scantable.allaxes']284 if insitu is None: insitu = rcParams['insitu']285 varlist = vars()286 if not insitu:287 from asap._asap import opacity as _opacity288 s = scantable(_opacity(scan, tau, allaxes))289 s._add_history("opacity", varlist)290 return s291 else:292 from asap._asap import opacity_insitu as _opacity293 _opacity(scan, tau, allaxes)294 scan._add_history("opacity", varlist)295 return296 297 def bin(scan, width=5, insitu=None):298 """299 Return a scan where all spectra have been binned up300 width: The bin width (default=5) in pixels301 insitu: if False a new scantable is returned.302 Otherwise, the scaling is done in-situ303 The default is taken from .asaprc (False)304 """305 if insitu is None: insitu = rcParams['insitu']306 varlist = vars()307 if not insitu:308 from asap._asap import bin as _bin309 s = scantable(_bin(scan, width))310 s._add_history("bin",varlist)311 return s312 else:313 from asap._asap import bin_insitu as _bin314 _bin(scan, width)315 scan._add_history("bin",varlist)316 return317 318 def resample(scan, width=5, method='cubic', insitu=None):319 """320 Return a scan where all spectra have been binned up321 width: The bin width (default=5) in pixels322 method: Interpolation method when correcting from a table. Values323 are "nearest", "linear", "cubic" (default) and "spline"324 insitu: if False a new scantable is returned.325 Otherwise, the scaling is done in-situ326 The default is taken from .asaprc (False)327 """328 if insitu is None: insitu = rcParams['insitu']329 varlist = vars()330 if not insitu:331 from asap._asap import resample as _resample332 s = scantable(_resample(scan, method, width))333 s._add_history("resample",varlist)334 return s335 else:336 from asap._asap import resample_insitu as _resample337 _resample(scan, method, width)338 scan._add_history("resample",varlist)339 return340 341 def average_pol(scan, mask=None, weight='none', insitu=None):342 """343 Average the Polarisations together.344 The polarisation cursor of the output scan is set to 0345 Parameters:346 scan: The scantable347 mask: An optional mask defining the region, where the348 averaging will be applied. The output will have all349 specified points masked.350 weight: Weighting scheme. 'none' (default), or 'var' (variance351 weighted)352 insitu: if False a new scantable is returned.353 Otherwise, the scaling is done in-situ354 The default is taken from .asaprc (False)355 Example:356 polav = average_pols(myscan)357 """358 if insitu is None: insitu = rcParams['insitu']359 varlist = vars()360 361 if mask is None:362 mask = ()363 if not insitu:364 from asap._asap import averagepol as _avpol365 s = scantable(_avpol(scan, mask, weight))366 s._add_history("average_pol",varlist)367 return s368 else:369 from asap._asap import averagepol_insitu as _avpol370 _avpol(scan, mask, weight)371 scan._add_history("average_pol",varlist)372 return373 374 def smooth(scan, kernel="hanning", width=5.0, insitu=None, allaxes=None):375 """376 Smooth the spectrum by the specified kernel (conserving flux).377 Parameters:378 scan: The input scan379 kernel: The type of smoothing kernel. Select from380 'hanning' (default), 'gaussian' and 'boxcar'.381 The first three characters are sufficient.382 width: The width of the kernel in pixels. For hanning this is383 ignored otherwise it defauls to 5 pixels.384 For 'gaussian' it is the Full Width Half385 Maximum. For 'boxcar' it is the full width.386 insitu: if False a new scantable is returned.387 Otherwise, the scaling is done in-situ388 The default is taken from .asaprc (False)389 allaxes: If True (default) apply to all spectra. Otherwise390 apply only to the selected (beam/pol/if)spectra only391 The default is taken from .asaprc (True if none)392 Example:393 none394 """395 if allaxes is None: allaxes = rcParams['scantable.allaxes']396 if insitu is None: insitu = rcParams['insitu']397 varlist = vars()398 if not insitu:399 from asap._asap import smooth as _smooth400 s = scantable(_smooth(scan,kernel,width,allaxes))401 s._add_history("smooth", varlist)402 return s403 else:404 from asap._asap import smooth_insitu as _smooth405 _smooth(scan,kernel,width,allaxes)406 scan._add_history("smooth", varlist)407 return408 409 def poly_baseline(scan, mask=None, order=0, insitu=None):410 """411 Return a scan which has been baselined (all rows) by a polynomial.412 Parameters:413 scan: a scantable414 mask: an optional mask415 order: the order of the polynomial (default is 0)416 insitu: if False a new scantable is returned.417 Otherwise, the scaling is done in-situ418 The default is taken from .asaprc (False)419 Example:420 # return a scan baselined by a third order polynomial,421 # not using a mask422 bscan = poly_baseline(scan, order=3)423 """424 if insitu is None: insitu = rcParams['insitu']425 varlist = vars()426 from asap.asapfitter import fitter427 if mask is None:428 from numarray import ones429 mask = tuple(ones(scan.nchan()))430 f = fitter()431 f._verbose(True)432 f.set_scan(scan, mask)433 f.set_function(poly=order)434 sf = f.auto_fit(insitu)435 sf._add_history("poly_baseline", varlist)436 return sf437 438 def rotate_xyphase(scan, angle, allaxes=None):439 """440 Rotate the phase of the XY correlation. This is always done in situ441 in the data. So if you call this function more than once442 then each call rotates the phase further.443 Parameters:444 angle: The angle (degrees) to rotate (add) by.445 allaxes: If True apply to all spectra. Otherwise446 apply only to the selected (beam/pol/if)spectra only.447 The default is taken from .asaprc (True if none)448 Examples:449 rotate_xyphase(scan, 2.3)450 """451 if allaxes is None: allaxes = rcParams['scantable.allaxes']452 varlist = vars()453 from asap._asap import _rotate_xyphase as _rotate454 _rotate(scan, angle, allaxes)455 scan._add_history("rotate_xyphase", varlist)456 return457 458 def rotate_linpolphase(scan, angle, allaxes=None):459 """460 Rotate the phase of the complex polarization O=Q+iU correlation.461 This is always done in situ in the raw data. So if you call this462 function more than once then each call rotates the phase further.463 Parameters:464 angle: The angle (degrees) to rotate (add) by.465 allaxes: If True apply to all spectra. Otherwise466 apply only to the selected (beam/pol/if)spectra only.467 The default is taken from .asaprc (True if none)468 Examples:469 rotate_linpolphase(scan, 2.3)470 """471 if allaxes is None: allaxes = rcParams['scantable.allaxes']472 varlist = vars()473 from asap._asap import _rotate_linpolphase as _rotate474 _rotate(scan, angle, allaxes)475 scan._add_history("rotate_linpolphase", varlist)476 return477
Note: See TracChangeset
for help on using the changeset viewer.