Changes in trunk/python/scantable.py [2351:2435]
- File:
-
- 1 edited
-
trunk/python/scantable.py (modified) (26 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r2351 r2435 19 19 from asap.utils import _n_bools, mask_not, mask_and, mask_or, page 20 20 from asap.asapfitter import fitter 21 22 ############################################################### 23 ### WK temporarily added these lines for testing 2011/11/28 ### 24 ############################################################### 25 #from asap._asap import TestClass 26 27 #class testclass(TestClass): 28 # def __init__(self, nelem): 29 # TestClass.__init__(self, nelem) 30 31 ############################################################### 21 32 22 33 … … 264 275 Parameters: 265 276 266 name: the name of the outputfile. For format "ASCII"277 name: the name of the outputfile. For format 'ASCII' 267 278 this is the root file name (data in 'name'.txt 268 279 and header in 'name'_header.txt) … … 522 533 523 534 selection: a selector object (default unset the selection), or 524 any combination of "pols", "ifs", "beams", "scans",525 "cycles", "name", "query"535 any combination of 'pols', 'ifs', 'beams', 'scans', 536 'cycles', 'name', 'query' 526 537 527 538 Examples:: … … 757 768 return self._row_callback(self._gettsys, "Tsys") 758 769 770 def get_tsysspectrum(self, row=-1): 771 """\ 772 Return the channel dependent system temperatures. 773 774 Parameters: 775 776 row: the rowno to get the information for. (default all rows) 777 778 Returns: 779 780 a list of Tsys values for the current selection 781 782 """ 783 return self._get_column( self._gettsysspectrum, row ) 759 784 760 785 def get_weather(self, row=-1): … … 1177 1202 end: the end frequency or period to remove 1178 1203 1179 unit: the frequency unit (default "MHz") or ""for1204 unit: the frequency unit (default 'MHz') or '' for 1180 1205 explicit lag channels 1181 1206 … … 1239 1264 if rowno is None: 1240 1265 rowno = [] 1241 if mask is None:1242 mask = []1243 1266 if isinstance(rowno, int): 1244 1267 rowno = [rowno] 1245 1268 elif not (isinstance(rowno, list) or isinstance(rowno, tuple)): 1246 1269 raise TypeError("The row number(s) must be int, list or tuple.") 1247 1248 1270 if len(rowno) == 0: rowno = [i for i in xrange(self.nrow())] 1249 1271 1250 if not (isinstance(mask, list) or isinstance(mask, tuple)): 1272 usecommonmask = True 1273 1274 if mask is None: 1275 mask = [] 1276 if isinstance(mask, list) or isinstance(mask, tuple): 1277 if len(mask) == 0: 1278 mask = [[]] 1279 else: 1280 if isinstance(mask[0], bool): 1281 if len(mask) != self.nchan(self.getif(rowno[0])): 1282 raise ValueError("The spectra and the mask have " 1283 "different length.") 1284 mask = [mask] 1285 elif isinstance(mask[0], list) or isinstance(mask[0], tuple): 1286 usecommonmask = False 1287 if len(mask) != len(rowno): 1288 raise ValueError("When specifying masks for each " 1289 "spectrum, the numbers of them " 1290 "must be identical.") 1291 for i in xrange(mask): 1292 if len(mask[i]) != self.nchan(self.getif(rowno[i])): 1293 raise ValueError("The spectra and the mask have " 1294 "different length.") 1295 else: 1296 raise TypeError("The mask must be a boolean list or " 1297 "a list of boolean list.") 1298 else: 1251 1299 raise TypeError("The mask must be a boolean list or a list of " 1252 1300 "boolean list.") 1253 if len(mask) == 0: mask = [True for i in xrange(self.nchan())] 1254 if isinstance(mask[0], bool): mask = [mask] 1255 elif not (isinstance(mask[0], list) or isinstance(mask[0], tuple)): 1256 raise TypeError("The mask must be a boolean list or a list of " 1257 "boolean list.") 1258 1259 usecommonmask = (len(mask) == 1) 1260 if not usecommonmask: 1261 if len(mask) != len(rowno): 1262 raise ValueError("When specifying masks for each spectrum, " 1263 "the numbers of them must be identical.") 1264 for amask in mask: 1265 if len(amask) != self.nchan(): 1266 raise ValueError("The spectra and the mask have different " 1267 "length.") 1268 1301 1269 1302 res = [] 1270 1303 … … 1393 1426 if not (isinstance(mask,list) or isinstance(mask, tuple)): 1394 1427 raise TypeError("The mask should be list or tuple.") 1395 if len(mask) < 2:1396 raise TypeError("The mask elements should be > 1")1428 if len(mask) <= 0: 1429 raise TypeError("The mask elements should be > 0") 1397 1430 data = self._getabcissa(row) 1398 1431 if len(data) != len(mask): … … 1434 1467 if not (isinstance(mask,list) or isinstance(mask, tuple)): 1435 1468 raise TypeError("The mask should be list or tuple.") 1436 if len(mask) < 2:1437 raise TypeError("The mask elements should be > 1")1469 if len(mask) <= 0: 1470 raise TypeError("The mask elements should be > 0") 1438 1471 istart = [] 1439 1472 iend = [] … … 1721 1754 # provided your scantable is called scan 1722 1755 selection = selector() 1723 selection.set_name( "ORION*")1756 selection.set_name('ORION*') 1724 1757 selection.set_ifs([1]) 1725 1758 scan.set_selection(selection) … … 1962 1995 The first row of the ascii file must give the column 1963 1996 names and these MUST include columns 1964 "ELEVATION" (degrees) and "FACTOR"(multiply data1997 'ELEVATION' (degrees) and 'FACTOR' (multiply data 1965 1998 by this) somewhere. 1966 1999 The second row must give the data type of the … … 1979 2012 1980 2013 method: Interpolation method when correcting from a table. 1981 Values are "nearest", "linear" (default), "cubic"1982 and "spline"2014 Values are 'nearest', 'linear' (default), 'cubic' 2015 and 'spline' 1983 2016 1984 2017 insitu: if False a new scantable is returned. … … 2014 2047 2015 2048 method: Interpolation method for regridding the spectra. 2016 Choose from "nearest", "linear", "cubic"(default)2017 and "spline"2049 Choose from 'nearest', 'linear', 'cubic' (default) 2050 and 'spline' 2018 2051 2019 2052 insitu: if False a new scantable is returned. … … 2023 2056 """ 2024 2057 if insitu is None: insitu = rcParams["insitu"] 2058 oldInsitu = self._math._insitu() 2025 2059 self._math._setinsitu(insitu) 2026 2060 varlist = vars() … … 2028 2062 s = scantable(self._math._freq_align(self, reftime, method)) 2029 2063 s._add_history("freq_align", varlist) 2064 self._math._setinsitu(oldInsitu) 2030 2065 if insitu: 2031 2066 self._assign(s) … … 2103 2138 2104 2139 method: Interpolation method when correcting from a table. 2105 Values are "nearest", "linear", "cubic"(default)2106 and "spline"2140 Values are 'nearest', 'linear', 'cubic' (default) 2141 and 'spline' 2107 2142 2108 2143 insitu: if False a new scantable is returned. … … 2187 2222 2188 2223 poltype: The new polarisation type. Valid types are: 2189 "linear", "circular", "stokes" and "linpol"2224 'linear', 'circular', 'stokes' and 'linpol' 2190 2225 2191 2226 """ … … 2274 2309 2275 2310 @asaplog_post_dec 2311 def regrid_channel(self, width=5, plot=False, insitu=None): 2312 """\ 2313 Regrid the spectra by the specified channel width 2314 2315 Parameters: 2316 2317 width: The channel width (float) of regridded spectra 2318 in the current spectral unit. 2319 2320 plot: [NOT IMPLEMENTED YET] 2321 plot the original and the regridded spectra. 2322 In this each indivual fit has to be approved, by 2323 typing 'y' or 'n' 2324 2325 insitu: if False a new scantable is returned. 2326 Otherwise, the scaling is done in-situ 2327 The default is taken from .asaprc (False) 2328 2329 """ 2330 if insitu is None: insitu = rcParams['insitu'] 2331 varlist = vars() 2332 2333 if plot: 2334 asaplog.post() 2335 asaplog.push("Verification plot is not implemtnetd yet.") 2336 asaplog.post("WARN") 2337 2338 s = self.copy() 2339 s._regrid_specchan(width) 2340 2341 s._add_history("regrid_channel", varlist) 2342 2343 # if plot: 2344 # from asap.asapplotter import new_asaplot 2345 # theplot = new_asaplot(rcParams['plotter.gui']) 2346 # theplot.set_panels() 2347 # ylab=s._get_ordinate_label() 2348 # #theplot.palette(0,["#777777","red"]) 2349 # for r in xrange(s.nrow()): 2350 # xsm=s._getabcissa(r) 2351 # ysm=s._getspectrum(r) 2352 # xorg=orgscan._getabcissa(r) 2353 # yorg=orgscan._getspectrum(r) 2354 # theplot.clear() 2355 # theplot.hold() 2356 # theplot.set_axes('ylabel',ylab) 2357 # theplot.set_axes('xlabel',s._getabcissalabel(r)) 2358 # theplot.set_axes('title',s._getsourcename(r)) 2359 # theplot.set_line(label='Original',color="#777777") 2360 # theplot.plot(xorg,yorg) 2361 # theplot.set_line(label='Smoothed',color="red") 2362 # theplot.plot(xsm,ysm) 2363 # ### Ugly part for legend 2364 # for i in [0,1]: 2365 # theplot.subplots[0]['lines'].append( 2366 # [theplot.subplots[0]['axes'].lines[i]] 2367 # ) 2368 # theplot.release() 2369 # ### Ugly part for legend 2370 # theplot.subplots[0]['lines']=[] 2371 # res = raw_input("Accept smoothing ([y]/n): ") 2372 # if res.upper() == 'N': 2373 # s._setspectrum(yorg, r) 2374 # theplot.quit() 2375 # del theplot 2376 # del orgscan 2377 2378 if insitu: self._assign(s) 2379 else: return s 2380 2381 @asaplog_post_dec 2276 2382 def _parse_wn(self, wn): 2277 2383 if isinstance(wn, list) or isinstance(wn, tuple): … … 2297 2403 val = int(wn[:-1]) 2298 2404 res = [i for i in xrange(val)] 2299 elif wn[:2] == '>=' or wn[:2] == '=>': # cases '>=a','=>a' : return [a,a+1,...,a_nyq] 2405 elif wn[:2] == '>=' or wn[:2] == '=>': # cases '>=a','=>a' : return [a,-999], which is 2406 # then interpreted in C++ 2407 # side as [a,a+1,...,a_nyq] 2408 # (CAS-3759) 2300 2409 val = int(wn[2:]) 2301 res = [i for i in xrange(val, self.nchan()/2+1)] 2302 elif wn[-2:] == '<=' or wn[-2:] == '=<': # cases 'a<=','a=<' : return [a,a+1,...,a_nyq] 2410 res = [val, -999] 2411 #res = [i for i in xrange(val, self.nchan()/2+1)] 2412 elif wn[-2:] == '<=' or wn[-2:] == '=<': # cases 'a<=','a=<' : return [a,-999], which is 2413 # then interpreted in C++ 2414 # side as [a,a+1,...,a_nyq] 2415 # (CAS-3759) 2303 2416 val = int(wn[:-2]) 2304 res = [i for i in xrange(val, self.nchan()/2+1)] 2305 elif wn[0] == '>': # case '>a' : return [a+1,a+2,...,a_nyq] 2417 res = [val, -999] 2418 #res = [i for i in xrange(val, self.nchan()/2+1)] 2419 elif wn[0] == '>': # case '>a' : return [a+1,-999], which is 2420 # then interpreted in C++ 2421 # side as [a+1,a+2,...,a_nyq] 2422 # (CAS-3759) 2306 2423 val = int(wn[1:])+1 2307 res = [i for i in xrange(val, self.nchan()/2+1)] 2308 elif wn[-1] == '<': # case 'a<' : return [a+1,a+2,...,a_nyq] 2424 res = [val, -999] 2425 #res = [i for i in xrange(val, self.nchan()/2+1)] 2426 elif wn[-1] == '<': # case 'a<' : return [a+1,-999], which is 2427 # then interpreted in C++ 2428 # side as [a+1,a+2,...,a_nyq] 2429 # (CAS-3759) 2309 2430 val = int(wn[:-1])+1 2310 res = [i for i in xrange(val, self.nchan()/2+1)] 2431 res = [val, -999] 2432 #res = [i for i in xrange(val, self.nchan()/2+1)] 2311 2433 2312 2434 return res … … 2357 2479 number corresponding to the Nyquist 2358 2480 frequency for the case of FFT). 2359 default is [ ].2481 default is [0]. 2360 2482 rejwn: the wave numbers NOT to be used for fitting. 2361 2483 can be set just as addwn but has higher priority: … … 2401 2523 workscan = self.copy() 2402 2524 2403 if mask is None: mask = [True for i in xrange(workscan.nchan())] 2525 #if mask is None: mask = [True for i in xrange(workscan.nchan())] 2526 if mask is None: mask = [] 2404 2527 if applyfft is None: applyfft = True 2405 2528 if fftmethod is None: fftmethod = 'fft' 2406 2529 if fftthresh is None: fftthresh = 3.0 2407 if addwn is None: addwn = [ ]2530 if addwn is None: addwn = [0] 2408 2531 if rejwn is None: rejwn = [] 2409 2532 if clipthresh is None: clipthresh = 3.0 … … 2480 2603 number corresponding to the Nyquist 2481 2604 frequency for the case of FFT). 2482 default is [ ].2605 default is [0]. 2483 2606 rejwn: the wave numbers NOT to be used for fitting. 2484 2607 can be set just as addwn but has higher priority: … … 2541 2664 workscan = self.copy() 2542 2665 2543 if mask is None: mask = [True for i in xrange(workscan.nchan())] 2666 #if mask is None: mask = [True for i in xrange(workscan.nchan())] 2667 if mask is None: mask = [] 2544 2668 if applyfft is None: applyfft = True 2545 2669 if fftmethod is None: fftmethod = 'fft' 2546 2670 if fftthresh is None: fftthresh = 3.0 2547 if addwn is None: addwn = [ ]2671 if addwn is None: addwn = [0] 2548 2672 if rejwn is None: rejwn = [] 2549 2673 if clipthresh is None: clipthresh = 3.0 … … 2636 2760 workscan = self.copy() 2637 2761 2638 if mask is None: mask = [True for i in xrange(workscan.nchan())] 2762 #if mask is None: mask = [True for i in xrange(workscan.nchan())] 2763 if mask is None: mask = [] 2639 2764 if npiece is None: npiece = 2 2640 2765 if clipthresh is None: clipthresh = 3.0 … … 2738 2863 workscan = self.copy() 2739 2864 2740 if mask is None: mask = [True for i in xrange(workscan.nchan())] 2865 #if mask is None: mask = [True for i in xrange(workscan.nchan())] 2866 if mask is None: mask = [] 2741 2867 if npiece is None: npiece = 2 2742 2868 if clipthresh is None: clipthresh = 3.0 … … 2814 2940 workscan = self.copy() 2815 2941 2816 if mask is None: mask = [True for i in \ 2817 xrange(workscan.nchan())] 2942 #if mask is None: mask = [True for i in \ 2943 # xrange(workscan.nchan())] 2944 if mask is None: mask = [] 2818 2945 if order is None: order = 0 2819 2946 if plot is None: plot = False … … 2953 3080 workscan = self.copy() 2954 3081 2955 if mask is None: mask = [True for i in xrange(workscan.nchan())] 3082 #if mask is None: mask = [True for i in xrange(workscan.nchan())] 3083 if mask is None: mask = [] 2956 3084 if order is None: order = 0 2957 3085 if edge is None: edge = (0, 0)
Note:
See TracChangeset
for help on using the changeset viewer.
