source: trunk/python/asapmath.py @ 166

Last change on this file since 166 was 166, checked in by kil064, 19 years ago

function 'average_pol' now has insitu version as well

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 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 (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'
13    Example:
14        # return a time averaged scan from scana and scanb
15        # without using a mask
16        scanav = average_time(scana,scanb)
17        # return the (time) averaged scan, i.e. the average of
18        # all correlator cycles
19        scanav = average_time(scan)
20
21    """
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
36    for s in lst:
37        if not isinstance(s,scantable):
38            print "Please give a list of scantables"
39            return
40    return scantable(_av(lst, mask, scanAv, weight))
41
42def 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
52def scale(scan, factor, insitu=False, all=True):
53    """
54    Return a scan where all spectra are scaled by the give 'factor'
55    Parameters:
56        scan:        a scantable
57        factor:      the scaling factor
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
62    """
63    if not insitu:
64        from asap._asap import scale as _scale
65        return scantable(_scale(scan, factor, all))
66    else:
67        from asap._asap import scale_insitu as _scale
68        _scale(scan, factor, all)
69        return
70       
71
72def add(scan, offset, insitu=False, all=True):
73    """
74    Return a scan where all spectra have the offset added
75    Parameters:
76        scan:        a scantable
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
82    """
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       
91def bin(scan, binwidth=5):
92    """
93    """
94    from asap._asap import bin as _bin
95    return scantable(_bin(scan, binwidth))
96
97def average_pol(scan, mask=None, insitu=False):
98    """
99    Average the Polarisations together.
100    Parameters:
101        scan   - a scantable
102        mask   - an optional mask defining the region, where the
103                 averaging will be applied. The output will have all
104                 specified points masked.
105        insitu:      if False (default) a new scantable is returned.
106                     Otherwise, the averaging is done in-situ
107    Example:
108        polav = average_pols(myscan)
109    """
110    if mask is None:
111        mask = ()
112    if not insitu:
113        from asap._asap import averagepol as _avpol
114        return scantable(_avpol(scan, mask))
115    else:
116        from asap._asap import averagepol_insitu as _avpol
117        _avpol(scan, mask)
118        return
119   
120def hanning(scan):
121    """
122    Hanning smooth the channels.
123    Parameters:
124         scan    - the input scan
125    Example:
126         none
127    """
128    from asap._asap import hanning as _han
129    return scantable(_han(scan))
130
131   
132def poly_baseline(scan, mask=None, order=0):
133    """
134    Return a scan which has been baselined (all rows) by a polynomial.
135    Parameters:
136        scan:    a scantable
137        mask:    an optional mask
138        order:   the order of the polynomial (default is 0)
139    Example:
140        # return a scan baselined by a third order polynomial,
141        # not using a mask
142        bscan = poly_baseline(scan, order=3)
143    """
144    from asap.asapfitter import fitter
145    if mask is None:
146        from numarray import ones
147        mask = tuple(ones(scan.nchan()))
148    f = fitter()
149    f._verbose(True)
150    f.set_scan(scan, mask)
151    f.set_function(poly=order)   
152    sf = f.auto_fit()
153    return sf
Note: See TracBrowser for help on using the repository browser.