source: trunk/python/asapmath.py@ 515

Last change on this file since 515 was 513, checked in by mar637, 20 years ago

*Moved most asapmath functions to scantable member functions. Only ones taking more than one scantable as input remain.

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