source: trunk/python/asapmath.py@ 913

Last change on this file since 913 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
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
[876]47 from asap._asap import stmath
48 stm = stmath()
[113]49 for s in lst:
[101]50 if not isinstance(s,scantable):
[720]51 msg = "Please give a list of scantables"
52 if rcParams['verbose']:
53 print msg
54 return
55 else:
56 raise TypeError(msg)
[876]57 if scanAv: scanAv = "SCAN"
58 else: scanAv = "NONE"
59 s = scantable(stm._average(lst, mask, weight, scanAv, False))
[489]60 s._add_history("average_time",varlist)
[720]61 print_log()
[489]62 return s
[101]63
[876]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
[101]84
[296]85def simple_math(left, right, op='add', tsys=True):
[242]86 """
[720]87 Apply simple mathematical binary operations to two
[242]88 scan tables, returning the result in a new scan table.
89 The operation is applied to both the correlations and the TSys data
[305]90 The cursor of the output scan is set to 0
[242]91 Parameters:
92 left: the 'left' scan
93 right: the 'right' scan
94 op: the operation: 'add' (default), 'sub', 'mul', 'div'
[296]95 tsys: if True (default) then apply the operation to Tsys
96 as well as the data
[242]97 """
[489]98 varlist = vars()
[876]99 print "Not yet available in asap"
100 return
[258]101 if not isinstance(left,scantable) and not isinstance(right,scantable):
[720]102 msg = "Please provide two scantables as input"
103 if rcParams['verbose']:
104 print msg
105 return
106 else:
107 raise TypeError(msg)
[242]108 from asap._asap import b_operate as _bop
[489]109 s = scantable(_bop(left, right, op, tsys))
110 s._add_history("simple_math", varlist)
[720]111 print_log()
[489]112 return s
Note: See TracBrowser for help on using the repository browser.