Changeset 2276 for trunk/python
- Timestamp:
- 08/17/11 10:54:03 (13 years ago)
- Location:
- trunk/python
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/asapplotter.py
r2173 r2276 914 914 n = min(n,self._rows*self._cols) 915 915 self._plotter.set_panels(rows=self._rows,cols=self._cols, 916 nplots=n,margin=self._margins,ganged=ganged) 916 nplots=n,margin=self._margins, 917 ganged=ganged) 917 918 else: 918 919 n = min(n,maxpanel) 919 self._plotter.set_panels(rows=n,cols=0,nplots=n,margin=self._margins,ganged=ganged) 920 self._plotter.set_panels(rows=n,cols=0,nplots=n, 921 margin=self._margins,ganged=ganged) 920 922 else: 921 923 self._plotter.set_panels(margin=self._margins) … … 972 974 973 975 #if (b > b0 or newpanel) and stackcount < nstack: 974 if stackcount < nstack and (newpanel or rowstack or (a == a0 and b > b0)): 976 if stackcount < nstack and (newpanel or rowstack 977 or (a == a0 and b > b0)): 975 978 y = [] 976 979 if len(polmodes): … … 980 983 # flag application 981 984 mr = scan._getflagrow(r) 985 #mr = False 982 986 from numpy import ma, array 983 987 if mr: … … 987 991 from numpy import logical_not, logical_and 988 992 if self._maskselection and len(self._usermask) == len(m): 989 if d[self._stacking](r) in self._maskselection[self._stacking]: 993 if d[self._stacking](r) in \ 994 self._maskselection[self._stacking]: 990 995 m = logical_and(m, self._usermask) 991 y = ma.masked_array(y,mask=logical_not(array(m,copy=False))) 996 y = ma.masked_array(y,mask=logical_not(array(m, 997 copy=False))) 992 998 993 999 x = array(scan._getabcissa(r)) -
trunk/python/scantable.py
r2269 r2276 88 88 * an integer - will be used for both sides of spectra of all IFs. 89 89 e.g. 10 is converted to [10,10] 90 * an empty list/tuple [] - converted to [0, 0] and used for all IFs. 90 * an empty list/tuple [] - converted to [0, 0] and used for all 91 IFs. 91 92 * a list/tuple containing an integer - same as the above case. 92 93 e.g. [10] is converted to [10,10] … … 95 96 * a list/tuple of lists/tuples containing TWO integers - 96 97 each element of edge will be used for each IF. 97 e.g. [[5,10],[15,20]] - [5,10] for IF[0] and [15,20] for IF[1]. 98 99 If an element contains the same integer values, the input 'edge' 100 parameter can be given in a simpler shape in the following cases: 98 e.g. [[5,10],[15,20]] - [5,10] for IF[0] and [15,20] for 99 IF[1]. 100 If an element contains the same integer values, the input 101 'edge' parameter can be given in a simpler shape in the 102 following cases: 101 103 ** when len(edge)!=2 102 any elements containing the same values can be replaced 103 to single integers. 104 e.g. [[15,15]] can be simplified to [15] (or [15,15] or 15 also). 105 e.g. [[1,1],[2,2],[3,3]] can be simplified to [1,2,3]. 104 any elements containing the same values can be 105 replaced to single integers. 106 e.g. [[15,15]] can be simplified to [15] 107 (or [15,15] or 15 also). 108 e.g. [[1,1],[2,2],[3,3]] can be simplified to 109 [1,2,3]. 106 110 ** when len(edge)=2 107 111 care is needed for this case: ONLY ONE of the 108 112 elements can be a single integer, 109 113 e.g. [[5,5],[10,10]] can be simplified to [5,[10,10]] 110 or [[5,5],10], but can NOT be simplified to [5,10]. 114 or [[5,5],10], but can NOT be simplified to 115 [5,10]. 111 116 when [5,10] given, it is interpreted as 112 [[5,10],[5,10],[5,10],...] instead, as shown before. 117 [[5,10],[5,10],[5,10],...] instead, as shown 118 before. 113 119 """ 114 120 from asap import _is_sequence_or_number as _is_valid … … 181 187 #def __init__(self, filename, average=None, unit=None, getpt=None, 182 188 # antenna=None, parallactify=None): 183 def __init__(self, filename, average=None, unit=None, parallactify=None, **args): 189 def __init__(self, filename, average=None, unit=None, parallactify=None, 190 **args): 184 191 """\ 185 192 Create a scantable from a saved one or make a reference … … 208 215 209 216 antenna: for MeasurementSet input data only: 210 Antenna selection. integer (id) or string (name or id). 217 Antenna selection. integer (id) or string (name 218 or id). 211 219 212 220 parallactify: Indicate that the data had been parallatified. Default … … 302 310 * 'ASCII' (saves as ascii text file) 303 311 * 'MS2' (saves as an casacore MeasurementSet V2) 304 * 'FITS' (save as image FITS - not readable by class) 312 * 'FITS' (save as image FITS - not readable by 313 CLASS) 305 314 * 'CLASS' (save as FITS readable by CLASS) 306 315 … … 370 379 from asap import unique 371 380 if not _is_valid(scanid): 372 raise RuntimeError( 'Please specify a scanno to drop from the scantable' ) 381 raise RuntimeError( 'Please specify a scanno to drop from the '\ 382 'scantable' ) 373 383 scanid = _to_list(scanid) 374 384 allscans = unique([ self.getscan(i) for i in range(self.nrow())]) … … 852 862 asdatetime: return values as datetime objects rather than strings 853 863 854 prec: number of digits shown. Default -1 to automatic calculation. 864 prec: number of digits shown. Default -1 to automatic 865 calculation. 855 866 Note this number is equals to the digits of MVTime, 856 867 i.e., 0<prec<3: dates with hh:: only, … … 1145 1156 1146 1157 rows: list of row numbers to be flagged. Default is no row 1147 (must be explicitly specified to execute row-based flagging). 1158 (must be explicitly specified to execute row-based 1159 flagging). 1148 1160 1149 1161 unflag: if True, unflag the data. … … 1165 1177 dthres: lower threshold 1166 1178 1167 clipoutside: True for flagging data outside the range [dthres:uthres]. 1179 clipoutside: True for flagging data outside the range 1180 [dthres:uthres]. 1168 1181 False for flagging data inside the range. 1169 1182 … … 2255 2268 return [ wn ] 2256 2269 elif isinstance(wn, str): 2257 if '-' in wn: # case 'a-b' : return [a,a+1,...,b-1,b] 2270 if '-' in wn: 2271 # case 'a-b' : return [a,a+1,...,b-1,b] 2258 2272 val = wn.split('-') 2259 2273 val = [int(val[0]), int(val[1])] 2260 2274 val.sort() 2261 2275 res = [i for i in xrange(val[0], val[1]+1)] 2262 elif wn[:2] == '<=' or wn[:2] == '=<': # cases '<=a','=<a' : return [0,1,...,a-1,a] 2276 elif wn[:2] == '<=' or wn[:2] == '=<': 2277 # cases '<=a','=<a' : return [0,1,...,a-1,a] 2263 2278 val = int(wn[2:])+1 2264 2279 res = [i for i in xrange(val)] 2265 elif wn[-2:] == '>=' or wn[-2:] == '=>': # cases 'a>=','a=>' : return [0,1,...,a-1,a] 2280 elif wn[-2:] == '>=' or wn[-2:] == '=>': 2281 # cases 'a>=','a=>' : return [0,1,...,a-1,a] 2266 2282 val = int(wn[:-2])+1 2267 2283 res = [i for i in xrange(val)] 2268 elif wn[0] == '<': # case '<a' : return [0,1,...,a-2,a-1] 2284 elif wn[0] == '<': 2285 # case '<a' : return [0,1,...,a-2,a-1] 2269 2286 val = int(wn[1:]) 2270 2287 res = [i for i in xrange(val)] 2271 elif wn[-1] == '>': # case 'a>' : return [0,1,...,a-2,a-1] 2288 elif wn[-1] == '>': 2289 # case 'a>' : return [0,1,...,a-2,a-1] 2272 2290 val = int(wn[:-1]) 2273 2291 res = [i for i in xrange(val)] 2274 elif wn[:2] == '>=' or wn[:2] == '=>': # cases '>=a','=>a' : return [a,a+1,...,a_nyq] 2292 elif wn[:2] == '>=' or wn[:2] == '=>': 2293 # cases '>=a','=>a' : return [a,a+1,...,a_nyq] 2275 2294 val = int(wn[2:]) 2276 2295 res = [i for i in xrange(val, self.nchan()/2+1)] 2277 elif wn[-2:] == '<=' or wn[-2:] == '=<': # cases 'a<=','a=<' : return [a,a+1,...,a_nyq] 2296 elif wn[-2:] == '<=' or wn[-2:] == '=<': 2297 # cases 'a<=','a=<' : return [a,a+1,...,a_nyq] 2278 2298 val = int(wn[:-2]) 2279 2299 res = [i for i in xrange(val, self.nchan()/2+1)] 2280 elif wn[0] == '>': # case '>a' : return [a+1,a+2,...,a_nyq] 2300 elif wn[0] == '>': 2301 # case '>a' : return [a+1,a+2,...,a_nyq] 2281 2302 val = int(wn[1:])+1 2282 2303 res = [i for i in xrange(val, self.nchan()/2+1)] 2283 elif wn[-1] == '<': # case 'a<' : return [a+1,a+2,...,a_nyq] 2304 elif wn[-1] == '<': 2305 # case 'a<' : return [a+1,a+2,...,a_nyq] 2284 2306 val = int(wn[:-1])+1 2285 2307 res = [i for i in xrange(val, self.nchan()/2+1)] … … 2292 2314 2293 2315 @asaplog_post_dec 2294 def sinusoid_baseline(self, insitu=None, mask=None, applyfft=None,2316 def sinusoid_baseline(self, mask=None, insitu=None, applyfft=None, 2295 2317 fftmethod=None, fftthresh=None, 2296 2318 addwn=None, rejwn=None, clipthresh=None, … … 2372 2394 workscan = self.copy() 2373 2395 2374 if mask is None: mask = [True for i in xrange(workscan.nchan())] 2396 if mask is None: mask = \ 2397 [True for i in xrange(workscan.nchan())] 2375 2398 if applyfft is None: applyfft = True 2376 2399 if fftmethod is None: fftmethod = 'fft' … … 2388 2411 2389 2412 #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method. 2390 workscan._sinusoid_baseline(mask, applyfft, fftmethod.lower(), str(fftthresh).lower(), workscan._parse_wn(addwn), workscan._parse_wn(rejwn), clipthresh, clipniter, getresidual, pack_progress_params(showprogress, minnrow), outlog, blfile) 2413 workscan._sinusoid_baseline(mask, applyfft, fftmethod.lower(), 2414 str(fftthresh).lower(), 2415 workscan._parse_wn(addwn), 2416 workscan._parse_wn(rejwn), clipthresh, 2417 clipniter, getresidual, 2418 pack_progress_params(showprogress, 2419 minnrow), 2420 outlog, blfile) 2391 2421 workscan._add_history('sinusoid_baseline', varlist) 2392 2422 … … 2401 2431 2402 2432 @asaplog_post_dec 2403 def auto_sinusoid_baseline(self, insitu=None, mask=None, applyfft=None, fftmethod=None, fftthresh=None, 2404 addwn=None, rejwn=None, clipthresh=None, clipniter=None, edge=None, threshold=None, 2405 chan_avg_limit=None, plot=None, getresidual=None, showprogress=None, minnrow=None, 2433 def auto_sinusoid_baseline(self, mask=None, insitu=None, applyfft=None, 2434 fftmethod=None, fftthresh=None, 2435 addwn=None, rejwn=None, clipthresh=None, 2436 clipniter=None, edge=None, threshold=None, 2437 chan_avg_limit=None, plot=None, 2438 getresidual=None, showprogress=None, 2439 minnrow=None, 2406 2440 outlog=None, blfile=None): 2407 2441 """\ 2408 Return a scan which has been baselined (all rows) with sinusoidal functions. 2442 Return a scan which has been baselined (all rows) with sinusoidal 2443 functions. 2409 2444 Spectral lines are detected first using linefinder and masked out 2410 2445 to avoid them affecting the baseline solution. … … 2427 2462 given a float value, the unit is set to sigma. 2428 2463 for string values, allowed formats include: 2429 'xsigma' or 'x' (= x-sigma level. e.g., '3sigma'), or 2464 'xsigma' or 'x' (= x-sigma level. e.g., 2465 '3sigma'), or 2430 2466 'topx' (= the x strongest ones, e.g. 'top5'). 2431 2467 default is 3.0 (unit: sigma). … … 2445 2481 and rejwn will NOT be used. default is []. 2446 2482 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 2447 clipniter: maximum number of iteration of 'clipthresh'-sigma clipping (default is 0) 2483 clipniter: maximum number of iteration of 'clipthresh'-sigma 2484 clipping (default is 0) 2448 2485 edge: an optional number of channel to drop at 2449 2486 the edge of spectrum. If only one value is … … 2499 2536 workscan = self.copy() 2500 2537 2501 if mask is None: mask = [True for i in xrange(workscan.nchan())] 2538 if mask is None: mask = \ 2539 [True for i in xrange(workscan.nchan())] 2502 2540 if applyfft is None: applyfft = True 2503 2541 if fftmethod is None: fftmethod = 'fft' … … 2517 2555 if blfile is None: blfile = '' 2518 2556 2519 #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method. 2520 workscan._auto_sinusoid_baseline(mask, applyfft, fftmethod.lower(), str(fftthresh).lower(), workscan._parse_wn(addwn), workscan._parse_wn(rejwn), clipthresh, clipniter, normalise_edge_param(edge), threshold, chan_avg_limit, getresidual, pack_progress_params(showprogress, minnrow), outlog, blfile) 2557 #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is 2558 # implemented as a fitter method. 2559 workscan._auto_sinusoid_baseline(mask, applyfft, fftmethod.lower(), 2560 str(fftthresh).lower(), 2561 workscan._parse_wn(addwn), 2562 workscan._parse_wn(rejwn), 2563 clipthresh, clipniter, 2564 normalise_edge_param(edge), 2565 threshold, chan_avg_limit, 2566 getresidual, 2567 pack_progress_params(showprogress, 2568 minnrow), 2569 outlog, blfile) 2521 2570 workscan._add_history("auto_sinusoid_baseline", varlist) 2522 2571 … … 2530 2579 2531 2580 @asaplog_post_dec 2532 def cspline_baseline(self, insitu=None, mask=None, npiece=None, clipthresh=None, clipniter=None, 2533 plot=None, getresidual=None, showprogress=None, minnrow=None, outlog=None, blfile=None): 2534 """\ 2535 Return a scan which has been baselined (all rows) by cubic spline function (piecewise cubic polynomial). 2581 def cspline_baseline(self, mask=None, insitu=None, npiece=None, 2582 clipthresh=None, clipniter=None, plot=None, 2583 getresidual=None, showprogress=None, minnrow=None, 2584 outlog=None, blfile=None): 2585 """\ 2586 Return a scan which has been baselined (all rows) by cubic spline 2587 function (piecewise cubic polynomial). 2536 2588 Parameters: 2537 2589 insitu: If False a new scantable is returned. … … 2541 2593 npiece: Number of pieces. (default is 2) 2542 2594 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 2543 clipniter: maximum number of iteration of 'clipthresh'-sigma clipping (default is 0) 2595 clipniter: maximum number of iteration of 'clipthresh'-sigma 2596 clipping (default is 0) 2544 2597 plot: *** CURRENTLY UNAVAILABLE, ALWAYS FALSE *** 2545 2598 plot the fit and the residual. In this each … … 2559 2612 2560 2613 Example: 2561 # return a scan baselined by a cubic spline consisting of 2 pieces (i.e., 1 internal knot), 2614 # return a scan baselined by a cubic spline consisting of 2 2615 # pieces (i.e., 1 internal knot), 2562 2616 # also with 3-sigma clipping, iteration up to 4 times 2563 2617 bscan = scan.cspline_baseline(npiece=2,clipthresh=3.0,clipniter=4) … … 2577 2631 workscan = self.copy() 2578 2632 2579 if mask is None: mask = [True for i in xrange(workscan.nchan())] 2633 if mask is None: mask = \ 2634 [True for i in xrange(workscan.nchan())] 2580 2635 if npiece is None: npiece = 2 2581 2636 if clipthresh is None: clipthresh = 3.0 … … 2589 2644 2590 2645 #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method. 2591 workscan._cspline_baseline(mask, npiece, clipthresh, clipniter, getresidual, pack_progress_params(showprogress, minnrow), outlog, blfile) 2646 workscan._cspline_baseline(mask, npiece, clipthresh, clipniter, 2647 getresidual, 2648 pack_progress_params(showprogress, 2649 minnrow), 2650 outlog, blfile) 2592 2651 workscan._add_history("cspline_baseline", varlist) 2593 2652 … … 2601 2660 2602 2661 @asaplog_post_dec 2603 def auto_cspline_baseline(self, insitu=None, mask=None, npiece=None, clipthresh=None, clipniter=None, 2604 edge=None, threshold=None, chan_avg_limit=None, getresidual=None, plot=None, 2605 showprogress=None, minnrow=None, outlog=None, blfile=None): 2662 def auto_cspline_baseline(self, mask=None, insitu=None, npiece=None, 2663 clipthresh=None, clipniter=None, 2664 edge=None, threshold=None, chan_avg_limit=None, 2665 getresidual=None, plot=None, 2666 showprogress=None, minnrow=None, outlog=None, 2667 blfile=None): 2606 2668 """\ 2607 2669 Return a scan which has been baselined (all rows) by cubic spline … … 2617 2679 npiece: Number of pieces. (default is 2) 2618 2680 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 2619 clipniter: maximum number of iteration of 'clipthresh'-sigma clipping (default is 0) 2681 clipniter: maximum number of iteration of 'clipthresh'-sigma 2682 clipping (default is 0) 2620 2683 edge: an optional number of channel to drop at 2621 2684 the edge of spectrum. If only one value is … … 2671 2734 workscan = self.copy() 2672 2735 2673 if mask is None: mask = [True for i in xrange(workscan.nchan())] 2736 if mask is None: mask = \ 2737 [True for i in xrange(workscan.nchan())] 2674 2738 if npiece is None: npiece = 2 2675 2739 if clipthresh is None: clipthresh = 3.0 … … 2685 2749 if blfile is None: blfile = '' 2686 2750 2687 #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method. 2751 #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is 2752 # implemented as a fitter method. 2688 2753 workscan._auto_cspline_baseline(mask, npiece, clipthresh, 2689 2754 clipniter, … … 2747 2812 workscan = self.copy() 2748 2813 2749 if mask is None: mask = [True for i in\2750 2814 if mask is None: mask = \ 2815 [True for i in xrange(workscan.nchan())] 2751 2816 if order is None: order = 0 2752 2817 if plot is None: plot = False … … 2883 2948 workscan = self.copy() 2884 2949 2885 if mask is None: mask = [True for i in xrange(workscan.nchan())] 2950 if mask is None: mask = \ 2951 [True for i in xrange(workscan.nchan())] 2886 2952 if order is None: order = 0 2887 2953 if edge is None: edge = (0, 0) … … 3295 3361 s = scantable(self._math._unaryop(self, other, "SUB", False)) 3296 3362 elif isinstance(other, list) or isinstance(other, numpy.ndarray): 3297 if isinstance(other[0], list) or isinstance(other[0], numpy.ndarray): 3363 if isinstance(other[0], list) or isinstance(other[0], 3364 numpy.ndarray): 3298 3365 from asapmath import _array2dOp 3299 3366 s = _array2dOp( self.copy(), other, "SUB", False ) 3300 3367 else: 3301 s = scantable( self._math._arrayop( self.copy(), other, "SUB", False ) ) 3368 s = scantable( self._math._arrayop( self.copy(), other, 3369 "SUB", False ) ) 3302 3370 else: 3303 3371 raise TypeError("Other input is not a scantable or float value") … … 3317 3385 s = scantable(self._math._unaryop(self, other, "MUL", False)) 3318 3386 elif isinstance(other, list) or isinstance(other, numpy.ndarray): 3319 if isinstance(other[0], list) or isinstance(other[0], numpy.ndarray): 3387 if isinstance(other[0], list) or isinstance(other[0], 3388 numpy.ndarray): 3320 3389 from asapmath import _array2dOp 3321 3390 s = _array2dOp( self.copy(), other, "MUL", False ) 3322 3391 else: 3323 s = scantable( self._math._arrayop( self.copy(), other, "MUL", False ) ) 3392 s = scantable( self._math._arrayop( self.copy(), other, 3393 "MUL", False ) ) 3324 3394 else: 3325 3395 raise TypeError("Other input is not a scantable or float value") … … 3342 3412 s = scantable(self._math._unaryop(self, other, "DIV", False)) 3343 3413 elif isinstance(other, list) or isinstance(other, numpy.ndarray): 3344 if isinstance(other[0], list) or isinstance(other[0], numpy.ndarray): 3414 if isinstance(other[0], list) or isinstance(other[0], 3415 numpy.ndarray): 3345 3416 from asapmath import _array2dOp 3346 3417 s = _array2dOp( self.copy(), other, "DIV", False ) 3347 3418 else: 3348 s = scantable( self._math._arrayop( self.copy(), other, "DIV", False ) ) 3419 s = scantable( self._math._arrayop( self.copy(), other, 3420 "DIV", False ) ) 3349 3421 else: 3350 3422 raise TypeError("Other input is not a scantable or float value")
Note:
See TracChangeset
for help on using the changeset viewer.