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