source: trunk/python/asapmath.py @ 113

Last change on this file since 113 was 113, checked in by mar637, 19 years ago

version 0.1a

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1from scantable import scantable
2
3def average_time(*args, **kwargs):
4    """
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
12        scanav = average_scans(scana,scanb)
13        # return the (time) averaged scan, i.e. the average of
14        # all correlator cycles
15        scanav = average_time(scan)
16       
17    """
18    lst = args
19    if len(args) < 2:
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:
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'):
46        return scantable(_avs(lst, kwargs.get('mask')))
47    else:
48        from numarray import ones
49        mask = tuple(ones(d[3]))
50        return scantable(_avs(lst, mask))
51
52def 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
62def scale(scan, factor):
63    """
64    Return a scan where all spectra are scaled by the give 'factor'
65    Parameters:
66        scan:        a scantable
67        factor:      the scaling factor
68    Note:
69        This currently applies the all beams/IFs/pols
70    """
71    from asap._asap import scale as _scale
72    return scantable(_scale(scan, factor))
73
74def add(scan, offset):
75    """
76    Return a scan where the offset is added.
77    Parameters:
78        scan:        a scantable
79        offset:      the value to add
80    Note:
81        This currently applies the all beams/IFs/pols
82    """
83    from asap._asap import add as _add
84    return scantable(_add(scan, offset))
85
86
87def bin(scan, binwidth=5):
88    """
89    """
90    from asap._asap import bin as _bin
91    return scantable(_bin(scan, binwidth))
92
93def average_pol(scan, mask=None):
94    """
95    Average the Polarisations together.
96    Parameters:
97        scan   - a scantable
98        mask   - an optional mask defining the region, where
99                 the averaging will be applied. The output
100                 will have all specified points masked.
101                 The dimension won't be reduced and
102                 all polarisations will contain the
103                 averaged spectrum.
104    Example:
105        polav = average_pols(myscan)
106    """
107    from asap._asap import averagepol as _avpol
108    from numarray import ones
109    if mask is None:
110        mask = tuple(ones(scan.nchan()))
111    return scantable(_avpol(scan, mask))
112   
113def hanning(scan):
114    """
115    Hanning smooth the channels.
116    Parameters:
117         scan    - the input scan
118    Example:
119         none
120    """
121    from asap._asap import hanning as _han
122    return scantable(_han(scan))
123
124   
125def poly_baseline(scan, mask=None, order=0):
126    """
127    Return a scan which has been baselined by a polynomial.
128    Parameters:
129        scan:    a scantable
130        mask:    an optional mask
131        order:   the order of the polynomial (default is 0)
132    Example:
133        # return a scan baselined by a third order polynomial,
134        # not using a mask
135        bscan = poly_baseline(scan, order=3)
136    """
137    from asap.asapfitter import fitter
138    if mask is None:
139        from numarray import ones
140        mask = tuple(ones(scan.nchan()))
141    f = fitter()
142    f._verbose(True)
143    f.set_scan(scan, mask)
144    f.set_function(poly=order)   
145    sf = f.auto_fit()
146    return sf
Note: See TracBrowser for help on using the repository browser.