Changeset 1603 for branches/alma/python/scantable.py
- Timestamp:
- 07/18/09 06:35:47 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/alma/python/scantable.py
r1530 r1603 45 45 Scantable.__init__(self, filename) 46 46 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): 48 50 import os.path 49 51 filename = os.path.expandvars(filename) … … 96 98 'MS2' (saves as an aips++ 97 99 MeasurementSet V2) 100 'FITS' (save as image FITS - not 101 readable by class) 102 'CLASS' (save as FITS readable by CLASS) 98 103 overwrite: If the file should be overwritten if it exists. 99 104 The default False is to return with warning … … 279 284 return info 280 285 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) 281 308 282 309 def get_selection(self): … … 518 545 times = self._get_column(self._gettime, row) 519 546 if not asdatetime: 520 return times 547 return times 521 548 format = "%Y/%m/%d/%H:%M:%S" 522 549 if isinstance(times, list): … … 755 782 to remove 756 783 width: the width of the frequency to remove, to remove a 757 range of frequencies aroun gthe centre.784 range of frequencies around the centre. 758 785 unit: the frequency unit (default "GHz") 759 786 Notes: … … 964 991 IF 1 gets restfreq 2e9. 965 992 ********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. 967 994 968 995 Parameters: … … 1687 1714 return s 1688 1715 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 1689 1752 def auto_quotient(self, preserve=True, mode='paired'): 1690 1753 """ … … 1703 1766 '_e'/'_w' (Tid) and matches 1704 1767 on/off pairs from the observing pattern 1705 'time'1706 finds the closest off in time1768 'time' 1769 finds the closest off in time 1707 1770 1708 1771 """ … … 1864 1927 return fit.as_dict() 1865 1928 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 1866 1949 def _add_history(self, funcname, parameters): 1950 if not rcParams['scantable.history']: 1951 return 1867 1952 # create date 1868 1953 sep = "##" … … 1954 2039 tbl = Scantable(stype) 1955 2040 r = stfiller(tbl) 2041 rx = rcParams['scantable.reference'] 2042 r._setreferenceexpr(rx) 1956 2043 msg = "Importing %s..." % (name) 1957 2044 asaplog.push(msg, False) … … 1959 2046 r._open(name, -1, -1, getpt) 1960 2047 r._read() 1961 #tbl = r._getdata()1962 2048 if average: 1963 2049 tbl = self._math._average((tbl, ), (), 'NONE', 'SCAN') 1964 #tbl = tbl21965 2050 if not first: 1966 2051 tbl = self._math._merge([self, tbl]) 1967 #tbl = tbl21968 2052 Scantable.__init__(self, tbl) 1969 2053 r._close() … … 1974 2058 #self.set_freqframe(rcParams['scantable.freqframe']) 1975 2059 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.