source: trunk/python/asapmath.py@ 518

Last change on this file since 518 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
RevLine 
[101]1from scantable import scantable
[258]2from asap import rcParams
[101]3
[143]4def average_time(*args, **kwargs):
[101]5 """
[113]6 Return the (time) average of a scan or list of scans. [in channels only]
[305]7 The cursor of the output scan is set to 0
[113]8 Parameters:
9 one scan or comma separated scans
[143]10 mask: an optional mask (only used for 'var' and 'tsys' weighting)
[424]11 scanav: True (default) averages each scan separately
12 False averages all scans together,
[143]13 weight: Weighting scheme. 'none' (default), 'var' (variance
14 weighted), 'tsys'
[113]15 Example:
16 # return a time averaged scan from scana and scanb
17 # without using a mask
[129]18 scanav = average_time(scana,scanb)
[113]19 # return the (time) averaged scan, i.e. the average of
20 # all correlator cycles
21 scanav = average_time(scan)
[143]22
[101]23 """
[424]24 scanAv = True
[143]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')
[489]33 varlist = vars()
[143]34 lst = tuple(args)
[489]35 del varlist["kwargs"]
36 varlist["args"] = "%d scantables" % len(lst)
37 # need special formatting her for history...
38
[143]39 from asap._asap import average as _av
[113]40 for s in lst:
[101]41 if not isinstance(s,scantable):
42 print "Please give a list of scantables"
43 return
[489]44 s = scantable(_av(lst, mask, scanAv, weight))
45 s._add_history("average_time",varlist)
46 return s
[101]47
[245]48def quotient(source, reference, preserve=True):
[101]49 """
[246]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.
[305]53 The cursor of the output scan is set to 0
[101]54 Parameters:
55 source: the 'on' scan
56 reference: the 'off' scan
[245]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
[101]61 """
[513]62 varlist = vars()
[101]63 from asap._asap import quotient as _quot
[513]64 s = scantable(_quot(source, reference, preserve))
65 s._add_history("quotient",varlist)
66 return s
[101]67
[296]68def simple_math(left, right, op='add', tsys=True):
[242]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
[305]73 The cursor of the output scan is set to 0
[242]74 Parameters:
75 left: the 'left' scan
76 right: the 'right' scan
77 op: the operation: 'add' (default), 'sub', 'mul', 'div'
[296]78 tsys: if True (default) then apply the operation to Tsys
79 as well as the data
[242]80 """
[489]81 varlist = vars()
[258]82 if not isinstance(left,scantable) and not isinstance(right,scantable):
83 print "Please provide two scantables as input"
84 return
[242]85 from asap._asap import b_operate as _bop
[489]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.