Changeset 113 for trunk/python/asapmath.py
- Timestamp:
- 12/01/04 11:29:39 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapmath.py
r101 r113 1 1 from scantable import scantable 2 def average_scan(scan): 2 3 def average_time(*args, **kwargs): 3 4 """ 4 Return a (time) averaged a scan, i.e. all correlator cycles 5 are averaged into one "scan". 5 Return the (time) average of a scan or list of scans. [in channels only] 6 Parameters: 7 one scan or comma separated scans 8 mask: an optional mask 9 Example: 10 # return a time averaged scan from scana and scanb 11 # without using a mask 12 scanav = average_scans(scana,scanb) 13 # return the (time) averaged scan, i.e. the average of 14 # all correlator cycles 15 scanav = average_time(scan) 16 6 17 """ 7 from asap._asap import average as _av 8 return scantable(_av(scan)) 9 10 11 def average_scans(*args, **kwargs): 12 """ 13 Return the (time) average of a list of scans. [in channels only] 14 Parameters: 15 a comma separated list of scans 16 mask: an optional mask 17 Example: 18 scanav = average_scans(scana,scanb) 19 # return a time averaged scan from scan and scanb 20 # without using a mask 21 """ 22 18 lst = args 23 19 if len(args) < 2: 24 print "Please give at least two scantables" 25 return 26 27 from asap._asap import averages as _av 28 d = [args[0].nbeam(),args[0].nif(),args[0].npol(),args[0].nchan()] 29 for s in args: 20 if type(args[0]) is list: 21 if len(args[0]) < 2: 22 print "Please give at least two scantables" 23 return 24 else: 25 s = args[0] 26 if s.nrow() > 1: 27 from asap._asap import average as _av 28 return scantable(_av(s)) 29 else: 30 print "Given scantable is already time averaged" 31 return 32 lst = tuple(args[0]) 33 else: 34 lst = tuple(args) 35 from asap._asap import averages as _avs 36 d = [lst[0].nbeam(),lst[0].nif(),lst[0].npol(),lst[0].nchan()] 37 for s in lst: 30 38 if not isinstance(s,scantable): 31 39 print "Please give a list of scantables" … … 36 44 return 37 45 if kwargs.has_key('mask'): 38 return scantable(_av (args, kwargs.get('mask')))46 return scantable(_avs(lst, kwargs.get('mask'))) 39 47 else: 40 48 from numarray import ones 41 mask = list(ones(d[3]))42 return scantable(_av ((args), mask))49 mask = tuple(ones(d[3])) 50 return scantable(_avs(lst, mask)) 43 51 44 52 def quotient(source, reference): … … 57 65 Parameters: 58 66 scan: a scantable 59 factor: the sc laing factor67 factor: the scaling factor 60 68 Note: 61 69 This currently applies the all beams/IFs/pols … … 63 71 from asap._asap import scale as _scale 64 72 return scantable(_scale(scan, factor)) 73 74 def add(scan, offset): 75 """ 76 Return a scan where the offset is added. 77 Parameters: 78 scan: a scantable 79 offset: the value to add 80 Note: 81 This currently applies the all beams/IFs/pols 82 """ 83 from asap._asap import add as _add 84 return scantable(_add(scan, offset)) 65 85 66 86 … … 70 90 from asap._asap import bin as _bin 71 91 return scantable(_bin(scan, binwidth)) 92 93 def average_pol(scan, mask=None): 94 """ 95 Average the Polarisations together. 96 Parameters: 97 scan - a scantable 98 mask - an optional mask defining the region, where 99 the averaging will be applied. The output 100 will have all specified points masked. 101 The dimension won't be reduced and 102 all polarisations will contain the 103 averaged spectrum. 104 Example: 105 polav = average_pols(myscan) 106 """ 107 from asap._asap import averagepol as _avpol 108 from numarray import ones 109 if mask is None: 110 mask = tuple(ones(scan.nchan())) 111 return scantable(_avpol(scan, mask)) 112 113 def hanning(scan): 114 """ 115 Hanning smooth the channels. 116 Parameters: 117 scan - the input scan 118 Example: 119 none 120 """ 121 from asap._asap import hanning as _han 122 return scantable(_han(scan)) 123 124 125 def poly_baseline(scan, mask=None, order=0): 126 """ 127 Return a scan which has been baselined by a polynomial. 128 Parameters: 129 scan: a scantable 130 mask: an optional mask 131 order: the order of the polynomial (default is 0) 132 Example: 133 # return a scan baselined by a third order polynomial, 134 # not using a mask 135 bscan = poly_baseline(scan, order=3) 136 """ 137 from asap.asapfitter import fitter 138 if mask is None: 139 from numarray import ones 140 mask = tuple(ones(scan.nchan())) 141 f = fitter() 142 f._verbose(True) 143 f.set_scan(scan, mask) 144 f.set_function(poly=order) 145 sf = f.auto_fit() 146 return sf
Note: See TracChangeset
for help on using the changeset viewer.