Changeset 1931 for trunk/python
- Timestamp:
- 09/17/10 18:00:47 (14 years ago)
- File:
-
- 1 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:
Note:
See TracChangeset
for help on using the changeset viewer.