source: trunk/python/asapmath.py@ 542

Last change on this file since 542 was 524, checked in by kil064, 20 years ago

make 'tint' weigting the default for average_time

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 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,
[524]13 weight: Weighting scheme. 'none, 'var' (1/var(spec)
[520]14 weighted), 'tsys' (1/Tsys**2 weighted), or 'tint'
[524]15 (integration time weighted). The default is 'tint'
[113]16 Example:
17 # return a time averaged scan from scana and scanb
18 # without using a mask
[129]19 scanav = average_time(scana,scanb)
[113]20 # return the (time) averaged scan, i.e. the average of
21 # all correlator cycles
22 scanav = average_time(scan)
[143]23
[101]24 """
[424]25 scanAv = True
[143]26 if kwargs.has_key('scanav'):
27 scanAv = kwargs.get('scanav')
[524]28 weight = 'tint'
[143]29 if kwargs.has_key('weight'):
30 weight = kwargs.get('weight')
31 mask = ()
32 if kwargs.has_key('mask'):
33 mask = kwargs.get('mask')
[489]34 varlist = vars()
[143]35 lst = tuple(args)
[489]36 del varlist["kwargs"]
37 varlist["args"] = "%d scantables" % len(lst)
38 # need special formatting her for history...
39
[143]40 from asap._asap import average as _av
[113]41 for s in lst:
[101]42 if not isinstance(s,scantable):
43 print "Please give a list of scantables"
44 return
[489]45 s = scantable(_av(lst, mask, scanAv, weight))
46 s._add_history("average_time",varlist)
47 return s
[101]48
[245]49def quotient(source, reference, preserve=True):
[101]50 """
[246]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.
[305]54 The cursor of the output scan is set to 0
[101]55 Parameters:
56 source: the 'on' scan
57 reference: the 'off' scan
[245]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
[101]62 """
[513]63 varlist = vars()
[101]64 from asap._asap import quotient as _quot
[513]65 s = scantable(_quot(source, reference, preserve))
66 s._add_history("quotient",varlist)
67 return s
[101]68
[296]69def simple_math(left, right, op='add', tsys=True):
[242]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
[305]74 The cursor of the output scan is set to 0
[242]75 Parameters:
76 left: the 'left' scan
77 right: the 'right' scan
78 op: the operation: 'add' (default), 'sub', 'mul', 'div'
[296]79 tsys: if True (default) then apply the operation to Tsys
80 as well as the data
[242]81 """
[489]82 varlist = vars()
[258]83 if not isinstance(left,scantable) and not isinstance(right,scantable):
84 print "Please provide two scantables as input"
85 return
[242]86 from asap._asap import b_operate as _bop
[489]87 s = scantable(_bop(left, right, op, tsys))
88 s._add_history("simple_math", varlist)
89 return s
Note: See TracBrowser for help on using the repository browser.