source: branches/Release-1-fixes/python/asapmath.py@ 2360

Last change on this file since 2360 was 580, checked in by mar637, 20 years ago

Fix for asap0003

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