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