Changeset 2645 for trunk/python
- Timestamp:
- 09/04/12 18:58:06 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r2643 r2645 3007 3007 3008 3008 @asaplog_post_dec 3009 def chebyshev_baseline(self, insitu=None, mask=None, order=None, 3010 clipthresh=None, clipniter=None, plot=None, 3011 getresidual=None, showprogress=None, minnrow=None, 3012 outlog=None, blfile=None, csvformat=None): 3013 """\ 3014 Return a scan which has been baselined (all rows) by Chebyshev polynomials. 3015 3016 Parameters: 3017 insitu: If False a new scantable is returned. 3018 Otherwise, the scaling is done in-situ 3019 The default is taken from .asaprc (False) 3020 mask: An optional mask 3021 order: the maximum order of Chebyshev polynomial (default is 5) 3022 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 3023 clipniter: maximum number of iteration of 'clipthresh'-sigma 3024 clipping (default is 0) 3025 plot: *** CURRENTLY UNAVAILABLE, ALWAYS FALSE *** 3026 plot the fit and the residual. In this each 3027 indivual fit has to be approved, by typing 'y' 3028 or 'n' 3029 getresidual: if False, returns best-fit values instead of 3030 residual. (default is True) 3031 showprogress: show progress status for large data. 3032 default is True. 3033 minnrow: minimum number of input spectra to show. 3034 default is 1000. 3035 outlog: Output the coefficients of the best-fit 3036 function to logger (default is False) 3037 blfile: Name of a text file in which the best-fit 3038 parameter values to be written 3039 (default is "": no file/logger output) 3040 csvformat: if True blfile is csv-formatted, default is False. 3041 3042 Example: 3043 # return a scan baselined by a cubic spline consisting of 2 pieces 3044 # (i.e., 1 internal knot), 3045 # also with 3-sigma clipping, iteration up to 4 times 3046 bscan = scan.cspline_baseline(npiece=2,clipthresh=3.0,clipniter=4) 3047 3048 Note: 3049 The best-fit parameter values output in logger and/or blfile are now 3050 based on specunit of 'channel'. 3051 """ 3052 3053 try: 3054 varlist = vars() 3055 3056 if insitu is None: insitu = rcParams['insitu'] 3057 if insitu: 3058 workscan = self 3059 else: 3060 workscan = self.copy() 3061 3062 #if mask is None: mask = [True for i in xrange(workscan.nchan())] 3063 if mask is None: mask = [] 3064 if order is None: order = 5 3065 if clipthresh is None: clipthresh = 3.0 3066 if clipniter is None: clipniter = 0 3067 if plot is None: plot = False 3068 if getresidual is None: getresidual = True 3069 if showprogress is None: showprogress = True 3070 if minnrow is None: minnrow = 1000 3071 if outlog is None: outlog = False 3072 if blfile is None: blfile = '' 3073 if csvformat is None: csvformat = False 3074 3075 if csvformat: 3076 scsvformat = "T" 3077 else: 3078 scsvformat = "F" 3079 3080 #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method. 3081 workscan._chebyshev_baseline(mask, order, clipthresh, clipniter, 3082 getresidual, 3083 pack_progress_params(showprogress, 3084 minnrow), 3085 outlog, scsvformat+blfile) 3086 workscan._add_history("chebyshev_baseline", varlist) 3087 3088 if insitu: 3089 self._assign(workscan) 3090 else: 3091 return workscan 3092 3093 except RuntimeError, e: 3094 raise_fitting_failure_exception(e) 3095 3096 @asaplog_post_dec 3097 def auto_chebyshev_baseline(self, insitu=None, mask=None, order=None, 3098 clipthresh=None, clipniter=None, 3099 edge=None, threshold=None, chan_avg_limit=None, 3100 getresidual=None, plot=None, 3101 showprogress=None, minnrow=None, outlog=None, 3102 blfile=None, csvformat=None): 3103 """\ 3104 Return a scan which has been baselined (all rows) by Chebyshev polynomials. 3105 Spectral lines are detected first using linefinder and masked out 3106 to avoid them affecting the baseline solution. 3107 3108 Parameters: 3109 insitu: if False a new scantable is returned. 3110 Otherwise, the scaling is done in-situ 3111 The default is taken from .asaprc (False) 3112 mask: an optional mask retreived from scantable 3113 order: the maximum order of Chebyshev polynomial (default is 5) 3114 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 3115 clipniter: maximum number of iteration of 'clipthresh'-sigma 3116 clipping (default is 0) 3117 edge: an optional number of channel to drop at 3118 the edge of spectrum. If only one value is 3119 specified, the same number will be dropped 3120 from both sides of the spectrum. Default 3121 is to keep all channels. Nested tuples 3122 represent individual edge selection for 3123 different IFs (a number of spectral channels 3124 can be different) 3125 threshold: the threshold used by line finder. It is 3126 better to keep it large as only strong lines 3127 affect the baseline solution. 3128 chan_avg_limit: a maximum number of consequtive spectral 3129 channels to average during the search of 3130 weak and broad lines. The default is no 3131 averaging (and no search for weak lines). 3132 If such lines can affect the fitted baseline 3133 (e.g. a high order polynomial is fitted), 3134 increase this parameter (usually values up 3135 to 8 are reasonable). Most users of this 3136 method should find the default value sufficient. 3137 plot: *** CURRENTLY UNAVAILABLE, ALWAYS FALSE *** 3138 plot the fit and the residual. In this each 3139 indivual fit has to be approved, by typing 'y' 3140 or 'n' 3141 getresidual: if False, returns best-fit values instead of 3142 residual. (default is True) 3143 showprogress: show progress status for large data. 3144 default is True. 3145 minnrow: minimum number of input spectra to show. 3146 default is 1000. 3147 outlog: Output the coefficients of the best-fit 3148 function to logger (default is False) 3149 blfile: Name of a text file in which the best-fit 3150 parameter values to be written 3151 (default is "": no file/logger output) 3152 csvformat: if True blfile is csv-formatted, default is False. 3153 3154 Example: 3155 bscan = scan.auto_cspline_baseline(npiece=3, insitu=False) 3156 3157 Note: 3158 The best-fit parameter values output in logger and/or blfile are now 3159 based on specunit of 'channel'. 3160 """ 3161 3162 try: 3163 varlist = vars() 3164 3165 if insitu is None: insitu = rcParams['insitu'] 3166 if insitu: 3167 workscan = self 3168 else: 3169 workscan = self.copy() 3170 3171 #if mask is None: mask = [True for i in xrange(workscan.nchan())] 3172 if mask is None: mask = [] 3173 if order is None: order = 5 3174 if clipthresh is None: clipthresh = 3.0 3175 if clipniter is None: clipniter = 0 3176 if edge is None: edge = (0, 0) 3177 if threshold is None: threshold = 3 3178 if chan_avg_limit is None: chan_avg_limit = 1 3179 if plot is None: plot = False 3180 if getresidual is None: getresidual = True 3181 if showprogress is None: showprogress = True 3182 if minnrow is None: minnrow = 1000 3183 if outlog is None: outlog = False 3184 if blfile is None: blfile = '' 3185 if csvformat is None: csvformat = False 3186 3187 if csvformat: 3188 scsvformat = "T" 3189 else: 3190 scsvformat = "F" 3191 3192 #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method. 3193 workscan._auto_chebyshev_baseline(mask, order, clipthresh, 3194 clipniter, 3195 normalise_edge_param(edge), 3196 threshold, 3197 chan_avg_limit, getresidual, 3198 pack_progress_params(showprogress, 3199 minnrow), 3200 outlog, scsvformat+blfile) 3201 workscan._add_history("auto_chebyshev_baseline", varlist) 3202 3203 if insitu: 3204 self._assign(workscan) 3205 else: 3206 return workscan 3207 3208 except RuntimeError, e: 3209 raise_fitting_failure_exception(e) 3210 3211 @asaplog_post_dec 3009 3212 def poly_baseline(self, mask=None, order=None, insitu=None, plot=None, 3010 3213 getresidual=None, showprogress=None, minnrow=None,
Note:
See TracChangeset
for help on using the changeset viewer.