source: trunk/python/asapmath.py@ 908

Last change on this file since 908 was 876, checked in by mar637, 19 years ago

move to asap2 container

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.0 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 stmath
48 stm = stmath()
49 for s in lst:
50 if not isinstance(s,scantable):
51 msg = "Please give a list of scantables"
52 if rcParams['verbose']:
53 print msg
54 return
55 else:
56 raise TypeError(msg)
57 if scanAv: scanAv = "SCAN"
58 else: scanAv = "NONE"
59 s = scantable(stm._average(lst, mask, weight, scanAv, False))
60 s._add_history("average_time",varlist)
61 print_log()
62 return s
63
64# def quotient(source, reference, preserve=True):
65# """
66# Return the quotient of a 'source' (signal) scan and a 'reference' scan.
67# The reference can have just one row, even if the signal has many. Otherwise
68# they must have the same number of rows.
69# The cursor of the output scan is set to 0
70# Parameters:
71# source: the 'on' scan
72# reference: the 'off' scan
73# preserve: you can preserve (default) the continuum or
74# remove it. The equations used are
75# preserve: Output = Toff * (on/off) - Toff
76# remove: Output = Toff * (on/off) - Ton
77# """
78# varlist = vars()
79# from asap._asap import quotient as _quot
80# s = scantable(_quot(source, reference, preserve))
81# s._add_history("quotient",varlist)
82# print_log()
83# return s
84
85def simple_math(left, right, op='add', tsys=True):
86 """
87 Apply simple mathematical binary operations to two
88 scan tables, returning the result in a new scan table.
89 The operation is applied to both the correlations and the TSys data
90 The cursor of the output scan is set to 0
91 Parameters:
92 left: the 'left' scan
93 right: the 'right' scan
94 op: the operation: 'add' (default), 'sub', 'mul', 'div'
95 tsys: if True (default) then apply the operation to Tsys
96 as well as the data
97 """
98 varlist = vars()
99 print "Not yet available in asap"
100 return
101 if not isinstance(left,scantable) and not isinstance(right,scantable):
102 msg = "Please provide two scantables as input"
103 if rcParams['verbose']:
104 print msg
105 return
106 else:
107 raise TypeError(msg)
108 from asap._asap import b_operate as _bop
109 s = scantable(_bop(left, right, op, tsys))
110 s._add_history("simple_math", varlist)
111 print_log()
112 return s
Note: See TracBrowser for help on using the repository browser.