Changeset 2189


Ignore:
Timestamp:
06/09/11 19:17:30 (13 years ago)
Author:
WataruKawasaki
Message:

New Development: No

JIRA Issue: Yes CAS-3149

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: scantable.*_baseline() parameter

Test Programs:

Put in Release Notes: No

Module(s):

Description: Added two parameters 'showprogress' and 'minnrow' to scantable.*_baseline() to enable to show progress status during time-consuming processes.


Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r2186 r2189  
    169169    else:
    170170        raise RuntimeError(str(e)+'\n'+msg)
    171    
     171
     172def pack_progress_params(showprogress, minnrow):
     173    return str(showprogress).lower() + ',' + str(minnrow)
    172174
    173175class scantable(Scantable):
     
    22912293    def sinusoid_baseline(self, insitu=None, mask=None, applyfft=None, fftmethod=None, fftthresh=None,
    22922294                          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):
    22942296        """\
    22952297        Return a scan which has been baselined (all rows) with sinusoidal functions.
     
    23362338            getresidual:   if False, returns best-fit values instead of
    23372339                           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.
    23382344            outlog:        Output the coefficients of the best-fit
    23392345                           function to logger (default is False)
     
    23722378            if plot          is None: plot          = False
    23732379            if getresidual   is None: getresidual   = True
     2380            if showprogress  is None: showprogress  = True
     2381            if minnrow       is None: minnrow       = 1000
    23742382            if outlog        is None: outlog        = False
    23752383            if blfile        is None: blfile        = ''
    23762384
    23772385            #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)
    23792387            workscan._add_history('sinusoid_baseline', varlist)
    23802388           
     
    23912399    def auto_sinusoid_baseline(self, insitu=None, mask=None, applyfft=None, fftmethod=None, fftthresh=None,
    23922400                               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):
    23942403        """\
    23952404        Return a scan which has been baselined (all rows) with sinusoidal functions.
     
    23982407
    23992408        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)
    24662479
    24672480        Example:
     
    24952508            if plot           is None: plot           = False
    24962509            if getresidual    is None: getresidual    = True
     2510            if showprogress   is None: showprogress   = True
     2511            if minnrow        is None: minnrow        = 1000
    24972512            if outlog         is None: outlog         = False
    24982513            if blfile         is None: blfile         = ''
    24992514
    25002515            #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)
    25022517            workscan._add_history("auto_sinusoid_baseline", varlist)
    25032518           
     
    25112526
    25122527    @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):
    25152530        """\
    25162531        Return a scan which has been baselined (all rows) by cubic spline function (piecewise cubic polynomial).
    25172532        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)
    25362555
    25372556        Example:
     
    25542573                workscan = self.copy()
    25552574
    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       = ''
    25642585
    25652586            #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)
    25672588            workscan._add_history("cspline_baseline", varlist)
    25682589           
     
    25762597
    25772598    @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):
    25812602        """\
    25822603        Return a scan which has been baselined (all rows) by cubic spline
     
    25862607
    25872608        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)
    26272651
    26282652        Example:
     
    26522676            if plot           is None: plot           = False
    26532677            if getresidual    is None: getresidual    = True
     2678            if showprogress   is None: showprogress   = True
     2679            if minnrow        is None: minnrow        = 1000
    26542680            if outlog         is None: outlog         = False
    26552681            if blfile         is None: blfile         = ''
    26562682
    26572683            #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)
    26592685            workscan._add_history("auto_cspline_baseline", varlist)
    26602686           
     
    26682694
    26692695    @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):
    26712698        """\
    26722699        Return a scan which has been baselined (all rows) by a polynomial.
    26732700        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)
    26892720
    26902721        Example:
     
    27032734                workscan = self.copy()
    27042735
    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       = ""
    27112744
    27122745            if plot:
     
    27482781                if outblfile: blf.close()
    27492782            else:
    2750                 workscan._poly_baseline(mask, order, getresidual, outlog, blfile)
     2783                workscan._poly_baseline(mask, order, getresidual, pack_progress_params(showprogress, minnrow), outlog, blfile)
    27512784           
    27522785            workscan._add_history("poly_baseline", varlist)
     
    27612794
    27622795    @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):
    27652798        """\
    27662799        Return a scan which has been baselined (all rows) by a polynomial.
     
    27692802
    27702803        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)
    28072843
    28082844        Example:
     
    28262862            if plot           is None: plot           = False
    28272863            if getresidual    is None: getresidual    = True
     2864            if showprogress   is None: showprogress   = True
     2865            if minnrow        is None: minnrow        = 1000
    28282866            if outlog         is None: outlog         = False
    28292867            if blfile         is None: blfile         = ''
     
    28772915                if outblfile: blf.close()
    28782916            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)
    28802918
    28812919            workscan._add_history("auto_poly_baseline", varlist)
  • trunk/src/Scantable.cpp

    r2186 r2189  
    18171817}
    18181818
    1819 void Scantable::polyBaseline(const std::vector<bool>& mask, int order, bool getResidual, bool outLogger, const std::string& blfile)
     1819void Scantable::polyBaseline(const std::vector<bool>& mask, int order, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile)
    18201820{
    18211821  ofstream ofs;
     
    18411841  int nRow = nrow();
    18421842  std::vector<bool> chanMask;
     1843  bool showProgress;
     1844  int minNRow;
     1845  parseProgressInfo(progressInfo, showProgress, minNRow);
    18431846
    18441847  for (int whichrow = 0; whichrow < nRow; ++whichrow) {
     
    18471850    setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow);
    18481851    outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "polyBaseline()", fitter);
    1849     showProgressOnTerminal(whichrow, nRow);
     1852    showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    18501853  }
    18511854
     
    18531856}
    18541857
    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)
     1858void 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)
    18561859{
    18571860  ofstream ofs;
     
    18801883  STLineFinder lineFinder = STLineFinder();
    18811884  lineFinder.setOptions(threshold, 3, chanAvgLimit);
     1885
     1886  bool showProgress;
     1887  int minNRow;
     1888  parseProgressInfo(progressInfo, showProgress, minNRow);
    18821889
    18831890  for (int whichrow = 0; whichrow < nRow; ++whichrow) {
     
    19101917
    19111918    outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoPolyBaseline()", fitter);
    1912     showProgressOnTerminal(whichrow, nRow);
     1919    showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    19131920  }
    19141921
     
    19161923}
    19171924
    1918 void Scantable::cubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, bool getResidual, bool outLogger, const std::string& blfile)
     1925void 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)
    19191926{
    19201927  ofstream ofs;
     
    19401947  int nRow = nrow();
    19411948  std::vector<bool> chanMask;
     1949  bool showProgress;
     1950  int minNRow;
     1951  parseProgressInfo(progressInfo, showProgress, minNRow);
    19421952
    19431953  for (int whichrow = 0; whichrow < nRow; ++whichrow) {
     
    19521962
    19531963    outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "cubicSplineBaseline()", pieceEdges, params);
    1954     showProgressOnTerminal(whichrow, nRow);
     1964    showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    19551965  }
    19561966
     
    19581968}
    19591969
    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)
     1970void 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)
    19611971{
    19621972  ofstream ofs;
     
    19851995  STLineFinder lineFinder = STLineFinder();
    19861996  lineFinder.setOptions(threshold, 3, chanAvgLimit);
     1997
     1998  bool showProgress;
     1999  int minNRow;
     2000  parseProgressInfo(progressInfo, showProgress, minNRow);
    19872001
    19882002  for (int whichrow = 0; whichrow < nRow; ++whichrow) {
     
    20212035
    20222036    outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoCubicSplineBaseline()", pieceEdges, params);
    2023     showProgressOnTerminal(whichrow, nRow);
     2037    showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    20242038  }
    20252039
     
    23702384}
    23712385
    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)
     2386void 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)
    23732387{
    23742388  ofstream ofs;
     
    23952409  std::vector<bool> chanMask;
    23962410  std::vector<int> nWaves;
     2411
     2412  bool showProgress;
     2413  int minNRow;
     2414  parseProgressInfo(progressInfo, showProgress, minNRow);
    23972415
    23982416  for (int whichrow = 0; whichrow < nRow; ++whichrow) {
     
    24222440
    24232441    outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "sinusoidBaseline()", params);
    2424     showProgressOnTerminal(whichrow, nRow);
     2442    showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    24252443  }
    24262444
     
    24282446}
    24292447
    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)
     2448void 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)
    24312449{
    24322450  ofstream ofs;
     
    24572475  STLineFinder lineFinder = STLineFinder();
    24582476  lineFinder.setOptions(threshold, 3, chanAvgLimit);
     2477
     2478  bool showProgress;
     2479  int minNRow;
     2480  parseProgressInfo(progressInfo, showProgress, minNRow);
    24592481
    24602482  for (int whichrow = 0; whichrow < nRow; ++whichrow) {
     
    24932515
    24942516    outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoSinusoidBaseline()", params);
    2495     showProgressOnTerminal(whichrow, nRow);
     2517    showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    24962518  }
    24972519
     
    28152837}
    28162838
    2817 void Scantable::showProgressOnTerminal(const int nProcessed, const int nTotal, const int nTotalThreshold)
    2818 {
    2819   if (nTotal >= nTotalThreshold) {
     2839void 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
     2850void Scantable::showProgressOnTerminal(const int nProcessed, const int nTotal, const bool showProgress, const int nTotalThreshold)
     2851{
     2852  if (showProgress && (nTotal >= nTotalThreshold)) {
    28202853    int nInterval = int(floor(double(nTotal)/100.0));
    28212854    if (nInterval == 0) nInterval++;
     
    28242857      printf("\x1b[31m\x1b[1m");             //set red color, highlighted
    28252858      printf("[  0%%]");
    2826       printf("\x1b[39m\x1b[0m");             //default attributes
     2859      printf("\x1b[39m\x1b[0m");             //set default attributes
    28272860      fflush(NULL);
    28282861    } else if (nProcessed % nInterval == 0) {
    2829       printf("\r\x1b[1C");                   //go to the 2nd column
     2862      printf("\r");                          //go to the head of line
    28302863      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
    28342866      fflush(NULL);
    28352867    }
  • trunk/src/Scantable.h

    r2186 r2189  
    502502                    int order,
    503503                    bool getResidual=true,
    504                     bool outLogger=false,
     504                    const std::string& progressInfo="true,1000",
     505                    const bool outLogger=false,
    505506                    const std::string& blfile="");
    506507  void autoPolyBaseline(const std::vector<bool>& mask,
     
    510511                        int chanAvgLimit=1,
    511512                        bool getResidual=true,
    512                         bool outLogger=false,
     513                        const std::string& progressInfo="true,1000",
     514                        const bool outLogger=false,
    513515                        const std::string& blfile="");
    514516  void cubicSplineBaseline(const std::vector<bool>& mask,
     
    517519                           int nIterClip,
    518520                           bool getResidual=true,
    519                            bool outLogger=false,
     521                           const std::string& progressInfo="true,1000",
     522                           const bool outLogger=false,
    520523                           const std::string& blfile="");
    521524  void autoCubicSplineBaseline(const std::vector<bool>& mask,
     
    527530                               int chanAvgLimit=1,
    528531                               bool getResidual=true,
    529                                bool outLogger=false,
     532                               const std::string& progressInfo="true,1000",
     533                               const bool outLogger=false,
    530534                               const std::string& blfile="");
    531535  void sinusoidBaseline(const std::vector<bool>& mask,
     
    538542                        int nIterClip,
    539543                        bool getResidual=true,
    540                         bool outLogger=false,
     544                        const std::string& progressInfo="true,1000",
     545                        const bool outLogger=false,
    541546                        const std::string& blfile="");
    542547  void autoSinusoidBaseline(const std::vector<bool>& mask,
     
    552557                            int chanAvgLimit=1,
    553558                            bool getResidual=true,
    554                             bool outLogger=false,
     559                            const std::string& progressInfo="true,1000",
     560                            const bool outLogger=false,
    555561                            const std::string& blfile="");
    556562  std::vector<float> execFFT(const int whichrow,
     
    741747  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);
    742748  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);
    744751
    745752  void applyChanFlag( casa::uInt whichrow, const std::vector<bool>& msk, casa::uChar flagval);
  • trunk/src/ScantableWrapper.h

    r2186 r2189  
    264264  { table_->reshapeSpectrum( nmin, nmax ); }
    265265
    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); }
    283283
    284284  float getRms(const std::vector<bool>& mask, int whichrow)
Note: See TracChangeset for help on using the changeset viewer.