source: branches/Release-1-fixes/python/asapmath.py@ 804

Last change on this file since 804 was 580, checked in by mar637, 20 years ago

Fix for asap0003

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 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 """
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 lst = tuple(args)
37 del varlist["kwargs"]
38 varlist["args"] = "%d scantables" % len(lst)
39 # need special formatting her for history...
40
41 from asap._asap import average as _av
42 for s in lst:
43 if not isinstance(s,scantable):
44 print "Please give a list of scantables"
45 return
46 s = scantable(_av(lst, mask, scanAv, weight))
47 s._add_history("average_time",varlist)
48 return s
49
50def quotient(source, reference, preserve=True):
51 """
52 Return the quotient of a 'source' (signal) scan and a 'reference' scan.
53 The reference can have just one row, even if the signal has many. Otherwise
54 they must have the same number of rows.
55 The cursor of the output scan is set to 0
56 Parameters:
57 source: the 'on' scan
58 reference: the 'off' scan
59 preserve: you can preserve (default) the continuum or
60 remove it. The equations used are
61 preserve: Output = Toff * (on/off) - Toff
62 remove: Output = Toff * (on/off) - Ton
63 """
64 varlist = vars()
65 from asap._asap import quotient as _quot
66 s = scantable(_quot(source, reference, preserve))
67 s._add_history("quotient",varlist)
68 return s
69
70def simple_math(left, right, op='add', tsys=True):
71 """
72 Apply simple mathematical binary operations to two
73 scan tables, returning the result in a new scan table.
74 The operation is applied to both the correlations and the TSys data
75 The cursor of the output scan is set to 0
76 Parameters:
77 left: the 'left' scan
78 right: the 'right' scan
79 op: the operation: 'add' (default), 'sub', 'mul', 'div'
80 tsys: if True (default) then apply the operation to Tsys
81 as well as the data
82 """
83 varlist = vars()
84 if not isinstance(left,scantable) and not isinstance(right,scantable):
85 print "Please provide two scantables as input"
86 return
87 from asap._asap import b_operate as _bop
88 s = scantable(_bop(left, right, op, tsys))
89 s._add_history("simple_math", varlist)
90 return s
Note: See TracBrowser for help on using the repository browser.