Changeset 1931
- Timestamp:
- 09/17/10 18:00:47 (14 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r1928 r1931 337 337 Parameters: 338 338 339 filename: the name of a file to write the output to339 filename: the name of a file to write the putput to 340 340 Default - no file output 341 341 … … 377 377 378 378 def set_spectrum(self, spec, rowno): 379 """ Set the spectrum for the current row in the scantable.379 """Return the spectrum for the current row in the scantable as a list. 380 380 381 381 Parameters: … … 738 738 """\ 739 739 Get a list of time stamps for the observations. 740 Return a datetime object or a string (default) for each 741 integration time stamp in the scantable. 740 Return a datetime object for each integration time stamp in the scantable. 742 741 743 742 Parameters: … … 1159 1158 return msk 1160 1159 1161 def get_masklist(self, mask=None, row=0 ):1160 def get_masklist(self, mask=None, row=0, silent=False): 1162 1161 """\ 1163 1162 Compute and return a list of mask windows, [min, max]. … … 1193 1192 if not i: 1194 1193 msg += "\nThis mask is only valid for IF=%d" % (self.getif(i)) 1195 asaplog.push(msg) 1194 if not silent: 1195 asaplog.push(msg) 1196 1196 masklist=[] 1197 1197 ist, ien = None, None … … 1284 1284 """\ 1285 1285 Set or replace the restfrequency specified and 1286 if the 'freqs' argument holds a scalar,1286 If the 'freqs' argument holds a scalar, 1287 1287 then that rest frequency will be applied to all the selected 1288 1288 data. If the 'freqs' argument holds … … 1434 1434 out += "Function: %s\n Parameters:" % (func) 1435 1435 for i in items: 1436 if i == '':1437 continue1438 1436 s = i.split("=") 1439 1437 out += "\n %s = %s" % (s[0], s[1]) … … 1937 1935 workscan._setspectrum(f.fitter.getresidual(), r) 1938 1936 self.blpars.append(f.get_parameters()) 1939 self.masklists.append(workscan.get_masklist(f.mask, row=r ))1937 self.masklists.append(workscan.get_masklist(f.mask, row=r, silent=True)) 1940 1938 self.actualmask.append(f.mask) 1941 1939 … … 1952 1950 raise RuntimeError(msg) 1953 1951 1954 1952 @asaplog_post_dec 1955 1953 def poly_baseline(self, mask=None, order=0, plot=False, batch=False, insitu=None, rows=None): 1956 1954 """\ … … 1968 1966 Otherwise, the scaling is done in-situ 1969 1967 The default is taken from .asaprc (False) 1970 rows: row numbers of spectra to be processed.1968 rows: row numbers of spectra to be baselined. 1971 1969 (default is None: for all rows) 1972 1970 Example: … … 1975 1973 bscan = scan.poly_baseline(order=3) 1976 1974 """ 1975 1976 varlist = vars() 1977 1977 1978 if insitu is None: insitu = rcParams["insitu"] 1978 1979 if insitu: … … 1981 1982 workscan = self.copy() 1982 1983 1983 varlist = vars()1984 1984 nchan = workscan.nchan() 1985 1985 … … 1994 1994 1995 1995 if len(rows) > 0: 1996 self.blpars = []1997 self.masklists = []1998 self.actualmask = []1996 workscan.blpars = [] 1997 workscan.masklists = [] 1998 workscan.actualmask = [] 1999 1999 2000 2000 if batch: 2001 for r in rows: 2002 workscan._poly_baseline_batch(mask, order, r) 2001 workscan._poly_baseline_batch(mask, order) 2003 2002 elif plot: 2004 2003 f = fitter() … … 2019 2018 continue 2020 2019 workscan._setspectrum(f.fitter.getresidual(), r) 2021 self.blpars.append(f.get_parameters())2022 self.masklists.append(workscan.get_masklist(f.mask, row=r))2023 self.actualmask.append(f.mask)2020 workscan.blpars.append(f.get_parameters()) 2021 workscan.masklists.append(workscan.get_masklist(f.mask, row=r)) 2022 workscan.actualmask.append(f.mask) 2024 2023 2025 2024 f._p.unmap() 2026 2025 f._p = None 2027 2026 else: 2028 import array2029 2027 for r in rows: 2030 pars = array.array("f", [0.0 for i in range(order+1)]) 2031 pars_adr = pars.buffer_info()[0] 2032 pars_len = pars.buffer_info()[1] 2028 fitparams = workscan._poly_baseline(mask, order, r) 2029 params = fitparams.getparameters() 2030 fmtd = ", ".join(["p%d = %3.6f" % (i, v) for i, v in enumerate(params)]) 2031 errors = fitparams.geterrors() 2032 fmask = mask_and(mask, workscan._getmask(r)) 2033 2034 workscan.blpars.append({"params":params, 2035 "fixed": fitparams.getfixedparameters(), 2036 "formatted":fmtd, "errors":errors}) 2037 workscan.masklists.append(workscan.get_masklist(fmask, r, silent=True)) 2038 workscan.actualmask.append(fmask) 2033 2039 2034 errs = array.array("f", [0.0 for i in range(order+1)]) 2035 errs_adr = errs.buffer_info()[0] 2036 errs_len = errs.buffer_info()[1] 2037 2038 fmsk = array.array("i", [1 for i in range(nchan)]) 2039 fmsk_adr = fmsk.buffer_info()[0] 2040 fmsk_len = fmsk.buffer_info()[1] 2041 2042 workscan._poly_baseline(mask, order, r, pars_adr, pars_len, errs_adr, errs_len, fmsk_adr, fmsk_len) 2043 2044 params = pars.tolist() 2045 fmtd = "" 2046 for i in xrange(len(params)): fmtd += " p%d= %3.6f," % (i, params[i]) 2047 fmtd = fmtd[:-1] # remove trailing "," 2048 errors = errs.tolist() 2049 fmask = fmsk.tolist() 2050 for i in xrange(len(fmask)): fmask[i] = (fmask[i] > 0) # transform (1/0) -> (True/False) 2051 2052 self.blpars.append({"params":params, "fixed":[], "formatted":fmtd, "errors":errors}) 2053 self.masklists.append(workscan.get_masklist(fmask, r)) 2054 self.actualmask.append(fmask) 2055 2056 asaplog.push(str(fmtd)) 2040 asaplog.push(fmtd) 2057 2041 2058 2042 workscan._add_history("poly_baseline", varlist) … … 2077 2061 insitu=None, rows=None): 2078 2062 """\ 2079 Return a scan which has been baselined (all rows by default) 2080 by a polynomial. 2063 Return a scan which has been baselined (all rows) by a polynomial. 2081 2064 Spectral lines are detected first using linefinder and masked out 2082 2065 to avoid them affecting the baseline solution. … … 2206 2189 2207 2190 # Show mask list 2208 masklist=workscan.get_masklist(f.mask, row=r )2191 masklist=workscan.get_masklist(f.mask, row=r, silent=True) 2209 2192 msg = "mask range: "+str(masklist) 2210 2193 asaplog.push(msg, False) … … 2323 2306 """\ 2324 2307 2325 Return a scan where all spectra are scaled by the give n'factor'2308 Return a scan where all spectra are scaled by the give 'factor' 2326 2309 2327 2310 Parameters: -
trunk/src/Scantable.cpp
r1929 r1931 543 543 // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these 544 544 Table t = table_(table_.col("SCANNO") == scanno); 545 if ( t.nrow() == 0 ) return 0 ;546 545 ROTableRow row(t); 547 546 const TableRecord& rec = row.get(0); … … 564 563 // take the first POLNO,BEAMNO,CYCLENO as nbeam shouldn't vary with these 565 564 Table t = table_(table_.col("SCANNO") == scanno); 566 if ( t.nrow() == 0 ) return 0 ;567 565 ROTableRow row(t); 568 566 const TableRecord& rec = row.get(0); … … 586 584 // take the first POLNO,IFNO,CYCLENO as nbeam shouldn't vary with these 587 585 Table t = table_(table_.col("SCANNO") == scanno); 588 if ( t.nrow() == 0 ) return 0 ;589 586 ROTableRow row(t); 590 587 const TableRecord& rec = row.get(0); … … 614 611 } else { 615 612 Table t = table_(table_.col("SCANNO") == scanno); 616 if ( t.nrow() == 0 ) return 0 ;617 613 ROTableRow row(t); 618 614 const TableRecord& rec = row.get(0); … … 1754 1750 } 1755 1751 1756 void Scantable::polyBaselineBatch(const std::vector<bool>& mask, int order, int rowno) 1752 void Scantable::polyBaselineBatch(const std::vector<bool>& mask, int order) 1753 { 1754 Fitter fitter = Fitter(); 1755 for (uInt rowno=0; rowno < nrow(); ++rowno) { 1756 doPolyBaseline(mask, order, rowno, fitter); 1757 setSpectrum(fitter.getResidual(), rowno); 1758 } 1759 } 1760 1761 STFitEntry Scantable::polyBaseline(const std::vector<bool>& mask, int order, int rowno) 1757 1762 { 1758 1763 Fitter fitter = Fitter(); 1759 1764 doPolyBaseline(mask, order, rowno, fitter); 1760 1765 setSpectrum(fitter.getResidual(), rowno); 1761 } 1762 1763 void Scantable::polyBaseline(const std::vector<bool>& mask, int order, int rowno, long pars_ptr, long pars_size, long errs_ptr, long errs_size, long fmask_ptr, long fmask_size) 1764 { 1765 Fitter fitter = Fitter(); 1766 doPolyBaseline(mask, order, rowno, fitter); 1767 setSpectrum(fitter.getResidual(), rowno); 1768 1769 std::vector<float> pars = fitter.getParameters(); 1770 if (pars_size != pars.size()) { 1771 throw(AipsError("wrong pars size")); 1772 } 1773 float *ppars = reinterpret_cast<float*>(pars_ptr); 1774 for (int i = 0; i < pars_size; i++) { 1775 ppars[i] = pars[i]; 1776 } 1777 1778 std::vector<float> errs = fitter.getErrors(); 1779 if (errs_size != errs.size()) { 1780 throw(AipsError("wrong errors size")); 1781 } 1782 float *perrs = reinterpret_cast<float*>(errs_ptr); 1783 for (int i = 0; i < errs_size; i++) { 1784 perrs[i] = errs[i]; 1785 } 1786 1787 std::vector<bool> fmask = getMask(rowno); 1788 if (fmask_size != fmask.size()) { 1789 throw(AipsError("wrong fmask size")); 1790 } 1791 int *pfmask = reinterpret_cast<int*>(fmask_ptr); 1792 for (int i = 0; i < fmask_size; i++) { 1793 pfmask[i] = ((fmask[i] && mask[i]) ? 1 : 0); 1794 } 1766 return fitter.getFitEntry(); 1795 1767 } 1796 1768 -
trunk/src/Scantable.h
r1919 r1931 18 18 // AIPS++ 19 19 #include <casa/aips.h> 20 #include <casa/Containers/Record.h> 20 21 #include <casa/Arrays/MaskedArray.h> 21 22 #include <casa/BasicSL/String.h> … … 489 490 bool getFlagtraFast(int whichrow); 490 491 491 void polyBaselineBatch(const std::vector<bool>& mask, int order, int rowno); 492 void polyBaseline(const std::vector<bool>& mask, int order, int rowno, long pars_ptr, long pars_size, long errs_ptr, long errs_size, long fmask_ptr, long fmask_size); 493 492 void polyBaselineBatch(const std::vector<bool>& mask, int order); 493 STFitEntry polyBaseline(const std::vector<bool>& mask, int order, int rowno); 494 494 495 495 private: -
trunk/src/ScantableWrapper.h
r1919 r1931 19 19 #include "MathUtils.h" 20 20 #include "STFit.h" 21 #include "STFitEntry.h" 21 22 #include "Scantable.h" 22 23 #include "STCoordinate.h" … … 250 251 { table_->reshapeSpectrum( nmin, nmax ); } 251 252 252 void polyBaseline(const std::vector<bool>& mask, int order, int rowno, long pars_ptr, long pars_size, long errs_ptr, long errs_size, long fmask_ptr, long fmask_size)253 { table_->polyBaseline(mask, order, rowno, pars_ptr, pars_size, errs_ptr, errs_size, fmask_ptr, fmask_size); }254 255 void polyBaselineBatch(const std::vector<bool>& mask, int order , int rowno)256 { table_->polyBaselineBatch(mask, order , rowno); }253 STFitEntry polyBaseline(const std::vector<bool>& mask, int order, int rowno) 254 { return table_->polyBaseline(mask, order, rowno); } 255 256 void polyBaselineBatch(const std::vector<bool>& mask, int order) 257 { table_->polyBaselineBatch(mask, order); } 257 258 258 259 bool getFlagtraFast(int whichrow=0) const
Note:
See TracChangeset
for help on using the changeset viewer.