[101] | 1 | from scantable import scantable
|
---|
[258] | 2 | from asap import rcParams
|
---|
[101] | 3 |
|
---|
[143] | 4 | def 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)
|
---|
[101] | 24 | """
|
---|
[558] | 25 | scanAv = False
|
---|
[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()
|
---|
[662] | 35 | if isinstance(args[0],list):
|
---|
| 36 | lst = tuple(args[0])
|
---|
| 37 | elif isinstance(args[0],tuple):
|
---|
| 38 | lst = args[0]
|
---|
| 39 | else:
|
---|
| 40 | lst = tuple(args)
|
---|
| 41 |
|
---|
[489] | 42 | del varlist["kwargs"]
|
---|
| 43 | varlist["args"] = "%d scantables" % len(lst)
|
---|
| 44 | # need special formatting her for history...
|
---|
| 45 |
|
---|
[143] | 46 | from asap._asap import average as _av
|
---|
[113] | 47 | for s in lst:
|
---|
[101] | 48 | if not isinstance(s,scantable):
|
---|
| 49 | print "Please give a list of scantables"
|
---|
| 50 | return
|
---|
[489] | 51 | s = scantable(_av(lst, mask, scanAv, weight))
|
---|
| 52 | s._add_history("average_time",varlist)
|
---|
| 53 | return s
|
---|
[101] | 54 |
|
---|
[245] | 55 | def quotient(source, reference, preserve=True):
|
---|
[101] | 56 | """
|
---|
[246] | 57 | Return the quotient of a 'source' (signal) scan and a 'reference' scan.
|
---|
| 58 | The reference can have just one row, even if the signal has many. Otherwise
|
---|
| 59 | they must have the same number of rows.
|
---|
[305] | 60 | The cursor of the output scan is set to 0
|
---|
[101] | 61 | Parameters:
|
---|
| 62 | source: the 'on' scan
|
---|
| 63 | reference: the 'off' scan
|
---|
[245] | 64 | preserve: you can preserve (default) the continuum or
|
---|
| 65 | remove it. The equations used are
|
---|
[582] | 66 | preserve: Output = Toff * (on/off) - Toff
|
---|
| 67 | remove: Output = Toff * (on/off) - Ton
|
---|
[101] | 68 | """
|
---|
[513] | 69 | varlist = vars()
|
---|
[101] | 70 | from asap._asap import quotient as _quot
|
---|
[513] | 71 | s = scantable(_quot(source, reference, preserve))
|
---|
| 72 | s._add_history("quotient",varlist)
|
---|
| 73 | return s
|
---|
[101] | 74 |
|
---|
[296] | 75 | def simple_math(left, right, op='add', tsys=True):
|
---|
[242] | 76 | """
|
---|
| 77 | Apply simple mathematical binary operations to two
|
---|
| 78 | scan tables, returning the result in a new scan table.
|
---|
| 79 | The operation is applied to both the correlations and the TSys data
|
---|
[305] | 80 | The cursor of the output scan is set to 0
|
---|
[242] | 81 | Parameters:
|
---|
| 82 | left: the 'left' scan
|
---|
| 83 | right: the 'right' scan
|
---|
| 84 | op: the operation: 'add' (default), 'sub', 'mul', 'div'
|
---|
[296] | 85 | tsys: if True (default) then apply the operation to Tsys
|
---|
| 86 | as well as the data
|
---|
[242] | 87 | """
|
---|
[489] | 88 | varlist = vars()
|
---|
[258] | 89 | if not isinstance(left,scantable) and not isinstance(right,scantable):
|
---|
| 90 | print "Please provide two scantables as input"
|
---|
| 91 | return
|
---|
[242] | 92 | from asap._asap import b_operate as _bop
|
---|
[489] | 93 | s = scantable(_bop(left, right, op, tsys))
|
---|
| 94 | s._add_history("simple_math", varlist)
|
---|
| 95 | return s
|
---|