source: trunk/python/asapmath.py@ 823

Last change on this file since 823 was 720, checked in by mar637, 19 years ago

added asaplog

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