Ignore:
Timestamp:
03/30/11 21:43:43 (14 years ago)
Author:
WataruKawasaki
Message:

merged bug fixes from trunk (r2081)

Location:
branches/casa-prerelease/pre-asap
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/casa-prerelease/pre-asap

    • Property svn:mergeinfo changed
      /trunkmerged: 2081
  • branches/casa-prerelease/pre-asap/python

  • branches/casa-prerelease/pre-asap/python/scantable.py

    r2047 r2082  
    20702070
    20712071    @asaplog_post_dec
    2072     def sinusoid_baseline(self, insitu=None, mask=None, minnwave=None, maxnwave=None,
    2073                           clipthresh=None, clipniter=None, plot=None, outlog=None, blfile=None):
    2074         """\
    2075         Return a scan which has been baselined (all rows) by cubic spline function (piecewise cubic polynomial).
    2076         Parameters:
    2077             insitu:     If False a new scantable is returned.
    2078                         Otherwise, the scaling is done in-situ
    2079                         The default is taken from .asaprc (False)
    2080             mask:       An optional mask
    2081             minnwave:   Minimum wave number in spectral window (default is 0)
    2082             maxnwave:   Maximum wave number in spectral window (default is 3)
    2083             clipthresh: Clipping threshold. (default is 3.0, unit: sigma)
    2084             clipniter:  maximum number of iteration of 'clipthresh'-sigma clipping (default is 1)
    2085             plot:   *** CURRENTLY UNAVAILABLE, ALWAYS FALSE ***
    2086                         plot the fit and the residual. In this each
    2087                         indivual fit has to be approved, by typing 'y'
    2088                         or 'n'
    2089             outlog:     Output the coefficients of the best-fit
    2090                         function to logger (default is False)
    2091             blfile:     Name of a text file in which the best-fit
    2092                         parameter values to be written
    2093                         (default is "": no file/logger output)
     2072    def sinusoid_baseline(self, insitu=None, mask=None, nwave=None, maxwavelength=None,
     2073                          clipthresh=None, clipniter=None, plot=None, getresidual=None, outlog=None, blfile=None):
     2074        """\
     2075        Return a scan which has been baselined (all rows) by sinusoidal functions.
     2076        Parameters:
     2077            insitu:        If False a new scantable is returned.
     2078                           Otherwise, the scaling is done in-situ
     2079                           The default is taken from .asaprc (False)
     2080            mask:          An optional mask
     2081            nwave:         the maximum wave number of sinusoids within
     2082                           maxwavelength * (spectral range).
     2083                           The default is 3 (i.e., sinusoids with wave
     2084                           number of 0(=constant), 1, 2, and 3 are
     2085                           used for fitting). Also it is possible to
     2086                           explicitly specify all the wave numbers to
     2087                           be used, by giving a list including them
     2088                           (e.g. [0,1,2,15,16]).
     2089            maxwavelength: the longest sinusoidal wavelength. The
     2090                           default is 1.0 (unit: spectral range).
     2091            clipthresh:    Clipping threshold. (default is 3.0, unit: sigma)
     2092            clipniter:     maximum number of iteration of 'clipthresh'-sigma clipping (default is 1)
     2093            plot:      *** CURRENTLY UNAVAILABLE, ALWAYS FALSE ***
     2094                           plot the fit and the residual. In this each
     2095                           indivual fit has to be approved, by typing 'y'
     2096                           or 'n'
     2097            getresidual:   if False, returns best-fit values instead of
     2098                           residual. (default is True)
     2099            outlog:        Output the coefficients of the best-fit
     2100                           function to logger (default is False)
     2101            blfile:        Name of a text file in which the best-fit
     2102                           parameter values to be written
     2103                           (default is "": no file/logger output)
    20942104
    20952105        Example:
    20962106            # return a scan baselined by a combination of sinusoidal curves having
    2097             # wave numbers in spectral window from 1 to 10,
     2107            # wave numbers in spectral window up to 10,
    20982108            # also with 3-sigma clipping, iteration up to 4 times
    2099             bscan = scan.sinusoid_baseline(maxnwave=10,clipthresh=3.0,clipniter=4)
     2109            bscan = scan.sinusoid_baseline(nwave=10,clipthresh=3.0,clipniter=4)
     2110
     2111        Note:
     2112            The best-fit parameter values output in logger and/or blfile are now
     2113            based on specunit of 'channel'.
    21002114        """
    21012115       
     
    21102124        nchan = workscan.nchan()
    21112125       
    2112         if mask is None: mask = [True for i in xrange(nchan)]
    2113         if minnwave is None: minnwave = 0
    2114         if maxnwave is None: maxnwave = 3
    2115         if clipthresh is None: clipthresh = 3.0
    2116         if clipniter is None: clipniter = 1
    2117         if plot is None: plot = False
    2118         if outlog is None: outlog = False
    2119         if blfile is None: blfile = ""
    2120 
     2126        if mask          is None: mask          = [True for i in xrange(nchan)]
     2127        if nwave         is None: nwave         = 3
     2128        if maxwavelength is None: maxwavelength = 1.0
     2129        if clipthresh    is None: clipthresh    = 3.0
     2130        if clipniter     is None: clipniter     = 1
     2131        if plot          is None: plot          = False
     2132        if getresidual   is None: getresidual   = True
     2133        if outlog        is None: outlog        = False
     2134        if blfile        is None: blfile        = ""
     2135
     2136        if isinstance(nwave, int):
     2137            in_nwave = nwave
     2138            nwave = []
     2139            for i in xrange(in_nwave+1): nwave.append(i)
     2140       
    21212141        outblfile = (blfile != "") and os.path.exists(os.path.expanduser(os.path.expandvars(blfile)))
    21222142       
    21232143        try:
    2124             #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method.
    2125             workscan._sinusoid_baseline(mask, minnwave, maxnwave, clipthresh, clipniter, outlog, blfile)
     2144            #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method.
     2145            workscan._sinusoid_baseline(mask, nwave, maxwavelength, clipthresh, clipniter, getresidual, outlog, blfile)
    21262146           
    21272147            workscan._add_history("sinusoid_baseline", varlist)
     
    21422162
    21432163
    2144     def auto_sinusoid_baseline(self, insitu=None, mask=None, minnwave=None, maxnwave=None,
     2164    def auto_sinusoid_baseline(self, insitu=None, mask=None, nwave=None, maxwavelength=None,
    21452165                               clipthresh=None, clipniter=None, edge=None, threshold=None,
    2146                                chan_avg_limit=None, plot=None, outlog=None, blfile=None):
     2166                               chan_avg_limit=None, plot=None, getresidual=None, outlog=None, blfile=None):
    21472167        """\
    21482168        Return a scan which has been baselined (all rows) by cubic spline
     
    21522172
    21532173        Parameters:
    2154             insitu:     if False a new scantable is returned.
    2155                         Otherwise, the scaling is done in-situ
    2156                         The default is taken from .asaprc (False)
    2157             mask:       an optional mask retreived from scantable
    2158             minnwave:   Minimum wave number in spectral window (default is 0)
    2159             maxnwave:   Maximum wave number in spectral window (default is 3)
    2160             clipthresh: Clipping threshold. (default is 3.0, unit: sigma)
    2161             clipniter:  maximum number of iteration of 'clipthresh'-sigma clipping (default is 1)
    2162             edge:       an optional number of channel to drop at
    2163                         the edge of spectrum. If only one value is
    2164                         specified, the same number will be dropped
    2165                         from both sides of the spectrum. Default
    2166                         is to keep all channels. Nested tuples
    2167                         represent individual edge selection for
    2168                         different IFs (a number of spectral channels
    2169                         can be different)
    2170             threshold:  the threshold used by line finder. It is
    2171                         better to keep it large as only strong lines
    2172                         affect the baseline solution.
    2173             chan_avg_limit:
    2174                         a maximum number of consequtive spectral
    2175                         channels to average during the search of
    2176                         weak and broad lines. The default is no
    2177                         averaging (and no search for weak lines).
    2178                         If such lines can affect the fitted baseline
    2179                         (e.g. a high order polynomial is fitted),
    2180                         increase this parameter (usually values up
    2181                         to 8 are reasonable). Most users of this
    2182                         method should find the default value sufficient.
    2183             plot:   *** CURRENTLY UNAVAILABLE, ALWAYS FALSE ***
    2184                         plot the fit and the residual. In this each
    2185                         indivual fit has to be approved, by typing 'y'
    2186                         or 'n'
    2187             outlog:     Output the coefficients of the best-fit
    2188                         function to logger (default is False)
    2189             blfile:     Name of a text file in which the best-fit
    2190                         parameter values to be written
    2191                         (default is "": no file/logger output)
     2174            insitu:        if False a new scantable is returned.
     2175                           Otherwise, the scaling is done in-situ
     2176                           The default is taken from .asaprc (False)
     2177            mask:          an optional mask retreived from scantable
     2178            nwave:         the maximum wave number of sinusoids within
     2179                           maxwavelength * (spectral range).
     2180                           The default is 3 (i.e., sinusoids with wave
     2181                           number of 0(=constant), 1, 2, and 3 are
     2182                           used for fitting). Also it is possible to
     2183                           explicitly specify all the wave numbers to
     2184                           be used, by giving a list including them
     2185                           (e.g. [0,1,2,15,16]).
     2186            maxwavelength: the longest sinusoidal wavelength. The
     2187                           default is 1.0 (unit: spectral range).
     2188            clipthresh:    Clipping threshold. (default is 3.0, unit: sigma)
     2189            clipniter:     maximum number of iteration of 'clipthresh'-sigma clipping (default is 1)
     2190            edge:          an optional number of channel to drop at
     2191                           the edge of spectrum. If only one value is
     2192                           specified, the same number will be dropped
     2193                           from both sides of the spectrum. Default
     2194                           is to keep all channels. Nested tuples
     2195                           represent individual edge selection for
     2196                           different IFs (a number of spectral channels
     2197                           can be different)
     2198            threshold:     the threshold used by line finder. It is
     2199                           better to keep it large as only strong lines
     2200                           affect the baseline solution.
     2201            chan_avg_limit:a maximum number of consequtive spectral
     2202                           channels to average during the search of
     2203                           weak and broad lines. The default is no
     2204                           averaging (and no search for weak lines).
     2205                           If such lines can affect the fitted baseline
     2206                           (e.g. a high order polynomial is fitted),
     2207                           increase this parameter (usually values up
     2208                           to 8 are reasonable). Most users of this
     2209                           method should find the default value sufficient.
     2210            plot:      *** CURRENTLY UNAVAILABLE, ALWAYS FALSE ***
     2211                           plot the fit and the residual. In this each
     2212                           indivual fit has to be approved, by typing 'y'
     2213                           or 'n'
     2214            getresidual:   if False, returns best-fit values instead of
     2215                           residual. (default is True)
     2216            outlog:        Output the coefficients of the best-fit
     2217                           function to logger (default is False)
     2218            blfile:        Name of a text file in which the best-fit
     2219                           parameter values to be written
     2220                           (default is "": no file/logger output)
    21922221
    21932222        Example:
    2194             bscan = scan.auto_sinusoid_baseline(maxnwave=10, insitu=False)
     2223            bscan = scan.auto_sinusoid_baseline(nwave=10, insitu=False)
     2224       
     2225        Note:
     2226            The best-fit parameter values output in logger and/or blfile are now
     2227            based on specunit of 'channel'.
    21952228        """
    21962229
     
    22052238        nchan = workscan.nchan()
    22062239       
    2207         if mask is None: mask = [True for i in xrange(nchan)]
    2208         if minnwave is None: minnwave = 0
    2209         if maxnwave is None: maxnwave = 3
    2210         if clipthresh is None: clipthresh = 3.0
    2211         if clipniter is None: clipniter = 1
    2212         if edge is None: edge = (0, 0)
    2213         if threshold is None: threshold = 3
     2240        if mask           is None: mask          = [True for i in xrange(nchan)]
     2241        if nwave          is None: nwave          = 3
     2242        if maxwavelength  is None: maxwavelength  = 1.0
     2243        if clipthresh     is None: clipthresh    = 3.0
     2244        if clipniter      is None: clipniter      = 1
     2245        if edge           is None: edge           = (0,0)
     2246        if threshold      is None: threshold      = 3
    22142247        if chan_avg_limit is None: chan_avg_limit = 1
    2215         if plot is None: plot = False
    2216         if outlog is None: outlog = False
    2217         if blfile is None: blfile = ""
     2248        if plot           is None: plot           = False
     2249        if getresidual    is None: getresidual    = True
     2250        if outlog         is None: outlog         = False
     2251        if blfile         is None: blfile         = ""
    22182252
    22192253        outblfile = (blfile != "") and os.path.exists(os.path.expanduser(os.path.expandvars(blfile)))
     
    22212255        from asap.asaplinefind import linefinder
    22222256        from asap import _is_sequence_or_number as _is_valid
     2257
     2258        if isinstance(nwave, int):
     2259            in_nwave = nwave
     2260            nwave = []
     2261            for i in xrange(in_nwave+1): nwave.append(i)
    22232262
    22242263        if not (isinstance(edge, list) or isinstance(edge, tuple)): edge = [ edge ]
     
    22442283
    22452284        try:
    2246             #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method.
     2285            #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method.
    22472286            if individualedge:
    22482287                curedge = []
     
    22502289                    curedge += edge[i]
    22512290               
    2252             workscan._auto_sinusoid_baseline(mask, minnwave, maxnwave, clipthresh, clipniter, curedge, threshold, chan_avg_limit, outlog, blfile)
     2291            workscan._auto_sinusoid_baseline(mask, nwave, maxwavelength, clipthresh, clipniter, curedge, threshold, chan_avg_limit, getresidual, outlog, blfile)
    22532292
    22542293            workscan._add_history("auto_sinusoid_baseline", varlist)
     
    22952334            # also with 3-sigma clipping, iteration up to 4 times
    22962335            bscan = scan.cspline_baseline(npiece=2,clipthresh=3.0,clipniter=4)
     2336       
     2337        Note:
     2338            The best-fit parameter values output in logger and/or blfile are now
     2339            based on specunit of 'channel'.
    22972340        """
    22982341       
     
    23882431        Example:
    23892432            bscan = scan.auto_cspline_baseline(npiece=3, insitu=False)
     2433       
     2434        Note:
     2435            The best-fit parameter values output in logger and/or blfile are now
     2436            based on specunit of 'channel'.
    23902437        """
    23912438
Note: See TracChangeset for help on using the changeset viewer.