[101] | 1 | from scantable import scantable
|
---|
| 2 |
|
---|
[143] | 3 | def average_time(*args, **kwargs):
|
---|
[101] | 4 | """
|
---|
[113] | 5 | Return the (time) average of a scan or list of scans. [in channels only]
|
---|
| 6 | Parameters:
|
---|
| 7 | one scan or comma separated scans
|
---|
[143] | 8 | mask: an optional mask (only used for 'var' and 'tsys' weighting)
|
---|
| 9 | scanav: False (default) averages all scans together,
|
---|
| 10 | True averages each scan separately
|
---|
| 11 | weight: Weighting scheme. 'none' (default), 'var' (variance
|
---|
| 12 | weighted), 'tsys'
|
---|
[113] | 13 | Example:
|
---|
| 14 | # return a time averaged scan from scana and scanb
|
---|
| 15 | # without using a mask
|
---|
[129] | 16 | scanav = average_time(scana,scanb)
|
---|
[113] | 17 | # return the (time) averaged scan, i.e. the average of
|
---|
| 18 | # all correlator cycles
|
---|
| 19 | scanav = average_time(scan)
|
---|
[143] | 20 |
|
---|
[101] | 21 | """
|
---|
[143] | 22 | scanAv = False
|
---|
| 23 | if kwargs.has_key('scanav'):
|
---|
| 24 | scanAv = kwargs.get('scanav')
|
---|
| 25 | #
|
---|
| 26 | weight = 'none'
|
---|
| 27 | if kwargs.has_key('weight'):
|
---|
| 28 | weight = kwargs.get('weight')
|
---|
| 29 | #
|
---|
| 30 | mask = ()
|
---|
| 31 | if kwargs.has_key('mask'):
|
---|
| 32 | mask = kwargs.get('mask')
|
---|
| 33 | #
|
---|
| 34 | lst = tuple(args)
|
---|
| 35 | from asap._asap import average as _av
|
---|
[113] | 36 | for s in lst:
|
---|
[101] | 37 | if not isinstance(s,scantable):
|
---|
| 38 | print "Please give a list of scantables"
|
---|
| 39 | return
|
---|
[143] | 40 | return scantable(_av(lst, mask, scanAv, weight))
|
---|
[101] | 41 |
|
---|
| 42 | def quotient(source, reference):
|
---|
| 43 | """
|
---|
| 44 | Return the quotient of a 'source' scan and a 'reference' scan
|
---|
| 45 | Parameters:
|
---|
| 46 | source: the 'on' scan
|
---|
| 47 | reference: the 'off' scan
|
---|
| 48 | """
|
---|
| 49 | from asap._asap import quotient as _quot
|
---|
| 50 | return scantable(_quot(source, reference))
|
---|
| 51 |
|
---|
[150] | 52 | def scale(scan, factor, insitu=False, all=True):
|
---|
[101] | 53 | """
|
---|
| 54 | Return a scan where all spectra are scaled by the give 'factor'
|
---|
| 55 | Parameters:
|
---|
| 56 | scan: a scantable
|
---|
[113] | 57 | factor: the scaling factor
|
---|
[150] | 58 | insitu: if False (default) a new scantable is returned.
|
---|
| 59 | Otherwise, the scaling is done in-situ
|
---|
| 60 | all: if True (default) apply to all spectra. Otherwise
|
---|
| 61 | apply only to the selected (beam/pol/if)spectra only
|
---|
[101] | 62 | """
|
---|
[141] | 63 | if not insitu:
|
---|
| 64 | from asap._asap import scale as _scale
|
---|
[150] | 65 | return scantable(_scale(scan, factor, all))
|
---|
[141] | 66 | else:
|
---|
| 67 | from asap._asap import scale_insitu as _scale
|
---|
[150] | 68 | _scale(scan, factor, all)
|
---|
[141] | 69 | return
|
---|
| 70 |
|
---|
[101] | 71 |
|
---|
[150] | 72 | def add(scan, offset, insitu=False, all=True):
|
---|
[113] | 73 | """
|
---|
[150] | 74 | Return a scan where all spectra have the offset added
|
---|
[113] | 75 | Parameters:
|
---|
| 76 | scan: a scantable
|
---|
[150] | 77 | offset: the offset
|
---|
| 78 | insitu: if False (default) a new scantable is returned.
|
---|
| 79 | Otherwise, the addition is done in-situ
|
---|
| 80 | all: if True (default) apply to all spectra. Otherwise
|
---|
| 81 | apply only to the selected (beam/pol/if)spectra only
|
---|
[113] | 82 | """
|
---|
[150] | 83 | if not insitu:
|
---|
| 84 | from asap._asap import add as _add
|
---|
| 85 | return scantable(_add(scan, offset, all))
|
---|
| 86 | else:
|
---|
| 87 | from asap._asap import add_insitu as _add
|
---|
| 88 | _add(scan, offset, all)
|
---|
| 89 | return
|
---|
| 90 |
|
---|
[101] | 91 | def bin(scan, binwidth=5):
|
---|
| 92 | """
|
---|
| 93 | """
|
---|
| 94 | from asap._asap import bin as _bin
|
---|
| 95 | return scantable(_bin(scan, binwidth))
|
---|
[113] | 96 |
|
---|
| 97 | def average_pol(scan, mask=None):
|
---|
| 98 | """
|
---|
| 99 | Average the Polarisations together.
|
---|
| 100 | Parameters:
|
---|
| 101 | scan - a scantable
|
---|
| 102 | mask - an optional mask defining the region, where
|
---|
| 103 | the averaging will be applied. The output
|
---|
| 104 | will have all specified points masked.
|
---|
| 105 | The dimension won't be reduced and
|
---|
| 106 | all polarisations will contain the
|
---|
| 107 | averaged spectrum.
|
---|
| 108 | Example:
|
---|
| 109 | polav = average_pols(myscan)
|
---|
| 110 | """
|
---|
| 111 | from asap._asap import averagepol as _avpol
|
---|
| 112 | from numarray import ones
|
---|
| 113 | if mask is None:
|
---|
| 114 | mask = tuple(ones(scan.nchan()))
|
---|
| 115 | return scantable(_avpol(scan, mask))
|
---|
| 116 |
|
---|
| 117 | def hanning(scan):
|
---|
| 118 | """
|
---|
| 119 | Hanning smooth the channels.
|
---|
| 120 | Parameters:
|
---|
| 121 | scan - the input scan
|
---|
| 122 | Example:
|
---|
| 123 | none
|
---|
| 124 | """
|
---|
| 125 | from asap._asap import hanning as _han
|
---|
| 126 | return scantable(_han(scan))
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | def poly_baseline(scan, mask=None, order=0):
|
---|
| 130 | """
|
---|
| 131 | Return a scan which has been baselined by a polynomial.
|
---|
| 132 | Parameters:
|
---|
| 133 | scan: a scantable
|
---|
| 134 | mask: an optional mask
|
---|
| 135 | order: the order of the polynomial (default is 0)
|
---|
| 136 | Example:
|
---|
| 137 | # return a scan baselined by a third order polynomial,
|
---|
| 138 | # not using a mask
|
---|
| 139 | bscan = poly_baseline(scan, order=3)
|
---|
| 140 | """
|
---|
| 141 | from asap.asapfitter import fitter
|
---|
| 142 | if mask is None:
|
---|
| 143 | from numarray import ones
|
---|
| 144 | mask = tuple(ones(scan.nchan()))
|
---|
| 145 | f = fitter()
|
---|
| 146 | f._verbose(True)
|
---|
| 147 | f.set_scan(scan, mask)
|
---|
| 148 | f.set_function(poly=order)
|
---|
| 149 | sf = f.auto_fit()
|
---|
| 150 | return sf
|
---|