Ignore:
Timestamp:
07/18/09 06:35:47 (15 years ago)
Author:
TakTsutsumi
Message:

New Development: No, merge with asap2.3.1

JIRA Issue: Yes CAS-1450

Ready to Release: Yes/No?

Interface Changes: Yes/No?

What Interface Changed: Please list interface changes

Test Programs: List test programs

Put in Release Notes: Yes

Module(s): single dish

Description: Upgrade of alma branch based on ASAP2.2.0

(rev.1562) to ASAP2.3.1 (rev.1561)


File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/alma/python/scantable.py

    r1530 r1603  
    4545            Scantable.__init__(self, filename)
    4646        else:
    47             if isinstance(filename, str):
     47            if isinstance(filename, str):# or \
     48#                (isinstance(filename, list) or isinstance(filename, tuple)) \
     49#                  and isinstance(filename[-1], str):
    4850                import os.path
    4951                filename = os.path.expandvars(filename)
     
    9698                                       'MS2' (saves as an aips++
    9799                                              MeasurementSet V2)
     100                                       'FITS' (save as image FITS - not
     101                                               readable by class)
     102                                       'CLASS' (save as FITS readable by CLASS)
    98103            overwrite:   If the file should be overwritten if it exists.
    99104                         The default False is to return with warning
     
    279284            return info
    280285
     286    def get_spectrum(self, rowno):
     287        """Return the spectrum for the current row in the scantable as a list.
     288        Parameters:
     289             rowno:   the row number to retrieve the spectrum from       
     290        """
     291        return self._getspectrum(rowno)
     292
     293    def get_mask(self, rowno):
     294        """Return the mask for the current row in the scantable as a list.
     295        Parameters:
     296             rowno:   the row number to retrieve the mask from       
     297        """
     298        return self._getmask(rowno)
     299
     300    def set_spectrum(self, spec, rowno):
     301        """Return the spectrum for the current row in the scantable as a list.
     302        Parameters:
     303             spec:   the spectrum
     304             rowno:    the row number to set the spectrum for       
     305        """
     306        assert(len(spec) == self.nchan())
     307        return self._setspectrum(spec, rowno)
    281308
    282309    def get_selection(self):
     
    518545        times = self._get_column(self._gettime, row)
    519546        if not asdatetime:
    520             return times 
     547            return times
    521548        format = "%Y/%m/%d/%H:%M:%S"
    522549        if isinstance(times, list):
     
    755782                          to remove
    756783            width:        the width of the frequency to remove, to remove a
    757                           range of frequencies aroung the centre.
     784                          range of frequencies around the centre.
    758785            unit:         the frequency unit (default "GHz")
    759786        Notes:
     
    964991        IF 1 gets restfreq 2e9.
    965992        ********NEED TO BE UPDATED end************
    966         You can also specify the frequencies via a linecatalog/
     993        You can also specify the frequencies via a linecatalog.
    967994
    968995        Parameters:
     
    16871714            return s
    16881715
     1716    def set_sourcetype(self, match, matchtype="pattern",
     1717                       sourcetype="reference"):
     1718        """
     1719        Set the type of the source to be an source or reference scan
     1720        using the provided pattern:
     1721        Parameters:
     1722            match:          a Unix style pattern, regular expression or selector
     1723            matchtype:      'pattern' (default) UNIX style pattern or
     1724                            'regex' regular expression
     1725            sourcetype:     the type of the source to use (source/reference)
     1726        """
     1727        varlist = vars()
     1728        basesel = self.get_selection()
     1729        stype = -1
     1730        if sourcetype.lower().startswith("r"):
     1731            stype = 1
     1732        elif sourcetype.lower().startswith("s"):
     1733            stype = 0
     1734        else:
     1735            raise ValueError("Illegal sourcetype use s(ource) or r(eference)")
     1736        if matchtype.lower().startswith("p"):
     1737            matchtype = "pattern"
     1738        elif matchtype.lower().startswith("r"):
     1739            matchtype = "regex"
     1740        else:
     1741            raise ValueError("Illegal matchtype, use p(attern) or r(egex)")
     1742        sel = selector()
     1743        if isinstance(match, selector):
     1744            sel = match
     1745        else:
     1746            sel.set_query("SRCNAME == %s('%s')" % (matchtype, match))
     1747        self.set_selection(basesel+sel)
     1748        self._setsourcetype(stype)
     1749        self.set_selection(basesel)
     1750        s._add_history("set_sourcetype", varlist)
     1751
    16891752    def auto_quotient(self, preserve=True, mode='paired'):
    16901753        """
     
    17031766                            '_e'/'_w' (Tid) and matches
    17041767                            on/off pairs from the observing pattern
    1705                 'time'
    1706                    finds the closest off in time
     1768                            'time'
     1769                            finds the closest off in time
    17071770
    17081771        """
     
    18641927            return fit.as_dict()
    18651928
     1929    def flag_nans(self):
     1930        """
     1931        Utility function to flag NaN values in the scantable.
     1932        """
     1933        import numpy
     1934        basesel = self.get_selection()
     1935        for i in range(self.nrow()):
     1936            sel = selector()+basesel
     1937            sel.set_scans(self.getscan(i))
     1938            sel.set_beams(self.getbeam(i))
     1939            sel.set_ifs(self.getif(i))
     1940            sel.set_polarisations(self.getpol(i))
     1941            self.set_selection(sel)
     1942            nans = numpy.isnan(self._getspectrum(0))
     1943        if numpy.any(nans):
     1944            bnans = [ bool(v) for v in nans]
     1945            self.flag(bnans)
     1946        self.set_selection(basesel)
     1947       
     1948
    18661949    def _add_history(self, funcname, parameters):
     1950        if not rcParams['scantable.history']:
     1951            return
    18671952        # create date
    18681953        sep = "##"
     
    19542039            tbl = Scantable(stype)
    19552040            r = stfiller(tbl)
     2041            rx = rcParams['scantable.reference']
     2042            r._setreferenceexpr(rx)
    19562043            msg = "Importing %s..." % (name)
    19572044            asaplog.push(msg, False)
     
    19592046            r._open(name, -1, -1, getpt)
    19602047            r._read()
    1961             #tbl = r._getdata()
    19622048            if average:
    19632049                tbl = self._math._average((tbl, ), (), 'NONE', 'SCAN')
    1964                 #tbl = tbl2
    19652050            if not first:
    19662051                tbl = self._math._merge([self, tbl])
    1967                 #tbl = tbl2
    19682052            Scantable.__init__(self, tbl)
    19692053            r._close()
     
    19742058        #self.set_freqframe(rcParams['scantable.freqframe'])
    19752059
     2060    def __getitem__(self, key):
     2061        if key < 0:
     2062            key += self.nrow()
     2063        if key >= self.nrow():
     2064            raise IndexError("Row index out of range.")
     2065        return self._getspectrum(key)
     2066
     2067    def __setitem__(self, key, value):
     2068        if key < 0:
     2069            key += self.nrow()
     2070        if key >= self.nrow():
     2071            raise IndexError("Row index out of range.")
     2072        if not hasattr(value, "__len__") or \
     2073                len(value) > self.nchan(self.getif(key)):
     2074            raise ValueError("Spectrum length doesn't match.")
     2075        return self._setspectrum(value, key)
     2076
     2077    def __len__(self):
     2078        return self.nrow()
     2079
     2080    def __iter__(self):
     2081        for i in range(len(self)):
     2082            yield self[i]
Note: See TracChangeset for help on using the changeset viewer.