Changeset 992 for trunk/python


Ignore:
Timestamp:
04/06/06 10:12:03 (18 years ago)
Author:
mar637
Message:

added function to convert between polarisation types

Location:
trunk/python
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/__init__.py

    r984 r992  
    232232
    233233def unique(x):
     234    """
     235    Return the unique values in a list
     236    Parameters:
     237        x:      the list to reduce
     238    Examples:
     239        x = [1,2,3,3,4]
     240        print unique(x)
     241        [1,2,3,4]
     242    """
    234243    return dict([ (val, 1) for val in x]).keys()
     244
     245def list_files(path=".",suffix="rpf"):
     246    """
     247    Return a list files readable by asap, such as rpf, sdfits, mbf, asap
     248    Parameters:
     249        path:     The directory to list (default '.')
     250        suffix:   The file extension (default rpf)
     251    Example:
     252        files = list_files("data/","sdfits")
     253        print files
     254        ['data/2001-09-01_0332_P363.sdfits',
     255        'data/2003-04-04_131152_t0002.sdfits',
     256        'data/Sgr_86p262_best_SPC.sdfits']
     257    """
     258    import os
     259    if not os.path.isdir(path):
     260        return None
     261    valid = "rpf sdf sdfits mbf asap".split()
     262    if not suffix in valid:
     263        return None
     264    files = [os.path.expanduser(os.path.expandvars(path+"/"+f)) for f in os.listdir(path)]
     265    return filter(lambda x: x.endswith(suffix),files)
    235266
    236267# workaround for ipython, which redirects this if banner=0 in ipythonrc
     
    335366                              all polarisations will contain the
    336367                              averaged spectrum.
     368            convert_pol     - convert to a different polarisation type
    337369            auto_quotient   - return the on/off quotient with
    338370                              automatic detection of the on/off scans
     
    417449        print               - print details about a variable
    418450        list_scans          - list all scantables created bt the user
     451        list_files          - list all files readable by asap (default rpf)
    419452        del                 - delete the given variable from memory
    420453        range               - create a list of values, e.g.
  • trunk/python/scantable.py

    r989 r992  
    974974        if mask is None:
    975975            mask = ()
    976         s = self._math._averagepol(self, mask, weight)
     976        s = scantable(self._math._averagepol(self, mask, weight))
    977977        s._add_history("average_pol",varlist)
    978978        print_log()
    979         return scantable(s)
     979        return s
     980
     981    def convert_pol(self, poltype=None):
     982        """
     983        Convert the data to a different polarisation type.
     984        Parameters:
     985            poltype:    The new polarisation type. Valid types are:
     986                        "linear", "stokes" and "circular"
     987        """
     988        varlist = vars()
     989        try:
     990            s = scantable(self._math._convertpol(self, poltype))
     991        except RuntimeError,msg:
     992            if rcParams['verbose']:
     993              print msg
     994              return
     995            else:
     996                raise
     997        s._add_history("convert_pol",varlist)
     998        print_log()
     999        return s
    9801000
    9811001    def smooth(self, kernel="hanning", width=5.0, insitu=None):
Note: See TracChangeset for help on using the changeset viewer.