Changeset 2767 for trunk/python
- Timestamp:
- 02/08/13 22:23:22 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r2761 r2767 173 173 def pack_progress_params(showprogress, minnrow): 174 174 return str(showprogress).lower() + ',' + str(minnrow) 175 176 def pack_blinfo(blinfo, maxirow): 177 """\ 178 convert a dictionary or a list of dictionaries of baseline info 179 into a list of comma-separated strings. 180 """ 181 if isinstance(blinfo, dict): 182 res = do_pack_blinfo(blinfo, maxirow) 183 return [res] if res != '' else [] 184 elif isinstance(blinfo, list) or isinstance(blinfo, tuple): 185 res = [] 186 for i in xrange(len(blinfo)): 187 resi = do_pack_blinfo(blinfo[i], maxirow) 188 if resi != '': 189 res.append(resi) 190 return res 191 192 def do_pack_blinfo(blinfo, maxirow): 193 """\ 194 convert a dictionary of baseline info for a spectrum into 195 a comma-separated string. 196 """ 197 dinfo = {} 198 for key in ['row', 'blfunc', 'masklist']: 199 if blinfo.has_key(key): 200 val = blinfo[key] 201 if key == 'row': 202 irow = val 203 if isinstance(val, list) or isinstance(val, tuple): 204 slval = [] 205 for i in xrange(len(val)): 206 if isinstance(val[i], list) or isinstance(val[i], tuple): 207 for j in xrange(len(val[i])): 208 slval.append(str(val[i][j])) 209 else: 210 slval.append(str(val[i])) 211 sval = ",".join(slval) 212 else: 213 sval = str(val) 214 215 dinfo[key] = sval 216 else: 217 raise ValueError("'"+key+"' is missing in blinfo.") 218 219 if irow >= maxirow: return '' 220 221 for key in ['order', 'npiece', 'nwave']: 222 if blinfo.has_key(key): 223 val = blinfo[key] 224 if isinstance(val, list) or isinstance(val, tuple): 225 slval = [] 226 for i in xrange(len(val)): 227 slval.append(str(val[i])) 228 sval = ",".join(slval) 229 else: 230 sval = str(val) 231 dinfo[key] = sval 232 233 blfunc = dinfo['blfunc'] 234 fspec_keys = {'poly': 'order', 'chebyshev': 'order', 'cspline': 'npiece', 'sinusoid': 'nwave'} 235 236 fspec_key = fspec_keys[blfunc] 237 if not blinfo.has_key(fspec_key): 238 raise ValueError("'"+fspec_key+"' is missing in blinfo.") 239 240 clip_params_n = 0 241 for key in ['clipthresh', 'clipniter']: 242 if blinfo.has_key(key): 243 clip_params_n += 1 244 dinfo[key] = str(blinfo[key]) 245 246 if clip_params_n == 0: 247 dinfo['clipthresh'] = '0.0' 248 dinfo['clipniter'] = '0' 249 elif clip_params_n != 2: 250 raise ValueError("both 'clipthresh' and 'clipniter' must be given for n-sigma clipping.") 251 252 lf_params_n = 0 253 for key in ['thresh', 'edge', 'chan_avg_limit']: 254 if blinfo.has_key(key): 255 lf_params_n += 1 256 val = blinfo[key] 257 if isinstance(val, list) or isinstance(val, tuple): 258 slval = [] 259 for i in xrange(len(val)): 260 slval.append(str(val[i])) 261 sval = ",".join(slval) 262 else: 263 sval = str(val) 264 dinfo[key] = sval 265 266 if lf_params_n == 3: 267 dinfo['use_linefinder'] = 'true' 268 elif lf_params_n == 1: 269 dinfo['use_linefinder'] = 'false' 270 dinfo['thresh'] = '' 271 dinfo['edge'] = '' 272 dinfo['chan_avg_limit'] = '' 273 else: 274 raise ValueError("all of 'thresh', 'edge' and 'chan_avg_limit' must be given to use linefinder.") 275 276 slblinfo = [dinfo['row'], blfunc, dinfo[fspec_key], dinfo['masklist'], \ 277 dinfo['clipthresh'], dinfo['clipniter'], \ 278 dinfo['use_linefinder'], dinfo['thresh'], dinfo['edge'], dinfo['chan_avg_limit']] 279 280 return ":".join(slblinfo) 281 282 def parse_fitresult(sres): 283 """\ 284 Parse the returned value of apply_bltable() or sub_baseline() and 285 extract row number, the best-fit coefficients and rms, then pack 286 them into a dictionary. 287 The input value is generated by Scantable::packFittingResults() and 288 formatted as 'row:coeff[0],coeff[1],..,coeff[n-1]:rms'. 289 """ 290 res = [] 291 for i in xrange(len(sres)): 292 (srow, scoeff, srms) = sres[i].split(":") 293 row = int(srow) 294 rms = float(srms) 295 lscoeff = scoeff.split(",") 296 coeff = [] 297 for j in xrange(len(lscoeff)): 298 coeff.append(float(lscoeff[j])) 299 res.append({'row': row, 'coeff': coeff, 'rms': rms}) 300 301 return res 175 302 176 303 class scantable(Scantable): … … 2556 2683 2557 2684 @asaplog_post_dec 2685 def apply_bltable(self, insitu=None, inbltable=None, outbltable=None, overwrite=None): 2686 """\ 2687 Subtract baseline based on parameters written in Baseline Table. 2688 2689 Parameters: 2690 insitu: if False a new scantable is returned. 2691 Otherwise, the scaling is done in-situ 2692 The default is taken from .asaprc (False) 2693 inbltable: name of input baseline table. The row number of 2694 scantable and that of inbltable must be 2695 identical. 2696 outbltable: name of output baseline table where baseline 2697 parameters and fitting results recorded. 2698 default is ''(no output). 2699 overwrite: if True, overwrites the existing baseline table 2700 specified in outbltable. 2701 default is False. 2702 """ 2703 2704 try: 2705 varlist = vars() 2706 if inbltable is None: raise ValueError("bltable missing.") 2707 if outbltable is None: outbltable = '' 2708 if overwrite is None: overwrite = False 2709 2710 if insitu is None: insitu = rcParams['insitu'] 2711 if insitu: 2712 workscan = self 2713 else: 2714 workscan = self.copy() 2715 2716 sres = workscan._apply_bltable(inbltable, 2717 outbltable, 2718 os.path.exists(outbltable), 2719 overwrite) 2720 res = parse_fitresult(sres) 2721 2722 workscan._add_history('apply_bltable', varlist) 2723 2724 if insitu: 2725 self._assign(workscan) 2726 return res 2727 else: 2728 return {'scantable': workscan, 'fitresults': res} 2729 2730 except RuntimeError, e: 2731 raise_fitting_failure_exception(e) 2732 2733 @asaplog_post_dec 2734 def sub_baseline(self, insitu=None, blinfo=None, bltable=None, overwrite=None): 2735 """\ 2736 Subtract baseline based on parameters written in the input list. 2737 2738 Parameters: 2739 insitu: if False a new scantable is returned. 2740 Otherwise, the scaling is done in-situ 2741 The default is taken from .asaprc (False) 2742 blinfo: baseline parameter set stored in a dictionary 2743 or a list of dictionary. Each dictionary 2744 corresponds to each spectrum and must contain 2745 the following keys and values: 2746 'row': row number, 2747 'blfunc': function name. available ones include 2748 'poly', 'chebyshev', 'cspline' and 2749 'sinusoid', 2750 'order': maximum order of polynomial. needed 2751 if blfunc='poly' or 'chebyshev', 2752 'npiece': number or piecewise polynomial. 2753 needed if blfunc='cspline', 2754 'nwave': a list of sinusoidal wave numbers. 2755 needed if blfunc='sinusoid', and 2756 'masklist': min-max windows for channel mask. 2757 the specified ranges will be used 2758 for fitting. 2759 bltable: name of output baseline table where baseline 2760 parameters and fitting results recorded. 2761 default is ''(no output). 2762 overwrite: if True, overwrites the existing baseline table 2763 specified in bltable. 2764 default is False. 2765 2766 Example: 2767 sub_baseline(blinfo=[{'row':0, 'blfunc':'poly', 'order':5, 2768 'masklist':[[10,350],[352,510]]}, 2769 {'row':1, 'blfunc':'cspline', 'npiece':3, 2770 'masklist':[[3,16],[19,404],[407,511]]} 2771 ]) 2772 2773 the first spectrum (row=0) will be fitted with polynomial 2774 of order=5 and the next one (row=1) will be fitted with cubic 2775 spline consisting of 3 pieces. 2776 """ 2777 2778 try: 2779 varlist = vars() 2780 if blinfo is None: blinfo = [] 2781 if bltable is None: bltable = '' 2782 if overwrite is None: overwrite = False 2783 2784 if insitu is None: insitu = rcParams['insitu'] 2785 if insitu: 2786 workscan = self 2787 else: 2788 workscan = self.copy() 2789 2790 nrow = workscan.nrow() 2791 2792 in_blinfo = pack_blinfo(blinfo=blinfo, maxirow=nrow) 2793 2794 print "in_blinfo=< "+ str(in_blinfo)+" >" 2795 2796 sres = workscan._sub_baseline(in_blinfo, 2797 bltable, 2798 os.path.exists(bltable), 2799 overwrite) 2800 res = parse_fitresult(sres) 2801 2802 workscan._add_history('sub_baseline', varlist) 2803 2804 if insitu: 2805 self._assign(workscan) 2806 return res 2807 else: 2808 return {'scantable': workscan, 'fitresults': res} 2809 2810 except RuntimeError, e: 2811 raise_fitting_failure_exception(e) 2812 2813 @asaplog_post_dec 2558 2814 def calc_aic(self, value=None, blfunc=None, order=None, mask=None, 2559 2815 whichrow=None, uselinefinder=None, edge=None, … … 2638 2894 clipniter=None, plot=None, 2639 2895 getresidual=None, showprogress=None, 2640 minnrow=None, outlog=None, blfile=None, csvformat=None): 2896 minnrow=None, outlog=None, 2897 blfile=None, csvformat=None, 2898 bltable=None): 2641 2899 """\ 2642 2900 Return a scan which has been baselined (all rows) with sinusoidal … … 2697 2955 (default is '': no file/logger output) 2698 2956 csvformat: if True blfile is csv-formatted, default is False. 2957 bltable: name of a baseline table where fitting results 2958 (coefficients, rms, etc.) are to be written. 2959 if given, fitting results will NOT be output to 2960 scantable (insitu=True) or None will be 2961 returned (insitu=False). 2962 (default is "": no table output) 2699 2963 2700 2964 Example: … … 2734 2998 if blfile is None: blfile = '' 2735 2999 if csvformat is None: csvformat = False 2736 2737 if csvformat: 2738 scsvformat = "T" 2739 else: 2740 scsvformat = "F" 3000 if bltable is None: bltable = '' 3001 3002 sapplyfft = 'true' if applyfft else 'false' 3003 fftinfo = ','.join([sapplyfft, fftmethod.lower(), str(fftthresh).lower()]) 3004 3005 scsvformat = 'T' if csvformat else 'F' 2741 3006 2742 3007 #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method. 2743 workscan._sinusoid_baseline(mask, applyfft, fftmethod.lower(), 2744 str(fftthresh).lower(), 3008 workscan._sinusoid_baseline(mask, 3009 fftinfo, 3010 #applyfft, fftmethod.lower(), 3011 #str(fftthresh).lower(), 2745 3012 workscan._parse_wn(addwn), 2746 3013 workscan._parse_wn(rejwn), … … 2749 3016 pack_progress_params(showprogress, 2750 3017 minnrow), 2751 outlog, scsvformat+blfile) 3018 outlog, scsvformat+blfile, 3019 bltable) 2752 3020 workscan._add_history('sinusoid_baseline', varlist) 2753 2754 if insitu: 2755 self._assign(workscan) 3021 3022 if bltable == '': 3023 if insitu: 3024 self._assign(workscan) 3025 else: 3026 return workscan 2756 3027 else: 2757 return workscan 3028 if not insitu: 3029 return None 2758 3030 2759 3031 except RuntimeError, e: … … 2768 3040 chan_avg_limit=None, plot=None, 2769 3041 getresidual=None, showprogress=None, 2770 minnrow=None, outlog=None, blfile=None, csvformat=None): 3042 minnrow=None, outlog=None, 3043 blfile=None, csvformat=None, 3044 bltable=None): 2771 3045 """\ 2772 3046 Return a scan which has been baselined (all rows) with sinusoidal … … 2849 3123 (default is "": no file/logger output) 2850 3124 csvformat: if True blfile is csv-formatted, default is False. 3125 bltable: name of a baseline table where fitting results 3126 (coefficients, rms, etc.) are to be written. 3127 if given, fitting results will NOT be output to 3128 scantable (insitu=True) or None will be 3129 returned (insitu=False). 3130 (default is "": no table output) 2851 3131 2852 3132 Example: … … 2886 3166 if blfile is None: blfile = '' 2887 3167 if csvformat is None: csvformat = False 2888 2889 if csvformat: 2890 scsvformat = "T" 2891 else: 2892 scsvformat = "F" 3168 if bltable is None: bltable = '' 3169 3170 sapplyfft = 'true' if applyfft else 'false' 3171 fftinfo = ','.join([sapplyfft, fftmethod.lower(), str(fftthresh).lower()]) 3172 3173 scsvformat = 'T' if csvformat else 'F' 2893 3174 2894 3175 #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method. 2895 workscan._auto_sinusoid_baseline(mask, applyfft, 2896 fftmethod.lower(), 2897 str(fftthresh).lower(), 3176 workscan._auto_sinusoid_baseline(mask, 3177 fftinfo, 2898 3178 workscan._parse_wn(addwn), 2899 3179 workscan._parse_wn(rejwn), … … 2904 3184 pack_progress_params(showprogress, 2905 3185 minnrow), 2906 outlog, scsvformat+blfile )3186 outlog, scsvformat+blfile, bltable) 2907 3187 workscan._add_history("auto_sinusoid_baseline", varlist) 2908 2909 if insitu: 2910 self._assign(workscan) 3188 3189 if bltable == '': 3190 if insitu: 3191 self._assign(workscan) 3192 else: 3193 return workscan 2911 3194 else: 2912 return workscan 3195 if not insitu: 3196 return None 2913 3197 2914 3198 except RuntimeError, e: … … 2919 3203 clipthresh=None, clipniter=None, plot=None, 2920 3204 getresidual=None, showprogress=None, minnrow=None, 2921 outlog=None, blfile=None, csvformat=None): 3205 outlog=None, blfile=None, csvformat=None, 3206 bltable=None): 2922 3207 """\ 2923 3208 Return a scan which has been baselined (all rows) by cubic spline … … 2949 3234 (default is "": no file/logger output) 2950 3235 csvformat: if True blfile is csv-formatted, default is False. 3236 bltable: name of a baseline table where fitting results 3237 (coefficients, rms, etc.) are to be written. 3238 if given, fitting results will NOT be output to 3239 scantable (insitu=True) or None will be 3240 returned (insitu=False). 3241 (default is "": no table output) 2951 3242 2952 3243 Example: … … 2981 3272 if outlog is None: outlog = False 2982 3273 if blfile is None: blfile = '' 2983 if csvformat is None: csvformat = False 2984 2985 if csvformat: 2986 scsvformat = "T" 2987 else: 2988 scsvformat = "F" 3274 if csvformat is None: csvformat = False 3275 if bltable is None: bltable = '' 3276 3277 scsvformat = 'T' if csvformat else 'F' 2989 3278 2990 3279 #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method. 2991 workscan._cspline_baseline(mask, npiece, clipthresh, clipniter, 3280 workscan._cspline_baseline(mask, npiece, 3281 clipthresh, clipniter, 2992 3282 getresidual, 2993 3283 pack_progress_params(showprogress, 2994 3284 minnrow), 2995 outlog, scsvformat+blfile) 3285 outlog, scsvformat+blfile, 3286 bltable) 2996 3287 workscan._add_history("cspline_baseline", varlist) 2997 2998 if insitu: 2999 self._assign(workscan) 3288 3289 if bltable == '': 3290 if insitu: 3291 self._assign(workscan) 3292 else: 3293 return workscan 3000 3294 else: 3001 return workscan 3295 if not insitu: 3296 return None 3002 3297 3003 3298 except RuntimeError, e: … … 3010 3305 getresidual=None, plot=None, 3011 3306 showprogress=None, minnrow=None, outlog=None, 3012 blfile=None, csvformat=None ):3307 blfile=None, csvformat=None, bltable=None): 3013 3308 """\ 3014 3309 Return a scan which has been baselined (all rows) by cubic spline … … 3062 3357 (default is "": no file/logger output) 3063 3358 csvformat: if True blfile is csv-formatted, default is False. 3359 bltable: name of a baseline table where fitting results 3360 (coefficients, rms, etc.) are to be written. 3361 if given, fitting results will NOT be output to 3362 scantable (insitu=True) or None will be 3363 returned (insitu=False). 3364 (default is "": no table output) 3064 3365 3065 3366 Example: … … 3095 3396 if blfile is None: blfile = '' 3096 3397 if csvformat is None: csvformat = False 3097 3098 if csvformat: 3099 scsvformat = "T" 3100 else: 3101 scsvformat = "F" 3398 if bltable is None: bltable = '' 3399 3400 scsvformat = 'T' if csvformat else 'F' 3102 3401 3103 3402 #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method. 3104 workscan._auto_cspline_baseline(mask, npiece, clipthresh,3105 clip niter,3403 workscan._auto_cspline_baseline(mask, npiece, 3404 clipthresh, clipniter, 3106 3405 normalise_edge_param(edge), 3107 3406 threshold, … … 3109 3408 pack_progress_params(showprogress, 3110 3409 minnrow), 3111 outlog, scsvformat+blfile) 3410 outlog, 3411 scsvformat+blfile, 3412 bltable) 3112 3413 workscan._add_history("auto_cspline_baseline", varlist) 3113 3114 if insitu: 3115 self._assign(workscan) 3414 3415 if bltable == '': 3416 if insitu: 3417 self._assign(workscan) 3418 else: 3419 return workscan 3116 3420 else: 3117 return workscan 3421 if not insitu: 3422 return None 3118 3423 3119 3424 except RuntimeError, e: … … 3124 3429 clipthresh=None, clipniter=None, plot=None, 3125 3430 getresidual=None, showprogress=None, minnrow=None, 3126 outlog=None, blfile=None, csvformat=None): 3431 outlog=None, blfile=None, csvformat=None, 3432 bltable=None): 3127 3433 """\ 3128 3434 Return a scan which has been baselined (all rows) by Chebyshev polynomials. … … 3153 3459 (default is "": no file/logger output) 3154 3460 csvformat: if True blfile is csv-formatted, default is False. 3461 bltable: name of a baseline table where fitting results 3462 (coefficients, rms, etc.) are to be written. 3463 if given, fitting results will NOT be output to 3464 scantable (insitu=True) or None will be 3465 returned (insitu=False). 3466 (default is "": no table output) 3155 3467 3156 3468 Example: … … 3174 3486 workscan = self.copy() 3175 3487 3176 #if mask is None: mask = [True for i in xrange(workscan.nchan())]3177 3488 if mask is None: mask = [] 3178 3489 if order is None: order = 5 … … 3185 3496 if outlog is None: outlog = False 3186 3497 if blfile is None: blfile = '' 3187 if csvformat is None: csvformat = False 3188 3189 if csvformat: 3190 scsvformat = "T" 3191 else: 3192 scsvformat = "F" 3498 if csvformat is None: csvformat = False 3499 if bltable is None: bltable = '' 3500 3501 scsvformat = 'T' if csvformat else 'F' 3193 3502 3194 3503 #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method. 3195 workscan._chebyshev_baseline(mask, order, clipthresh, clipniter, 3504 workscan._chebyshev_baseline(mask, order, 3505 clipthresh, clipniter, 3196 3506 getresidual, 3197 3507 pack_progress_params(showprogress, 3198 3508 minnrow), 3199 outlog, scsvformat+blfile) 3509 outlog, scsvformat+blfile, 3510 bltable) 3200 3511 workscan._add_history("chebyshev_baseline", varlist) 3201 3202 if insitu: 3203 self._assign(workscan) 3512 3513 if bltable == '': 3514 if insitu: 3515 self._assign(workscan) 3516 else: 3517 return workscan 3204 3518 else: 3205 return workscan 3519 if not insitu: 3520 return None 3206 3521 3207 3522 except RuntimeError, e: … … 3214 3529 getresidual=None, plot=None, 3215 3530 showprogress=None, minnrow=None, outlog=None, 3216 blfile=None, csvformat=None ):3531 blfile=None, csvformat=None, bltable=None): 3217 3532 """\ 3218 3533 Return a scan which has been baselined (all rows) by Chebyshev polynomials. … … 3265 3580 (default is "": no file/logger output) 3266 3581 csvformat: if True blfile is csv-formatted, default is False. 3582 bltable: name of a baseline table where fitting results 3583 (coefficients, rms, etc.) are to be written. 3584 if given, fitting results will NOT be output to 3585 scantable (insitu=True) or None will be 3586 returned (insitu=False). 3587 (default is "": no table output) 3267 3588 3268 3589 Example: … … 3283 3604 workscan = self.copy() 3284 3605 3285 #if mask is None: mask = [True for i in xrange(workscan.nchan())]3286 3606 if mask is None: mask = [] 3287 3607 if order is None: order = 5 … … 3298 3618 if blfile is None: blfile = '' 3299 3619 if csvformat is None: csvformat = False 3300 3301 if csvformat: 3302 scsvformat = "T" 3303 else: 3304 scsvformat = "F" 3620 if bltable is None: bltable = '' 3621 3622 scsvformat = 'T' if csvformat else 'F' 3305 3623 3306 3624 #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method. 3307 workscan._auto_chebyshev_baseline(mask, order, clipthresh,3308 clip niter,3625 workscan._auto_chebyshev_baseline(mask, order, 3626 clipthresh, clipniter, 3309 3627 normalise_edge_param(edge), 3310 3628 threshold, … … 3312 3630 pack_progress_params(showprogress, 3313 3631 minnrow), 3314 outlog, scsvformat+blfile) 3632 outlog, scsvformat+blfile, 3633 bltable) 3315 3634 workscan._add_history("auto_chebyshev_baseline", varlist) 3316 3317 if insitu: 3318 self._assign(workscan) 3635 3636 if bltable == '': 3637 if insitu: 3638 self._assign(workscan) 3639 else: 3640 return workscan 3319 3641 else: 3320 return workscan 3642 if not insitu: 3643 return None 3321 3644 3322 3645 except RuntimeError, e: … … 3324 3647 3325 3648 @asaplog_post_dec 3326 def poly_baseline(self, mask=None, order=None, insitu=None, plot=None, 3649 def poly_baseline(self, insitu=None, mask=None, order=None, 3650 clipthresh=None, clipniter=None, plot=None, 3327 3651 getresidual=None, showprogress=None, minnrow=None, 3328 outlog=None, blfile=None, csvformat=None): 3652 outlog=None, blfile=None, csvformat=None, 3653 bltable=None): 3329 3654 """\ 3330 3655 Return a scan which has been baselined (all rows) by a polynomial. … … 3335 3660 mask: an optional mask 3336 3661 order: the order of the polynomial (default is 0) 3662 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 3663 clipniter: maximum number of iteration of 'clipthresh'-sigma 3664 clipping (default is 0) 3337 3665 plot: plot the fit and the residual. In this each 3338 3666 indivual fit has to be approved, by typing 'y' … … 3350 3678 (default is "": no file/logger output) 3351 3679 csvformat: if True blfile is csv-formatted, default is False. 3680 bltable: name of a baseline table where fitting results 3681 (coefficients, rms, etc.) are to be written. 3682 if given, fitting results will NOT be output to 3683 scantable (insitu=True) or None will be 3684 returned (insitu=False). 3685 (default is "": no table output) 3352 3686 3353 3687 Example: … … 3367 3701 workscan = self.copy() 3368 3702 3369 #if mask is None: mask = [True for i in \3370 # xrange(workscan.nchan())]3371 3703 if mask is None: mask = [] 3372 3704 if order is None: order = 0 3705 if clipthresh is None: clipthresh = 3.0 3706 if clipniter is None: clipniter = 0 3373 3707 if plot is None: plot = False 3374 3708 if getresidual is None: getresidual = True … … 3376 3710 if minnrow is None: minnrow = 1000 3377 3711 if outlog is None: outlog = False 3378 if blfile is None: blfile = ""3712 if blfile is None: blfile = '' 3379 3713 if csvformat is None: csvformat = False 3380 3381 if csvformat: 3382 scsvformat = "T" 3383 else: 3384 scsvformat = "F" 3714 if bltable is None: bltable = '' 3715 3716 scsvformat = 'T' if csvformat else 'F' 3385 3717 3386 3718 if plot: … … 3446 3778 blf.close() 3447 3779 else: 3448 workscan._poly_baseline(mask, order, getresidual, 3780 workscan._poly_baseline(mask, order, 3781 clipthresh, clipniter, # 3782 getresidual, 3449 3783 pack_progress_params(showprogress, 3450 3784 minnrow), 3451 outlog, scsvformat+blfile) 3785 outlog, scsvformat+blfile, 3786 bltable) # 3452 3787 3453 3788 workscan._add_history("poly_baseline", varlist) … … 3462 3797 3463 3798 @asaplog_post_dec 3464 def auto_poly_baseline(self, mask=None, order=None, edge=None, 3465 threshold=None, chan_avg_limit=None, 3466 plot=None, insitu=None, 3467 getresidual=None, showprogress=None, 3468 minnrow=None, outlog=None, blfile=None, csvformat=None): 3799 def auto_poly_baseline(self, insitu=None, mask=None, order=None, 3800 clipthresh=None, clipniter=None, 3801 edge=None, threshold=None, chan_avg_limit=None, 3802 getresidual=None, plot=None, 3803 showprogress=None, minnrow=None, outlog=None, 3804 blfile=None, csvformat=None, bltable=None): 3469 3805 """\ 3470 3806 Return a scan which has been baselined (all rows) by a polynomial. … … 3478 3814 mask: an optional mask retreived from scantable 3479 3815 order: the order of the polynomial (default is 0) 3816 clipthresh: Clipping threshold. (default is 3.0, unit: sigma) 3817 clipniter: maximum number of iteration of 'clipthresh'-sigma 3818 clipping (default is 0) 3480 3819 edge: an optional number of channel to drop at 3481 3820 the edge of spectrum. If only one value is … … 3513 3852 (default is "": no file/logger output) 3514 3853 csvformat: if True blfile is csv-formatted, default is False. 3854 bltable: name of a baseline table where fitting results 3855 (coefficients, rms, etc.) are to be written. 3856 if given, fitting results will NOT be output to 3857 scantable (insitu=True) or None will be 3858 returned (insitu=False). 3859 (default is "": no table output) 3515 3860 3516 3861 Example: … … 3528 3873 workscan = self.copy() 3529 3874 3530 #if mask is None: mask = [True for i in xrange(workscan.nchan())]3531 3875 if mask is None: mask = [] 3532 3876 if order is None: order = 0 3877 if clipthresh is None: clipthresh = 3.0 3878 if clipniter is None: clipniter = 0 3533 3879 if edge is None: edge = (0, 0) 3534 3880 if threshold is None: threshold = 3 … … 3541 3887 if blfile is None: blfile = '' 3542 3888 if csvformat is None: csvformat = False 3543 3544 if csvformat: 3545 scsvformat = "T" 3546 else: 3547 scsvformat = "F" 3889 if bltable is None: bltable = '' 3890 3891 scsvformat = 'T' if csvformat else 'F' 3548 3892 3549 3893 edge = normalise_edge_param(edge) … … 3615 3959 if outblfile: blf.close() 3616 3960 else: 3617 workscan._auto_poly_baseline(mask, order, edge, threshold, 3961 workscan._auto_poly_baseline(mask, order, 3962 clipthresh, clipniter, 3963 edge, threshold, 3618 3964 chan_avg_limit, getresidual, 3619 3965 pack_progress_params(showprogress, 3620 3966 minnrow), 3621 outlog, scsvformat+blfile )3622 3967 outlog, scsvformat+blfile, 3968 bltable) 3623 3969 workscan._add_history("auto_poly_baseline", varlist) 3624 3625 if insitu: 3626 self._assign(workscan) 3970 3971 if bltable == '': 3972 if insitu: 3973 self._assign(workscan) 3974 else: 3975 return workscan 3627 3976 else: 3628 return workscan 3977 if not insitu: 3978 return None 3629 3979 3630 3980 except RuntimeError, e:
Note:
See TracChangeset
for help on using the changeset viewer.