source: branches/Release-2-fixes/python/asapmath.py@ 2353

Last change on this file since 2353 was 662, checked in by mar637, 19 years ago

fix to handle lists os scantables

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.5 KB
Line 
1from scantable import scantable
2from asap import rcParams
3
4def average_time(*args, **kwargs):
5 """
6 Return the (time) average of a scan or list of scans. [in channels only]
7 The cursor of the output scan is set to 0
8 Parameters:
9 one scan or comma separated scans
10 mask: an optional mask (only used for 'var' and 'tsys' weighting)
11 scanav: True averages each scan separately.
12 False (default) averages all scans together,
13 weight: Weighting scheme. 'none, 'var' (1/var(spec)
14 weighted), 'tsys' (1/Tsys**2 weighted), 'tint'
15 (integration time weighted) or 'tintsys' (Tsys
16 and tint). The default is 'tint'
17 Example:
18 # return a time averaged scan from scana and scanb
19 # without using a mask
20 scanav = average_time(scana,scanb)
21 # return the (time) averaged scan, i.e. the average of
22 # all correlator cycles
23 scanav = average_time(scan, scanav=True)
24 """
25 scanAv = False
26 if kwargs.has_key('scanav'):
27 scanAv = kwargs.get('scanav')
28 weight = 'tint'
29 if kwargs.has_key('weight'):
30 weight = kwargs.get('weight')
31 mask = ()
32 if kwargs.has_key('mask'):
33 mask = kwargs.get('mask')
34 varlist = vars()
35 if isinstance(args[0],list):
36 lst = tuple(args[0])
37 elif isinstance(args[0],tuple):
38 lst = args[0]
39 else:
40 lst = tuple(args)
41
42 del varlist["kwargs"]
43 varlist["args"] = "%d scantables" % len(lst)
44 # need special formatting her for history...
45
46 from asap._asap import average as _av
47 for s in lst:
48 if not isinstance(s,scantable):
49 print "Please give a list of scantables"
50 return
51 s = scantable(_av(lst, mask, scanAv, weight))
52 s._add_history("average_time",varlist)
53 return s
54
55def quotient(source, reference, preserve=True):
56 """
57 Return the quotient of a 'source' (signal) scan and a 'reference' scan.
58 The reference can have just one row, even if the signal has many. Otherwise
59 they must have the same number of rows.
60 The cursor of the output scan is set to 0
61 Parameters:
62 source: the 'on' scan
63 reference: the 'off' scan
64 preserve: you can preserve (default) the continuum or
65 remove it. The equations used are
66 preserve: Output = Toff * (on/off) - Toff
67 remove: Output = Toff * (on/off) - Ton
68 """
69 varlist = vars()
70 from asap._asap import quotient as _quot
71 s = scantable(_quot(source, reference, preserve))
72 s._add_history("quotient",varlist)
73 return s
74
75def simple_math(left, right, op='add', tsys=True):
76 """
77 Apply simple mathematical binary operations to two
78 scan tables, returning the result in a new scan table.
79 The operation is applied to both the correlations and the TSys data
80 The cursor of the output scan is set to 0
81 Parameters:
82 left: the 'left' scan
83 right: the 'right' scan
84 op: the operation: 'add' (default), 'sub', 'mul', 'div'
85 tsys: if True (default) then apply the operation to Tsys
86 as well as the data
87 """
88 varlist = vars()
89 if not isinstance(left,scantable) and not isinstance(right,scantable):
90 print "Please provide two scantables as input"
91 return
92 from asap._asap import b_operate as _bop
93 s = scantable(_bop(left, right, op, tsys))
94 s._add_history("simple_math", varlist)
95 return s
Note: See TracBrowser for help on using the repository browser.