source: branches/Release12/python/asapmath.py@ 3141

Last change on this file since 3141 was 720, checked in by mar637, 19 years ago

added asaplog

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