source: trunk/python/asapmath.py @ 143

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

rework binding to 'average_time'. Now invokes just one
C++ function. Add new arguments 'scanav' and 'weight'

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