source: trunk/python/asapmath.py@ 1359

Last change on this file since 1359 was 1357, checked in by mar637, 17 years ago

deprecated simple_math

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
RevLine 
[1085]1from asap.scantable import scantable
[258]2from asap import rcParams
[720]3from asap import print_log
[101]4
[143]5def average_time(*args, **kwargs):
[101]6 """
[113]7 Return the (time) average of a scan or list of scans. [in channels only]
[305]8 The cursor of the output scan is set to 0
[113]9 Parameters:
10 one scan or comma separated scans
[143]11 mask: an optional mask (only used for 'var' and 'tsys' weighting)
[558]12 scanav: True averages each scan separately.
13 False (default) averages all scans together,
[1232]14 weight: Weighting scheme.
15 'none' (mean no weight)
16 'var' (1/var(spec) weighted)
17 'tsys' (1/Tsys**2 weighted)
18 'tint' (integration time weighted)
19 'tintsys' (Tint/Tsys**2)
20 'median' ( median averaging)
[930]21 align: align the spectra in velocity before averaging. It takes
22 the time of the first spectrum in the first scantable
23 as reference time.
[113]24 Example:
25 # return a time averaged scan from scana and scanb
26 # without using a mask
[129]27 scanav = average_time(scana,scanb)
[113]28 # return the (time) averaged scan, i.e. the average of
29 # all correlator cycles
[558]30 scanav = average_time(scan, scanav=True)
[101]31 """
[930]32 scanav = False
[143]33 if kwargs.has_key('scanav'):
[930]34 scanav = kwargs.get('scanav')
[524]35 weight = 'tint'
[143]36 if kwargs.has_key('weight'):
37 weight = kwargs.get('weight')
38 mask = ()
39 if kwargs.has_key('mask'):
40 mask = kwargs.get('mask')
[930]41 align = False
42 if kwargs.has_key('align'):
43 align = kwargs.get('align')
[489]44 varlist = vars()
[665]45 if isinstance(args[0],list):
[981]46 lst = args[0]
[665]47 elif isinstance(args[0],tuple):
[981]48 lst = list(args[0])
[665]49 else:
[981]50 lst = list(args)
[720]51
[489]52 del varlist["kwargs"]
53 varlist["args"] = "%d scantables" % len(lst)
[981]54 # need special formatting here for history...
[720]55
[876]56 from asap._asap import stmath
57 stm = stmath()
[113]58 for s in lst:
[101]59 if not isinstance(s,scantable):
[720]60 msg = "Please give a list of scantables"
61 if rcParams['verbose']:
62 print msg
63 return
64 else:
65 raise TypeError(msg)
[945]66 if scanav: scanav = "SCAN"
67 else: scanav = "NONE"
[981]68 alignedlst = []
69 if align:
70 refepoch = lst[0].get_time(0)
71 for scan in lst:
72 alignedlst.append(scan.freq_align(refepoch,insitu=False))
73 else:
[1059]74 alignedlst = lst
[1232]75 if weight.upper() == 'MEDIAN':
76 # median doesn't support list of scantables - merge first
77 merged = None
78 if len(alignedlst) > 1:
79 merged = merge(alignedlst)
80 else:
81 merged = alignedlst[0]
82 s = scantable(stm._averagechannel(merged, 'MEDIAN', scanav))
83 del merged
84 else:
85 s = scantable(stm._average(alignedlst, mask, weight.upper(), scanav))
[489]86 s._add_history("average_time",varlist)
[720]87 print_log()
[489]88 return s
[101]89
[1074]90def quotient(source, reference, preserve=True):
91 """
92 Return the quotient of a 'source' (signal) scan and a 'reference' scan.
93 The reference can have just one scan, even if the signal has many. Otherwise
94 they must have the same number of scans.
95 The cursor of the output scan is set to 0
96 Parameters:
97 source: the 'on' scan
98 reference: the 'off' scan
99 preserve: you can preserve (default) the continuum or
100 remove it. The equations used are
101 preserve: Output = Toff * (on/off) - Toff
102 remove: Output = Toff * (on/off) - Ton
103 """
104 varlist = vars()
105 from asap._asap import stmath
106 stm = stmath()
107 stm._setinsitu(False)
108 s = scantable(stm._quotient(source, reference, preserve))
109 s._add_history("quotient",varlist)
110 print_log()
111 return s
[101]112
[296]113def simple_math(left, right, op='add', tsys=True):
[242]114 """
[720]115 Apply simple mathematical binary operations to two
[242]116 scan tables, returning the result in a new scan table.
117 The operation is applied to both the correlations and the TSys data
[305]118 The cursor of the output scan is set to 0
[242]119 Parameters:
120 left: the 'left' scan
121 right: the 'right' scan
122 op: the operation: 'add' (default), 'sub', 'mul', 'div'
[296]123 tsys: if True (default) then apply the operation to Tsys
124 as well as the data
[242]125 """
[1357]126 print "simple_math is deprecated use +=/* instead."
[918]127
128def merge(*args):
[945]129 """
130 """
[918]131 varlist = vars()
132 if isinstance(args[0],list):
133 lst = tuple(args[0])
134 elif isinstance(args[0],tuple):
135 lst = args[0]
136 else:
137 lst = tuple(args)
138 varlist["args"] = "%d scantables" % len(lst)
139 # need special formatting her for history...
140 from asap._asap import stmath
141 stm = stmath()
142 for s in lst:
143 if not isinstance(s,scantable):
144 msg = "Please give a list of scantables"
145 if rcParams['verbose']:
146 print msg
147 return
148 else:
149 raise TypeError(msg)
150 s = scantable(stm._merge(lst))
151 s._add_history("merge", varlist)
152 print_log()
153 return s
[1074]154
Note: See TracBrowser for help on using the repository browser.