Changeset 2189
- Timestamp:
- 06/09/11 19:17:30 (13 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r2186 r2189 169 169 else: 170 170 raise RuntimeError(str(e)+'\n'+msg) 171 171 172 def pack_progress_params(showprogress, minnrow): 173 return str(showprogress).lower() + ',' + str(minnrow) 172 174 173 175 class scantable(Scantable): … … 2291 2293 def sinusoid_baseline(self, insitu=None, mask=None, applyfft=None, fftmethod=None, fftthresh=None, 2292 2294 addwn=None, rejwn=None, clipthresh=None, clipniter=None, plot=None, 2293 getresidual=None, outlog=None, blfile=None):2295 getresidual=None, showprogress=None, minnrow=None, outlog=None, blfile=None): 2294 2296 """\ 2295 2297 Return a scan which has been baselined (all rows) with sinusoidal functions. … … 2336 2338 getresidual: if False, returns best-fit values instead of 2337 2339 residual. (default is True) 2340 showprogress: show progress status for large data. 2341 default is True. 2342 minnrow: minimum number of input spectra to show. 2343 default is 1000. 2338 2344 outlog: Output the coefficients of the best-fit 2339 2345 function to logger (default is False) … … 2372 2378 if plot is None: plot = False 2373 2379 if getresidual is None: getresidual = True 2380 if showprogress is None: showprogress = True 2381 if minnrow is None: minnrow = 1000 2374 2382 if outlog is None: outlog = False 2375 2383 if blfile is None: blfile = '' 2376 2384 2377 2385 #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method. 2378 workscan._sinusoid_baseline(mask, applyfft, fftmethod.lower(), str(fftthresh).lower(), workscan._parse_wn(addwn), workscan._parse_wn(rejwn), clipthresh, clipniter, getresidual, outlog, blfile)2386 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) 2379 2387 workscan._add_history('sinusoid_baseline', varlist) 2380 2388 … … 2391 2399 def auto_sinusoid_baseline(self, insitu=None, mask=None, applyfft=None, fftmethod=None, fftthresh=None, 2392 2400 addwn=None, rejwn=None, clipthresh=None, clipniter=None, edge=None, threshold=None, 2393 chan_avg_limit=None, plot=None, getresidual=None, outlog=None, blfile=None): 2401 chan_avg_limit=None, plot=None, getresidual=None, showprogress=None, minnrow=None, 2402 outlog=None, blfile=None): 2394 2403 """\ 2395 2404 Return a scan which has been baselined (all rows) with sinusoidal functions. … … 2398 2407 2399 2408 Parameters: 2400 insitu: if False a new scantable is returned. 2401 Otherwise, the scaling is done in-situ 2402 The default is taken from .asaprc (False) 2403 mask: an optional mask retreived from scantable 2404 applyfft: if True use some method, such as FFT, to find 2405 strongest sinusoidal components in the wavenumber 2406 domain to be used for baseline fitting. 2407 default is True. 2408 fftmethod: method to find the strong sinusoidal components. 2409 now only 'fft' is available and it is the default. 2410 fftthresh: the threshold to select wave numbers to be used for 2411 fitting from the distribution of amplitudes in the 2412 wavenumber domain. 2413 both float and string values accepted. 2414 given a float value, the unit is set to sigma. 2415 for string values, allowed formats include: 2416 'xsigma' or 'x' (= x-sigma level. e.g., '3sigma'), or 2417 'topx' (= the x strongest ones, e.g. 'top5'). 2418 default is 3.0 (unit: sigma). 2419 addwn: the additional wave numbers to be used for fitting. 2420 list or integer value is accepted to specify every 2421 wave numbers. also string value can be used in case 2422 you need to specify wave numbers in a certain range, 2423 e.g., 'a-b' (= a, a+1, a+2, ..., b-1, b), 2424 '<a' (= 0,1,...,a-2,a-1), 2425 '>=a' (= a, a+1, ... up to the maximum wave 2426 number corresponding to the Nyquist 2427 frequency for the case of FFT). 2428 default is []. 2429 rejwn: the wave numbers NOT to be used for fitting. 2430 can be set just as addwn but has higher priority: 2431 wave numbers which are specified both in addwn 2432 and rejwn will NOT be used. default is []. 2433 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 2434 clipniter: maximum number of iteration of 'clipthresh'-sigma clipping (default is 0) 2435 edge: an optional number of channel to drop at 2436 the edge of spectrum. If only one value is 2437 specified, the same number will be dropped 2438 from both sides of the spectrum. Default 2439 is to keep all channels. Nested tuples 2440 represent individual edge selection for 2441 different IFs (a number of spectral channels 2442 can be different) 2443 threshold: the threshold used by line finder. It is 2444 better to keep it large as only strong lines 2445 affect the baseline solution. 2446 chan_avg_limit:a maximum number of consequtive spectral 2447 channels to average during the search of 2448 weak and broad lines. The default is no 2449 averaging (and no search for weak lines). 2450 If such lines can affect the fitted baseline 2451 (e.g. a high order polynomial is fitted), 2452 increase this parameter (usually values up 2453 to 8 are reasonable). Most users of this 2454 method should find the default value sufficient. 2455 plot: *** CURRENTLY UNAVAILABLE, ALWAYS FALSE *** 2456 plot the fit and the residual. In this each 2457 indivual fit has to be approved, by typing 'y' 2458 or 'n' 2459 getresidual: if False, returns best-fit values instead of 2460 residual. (default is True) 2461 outlog: Output the coefficients of the best-fit 2462 function to logger (default is False) 2463 blfile: Name of a text file in which the best-fit 2464 parameter values to be written 2465 (default is "": no file/logger output) 2409 insitu: if False a new scantable is returned. 2410 Otherwise, the scaling is done in-situ 2411 The default is taken from .asaprc (False) 2412 mask: an optional mask retreived from scantable 2413 applyfft: if True use some method, such as FFT, to find 2414 strongest sinusoidal components in the wavenumber 2415 domain to be used for baseline fitting. 2416 default is True. 2417 fftmethod: method to find the strong sinusoidal components. 2418 now only 'fft' is available and it is the default. 2419 fftthresh: the threshold to select wave numbers to be used for 2420 fitting from the distribution of amplitudes in the 2421 wavenumber domain. 2422 both float and string values accepted. 2423 given a float value, the unit is set to sigma. 2424 for string values, allowed formats include: 2425 'xsigma' or 'x' (= x-sigma level. e.g., '3sigma'), or 2426 'topx' (= the x strongest ones, e.g. 'top5'). 2427 default is 3.0 (unit: sigma). 2428 addwn: the additional wave numbers to be used for fitting. 2429 list or integer value is accepted to specify every 2430 wave numbers. also string value can be used in case 2431 you need to specify wave numbers in a certain range, 2432 e.g., 'a-b' (= a, a+1, a+2, ..., b-1, b), 2433 '<a' (= 0,1,...,a-2,a-1), 2434 '>=a' (= a, a+1, ... up to the maximum wave 2435 number corresponding to the Nyquist 2436 frequency for the case of FFT). 2437 default is []. 2438 rejwn: the wave numbers NOT to be used for fitting. 2439 can be set just as addwn but has higher priority: 2440 wave numbers which are specified both in addwn 2441 and rejwn will NOT be used. default is []. 2442 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 2443 clipniter: maximum number of iteration of 'clipthresh'-sigma clipping (default is 0) 2444 edge: an optional number of channel to drop at 2445 the edge of spectrum. If only one value is 2446 specified, the same number will be dropped 2447 from both sides of the spectrum. Default 2448 is to keep all channels. Nested tuples 2449 represent individual edge selection for 2450 different IFs (a number of spectral channels 2451 can be different) 2452 threshold: the threshold used by line finder. It is 2453 better to keep it large as only strong lines 2454 affect the baseline solution. 2455 chan_avg_limit: a maximum number of consequtive spectral 2456 channels to average during the search of 2457 weak and broad lines. The default is no 2458 averaging (and no search for weak lines). 2459 If such lines can affect the fitted baseline 2460 (e.g. a high order polynomial is fitted), 2461 increase this parameter (usually values up 2462 to 8 are reasonable). Most users of this 2463 method should find the default value sufficient. 2464 plot: *** CURRENTLY UNAVAILABLE, ALWAYS FALSE *** 2465 plot the fit and the residual. In this each 2466 indivual fit has to be approved, by typing 'y' 2467 or 'n' 2468 getresidual: if False, returns best-fit values instead of 2469 residual. (default is True) 2470 showprogress: show progress status for large data. 2471 default is True. 2472 minnrow: minimum number of input spectra to show. 2473 default is 1000. 2474 outlog: Output the coefficients of the best-fit 2475 function to logger (default is False) 2476 blfile: Name of a text file in which the best-fit 2477 parameter values to be written 2478 (default is "": no file/logger output) 2466 2479 2467 2480 Example: … … 2495 2508 if plot is None: plot = False 2496 2509 if getresidual is None: getresidual = True 2510 if showprogress is None: showprogress = True 2511 if minnrow is None: minnrow = 1000 2497 2512 if outlog is None: outlog = False 2498 2513 if blfile is None: blfile = '' 2499 2514 2500 2515 #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method. 2501 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, outlog, blfile)2516 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) 2502 2517 workscan._add_history("auto_sinusoid_baseline", varlist) 2503 2518 … … 2511 2526 2512 2527 @asaplog_post_dec 2513 def cspline_baseline(self, insitu=None, mask=None, npiece=None, 2514 clipthresh=None, clipniter=None, plot=None, getresidual=None, outlog=None, blfile=None):2528 def cspline_baseline(self, insitu=None, mask=None, npiece=None, clipthresh=None, clipniter=None, 2529 plot=None, getresidual=None, showprogress=None, minnrow=None, outlog=None, blfile=None): 2515 2530 """\ 2516 2531 Return a scan which has been baselined (all rows) by cubic spline function (piecewise cubic polynomial). 2517 2532 Parameters: 2518 insitu: If False a new scantable is returned. 2519 Otherwise, the scaling is done in-situ 2520 The default is taken from .asaprc (False) 2521 mask: An optional mask 2522 npiece: Number of pieces. (default is 2) 2523 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 2524 clipniter: maximum number of iteration of 'clipthresh'-sigma clipping (default is 0) 2525 plot: *** CURRENTLY UNAVAILABLE, ALWAYS FALSE *** 2526 plot the fit and the residual. In this each 2527 indivual fit has to be approved, by typing 'y' 2528 or 'n' 2529 getresidual:if False, returns best-fit values instead of 2530 residual. (default is True) 2531 outlog: Output the coefficients of the best-fit 2532 function to logger (default is False) 2533 blfile: Name of a text file in which the best-fit 2534 parameter values to be written 2535 (default is "": no file/logger output) 2533 insitu: If False a new scantable is returned. 2534 Otherwise, the scaling is done in-situ 2535 The default is taken from .asaprc (False) 2536 mask: An optional mask 2537 npiece: Number of pieces. (default is 2) 2538 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 2539 clipniter: maximum number of iteration of 'clipthresh'-sigma clipping (default is 0) 2540 plot: *** CURRENTLY UNAVAILABLE, ALWAYS FALSE *** 2541 plot the fit and the residual. In this each 2542 indivual fit has to be approved, by typing 'y' 2543 or 'n' 2544 getresidual: if False, returns best-fit values instead of 2545 residual. (default is True) 2546 showprogress: show progress status for large data. 2547 default is True. 2548 minnrow: minimum number of input spectra to show. 2549 default is 1000. 2550 outlog: Output the coefficients of the best-fit 2551 function to logger (default is False) 2552 blfile: Name of a text file in which the best-fit 2553 parameter values to be written 2554 (default is "": no file/logger output) 2536 2555 2537 2556 Example: … … 2554 2573 workscan = self.copy() 2555 2574 2556 if mask is None: mask = [True for i in xrange(workscan.nchan())] 2557 if npiece is None: npiece = 2 2558 if clipthresh is None: clipthresh = 3.0 2559 if clipniter is None: clipniter = 0 2560 if plot is None: plot = False 2561 if getresidual is None: getresidual = True 2562 if outlog is None: outlog = False 2563 if blfile is None: blfile = '' 2575 if mask is None: mask = [True for i in xrange(workscan.nchan())] 2576 if npiece is None: npiece = 2 2577 if clipthresh is None: clipthresh = 3.0 2578 if clipniter is None: clipniter = 0 2579 if plot is None: plot = False 2580 if getresidual is None: getresidual = True 2581 if showprogress is None: showprogress = True 2582 if minnrow is None: minnrow = 1000 2583 if outlog is None: outlog = False 2584 if blfile is None: blfile = '' 2564 2585 2565 2586 #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method. 2566 workscan._cspline_baseline(mask, npiece, clipthresh, clipniter, getresidual, outlog, blfile)2587 workscan._cspline_baseline(mask, npiece, clipthresh, clipniter, getresidual, pack_progress_params(showprogress, minnrow), outlog, blfile) 2567 2588 workscan._add_history("cspline_baseline", varlist) 2568 2589 … … 2576 2597 2577 2598 @asaplog_post_dec 2578 def auto_cspline_baseline(self, insitu=None, mask=None, npiece=None, clipthresh=None, 2579 clipniter=None, edge=None, threshold=None,2580 chan_avg_limit=None, getresidual=None, plot=None, outlog=None, blfile=None):2599 def auto_cspline_baseline(self, insitu=None, mask=None, npiece=None, clipthresh=None, clipniter=None, 2600 edge=None, threshold=None, chan_avg_limit=None, getresidual=None, plot=None, 2601 showprogress=None, minnrow=None, outlog=None, blfile=None): 2581 2602 """\ 2582 2603 Return a scan which has been baselined (all rows) by cubic spline … … 2586 2607 2587 2608 Parameters: 2588 insitu: if False a new scantable is returned. 2589 Otherwise, the scaling is done in-situ 2590 The default is taken from .asaprc (False) 2591 mask: an optional mask retreived from scantable 2592 npiece: Number of pieces. (default is 2) 2593 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 2594 clipniter: maximum number of iteration of 'clipthresh'-sigma clipping (default is 0) 2595 edge: an optional number of channel to drop at 2596 the edge of spectrum. If only one value is 2597 specified, the same number will be dropped 2598 from both sides of the spectrum. Default 2599 is to keep all channels. Nested tuples 2600 represent individual edge selection for 2601 different IFs (a number of spectral channels 2602 can be different) 2603 threshold: the threshold used by line finder. It is 2604 better to keep it large as only strong lines 2605 affect the baseline solution. 2606 chan_avg_limit: 2607 a maximum number of consequtive spectral 2608 channels to average during the search of 2609 weak and broad lines. The default is no 2610 averaging (and no search for weak lines). 2611 If such lines can affect the fitted baseline 2612 (e.g. a high order polynomial is fitted), 2613 increase this parameter (usually values up 2614 to 8 are reasonable). Most users of this 2615 method should find the default value sufficient. 2616 plot: *** CURRENTLY UNAVAILABLE, ALWAYS FALSE *** 2617 plot the fit and the residual. In this each 2618 indivual fit has to be approved, by typing 'y' 2619 or 'n' 2620 getresidual:if False, returns best-fit values instead of 2621 residual. (default is True) 2622 outlog: Output the coefficients of the best-fit 2623 function to logger (default is False) 2624 blfile: Name of a text file in which the best-fit 2625 parameter values to be written 2626 (default is "": no file/logger output) 2609 insitu: if False a new scantable is returned. 2610 Otherwise, the scaling is done in-situ 2611 The default is taken from .asaprc (False) 2612 mask: an optional mask retreived from scantable 2613 npiece: Number of pieces. (default is 2) 2614 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 2615 clipniter: maximum number of iteration of 'clipthresh'-sigma clipping (default is 0) 2616 edge: an optional number of channel to drop at 2617 the edge of spectrum. If only one value is 2618 specified, the same number will be dropped 2619 from both sides of the spectrum. Default 2620 is to keep all channels. Nested tuples 2621 represent individual edge selection for 2622 different IFs (a number of spectral channels 2623 can be different) 2624 threshold: the threshold used by line finder. It is 2625 better to keep it large as only strong lines 2626 affect the baseline solution. 2627 chan_avg_limit: a maximum number of consequtive spectral 2628 channels to average during the search of 2629 weak and broad lines. The default is no 2630 averaging (and no search for weak lines). 2631 If such lines can affect the fitted baseline 2632 (e.g. a high order polynomial is fitted), 2633 increase this parameter (usually values up 2634 to 8 are reasonable). Most users of this 2635 method should find the default value sufficient. 2636 plot: *** CURRENTLY UNAVAILABLE, ALWAYS FALSE *** 2637 plot the fit and the residual. In this each 2638 indivual fit has to be approved, by typing 'y' 2639 or 'n' 2640 getresidual: if False, returns best-fit values instead of 2641 residual. (default is True) 2642 showprogress: show progress status for large data. 2643 default is True. 2644 minnrow: minimum number of input spectra to show. 2645 default is 1000. 2646 outlog: Output the coefficients of the best-fit 2647 function to logger (default is False) 2648 blfile: Name of a text file in which the best-fit 2649 parameter values to be written 2650 (default is "": no file/logger output) 2627 2651 2628 2652 Example: … … 2652 2676 if plot is None: plot = False 2653 2677 if getresidual is None: getresidual = True 2678 if showprogress is None: showprogress = True 2679 if minnrow is None: minnrow = 1000 2654 2680 if outlog is None: outlog = False 2655 2681 if blfile is None: blfile = '' 2656 2682 2657 2683 #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method. 2658 workscan._auto_cspline_baseline(mask, npiece, clipthresh, clipniter, normalise_edge_param(edge), threshold, chan_avg_limit, getresidual, outlog, blfile)2684 workscan._auto_cspline_baseline(mask, npiece, clipthresh, clipniter, normalise_edge_param(edge), threshold, chan_avg_limit, getresidual, pack_progress_params(showprogress, minnrow), outlog, blfile) 2659 2685 workscan._add_history("auto_cspline_baseline", varlist) 2660 2686 … … 2668 2694 2669 2695 @asaplog_post_dec 2670 def poly_baseline(self, insitu=None, mask=None, order=None, plot=None, getresidual=None, outlog=None, blfile=None): 2696 def poly_baseline(self, insitu=None, mask=None, order=None, plot=None, getresidual=None, 2697 showprogress=None, minnrow=None, outlog=None, blfile=None): 2671 2698 """\ 2672 2699 Return a scan which has been baselined (all rows) by a polynomial. 2673 2700 Parameters: 2674 insitu: if False a new scantable is returned. 2675 Otherwise, the scaling is done in-situ 2676 The default is taken from .asaprc (False) 2677 mask: an optional mask 2678 order: the order of the polynomial (default is 0) 2679 plot: plot the fit and the residual. In this each 2680 indivual fit has to be approved, by typing 'y' 2681 or 'n' 2682 getresidual:if False, returns best-fit values instead of 2683 residual. (default is True) 2684 outlog: Output the coefficients of the best-fit 2685 function to logger (default is False) 2686 blfile: Name of a text file in which the best-fit 2687 parameter values to be written 2688 (default is "": no file/logger output) 2701 insitu: if False a new scantable is returned. 2702 Otherwise, the scaling is done in-situ 2703 The default is taken from .asaprc (False) 2704 mask: an optional mask 2705 order: the order of the polynomial (default is 0) 2706 plot: plot the fit and the residual. In this each 2707 indivual fit has to be approved, by typing 'y' 2708 or 'n' 2709 getresidual: if False, returns best-fit values instead of 2710 residual. (default is True) 2711 showprogress: show progress status for large data. 2712 default is True. 2713 minnrow: minimum number of input spectra to show. 2714 default is 1000. 2715 outlog: Output the coefficients of the best-fit 2716 function to logger (default is False) 2717 blfile: Name of a text file in which the best-fit 2718 parameter values to be written 2719 (default is "": no file/logger output) 2689 2720 2690 2721 Example: … … 2703 2734 workscan = self.copy() 2704 2735 2705 if mask is None: mask = [True for i in xrange(workscan.nchan())] 2706 if order is None: order = 0 2707 if plot is None: plot = False 2708 if getresidual is None: getresidual = True 2709 if outlog is None: outlog = False 2710 if blfile is None: blfile = "" 2736 if mask is None: mask = [True for i in xrange(workscan.nchan())] 2737 if order is None: order = 0 2738 if plot is None: plot = False 2739 if getresidual is None: getresidual = True 2740 if showprogress is None: showprogress = True 2741 if minnrow is None: minnrow = 1000 2742 if outlog is None: outlog = False 2743 if blfile is None: blfile = "" 2711 2744 2712 2745 if plot: … … 2748 2781 if outblfile: blf.close() 2749 2782 else: 2750 workscan._poly_baseline(mask, order, getresidual, outlog, blfile)2783 workscan._poly_baseline(mask, order, getresidual, pack_progress_params(showprogress, minnrow), outlog, blfile) 2751 2784 2752 2785 workscan._add_history("poly_baseline", varlist) … … 2761 2794 2762 2795 @asaplog_post_dec 2763 def auto_poly_baseline(self, insitu=None, mask=None, order=None, edge=None, threshold=None, 2764 chan_avg_limit=None, plot=None, getresidual=None, outlog=None, blfile=None):2796 def auto_poly_baseline(self, insitu=None, mask=None, order=None, edge=None, threshold=None, chan_avg_limit=None, 2797 plot=None, getresidual=None, showprogress=None, minnrow=None, outlog=None, blfile=None): 2765 2798 """\ 2766 2799 Return a scan which has been baselined (all rows) by a polynomial. … … 2769 2802 2770 2803 Parameters: 2771 insitu: if False a new scantable is returned. 2772 Otherwise, the scaling is done in-situ 2773 The default is taken from .asaprc (False) 2774 mask: an optional mask retreived from scantable 2775 order: the order of the polynomial (default is 0) 2776 edge: an optional number of channel to drop at 2777 the edge of spectrum. If only one value is 2778 specified, the same number will be dropped 2779 from both sides of the spectrum. Default 2780 is to keep all channels. Nested tuples 2781 represent individual edge selection for 2782 different IFs (a number of spectral channels 2783 can be different) 2784 threshold: the threshold used by line finder. It is 2785 better to keep it large as only strong lines 2786 affect the baseline solution. 2787 chan_avg_limit: 2788 a maximum number of consequtive spectral 2789 channels to average during the search of 2790 weak and broad lines. The default is no 2791 averaging (and no search for weak lines). 2792 If such lines can affect the fitted baseline 2793 (e.g. a high order polynomial is fitted), 2794 increase this parameter (usually values up 2795 to 8 are reasonable). Most users of this 2796 method should find the default value sufficient. 2797 plot: plot the fit and the residual. In this each 2798 indivual fit has to be approved, by typing 'y' 2799 or 'n' 2800 getresidual:if False, returns best-fit values instead of 2801 residual. (default is True) 2802 outlog: Output the coefficients of the best-fit 2803 function to logger (default is False) 2804 blfile: Name of a text file in which the best-fit 2805 parameter values to be written 2806 (default is "": no file/logger output) 2804 insitu: if False a new scantable is returned. 2805 Otherwise, the scaling is done in-situ 2806 The default is taken from .asaprc (False) 2807 mask: an optional mask retreived from scantable 2808 order: the order of the polynomial (default is 0) 2809 edge: an optional number of channel to drop at 2810 the edge of spectrum. If only one value is 2811 specified, the same number will be dropped 2812 from both sides of the spectrum. Default 2813 is to keep all channels. Nested tuples 2814 represent individual edge selection for 2815 different IFs (a number of spectral channels 2816 can be different) 2817 threshold: the threshold used by line finder. It is 2818 better to keep it large as only strong lines 2819 affect the baseline solution. 2820 chan_avg_limit: a maximum number of consequtive spectral 2821 channels to average during the search of 2822 weak and broad lines. The default is no 2823 averaging (and no search for weak lines). 2824 If such lines can affect the fitted baseline 2825 (e.g. a high order polynomial is fitted), 2826 increase this parameter (usually values up 2827 to 8 are reasonable). Most users of this 2828 method should find the default value sufficient. 2829 plot: plot the fit and the residual. In this each 2830 indivual fit has to be approved, by typing 'y' 2831 or 'n' 2832 getresidual: if False, returns best-fit values instead of 2833 residual. (default is True) 2834 showprogress: show progress status for large data. 2835 default is True. 2836 minnrow: minimum number of input spectra to show. 2837 default is 1000. 2838 outlog: Output the coefficients of the best-fit 2839 function to logger (default is False) 2840 blfile: Name of a text file in which the best-fit 2841 parameter values to be written 2842 (default is "": no file/logger output) 2807 2843 2808 2844 Example: … … 2826 2862 if plot is None: plot = False 2827 2863 if getresidual is None: getresidual = True 2864 if showprogress is None: showprogress = True 2865 if minnrow is None: minnrow = 1000 2828 2866 if outlog is None: outlog = False 2829 2867 if blfile is None: blfile = '' … … 2877 2915 if outblfile: blf.close() 2878 2916 else: 2879 workscan._auto_poly_baseline(mask, order, edge, threshold, chan_avg_limit, getresidual, outlog, blfile)2917 workscan._auto_poly_baseline(mask, order, edge, threshold, chan_avg_limit, getresidual, pack_progress_params(showprogress, minnrow), outlog, blfile) 2880 2918 2881 2919 workscan._add_history("auto_poly_baseline", varlist) -
trunk/src/Scantable.cpp
r2186 r2189 1817 1817 } 1818 1818 1819 void Scantable::polyBaseline(const std::vector<bool>& mask, int order, bool getResidual, bool outLogger, const std::string& blfile)1819 void Scantable::polyBaseline(const std::vector<bool>& mask, int order, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile) 1820 1820 { 1821 1821 ofstream ofs; … … 1841 1841 int nRow = nrow(); 1842 1842 std::vector<bool> chanMask; 1843 bool showProgress; 1844 int minNRow; 1845 parseProgressInfo(progressInfo, showProgress, minNRow); 1843 1846 1844 1847 for (int whichrow = 0; whichrow < nRow; ++whichrow) { … … 1847 1850 setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow); 1848 1851 outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "polyBaseline()", fitter); 1849 showProgressOnTerminal(whichrow, nRow );1852 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 1850 1853 } 1851 1854 … … 1853 1856 } 1854 1857 1855 void Scantable::autoPolyBaseline(const std::vector<bool>& mask, int order, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool getResidual, bool outLogger, const std::string& blfile)1858 void Scantable::autoPolyBaseline(const std::vector<bool>& mask, int order, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile) 1856 1859 { 1857 1860 ofstream ofs; … … 1880 1883 STLineFinder lineFinder = STLineFinder(); 1881 1884 lineFinder.setOptions(threshold, 3, chanAvgLimit); 1885 1886 bool showProgress; 1887 int minNRow; 1888 parseProgressInfo(progressInfo, showProgress, minNRow); 1882 1889 1883 1890 for (int whichrow = 0; whichrow < nRow; ++whichrow) { … … 1910 1917 1911 1918 outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoPolyBaseline()", fitter); 1912 showProgressOnTerminal(whichrow, nRow );1919 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 1913 1920 } 1914 1921 … … 1916 1923 } 1917 1924 1918 void Scantable::cubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, bool getResidual, bool outLogger, const std::string& blfile)1925 void Scantable::cubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile) 1919 1926 { 1920 1927 ofstream ofs; … … 1940 1947 int nRow = nrow(); 1941 1948 std::vector<bool> chanMask; 1949 bool showProgress; 1950 int minNRow; 1951 parseProgressInfo(progressInfo, showProgress, minNRow); 1942 1952 1943 1953 for (int whichrow = 0; whichrow < nRow; ++whichrow) { … … 1952 1962 1953 1963 outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "cubicSplineBaseline()", pieceEdges, params); 1954 showProgressOnTerminal(whichrow, nRow );1964 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 1955 1965 } 1956 1966 … … 1958 1968 } 1959 1969 1960 void Scantable::autoCubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool getResidual, bool outLogger, const std::string& blfile)1970 void Scantable::autoCubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile) 1961 1971 { 1962 1972 ofstream ofs; … … 1985 1995 STLineFinder lineFinder = STLineFinder(); 1986 1996 lineFinder.setOptions(threshold, 3, chanAvgLimit); 1997 1998 bool showProgress; 1999 int minNRow; 2000 parseProgressInfo(progressInfo, showProgress, minNRow); 1987 2001 1988 2002 for (int whichrow = 0; whichrow < nRow; ++whichrow) { … … 2021 2035 2022 2036 outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoCubicSplineBaseline()", pieceEdges, params); 2023 showProgressOnTerminal(whichrow, nRow );2037 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 2024 2038 } 2025 2039 … … 2370 2384 } 2371 2385 2372 void Scantable::sinusoidBaseline(const std::vector<bool>& mask, const bool applyFFT, const std::string& fftMethod, const std::string& fftThresh, const std::vector<int>& addNWaves, const std::vector<int>& rejectNWaves, float thresClip, int nIterClip, bool getResidual, bool outLogger, const std::string& blfile)2386 void Scantable::sinusoidBaseline(const std::vector<bool>& mask, const bool applyFFT, const std::string& fftMethod, const std::string& fftThresh, const std::vector<int>& addNWaves, const std::vector<int>& rejectNWaves, float thresClip, int nIterClip, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile) 2373 2387 { 2374 2388 ofstream ofs; … … 2395 2409 std::vector<bool> chanMask; 2396 2410 std::vector<int> nWaves; 2411 2412 bool showProgress; 2413 int minNRow; 2414 parseProgressInfo(progressInfo, showProgress, minNRow); 2397 2415 2398 2416 for (int whichrow = 0; whichrow < nRow; ++whichrow) { … … 2422 2440 2423 2441 outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "sinusoidBaseline()", params); 2424 showProgressOnTerminal(whichrow, nRow );2442 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 2425 2443 } 2426 2444 … … 2428 2446 } 2429 2447 2430 void Scantable::autoSinusoidBaseline(const std::vector<bool>& mask, const bool applyFFT, const std::string& fftMethod, const std::string& fftThresh, const std::vector<int>& addNWaves, const std::vector<int>& rejectNWaves, float thresClip, int nIterClip, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool getResidual, bool outLogger, const std::string& blfile)2448 void Scantable::autoSinusoidBaseline(const std::vector<bool>& mask, const bool applyFFT, const std::string& fftMethod, const std::string& fftThresh, const std::vector<int>& addNWaves, const std::vector<int>& rejectNWaves, float thresClip, int nIterClip, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile) 2431 2449 { 2432 2450 ofstream ofs; … … 2457 2475 STLineFinder lineFinder = STLineFinder(); 2458 2476 lineFinder.setOptions(threshold, 3, chanAvgLimit); 2477 2478 bool showProgress; 2479 int minNRow; 2480 parseProgressInfo(progressInfo, showProgress, minNRow); 2459 2481 2460 2482 for (int whichrow = 0; whichrow < nRow; ++whichrow) { … … 2493 2515 2494 2516 outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoSinusoidBaseline()", params); 2495 showProgressOnTerminal(whichrow, nRow );2517 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 2496 2518 } 2497 2519 … … 2815 2837 } 2816 2838 2817 void Scantable::showProgressOnTerminal(const int nProcessed, const int nTotal, const int nTotalThreshold) 2818 { 2819 if (nTotal >= nTotalThreshold) { 2839 void Scantable::parseProgressInfo(const std::string& progressInfo, bool& showProgress, int& minNRow) 2840 { 2841 int idxDelimiter = progressInfo.find(","); 2842 if (idxDelimiter < 0) { 2843 throw(AipsError("wrong value in 'showprogress' parameter")) ; 2844 } 2845 showProgress = (progressInfo.substr(0, idxDelimiter) == "true"); 2846 std::istringstream is(progressInfo.substr(idxDelimiter+1)); 2847 is >> minNRow; 2848 } 2849 2850 void Scantable::showProgressOnTerminal(const int nProcessed, const int nTotal, const bool showProgress, const int nTotalThreshold) 2851 { 2852 if (showProgress && (nTotal >= nTotalThreshold)) { 2820 2853 int nInterval = int(floor(double(nTotal)/100.0)); 2821 2854 if (nInterval == 0) nInterval++; … … 2824 2857 printf("\x1b[31m\x1b[1m"); //set red color, highlighted 2825 2858 printf("[ 0%%]"); 2826 printf("\x1b[39m\x1b[0m"); // default attributes2859 printf("\x1b[39m\x1b[0m"); //set default attributes 2827 2860 fflush(NULL); 2828 2861 } else if (nProcessed % nInterval == 0) { 2829 printf("\r \x1b[1C"); //go to the 2nd column2862 printf("\r"); //go to the head of line 2830 2863 printf("\x1b[31m\x1b[1m"); //set red color, highlighted 2831 printf("%3d", (int)(100.0*(double(nProcessed+1))/(double(nTotal))) ); 2832 printf("\x1b[39m\x1b[0m"); //default attributes 2833 printf("\x1b[2C"); //go to the end of line 2864 printf("[%3d%%]", (int)(100.0*(double(nProcessed+1))/(double(nTotal))) ); 2865 printf("\x1b[39m\x1b[0m"); //set default attributes 2834 2866 fflush(NULL); 2835 2867 } -
trunk/src/Scantable.h
r2186 r2189 502 502 int order, 503 503 bool getResidual=true, 504 bool outLogger=false, 504 const std::string& progressInfo="true,1000", 505 const bool outLogger=false, 505 506 const std::string& blfile=""); 506 507 void autoPolyBaseline(const std::vector<bool>& mask, … … 510 511 int chanAvgLimit=1, 511 512 bool getResidual=true, 512 bool outLogger=false, 513 const std::string& progressInfo="true,1000", 514 const bool outLogger=false, 513 515 const std::string& blfile=""); 514 516 void cubicSplineBaseline(const std::vector<bool>& mask, … … 517 519 int nIterClip, 518 520 bool getResidual=true, 519 bool outLogger=false, 521 const std::string& progressInfo="true,1000", 522 const bool outLogger=false, 520 523 const std::string& blfile=""); 521 524 void autoCubicSplineBaseline(const std::vector<bool>& mask, … … 527 530 int chanAvgLimit=1, 528 531 bool getResidual=true, 529 bool outLogger=false, 532 const std::string& progressInfo="true,1000", 533 const bool outLogger=false, 530 534 const std::string& blfile=""); 531 535 void sinusoidBaseline(const std::vector<bool>& mask, … … 538 542 int nIterClip, 539 543 bool getResidual=true, 540 bool outLogger=false, 544 const std::string& progressInfo="true,1000", 545 const bool outLogger=false, 541 546 const std::string& blfile=""); 542 547 void autoSinusoidBaseline(const std::vector<bool>& mask, … … 552 557 int chanAvgLimit=1, 553 558 bool getResidual=true, 554 bool outLogger=false, 559 const std::string& progressInfo="true,1000", 560 const bool outLogger=false, 555 561 const std::string& blfile=""); 556 562 std::vector<float> execFFT(const int whichrow, … … 741 747 void outputFittingResult(bool outLogger, bool outTextFile, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, std::ofstream& ofs, const casa::String& funcName, const std::vector<int>& edge, const std::vector<float>& params); 742 748 void outputFittingResult(bool outLogger, bool outTextFile, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, std::ofstream& ofs, const casa::String& funcName, const std::vector<float>& params); 743 void showProgressOnTerminal(const int nProcessed, const int nTotal, const int nTotalThreshold=1000); 749 void parseProgressInfo(const std::string& progressInfo, bool& showProgress, int& minNRow); 750 void showProgressOnTerminal(const int nProcessed, const int nTotal, const bool showProgress=true, const int nTotalThreshold=1000); 744 751 745 752 void applyChanFlag( casa::uInt whichrow, const std::vector<bool>& msk, casa::uChar flagval); -
trunk/src/ScantableWrapper.h
r2186 r2189 264 264 { table_->reshapeSpectrum( nmin, nmax ); } 265 265 266 void polyBaseline(const std::vector<bool>& mask, int order, bool getresidual=true, bool outlog=false, const std::string& blfile="")267 { table_->polyBaseline(mask, order, getresidual, outlog, blfile); }268 269 void autoPolyBaseline(const std::vector<bool>& mask, int order, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool getresidual=true, bool outlog=false, const std::string& blfile="")270 { table_->autoPolyBaseline(mask, order, edge, threshold, chan_avg_limit, getresidual, outlog, blfile); }271 272 void cubicSplineBaseline(const std::vector<bool>& mask, int npiece, float clipthresh, int clipniter, bool getresidual=true, bool outlog=false, const std::string& blfile="")273 { table_->cubicSplineBaseline(mask, npiece, clipthresh, clipniter, getresidual, outlog, blfile); }274 275 void autoCubicSplineBaseline(const std::vector<bool>& mask, int npiece, float clipthresh, int clipniter, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool getresidual=true, bool outlog=false, const std::string& blfile="")276 { table_->autoCubicSplineBaseline(mask, npiece, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, outlog, blfile); }277 278 void sinusoidBaseline(const std::vector<bool>& mask, const bool applyfft, const std::string& fftmethod, const std::string& fftthresh, const std::vector<int>& addwn, const std::vector<int>& rejwn, float clipthresh, int clipniter, bool getresidual=true, bool outlog=false, const std::string& blfile="")279 { table_->sinusoidBaseline(mask, applyfft, fftmethod, fftthresh, addwn, rejwn, clipthresh, clipniter, getresidual, outlog, blfile); }280 281 void autoSinusoidBaseline(const std::vector<bool>& mask, const bool applyfft, const std::string& fftmethod, const std::string& fftthresh, const std::vector<int>& addwn, const std::vector<int>& rejwn, float clipthresh, int clipniter, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool getresidual=true, bool outlog=false, const std::string& blfile="")282 { table_->autoSinusoidBaseline(mask, applyfft, fftmethod, fftthresh, addwn, rejwn, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, outlog, blfile); }266 void polyBaseline(const std::vector<bool>& mask, int order, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="") 267 { table_->polyBaseline(mask, order, getresidual, showprogress, outlog, blfile); } 268 269 void autoPolyBaseline(const std::vector<bool>& mask, int order, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="") 270 { table_->autoPolyBaseline(mask, order, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile); } 271 272 void cubicSplineBaseline(const std::vector<bool>& mask, int npiece, float clipthresh, int clipniter, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="") 273 { table_->cubicSplineBaseline(mask, npiece, clipthresh, clipniter, getresidual, showprogress, outlog, blfile); } 274 275 void autoCubicSplineBaseline(const std::vector<bool>& mask, int npiece, float clipthresh, int clipniter, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="") 276 { table_->autoCubicSplineBaseline(mask, npiece, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile); } 277 278 void sinusoidBaseline(const std::vector<bool>& mask, const bool applyfft, const std::string& fftmethod, const std::string& fftthresh, const std::vector<int>& addwn, const std::vector<int>& rejwn, float clipthresh, int clipniter, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="") 279 { table_->sinusoidBaseline(mask, applyfft, fftmethod, fftthresh, addwn, rejwn, clipthresh, clipniter, getresidual, showprogress, outlog, blfile); } 280 281 void autoSinusoidBaseline(const std::vector<bool>& mask, const bool applyfft, const std::string& fftmethod, const std::string& fftthresh, const std::vector<int>& addwn, const std::vector<int>& rejwn, float clipthresh, int clipniter, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="") 282 { table_->autoSinusoidBaseline(mask, applyfft, fftmethod, fftthresh, addwn, rejwn, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile); } 283 283 284 284 float getRms(const std::vector<bool>& mask, int whichrow)
Note:
See TracChangeset
for help on using the changeset viewer.