source: branches/Release2.0/python/asapmath.py@ 2691

Last change on this file since 2691 was 1056, checked in by mar637, 19 years ago

Fix for Ticket #38; typo aligendlst caused this.

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