[101] | 1 | from scantable import scantable
|
---|
[258] | 2 | from asap import rcParams
|
---|
[720] | 3 | from asap import print_log
|
---|
[101] | 4 |
|
---|
[143] | 5 | def 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'
|
---|
[930] | 18 | align: align the spectra in velocity before averaging. It takes
|
---|
| 19 | the time of the first spectrum in the first scantable
|
---|
| 20 | as reference time.
|
---|
[113] | 21 | Example:
|
---|
| 22 | # return a time averaged scan from scana and scanb
|
---|
| 23 | # without using a mask
|
---|
[129] | 24 | scanav = average_time(scana,scanb)
|
---|
[113] | 25 | # return the (time) averaged scan, i.e. the average of
|
---|
| 26 | # all correlator cycles
|
---|
[558] | 27 | scanav = average_time(scan, scanav=True)
|
---|
[101] | 28 | """
|
---|
[930] | 29 | scanav = False
|
---|
[143] | 30 | if kwargs.has_key('scanav'):
|
---|
[930] | 31 | scanav = kwargs.get('scanav')
|
---|
[524] | 32 | weight = 'tint'
|
---|
[143] | 33 | if kwargs.has_key('weight'):
|
---|
| 34 | weight = kwargs.get('weight')
|
---|
| 35 | mask = ()
|
---|
| 36 | if kwargs.has_key('mask'):
|
---|
| 37 | mask = kwargs.get('mask')
|
---|
[930] | 38 | align = False
|
---|
| 39 | if kwargs.has_key('align'):
|
---|
| 40 | align = kwargs.get('align')
|
---|
[489] | 41 | varlist = vars()
|
---|
[665] | 42 | if isinstance(args[0],list):
|
---|
| 43 | lst = tuple(args[0])
|
---|
| 44 | elif isinstance(args[0],tuple):
|
---|
| 45 | lst = args[0]
|
---|
| 46 | else:
|
---|
| 47 | lst = tuple(args)
|
---|
[720] | 48 |
|
---|
[489] | 49 | del varlist["kwargs"]
|
---|
| 50 | varlist["args"] = "%d scantables" % len(lst)
|
---|
| 51 | # need special formatting her for history...
|
---|
[720] | 52 |
|
---|
[876] | 53 | from asap._asap import stmath
|
---|
| 54 | stm = stmath()
|
---|
[113] | 55 | for s in lst:
|
---|
[101] | 56 | if not isinstance(s,scantable):
|
---|
[720] | 57 | msg = "Please give a list of scantables"
|
---|
| 58 | if rcParams['verbose']:
|
---|
| 59 | print msg
|
---|
| 60 | return
|
---|
| 61 | else:
|
---|
| 62 | raise TypeError(msg)
|
---|
[876] | 63 | if scanAv: scanAv = "SCAN"
|
---|
| 64 | else: scanAv = "NONE"
|
---|
[930] | 65 | s = scantable(stm._average(lst, mask, weight, scanav, align))
|
---|
[489] | 66 | s._add_history("average_time",varlist)
|
---|
[720] | 67 | print_log()
|
---|
[489] | 68 | return s
|
---|
[101] | 69 |
|
---|
[876] | 70 | # def quotient(source, reference, preserve=True):
|
---|
| 71 | # """
|
---|
| 72 | # Return the quotient of a 'source' (signal) scan and a 'reference' scan.
|
---|
| 73 | # The reference can have just one row, even if the signal has many. Otherwise
|
---|
| 74 | # they must have the same number of rows.
|
---|
| 75 | # The cursor of the output scan is set to 0
|
---|
| 76 | # Parameters:
|
---|
| 77 | # source: the 'on' scan
|
---|
| 78 | # reference: the 'off' scan
|
---|
| 79 | # preserve: you can preserve (default) the continuum or
|
---|
| 80 | # remove it. The equations used are
|
---|
| 81 | # preserve: Output = Toff * (on/off) - Toff
|
---|
| 82 | # remove: Output = Toff * (on/off) - Ton
|
---|
| 83 | # """
|
---|
| 84 | # varlist = vars()
|
---|
| 85 | # from asap._asap import quotient as _quot
|
---|
| 86 | # s = scantable(_quot(source, reference, preserve))
|
---|
| 87 | # s._add_history("quotient",varlist)
|
---|
| 88 | # print_log()
|
---|
| 89 | # return s
|
---|
[101] | 90 |
|
---|
[296] | 91 | def simple_math(left, right, op='add', tsys=True):
|
---|
[242] | 92 | """
|
---|
[720] | 93 | Apply simple mathematical binary operations to two
|
---|
[242] | 94 | scan tables, returning the result in a new scan table.
|
---|
| 95 | The operation is applied to both the correlations and the TSys data
|
---|
[305] | 96 | The cursor of the output scan is set to 0
|
---|
[242] | 97 | Parameters:
|
---|
| 98 | left: the 'left' scan
|
---|
| 99 | right: the 'right' scan
|
---|
| 100 | op: the operation: 'add' (default), 'sub', 'mul', 'div'
|
---|
[296] | 101 | tsys: if True (default) then apply the operation to Tsys
|
---|
| 102 | as well as the data
|
---|
[242] | 103 | """
|
---|
[489] | 104 | varlist = vars()
|
---|
[876] | 105 | print "Not yet available in asap"
|
---|
| 106 | return
|
---|
[258] | 107 | if not isinstance(left,scantable) and not isinstance(right,scantable):
|
---|
[720] | 108 | msg = "Please provide two scantables as input"
|
---|
| 109 | if rcParams['verbose']:
|
---|
| 110 | print msg
|
---|
| 111 | return
|
---|
| 112 | else:
|
---|
| 113 | raise TypeError(msg)
|
---|
[918] | 114 | s = scantable(stm._bop(left, right, op, tsys))
|
---|
[489] | 115 | s._add_history("simple_math", varlist)
|
---|
[720] | 116 | print_log()
|
---|
[489] | 117 | return s
|
---|
[918] | 118 |
|
---|
| 119 | def merge(*args):
|
---|
| 120 | varlist = vars()
|
---|
| 121 | if isinstance(args[0],list):
|
---|
| 122 | lst = tuple(args[0])
|
---|
| 123 | elif isinstance(args[0],tuple):
|
---|
| 124 | lst = args[0]
|
---|
| 125 | else:
|
---|
| 126 | lst = tuple(args)
|
---|
| 127 | varlist["args"] = "%d scantables" % len(lst)
|
---|
| 128 | # need special formatting her for history...
|
---|
| 129 | from asap._asap import stmath
|
---|
| 130 | stm = stmath()
|
---|
| 131 | for s in lst:
|
---|
| 132 | if not isinstance(s,scantable):
|
---|
| 133 | msg = "Please give a list of scantables"
|
---|
| 134 | if rcParams['verbose']:
|
---|
| 135 | print msg
|
---|
| 136 | return
|
---|
| 137 | else:
|
---|
| 138 | raise TypeError(msg)
|
---|
| 139 | s = scantable(stm._merge(lst))
|
---|
| 140 | s._add_history("merge", varlist)
|
---|
| 141 | print_log()
|
---|
| 142 | return s
|
---|