Ignore:
Timestamp:
12/01/04 11:29:39 (19 years ago)
Author:
mar637
Message:

version 0.1a

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/asapmath.py

    r101 r113  
    11from scantable import scantable
    2 def average_scan(scan):
     2
     3def average_time(*args, **kwargs):
    34    """
    4         Return a (time) averaged a scan, i.e. all correlator cycles
    5         are averaged into one "scan".
     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       
    617    """
    7     from asap._asap import average as _av
    8     return scantable(_av(scan))
    9 
    10 
    11 def average_scans(*args, **kwargs):
    12     """
    13         Return the (time) average of a list of scans. [in channels only]
    14         Parameters:
    15             a comma separated list of scans
    16             mask:     an optional mask
    17         Example:
    18             scanav = average_scans(scana,scanb)
    19             # return a time averaged scan from scan and scanb
    20             # without using a mask
    21     """
    22 
     18    lst = args
    2319    if len(args) < 2:
    24         print "Please give at least two scantables"
    25         return
    26 
    27     from asap._asap import averages as _av
    28     d = [args[0].nbeam(),args[0].nif(),args[0].npol(),args[0].nchan()]
    29     for s in args:
     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:
    3038        if not isinstance(s,scantable):
    3139            print "Please give a list of scantables"
     
    3644            return
    3745    if kwargs.has_key('mask'):
    38         return scantable(_av(args, kwargs.get('mask')))
     46        return scantable(_avs(lst, kwargs.get('mask')))
    3947    else:
    4048        from numarray import ones
    41         mask = list(ones(d[3]))
    42         return scantable(_av((args), mask))
     49        mask = tuple(ones(d[3]))
     50        return scantable(_avs(lst, mask))
    4351
    4452def quotient(source, reference):
     
    5765    Parameters:
    5866        scan:        a scantable
    59         factor:      the sclaing factor
     67        factor:      the scaling factor
    6068    Note:
    6169        This currently applies the all beams/IFs/pols
     
    6371    from asap._asap import scale as _scale
    6472    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))
    6585
    6686
     
    7090    from asap._asap import bin as _bin
    7191    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 TracChangeset for help on using the changeset viewer.