Changeset 2767
- Timestamp:
- 02/08/13 22:23:22 (12 years ago)
- Location:
- trunk
- Files:
-
- 8 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: -
trunk/src/STBaselineEnum.h
r2737 r2767 28 28 class STBaselineFunc { 29 29 public: 30 enum FuncName {Polynomial = 0,30 enum FuncName {Polynomial = 1, 31 31 CSpline, 32 32 Sinusoid, -
trunk/src/STBaselineTable.cpp
r2740 r2767 51 51 void STBaselineTable::setup() 52 52 { 53 table_.addColumn(ScalarColumnDesc< uInt>("NCHAN"));53 table_.addColumn(ScalarColumnDesc<Bool>("APPLY")); 54 54 table_.addColumn(ScalarColumnDesc<uInt>("FUNC_TYPE")); 55 table_.addColumn(ArrayColumnDesc< uInt>("FUNC_PARAM"));55 table_.addColumn(ArrayColumnDesc<Int>("FUNC_PARAM")); 56 56 table_.addColumn(ArrayColumnDesc<Float>("FUNC_FPARAM")); 57 table_.addColumn(ScalarColumnDesc<uInt>("CLIP_ITERATION"));58 table_.addColumn(ScalarColumnDesc<Float>("CLIP_THRESHOLD"));59 57 table_.addColumn(ArrayColumnDesc<uInt>("MASKLIST")); 60 58 table_.addColumn(ArrayColumnDesc<Float>("RESULT")); 61 59 table_.addColumn(ScalarColumnDesc<Float>("RMS")); 60 table_.addColumn(ScalarColumnDesc<uInt>("NCHAN")); 61 table_.addColumn(ScalarColumnDesc<Float>("CLIP_THRESHOLD")); 62 table_.addColumn(ScalarColumnDesc<uInt>("CLIP_ITERATION")); 63 table_.addColumn(ScalarColumnDesc<Float>("LF_THRESHOLD")); 64 table_.addColumn(ScalarColumnDesc<uInt>("LF_AVERAGE")); 65 table_.addColumn(ArrayColumnDesc<uInt>("LF_EDGE")); 62 66 63 67 table_.rwKeywordSet().define("ApplyType", "BASELINE"); … … 68 72 void STBaselineTable::attachOptionalColumns() 69 73 { 70 nchanCol_.attach(table_, "NCHAN");74 applyCol_.attach(table_, "APPLY"); 71 75 ftypeCol_.attach(table_, "FUNC_TYPE"); 72 76 fparCol_.attach(table_, "FUNC_PARAM"); 73 77 ffparCol_.attach(table_, "FUNC_FPARAM"); 74 citerCol_.attach(table_, "CLIP_ITERATION");75 cthresCol_.attach(table_, "CLIP_THRESHOLD");76 78 maskCol_.attach(table_, "MASKLIST"); 77 79 resCol_.attach(table_, "RESULT"); 78 80 rmsCol_.attach(table_, "RMS"); 81 nchanCol_.attach(table_, "NCHAN"); 82 cthresCol_.attach(table_, "CLIP_THRESHOLD"); 83 citerCol_.attach(table_, "CLIP_ITERATION"); 84 lfthresCol_.attach(table_, "LF_THRESHOLD"); 85 lfavgCol_.attach(table_, "LF_AVERAGE"); 86 lfedgeCol_.attach(table_, "LF_EDGE"); 79 87 } 80 88 … … 90 98 uInt beamno, uInt ifno, uInt polno, 91 99 uInt freqid, Double time, 92 uInt nchan,100 Bool apply, 93 101 STBaselineFunc::FuncName ftype, 94 Vector< uInt> fpar,102 Vector<Int> fpar, 95 103 Vector<Float> ffpar, 96 uInt citer,97 Float cthres,98 104 Vector<uInt> mask, 99 105 Vector<Float> res, 100 Float rms) 106 Float rms, 107 uInt nchan, 108 Float cthres, 109 uInt citer, 110 Float lfthres, 111 uInt lfavg, 112 Vector<uInt> lfedge) 101 113 { 102 114 if (irow >= (uInt)nrow()) { … … 110 122 111 123 setbasedata(irow, scanno, cycleno, beamno, ifno, polno, freqid, time); 112 nchanCol_.put(irow, nchan);124 applyCol_.put(irow, apply); 113 125 ftypeCol_.put(irow, uInt(ftype)); 114 126 fparCol_.put(irow, fpar); 115 127 ffparCol_.put(irow, ffpar); 116 citerCol_.put(irow, citer);117 cthresCol_.put(irow, cthres);118 128 maskCol_.put(irow, mask); 119 129 resCol_.put(irow, res); 120 130 rmsCol_.put(irow, rms); 131 nchanCol_.put(irow, nchan); 132 cthresCol_.put(irow, cthres); 133 citerCol_.put(irow, citer); 134 lfthresCol_.put(irow, lfthres); 135 lfavgCol_.put(irow, lfavg); 136 lfedgeCol_.put(irow, lfedge); 121 137 } 122 138 … … 124 140 uInt beamno, uInt ifno, uInt polno, 125 141 uInt freqid, Double time, 126 uInt nchan,142 Bool apply, 127 143 STBaselineFunc::FuncName ftype, 128 Vector< uInt> fpar,144 Vector<Int> fpar, 129 145 Vector<Float> ffpar, 130 uInt citer,131 Float cthres,132 146 Vector<uInt> mask, 133 147 Vector<Float> res, 134 Float rms) 148 Float rms, 149 uInt nchan, 150 Float cthres, 151 uInt citer, 152 Float lfthres, 153 uInt lfavg, 154 Vector<uInt> lfedge) 135 155 { 136 156 uInt irow = nrow(); 137 157 table_.addRow(1, True); 138 158 setdata(irow, scanno, cycleno, beamno, ifno, polno, freqid, time, 139 nchan, ftype, fpar, ffpar, citer, cthres, mask, res, rms); 140 } 141 142 Vector<STBaselineFunc::FuncName> STBaselineTable::getFunctionAsString() 159 apply, ftype, fpar, ffpar, mask, res, rms, 160 nchan, cthres, citer, lfthres, lfavg, lfedge); 161 } 162 163 void STBaselineTable::appendbasedata(int scanno, int cycleno, 164 int beamno, int ifno, int polno, 165 int freqid, Double time) 166 { 167 uInt irow = nrow(); 168 table_.addRow(1, True); 169 setbasedata(irow, uInt(scanno), uInt(cycleno), uInt(beamno), uInt(ifno), uInt(polno), uInt(freqid), time); 170 } 171 172 void STBaselineTable::setresult(casa::uInt irow, 173 casa::Vector<casa::Float> res, 174 casa::Float rms) 175 { 176 resCol_.put(irow, res); 177 rmsCol_.put(irow, rms); 178 } 179 180 bool STBaselineTable::getApply(int irow) 181 { 182 return (bool)applyCol_.get(irow); 183 } 184 185 void STBaselineTable::setApply(int irow, bool apply) 186 { 187 applyCol_.put(uInt(irow), Bool(apply)); 188 } 189 190 Vector<STBaselineFunc::FuncName> STBaselineTable::getFunctionNames() 143 191 { 144 192 Vector<uInt> rawBlfuncColumn = ftypeCol_.getColumn(); … … 149 197 } 150 198 return blfuncColumn; 199 } 200 201 STBaselineFunc::FuncName STBaselineTable::getFunctionName(int irow) 202 { 203 return STBaselineFunc::FuncName(ftypeCol_.get(irow)); 204 } 205 206 std::vector<int> STBaselineTable::getFuncParam(int irow) 207 { 208 Vector<Int> uiparam = fparCol_.get(irow); 209 std::vector<int> res(uiparam.size()); 210 for (uInt i = 0; i < res.size(); ++i) { 211 res[i] = (int)uiparam[i]; 212 } 213 return res; 214 } 215 216 std::vector<bool> STBaselineTable::getMask(int irow) 217 { 218 uInt nchan = getNChan(irow); 219 Vector<uInt> masklist = maskCol_.get(irow); 220 std::vector<int> masklist1(masklist.size()); 221 for (uInt i = 0; i < masklist1.size(); ++i) { 222 masklist1[i] = (int)masklist[i]; 223 } 224 return Scantable::getMaskFromMaskList(nchan, masklist1); 225 } 226 227 uInt STBaselineTable::getNChan(int irow) 228 { 229 return nchanCol_.get(irow); 151 230 } 152 231 -
trunk/src/STBaselineTable.h
r2740 r2767 46 46 casa::uInt beamno, casa::uInt ifno, casa::uInt polno, 47 47 casa::uInt freqid, casa::Double time, 48 casa::uInt nchan, 48 casa::Bool apply, 49 49 STBaselineFunc::FuncName ftype, 50 casa::Vector<casa:: uInt> fpar,50 casa::Vector<casa::Int> fpar, 51 51 casa::Vector<casa::Float> ffpar, 52 casa::uInt citer,53 casa::Float cthres,54 52 casa::Vector<casa::uInt> mask, 55 53 casa::Vector<casa::Float> res, 56 casa::Float rms); 54 casa::Float rms, 55 casa::uInt nchan, 56 casa::Float cthres, 57 casa::uInt citer, 58 casa::Float lfthres, 59 casa::uInt lfavg, 60 casa::Vector<casa::uInt> lfedge); 57 61 void appenddata(casa::uInt scanno, casa::uInt cycleno, 58 62 casa::uInt beamno, casa::uInt ifno, casa::uInt polno, 59 63 casa::uInt freqid, casa::Double time, 60 casa:: uInt nchan,64 casa::Bool apply, 61 65 STBaselineFunc::FuncName ftype, 62 casa::Vector<casa:: uInt> fpar,66 casa::Vector<casa::Int> fpar, 63 67 casa::Vector<casa::Float> ffpar, 64 casa::uInt citer,65 casa::Float cthres,66 68 casa::Vector<casa::uInt> mask, 67 69 casa::Vector<casa::Float> res, 68 casa::Float rms); 70 casa::Float rms, 71 casa::uInt nchan, 72 casa::Float cthres, 73 casa::uInt citer, 74 casa::Float lfthres, 75 casa::uInt lfavg, 76 casa::Vector<casa::uInt> lfedge); 77 void appendbasedata(int scanno, int cycleno, 78 int beamno, int ifno, int polno, 79 int freqid, casa::Double time); 80 void setresult(casa::uInt irow, 81 casa::Vector<casa::Float> res, 82 casa::Float rms); 69 83 casa::uInt nchan(casa::uInt ifno); 84 casa::Vector<casa::Bool> getApply() {return applyCol_.getColumn();} 85 bool getApply(int irow); 70 86 casa::Vector<casa::uInt> getFunction() {return ftypeCol_.getColumn();} 71 casa::Vector<STBaselineFunc::FuncName> getFunctionAsString(); 72 casa::Matrix<casa::uInt> getFuncParam() {return fparCol_.getColumn();} 87 casa::Vector<STBaselineFunc::FuncName> getFunctionNames(); 88 STBaselineFunc::FuncName getFunctionName(int irow); 89 casa::Matrix<casa::Int> getFuncParam() {return fparCol_.getColumn();} 90 std::vector<int> getFuncParam(int irow); 73 91 casa::Matrix<casa::Float> getFuncFParam() {return ffparCol_.getColumn();} 74 casa::Vector<casa::uInt> getClipIteration() {return citerCol_.getColumn();}75 casa::Vector<casa::Float> getClipThreshold() {return cthresCol_.getColumn();}76 92 casa::Matrix<casa::uInt> getMaskList() {return maskCol_.getColumn();} 93 std::vector<bool> getMask(int irow); 77 94 casa::Matrix<casa::Float> getResult() {return resCol_.getColumn();} 78 95 casa::Vector<casa::Float> getRms() {return rmsCol_.getColumn();} 96 casa::Vector<casa::uInt> getNChan() {return nchanCol_.getColumn();} 97 casa::uInt getNChan(int irow); 98 casa::Vector<casa::Float> getClipThreshold() {return cthresCol_.getColumn();} 99 casa::Vector<casa::uInt> getClipIteration() {return citerCol_.getColumn();} 100 casa::Vector<casa::Float> getLineFinderThreshold() {return lfthresCol_.getColumn();} 101 casa::Vector<casa::uInt> getLineFinderChanAvg() {return lfavgCol_.getColumn();} 102 casa::Matrix<casa::uInt> getLineFinderEdge() {return lfedgeCol_.getColumn();} 103 void setApply(int irow, bool apply); 79 104 80 105 private: 81 106 static const casa::String name_ ; 82 casa::ScalarColumn<casa:: uInt> nchanCol_;107 casa::ScalarColumn<casa::Bool> applyCol_; 83 108 casa::ScalarColumn<casa::uInt> ftypeCol_; 84 casa::ArrayColumn<casa:: uInt> fparCol_;109 casa::ArrayColumn<casa::Int> fparCol_; 85 110 casa::ArrayColumn<casa::Float> ffparCol_; 86 casa::ScalarColumn<casa::uInt> citerCol_;87 casa::ScalarColumn<casa::Float> cthresCol_;88 111 casa::ArrayColumn<casa::uInt> maskCol_; 89 112 casa::ArrayColumn<casa::Float> resCol_; 90 113 casa::ScalarColumn<casa::Float> rmsCol_; 114 casa::ScalarColumn<casa::uInt> nchanCol_; 115 casa::ScalarColumn<casa::Float> cthresCol_; 116 casa::ScalarColumn<casa::uInt> citerCol_; 117 casa::ScalarColumn<casa::Float> lfthresCol_; 118 casa::ScalarColumn<casa::uInt> lfavgCol_; 119 casa::ArrayColumn<casa::uInt> lfedgeCol_; 91 120 }; 92 121 -
trunk/src/Scantable.cpp
r2740 r2767 2490 2490 } 2491 2491 2492 void Scantable::polyBaseline(const std::vector<bool>& mask, int order, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile) 2493 { 2492 std::vector<std::string> Scantable::applyBaselineTable(const std::string& bltable, const std::string& outbltable, const bool outbltableexists, const bool overwrite) 2493 { 2494 STBaselineTable* btin = new STBaselineTable(bltable); 2495 2496 Vector<Bool> applyCol = btin->getApply(); 2497 int nRowBl = applyCol.size(); 2498 if (nRowBl != nrow()) { 2499 throw(AipsError("Scantable and bltable have different number of rows.")); 2500 } 2501 2502 std::vector<std::string> res; 2503 res.clear(); 2504 2505 bool outBaselineTable = ((outbltable != "") && (!outbltableexists || overwrite)); 2506 bool bltableidentical = (bltable == outbltable); 2507 STBaselineTable* btout = new STBaselineTable(*this); 2508 ROScalarColumn<Double> *tcol = new ROScalarColumn<Double>(table_, "TIME"); 2509 Vector<Double> timeSecCol = tcol->getColumn(); 2510 2511 for (int whichrow = 0; whichrow < nRowBl; ++whichrow) { 2512 if (applyCol[whichrow]) { 2513 std::vector<float> spec = getSpectrum(whichrow); 2514 2515 //--channel mask-- maybe the following choices should be available 2516 std::vector<bool> mask = btin->getMask(whichrow); //use mask_bltable only (default) 2517 //std::vector<bool> mask = getMask(whichrow); // or mask_scantable only 2518 //std::vector<bool> mask = getCompositeChanMask(whichrow, btin->getMask(whichrow)); // or mask_scantable && mask_bltable 2519 2520 STBaselineFunc::FuncName ftype = btin->getFunctionName(whichrow); 2521 std::vector<int> fpar = btin->getFuncParam(whichrow); 2522 std::vector<float> params; 2523 float rms; 2524 std::vector<float> resfit = doApplyBaselineTable(spec, mask, ftype, fpar, params, rms); 2525 2526 setSpectrum(resfit, whichrow); 2527 2528 res.push_back(packFittingResults(whichrow, params, rms)); 2529 2530 if (outBaselineTable) { 2531 Vector<Int> fparam(fpar.size()); 2532 for (uInt j = 0; j < fparam.size(); ++j) { 2533 fparam[j] = (Int)fpar[j]; 2534 } 2535 std::vector<int> maskList0; 2536 maskList0.clear(); 2537 for (uInt j = 0; j < mask.size(); ++j) { 2538 if (mask[j]) { 2539 if ((j == 0)||(j == mask.size()-1)) { 2540 maskList0.push_back(j); 2541 } else { 2542 if ((mask[j])&&(!mask[j-1])) { 2543 maskList0.push_back(j); 2544 } 2545 if ((mask[j])&&(!mask[j+1])) { 2546 maskList0.push_back(j); 2547 } 2548 } 2549 } 2550 } 2551 Vector<uInt> maskList(maskList0.size()); 2552 for (uInt j = 0; j < maskList0.size(); ++j) { 2553 maskList[j] = (uInt)maskList0[j]; 2554 } 2555 2556 if (outbltableexists) { 2557 if (overwrite) { 2558 if (bltableidentical) { 2559 btin->setresult(uInt(whichrow), Vector<Float>(params), Float(rms)); 2560 } else { 2561 btout->setresult(uInt(whichrow), Vector<Float>(params), Float(rms)); 2562 } 2563 } 2564 } else { 2565 btout->appenddata(uInt(getScan(whichrow)), uInt(getCycle(whichrow)), 2566 uInt(getBeam(whichrow)), uInt(getIF(whichrow)), uInt(getPol(whichrow)), 2567 uInt(0), timeSecCol[whichrow], Bool(true), ftype, fparam, 2568 Vector<Float>(), maskList, Vector<Float>(params), 2569 Float(rms), uInt(spec.size()), Float(3.0), uInt(0), 2570 Float(0.0), uInt(0), Vector<uInt>()); 2571 } 2572 } 2573 } 2574 } 2575 2576 if (outBaselineTable) { 2577 if (bltableidentical) { 2578 btin->save(outbltable); 2579 } else { 2580 btout->save(outbltable); 2581 } 2582 } 2583 delete btin; 2584 delete btout; 2585 2586 return res; 2587 } 2588 2589 std::vector<std::string> Scantable::subBaseline(const std::vector<std::string>& blInfoList, const std::string& outbltable, const bool outbltableexists, const bool overwrite) 2590 { 2591 int nRowBl = blInfoList.size(); 2592 int nRowSt = nrow(); 2593 2594 std::vector<std::string> res; 2595 res.clear(); 2596 2597 bool outBaselineTable = ((outbltable != "") && (!outbltableexists || overwrite)); 2598 if ((outbltable != "") && outbltableexists && !overwrite) { 2599 throw(AipsError("Cannot overwrite bltable. Set overwrite=True.")); 2600 } 2601 2602 STBaselineTable* bt = new STBaselineTable(*this); 2603 ROScalarColumn<Double> *tcol = new ROScalarColumn<Double>(table_, "TIME"); 2604 Vector<Double> timeSecCol = tcol->getColumn(); 2605 2606 if (outBaselineTable && !outbltableexists) { 2607 for (int i = 0; i < nRowSt; ++i) { 2608 bt->appendbasedata(getScan(i), getCycle(i), getBeam(i), getIF(i), getPol(i), 2609 0, timeSecCol[i]); 2610 bt->setApply(i, false); 2611 } 2612 } 2613 2614 for (int i = 0; i < nRowBl; ++i) { 2615 int irow; 2616 STBaselineFunc::FuncName ftype; 2617 std::vector<bool> mask; 2618 std::vector<int> fpar; 2619 float clipth; 2620 int clipn; 2621 bool uself; 2622 float lfth; 2623 std::vector<int> lfedge; 2624 int lfavg; 2625 parseBlInfo(blInfoList[i], irow, ftype, fpar, mask, clipth, clipn, uself, lfth, lfedge, lfavg); 2626 2627 if (irow < nRowSt) { 2628 std::vector<float> spec = getSpectrum(irow); 2629 std::vector<float> params; 2630 float rms; 2631 std::vector<bool> finalmask; 2632 2633 std::vector<float> resfit = doSubtractBaseline(spec, mask, ftype, fpar, params, rms, finalmask, clipth, clipn, uself, irow, lfth, lfedge, lfavg); 2634 setSpectrum(resfit, irow); 2635 res.push_back(packFittingResults(irow, params, rms)); 2636 2637 if (outBaselineTable) { 2638 Vector<Int> fparam(fpar.size()); 2639 for (uInt j = 0; j < fparam.size(); ++j) { 2640 fparam[j] = (Int)fpar[j]; 2641 } 2642 std::vector<int> maskList0; 2643 maskList0.clear(); 2644 for (uInt j = 0; j < finalmask.size(); ++j) { 2645 if (finalmask[j]) { 2646 if ((j == 0)||(j == finalmask.size()-1)) { 2647 maskList0.push_back(j); 2648 } else { 2649 if ((finalmask[j])&&(!finalmask[j-1])) { 2650 maskList0.push_back(j); 2651 } 2652 if ((finalmask[j])&&(!finalmask[j+1])) { 2653 maskList0.push_back(j); 2654 } 2655 } 2656 } 2657 } 2658 Vector<uInt> maskList(maskList0.size()); 2659 for (uInt j = 0; j < maskList0.size(); ++j) { 2660 maskList[j] = (uInt)maskList0[j]; 2661 } 2662 2663 bt->setdata(uInt(irow), 2664 uInt(getScan(irow)), uInt(getCycle(irow)), 2665 uInt(getBeam(irow)), uInt(getIF(irow)), uInt(getPol(irow)), 2666 uInt(0), timeSecCol[irow], Bool(true), ftype, fparam, 2667 Vector<Float>(), maskList, Vector<Float>(params), 2668 Float(rms), uInt(spec.size()), Float(clipth), uInt(clipn), 2669 Float(0.0), uInt(0), Vector<uInt>()); 2670 } 2671 2672 } 2673 } 2674 2675 if (outBaselineTable) { 2676 bt->save(outbltable); 2677 } 2678 delete bt; 2679 2680 return res; 2681 } 2682 2683 std::vector<float> Scantable::doApplyBaselineTable(std::vector<float>& spec, std::vector<bool>& mask, const STBaselineFunc::FuncName ftype, std::vector<int>& fpar, std::vector<float>& params, float&rms) 2684 { 2685 std::vector<bool> finalmask; 2686 std::vector<int> lfedge; 2687 return doSubtractBaseline(spec, mask, ftype, fpar, params, rms, finalmask, 0.0, 0, false, 0, 0.0, lfedge, 0); 2688 } 2689 2690 std::vector<float> Scantable::doSubtractBaseline(std::vector<float>& spec, std::vector<bool>& mask, const STBaselineFunc::FuncName ftype, std::vector<int>& fpar, std::vector<float>& params, float&rms, std::vector<bool>& finalmask, float clipth, int clipn, bool uself, int irow, float lfth, std::vector<int>& lfedge, int lfavg) 2691 { 2692 //---replace mask with (mask AND mask_linefinder). 2693 if (uself) { 2694 STLineFinder lineFinder = STLineFinder(); 2695 lineFinder.setOptions(lfth, 3, lfavg); 2696 2697 int minEdgeSize = getIFNos().size()*2; 2698 int edgeSize = lfedge.size(); 2699 std::vector<int> currentEdge; 2700 currentEdge.clear(); 2701 if (edgeSize >= 2) { 2702 int idx = 0; 2703 if (edgeSize > 2) { 2704 if (edgeSize < minEdgeSize) { 2705 throw(AipsError("Length of edge element info is less than that of IFs")); 2706 } 2707 idx = 2 * getIF(irow); 2708 } 2709 currentEdge.push_back(lfedge[idx]); 2710 currentEdge.push_back(lfedge[idx+1]); 2711 } else { 2712 throw(AipsError("Wrong length of edge element")); 2713 } 2714 lineFinder.setData(spec); 2715 lineFinder.findLines(getCompositeChanMask(irow, mask), currentEdge, irow); 2716 2717 std::vector<bool> lfcompmask = lineFinder.getMask(); 2718 mask.clear(); 2719 mask.resize(lfcompmask.size()); 2720 for (uInt i = 0; i < mask.size(); ++i) { 2721 mask[i] = lfcompmask[i]; 2722 } 2723 } 2724 //--- 2725 2726 std::vector<float> res; 2727 if (ftype == STBaselineFunc::Polynomial) { 2728 res = doPolynomialFitting(spec, mask, fpar[0], params, rms, finalmask, clipth, clipn); 2729 } else if (ftype == STBaselineFunc::Chebyshev) { 2730 res = doChebyshevFitting(spec, mask, fpar[0], params, rms, finalmask, clipth, clipn); 2731 } else if (ftype == STBaselineFunc::CSpline) { 2732 if (fpar.size() > 1) { // reading from baseline table in which pieceEdges are already calculated and stored. 2733 res = doCubicSplineFitting(spec, mask, fpar, params, rms, finalmask, clipth, clipn); 2734 } else { // usual cspline fitting by giving nPiece only. fpar will be replaced with pieceEdges. 2735 res = doCubicSplineFitting(spec, mask, fpar[0], fpar, params, rms, finalmask, clipth, clipn); 2736 } 2737 } else if (ftype == STBaselineFunc::Sinusoid) { 2738 res = doSinusoidFitting(spec, mask, fpar, params, rms, finalmask, clipth, clipn); 2739 } 2740 2741 return res; 2742 } 2743 2744 std::string Scantable::packFittingResults(const int irow, const std::vector<float>& params, const float rms) 2745 { 2746 // returned value: "irow:params[0],params[1],..,params[n-1]:rms" 2747 ostringstream os; 2748 os << irow << ':'; 2749 for (uInt i = 0; i < params.size(); ++i) { 2750 if (i > 0) { 2751 os << ','; 2752 } 2753 os << params[i]; 2754 } 2755 os << ':' << rms; 2756 2757 return os.str(); 2758 } 2759 2760 void Scantable::parseBlInfo(const std::string& blInfo, int& irow, STBaselineFunc::FuncName& ftype, std::vector<int>& fpar, std::vector<bool>& mask, float& thresClip, int& nIterClip, bool& useLineFinder, float& thresLF, std::vector<int>& edgeLF, int& avgLF) 2761 { 2762 // The baseline info to be parsed must be column-delimited string like 2763 // "0:chebyshev:5:3,5,169,174,485,487" where the elements are 2764 // row number, funcType, funcOrder, maskList, clipThreshold, clipNIter, 2765 // useLineFinder, lfThreshold, lfEdge and lfChanAvgLimit. 2766 2767 std::vector<string> res = splitToStringList(blInfo, ':'); 2768 if (res.size() < 4) { 2769 throw(AipsError("baseline info has bad format")) ; 2770 } 2771 2772 string ftype0, fpar0, masklist0, uself0, edge0; 2773 std::vector<int> masklist; 2774 2775 stringstream ss; 2776 ss << res[0]; 2777 ss >> irow; 2778 ss.clear(); ss.str(""); 2779 2780 ss << res[1]; 2781 ss >> ftype0; 2782 if (ftype0 == "poly") { 2783 ftype = STBaselineFunc::Polynomial; 2784 } else if (ftype0 == "cspline") { 2785 ftype = STBaselineFunc::CSpline; 2786 } else if (ftype0 == "sinusoid") { 2787 ftype = STBaselineFunc::Sinusoid; 2788 } else if (ftype0 == "chebyshev") { 2789 ftype = STBaselineFunc::Chebyshev; 2790 } else { 2791 throw(AipsError("invalid function type.")); 2792 } 2793 ss.clear(); ss.str(""); 2794 2795 ss << res[2]; 2796 ss >> fpar0; 2797 fpar = splitToIntList(fpar0, ','); 2798 ss.clear(); ss.str(""); 2799 2800 ss << res[3]; 2801 ss >> masklist0; 2802 mask = getMaskFromMaskList(nchan(getIF(irow)), splitToIntList(masklist0, ',')); 2803 2804 ss << res[4]; 2805 ss >> thresClip; 2806 ss.clear(); ss.str(""); 2807 2808 ss << res[5]; 2809 ss >> nIterClip; 2810 ss.clear(); ss.str(""); 2811 2812 ss << res[6]; 2813 ss >> uself0; 2814 if (uself0 == "true") { 2815 useLineFinder = true; 2816 } else { 2817 useLineFinder = false; 2818 } 2819 ss.clear(); ss.str(""); 2820 2821 if (useLineFinder) { 2822 ss << res[7]; 2823 ss >> thresLF; 2824 ss.clear(); ss.str(""); 2825 2826 ss << res[8]; 2827 ss >> edge0; 2828 edgeLF = splitToIntList(edge0, ','); 2829 ss.clear(); ss.str(""); 2830 2831 ss << res[9]; 2832 ss >> avgLF; 2833 ss.clear(); ss.str(""); 2834 } 2835 2836 } 2837 2838 std::vector<int> Scantable::splitToIntList(const std::string& s, const char delim) 2839 { 2840 istringstream iss(s); 2841 string tmp; 2842 int tmpi; 2843 std::vector<int> res; 2844 stringstream ss; 2845 while (getline(iss, tmp, delim)) { 2846 ss << tmp; 2847 ss >> tmpi; 2848 res.push_back(tmpi); 2849 ss.clear(); ss.str(""); 2850 } 2851 2852 return res; 2853 } 2854 2855 std::vector<string> Scantable::splitToStringList(const std::string& s, const char delim) 2856 { 2857 istringstream iss(s); 2858 std::string tmp; 2859 std::vector<string> res; 2860 while (getline(iss, tmp, delim)) { 2861 res.push_back(tmp); 2862 } 2863 2864 return res; 2865 } 2866 2867 std::vector<bool> Scantable::getMaskFromMaskList(const int nchan, const std::vector<int>& masklist) 2868 { 2869 if (masklist.size() % 2 != 0) { 2870 throw(AipsError("masklist must have even number of elements.")); 2871 } 2872 2873 std::vector<bool> res(nchan); 2874 2875 for (int i = 0; i < nchan; ++i) { 2876 res[i] = false; 2877 } 2878 for (uInt j = 0; j < masklist.size(); j += 2) { 2879 for (int i = masklist[j]; i <= masklist[j+1]; ++i) { 2880 res[i] = true; 2881 } 2882 } 2883 2884 return res; 2885 } 2886 2887 void Scantable::polyBaseline(const std::vector<bool>& mask, int order, float thresClip, int nIterClip, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile, const std::string& bltable) 2888 { 2889 /**** 2890 double TimeStart = mathutil::gettimeofday_sec(); 2891 ****/ 2892 2494 2893 try { 2495 2894 ofstream ofs; … … 2511 2910 } 2512 2911 2513 Fitter fitter = Fitter();2514 fitter.setExpression("poly", order);2515 //fitter.setIterClipping(thresClip, nIterClip);2516 2517 int nRow = nrow();2518 std::vector<bool> chanMask;2519 2912 bool showProgress; 2520 2913 int minNRow; 2521 2914 parseProgressInfo(progressInfo, showProgress, minNRow); 2522 2915 2916 int nRow = nrow(); 2917 std::vector<bool> chanMask; 2918 std::vector<bool> finalChanMask; 2919 float rms; 2920 2921 //--- 2922 bool outBaselintTable = (bltable != ""); 2923 STBaselineTable* bt = new STBaselineTable(*this); 2924 ROScalarColumn<Double> *tcol = new ROScalarColumn<Double>(table_, "TIME"); 2925 Vector<Double> timeSecCol = tcol->getColumn(); 2926 //--- 2927 2523 2928 for (int whichrow = 0; whichrow < nRow; ++whichrow) { 2929 std::vector<float> sp = getSpectrum(whichrow); 2524 2930 chanMask = getCompositeChanMask(whichrow, mask); 2525 fitBaseline(chanMask, whichrow, fitter); 2526 setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow); 2527 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "polyBaseline()", fitter); 2931 std::vector<float> params(order+1); 2932 int nClipped = 0; 2933 std::vector<float> res = doPolynomialFitting(sp, chanMask, order, params, rms, finalChanMask, nClipped, thresClip, nIterClip, getResidual); 2934 2935 //--- 2936 if (outBaselintTable) { 2937 Vector<Int> fparam(1); 2938 fparam[0] = order; 2939 std::vector<int> finalMaskList0; 2940 finalMaskList0.clear(); 2941 for (uInt i = 0; i < finalChanMask.size(); ++i) { 2942 if (finalChanMask[i]) { 2943 if ((i == 0)||(i == finalChanMask.size()-1)) { 2944 finalMaskList0.push_back(i); 2945 } else { 2946 if ((finalChanMask[i])&&(!finalChanMask[i-1])) { 2947 finalMaskList0.push_back(i); 2948 } 2949 if ((finalChanMask[i])&&(!finalChanMask[i+1])) { 2950 finalMaskList0.push_back(i); 2951 } 2952 } 2953 } 2954 } 2955 Vector<uInt> finalMaskList(finalMaskList0.size()); 2956 for (uInt i = 0; i < finalMaskList0.size(); ++i) { 2957 finalMaskList[i] = (uInt)finalMaskList0[i]; 2958 } 2959 2960 bt->appenddata(uInt(getScan(whichrow)), uInt(getCycle(whichrow)), uInt(getBeam(whichrow)), uInt(getIF(whichrow)), uInt(getPol(whichrow)), 2961 uInt(0), 2962 timeSecCol[whichrow], 2963 Bool(true), 2964 STBaselineFunc::Polynomial, 2965 fparam, 2966 Vector<Float>(), 2967 finalMaskList, 2968 Vector<Float>(params), 2969 Float(rms), 2970 uInt(sp.size()), 2971 Float(thresClip), 2972 uInt(nIterClip), 2973 Float(0.0), 2974 uInt(0), 2975 Vector<uInt>()); 2976 } else { 2977 setSpectrum(res, whichrow); 2978 } 2979 //--- 2980 2981 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "chebyshevBaseline()", params, nClipped); 2528 2982 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 2529 2983 } 2984 2985 //--- 2986 if (outBaselintTable) { 2987 bt->save(bltable); 2988 } 2989 //--- 2990 delete bt; 2530 2991 2531 2992 if (outTextFile) ofs.close(); … … 2534 2995 throw; 2535 2996 } 2536 } 2537 2538 void Scantable::autoPolyBaseline(const std::vector<bool>& mask, int order, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile) 2997 2998 /**** 2999 double TimeEnd = mathutil::gettimeofday_sec(); 3000 double elapse1 = TimeEnd - TimeStart; 3001 std::cout << "poly-new : " << elapse1 << " (sec.)" << endl; 3002 ****/ 3003 } 3004 3005 void Scantable::autoPolyBaseline(const std::vector<bool>& mask, int order, 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, const std::string& bltable) 2539 3006 { 2540 3007 try { … … 2557 3024 } 2558 3025 2559 Fitter fitter = Fitter(); 2560 fitter.setExpression("poly", order); 2561 //fitter.setIterClipping(thresClip, nIterClip); 2562 2563 int nRow = nrow(); 2564 std::vector<bool> chanMask; 3026 bool showProgress; 3027 int minNRow; 3028 parseProgressInfo(progressInfo, showProgress, minNRow); 3029 2565 3030 int minEdgeSize = getIFNos().size()*2; 2566 3031 STLineFinder lineFinder = STLineFinder(); 2567 3032 lineFinder.setOptions(threshold, 3, chanAvgLimit); 2568 3033 2569 bool showProgress; 2570 int minNRow; 2571 parseProgressInfo(progressInfo, showProgress, minNRow); 3034 int nRow = nrow(); 3035 std::vector<bool> chanMask; 3036 std::vector<bool> finalChanMask; 3037 float rms; 3038 3039 //--- 3040 bool outBaselintTable = (bltable != ""); 3041 STBaselineTable* bt = new STBaselineTable(*this); 3042 ROScalarColumn<Double> *tcol = new ROScalarColumn<Double>(table_, "TIME"); 3043 Vector<Double> timeSecCol = tcol->getColumn(); 3044 //--- 2572 3045 2573 3046 for (int whichrow = 0; whichrow < nRow; ++whichrow) { 2574 2575 //------------------------------------------------------- 2576 //chanMask = getCompositeChanMask(whichrow, mask, edge, minEdgeSize, lineFinder); 2577 //------------------------------------------------------- 3047 std::vector<float> sp = getSpectrum(whichrow); 3048 //-- composote given channel mask and flagtra -------- 2578 3049 int edgeSize = edge.size(); 2579 3050 std::vector<int> currentEdge; 3051 currentEdge.clear(); 2580 3052 if (edgeSize >= 2) { 2581 3053 int idx = 0; … … 2591 3063 throw(AipsError("Wrong length of edge element")); 2592 3064 } 2593 lineFinder.setData( getSpectrum(whichrow));3065 lineFinder.setData(sp); 2594 3066 lineFinder.findLines(getCompositeChanMask(whichrow, mask), currentEdge, whichrow); 2595 3067 chanMask = lineFinder.getMask(); 2596 //------------------------------------------------------- 2597 2598 fitBaseline(chanMask, whichrow, fitter); 2599 setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow); 2600 2601 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoPolyBaseline()", fitter); 3068 //-- composote given channel mask and flagtra END -------- 3069 3070 std::vector<float> params(order+1); 3071 int nClipped = 0; 3072 std::vector<float> res = doPolynomialFitting(sp, chanMask, order, params, rms, finalChanMask, nClipped, thresClip, nIterClip, getResidual); 3073 3074 if (outBaselintTable) { 3075 Vector<Int> fparam(1); 3076 fparam[0] = order; 3077 std::vector<int> finalMaskList0; 3078 finalMaskList0.clear(); 3079 for (uInt i = 0; i < finalChanMask.size(); ++i) { 3080 if (finalChanMask[i]) { 3081 if ((i == 0)||(i == finalChanMask.size()-1)) { 3082 finalMaskList0.push_back(i); 3083 } else { 3084 if ((finalChanMask[i])&&(!finalChanMask[i-1])) { 3085 finalMaskList0.push_back(i); 3086 } 3087 if ((finalChanMask[i])&&(!finalChanMask[i+1])) { 3088 finalMaskList0.push_back(i); 3089 } 3090 } 3091 } 3092 } 3093 Vector<uInt> finalMaskList(finalMaskList0.size()); 3094 for (uInt i = 0; i < finalMaskList0.size(); ++i) { 3095 finalMaskList[i] = (uInt)finalMaskList0[i]; 3096 } 3097 3098 Vector<uInt> cEdge(currentEdge.size()); 3099 for (uInt i = 0; i < currentEdge.size(); ++i) { 3100 cEdge[i] = currentEdge[i]; 3101 } 3102 3103 bt->appenddata(uInt(getScan(whichrow)), uInt(getCycle(whichrow)), uInt(getBeam(whichrow)), uInt(getIF(whichrow)), uInt(getPol(whichrow)), 3104 uInt(0), 3105 timeSecCol[whichrow], 3106 Bool(true), 3107 STBaselineFunc::Polynomial, 3108 fparam, 3109 Vector<Float>(), 3110 finalMaskList, 3111 Vector<Float>(params), 3112 Float(rms), 3113 uInt(sp.size()), 3114 Float(thresClip), 3115 uInt(nIterClip), 3116 Float(threshold), 3117 uInt(chanAvgLimit), 3118 cEdge); 3119 } else { 3120 setSpectrum(res, whichrow); 3121 } 3122 3123 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoChebyshevBaseline()", params, nClipped); 2602 3124 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 2603 3125 } 3126 3127 //--- 3128 if (outBaselintTable) { 3129 bt->save(bltable); 3130 } 3131 //--- 3132 delete bt; 2604 3133 2605 3134 if (outTextFile) ofs.close(); … … 2610 3139 } 2611 3140 2612 void Scantable::chebyshevBaseline(const std::vector<bool>& mask, int order, float thresClip, int nIterClip, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile) 2613 { 3141 void Scantable::chebyshevBaseline(const std::vector<bool>& mask, int order, float thresClip, int nIterClip, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile, const std::string& bltable) 3142 { 3143 // 3144 double TimeStart = mathutil::gettimeofday_sec(); 3145 // 3146 2614 3147 try { 2615 3148 ofstream ofs; … … 2641 3174 2642 3175 //--- 2643 bool outBaselin eParamTable = false;3176 bool outBaselintTable = (bltable != ""); 2644 3177 STBaselineTable* bt = new STBaselineTable(*this); 3178 ROScalarColumn<Double> *tcol = new ROScalarColumn<Double>(table_, "TIME"); 3179 Vector<Double> timeSecCol = tcol->getColumn(); 2645 3180 //--- 2646 3181 … … 2650 3185 std::vector<float> params(order+1); 2651 3186 int nClipped = 0; 2652 std::vector<float> res = doChebyshevFitting(sp, chanMask, order, params, finalChanMask, rms, nClipped, thresClip, nIterClip, getResidual);3187 std::vector<float> res = doChebyshevFitting(sp, chanMask, order, params, rms, finalChanMask, nClipped, thresClip, nIterClip, getResidual); 2653 3188 2654 3189 //--- 2655 if (outBaselineParamTable) { 3190 if (outBaselintTable) { 3191 Vector<Int> fparam(1); 3192 fparam[0] = order; 3193 std::vector<int> finalMaskList0; 3194 finalMaskList0.clear(); 3195 for (uInt i = 0; i < finalChanMask.size(); ++i) { 3196 if (finalChanMask[i]) { 3197 if ((i == 0)||(i == finalChanMask.size()-1)) { 3198 finalMaskList0.push_back(i); 3199 } else { 3200 if ((finalChanMask[i])&&(!finalChanMask[i-1])) { 3201 finalMaskList0.push_back(i); 3202 } 3203 if ((finalChanMask[i])&&(!finalChanMask[i+1])) { 3204 finalMaskList0.push_back(i); 3205 } 3206 } 3207 } 3208 } 3209 Vector<uInt> finalMaskList(finalMaskList0.size()); 3210 for (uInt i = 0; i < finalMaskList0.size(); ++i) { 3211 finalMaskList[i] = (uInt)finalMaskList0[i]; 3212 } 3213 2656 3214 bt->appenddata(uInt(getScan(whichrow)), uInt(getCycle(whichrow)), uInt(getBeam(whichrow)), uInt(getIF(whichrow)), uInt(getPol(whichrow)), 2657 3215 uInt(0), 2658 Double(0.0), // <-- Double(getTime(whichrow, false)),2659 uInt(nchan(whichrow)),3216 timeSecCol[whichrow], 3217 Bool(true), 2660 3218 STBaselineFunc::Chebyshev, 2661 Vector<uInt>(1), // ==> MUST BE Vector<uInt> containing 'order'. 2662 Vector<Float>(), // ==> for ffpar. ** dummy ** 3219 fparam, 3220 Vector<Float>(), 3221 finalMaskList, 3222 Vector<Float>(params), 3223 Float(rms), 3224 uInt(sp.size()), 3225 Float(thresClip), 2663 3226 uInt(nIterClip), 2664 Float(thresClip), 2665 Vector<uInt>(5), // <-- Vector<uInt>(finalChanMask), 2666 Vector<Float>(params), 2667 Float(rms)); 3227 Float(0.0), 3228 uInt(0), 3229 Vector<uInt>()); 2668 3230 } else { 2669 3231 setSpectrum(res, whichrow); … … 2676 3238 2677 3239 //--- 2678 if (outBaselin eParamTable) {2679 bt->save( "chebyparamtable");3240 if (outBaselintTable) { 3241 bt->save(bltable); 2680 3242 } 2681 3243 //--- … … 2687 3249 throw; 2688 3250 } 3251 3252 double TimeEnd = mathutil::gettimeofday_sec(); 3253 double elapse1 = TimeEnd - TimeStart; 3254 std::cout << "cheby : " << elapse1 << " (sec.)" << endl; 3255 } 3256 3257 void Scantable::autoChebyshevBaseline(const std::vector<bool>& mask, int order, 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, const std::string& bltable) 3258 { 3259 try { 3260 ofstream ofs; 3261 String coordInfo = ""; 3262 bool hasSameNchan = true; 3263 bool outTextFile = false; 3264 bool csvFormat = false; 3265 3266 if (blfile != "") { 3267 csvFormat = (blfile.substr(0, 1) == "T"); 3268 ofs.open(blfile.substr(1).c_str(), ios::out | ios::app); 3269 if (ofs) outTextFile = true; 3270 } 3271 3272 if (outLogger || outTextFile) { 3273 coordInfo = getCoordInfo()[0]; 3274 if (coordInfo == "") coordInfo = "channel"; 3275 hasSameNchan = hasSameNchanOverIFs(); 3276 } 3277 3278 bool showProgress; 3279 int minNRow; 3280 parseProgressInfo(progressInfo, showProgress, minNRow); 3281 3282 int minEdgeSize = getIFNos().size()*2; 3283 STLineFinder lineFinder = STLineFinder(); 3284 lineFinder.setOptions(threshold, 3, chanAvgLimit); 3285 3286 int nRow = nrow(); 3287 std::vector<bool> chanMask; 3288 std::vector<bool> finalChanMask; 3289 float rms; 3290 3291 //--- 3292 bool outBaselintTable = (bltable != ""); 3293 STBaselineTable* bt = new STBaselineTable(*this); 3294 ROScalarColumn<Double> *tcol = new ROScalarColumn<Double>(table_, "TIME"); 3295 Vector<Double> timeSecCol = tcol->getColumn(); 3296 //--- 3297 3298 for (int whichrow = 0; whichrow < nRow; ++whichrow) { 3299 std::vector<float> sp = getSpectrum(whichrow); 3300 //-- composote given channel mask and flagtra -------- 3301 int edgeSize = edge.size(); 3302 std::vector<int> currentEdge; 3303 currentEdge.clear(); 3304 if (edgeSize >= 2) { 3305 int idx = 0; 3306 if (edgeSize > 2) { 3307 if (edgeSize < minEdgeSize) { 3308 throw(AipsError("Length of edge element info is less than that of IFs")); 3309 } 3310 idx = 2 * getIF(whichrow); 3311 } 3312 currentEdge.push_back(edge[idx]); 3313 currentEdge.push_back(edge[idx+1]); 3314 } else { 3315 throw(AipsError("Wrong length of edge element")); 3316 } 3317 lineFinder.setData(sp); 3318 lineFinder.findLines(getCompositeChanMask(whichrow, mask), currentEdge, whichrow); 3319 chanMask = lineFinder.getMask(); 3320 //-- composote given channel mask and flagtra END -------- 3321 3322 std::vector<float> params(order+1); 3323 int nClipped = 0; 3324 std::vector<float> res = doChebyshevFitting(sp, chanMask, order, params, rms, finalChanMask, nClipped, thresClip, nIterClip, getResidual); 3325 3326 if (outBaselintTable) { 3327 Vector<Int> fparam(1); 3328 fparam[0] = order; 3329 std::vector<int> finalMaskList0; 3330 finalMaskList0.clear(); 3331 for (uInt i = 0; i < finalChanMask.size(); ++i) { 3332 if (finalChanMask[i]) { 3333 if ((i == 0)||(i == finalChanMask.size()-1)) { 3334 finalMaskList0.push_back(i); 3335 } else { 3336 if ((finalChanMask[i])&&(!finalChanMask[i-1])) { 3337 finalMaskList0.push_back(i); 3338 } 3339 if ((finalChanMask[i])&&(!finalChanMask[i+1])) { 3340 finalMaskList0.push_back(i); 3341 } 3342 } 3343 } 3344 } 3345 Vector<uInt> finalMaskList(finalMaskList0.size()); 3346 for (uInt i = 0; i < finalMaskList0.size(); ++i) { 3347 finalMaskList[i] = (uInt)finalMaskList0[i]; 3348 } 3349 3350 Vector<uInt> cEdge(currentEdge.size()); 3351 for (uInt i = 0; i < currentEdge.size(); ++i) { 3352 cEdge[i] = currentEdge[i]; 3353 } 3354 3355 bt->appenddata(uInt(getScan(whichrow)), uInt(getCycle(whichrow)), uInt(getBeam(whichrow)), uInt(getIF(whichrow)), uInt(getPol(whichrow)), 3356 uInt(0), 3357 timeSecCol[whichrow], 3358 Bool(true), 3359 STBaselineFunc::Chebyshev, 3360 fparam, 3361 Vector<Float>(), 3362 finalMaskList, 3363 Vector<Float>(params), 3364 Float(rms), 3365 uInt(sp.size()), 3366 Float(thresClip), 3367 uInt(nIterClip), 3368 Float(threshold), 3369 uInt(chanAvgLimit), 3370 cEdge); 3371 } else { 3372 setSpectrum(res, whichrow); 3373 } 3374 3375 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoChebyshevBaseline()", params, nClipped); 3376 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 3377 } 3378 3379 //--- 3380 if (outBaselintTable) { 3381 bt->save(bltable); 3382 } 3383 //--- 3384 delete bt; 3385 3386 if (outTextFile) ofs.close(); 3387 3388 } catch (...) { 3389 throw; 3390 } 2689 3391 } 2690 3392 2691 3393 double Scantable::calculateModelSelectionCriteria(const std::string& valname, const std::string& blfunc, int order, const std::vector<bool>& inMask, int whichrow, bool useLineFinder, const std::vector<int>& edge, float threshold, int chanAvgLimit) 2692 3394 { 3395 std::vector<float> sp = getSpectrum(whichrow); 3396 std::vector<bool> chanMask; 3397 chanMask.clear(); 3398 2693 3399 if (useLineFinder) { 2694 3400 int minEdgeSize = getIFNos().size()*2; 2695 3401 2696 2697 3402 int edgeSize = edge.size(); 2698 3403 std::vector<int> currentEdge; 3404 currentEdge.clear(); 2699 3405 if (edgeSize >= 2) { 2700 3406 int idx = 0; … … 2712 3418 2713 3419 STLineFinder lineFinder = STLineFinder(); 2714 std::vector<float> sp = getSpectrum(whichrow);2715 3420 lineFinder.setData(sp); 2716 3421 lineFinder.setOptions(threshold, 3, chanAvgLimit); 2717 3422 lineFinder.findLines(getCompositeChanMask(whichrow, inMask), currentEdge, whichrow); 2718 std::vector<bool> chanMask = lineFinder.getMask(); 2719 2720 return doCalculateModelSelectionCriteria(valname, sp, chanMask, blfunc, order); 3423 chanMask = lineFinder.getMask(); 2721 3424 2722 3425 } else { 2723 return doCalculateModelSelectionCriteria(valname, getSpectrum(whichrow), getCompositeChanMask(whichrow, inMask), blfunc, order); 2724 } 2725 3426 3427 chanMask = getCompositeChanMask(whichrow, inMask); 3428 } 3429 3430 return doCalculateModelSelectionCriteria(valname, sp, chanMask, blfunc, order); 2726 3431 } 2727 3432 … … 2733 3438 float rms; 2734 3439 int nClipped = 0; 2735 float thresClip = 0.0;2736 int nIterClip = 0;2737 3440 std::vector<float> res; 2738 if (blfunc == " chebyshev") {3441 if (blfunc == "poly") { 2739 3442 nparam = order + 1; 2740 res = doChebyshevFitting(spec, mask, order, params, finalChanMask, rms, nClipped, thresClip, nIterClip, true); 3443 res = doPolynomialFitting(spec, mask, order, params, rms, finalChanMask, nClipped); 3444 } else if (blfunc == "chebyshev") { 3445 nparam = order + 1; 3446 res = doChebyshevFitting(spec, mask, order, params, rms, finalChanMask, nClipped); 3447 } else if (blfunc == "cspline") { 3448 std::vector<int> pieceEdges;//(order+1); //order = npiece 3449 nparam = order + 3; 3450 //params.resize(4*order); 3451 res = doCubicSplineFitting(spec, mask, order, false, pieceEdges, params, rms, finalChanMask, nClipped); 2741 3452 } else if (blfunc == "sinusoid") { 2742 3453 std::vector<int> nWaves; … … 2746 3457 } 2747 3458 nparam = 2*order + 1; // order = nwave 2748 res = doSinusoidFitting(spec, mask, nWaves, params, nClipped, thresClip, nIterClip, true); 2749 } else if (blfunc == "cspline") { 2750 std::vector<int> pieceEdges(order+1); //order = npiece 2751 nparam = order + 3; 2752 params.resize(4*order); 2753 res = doCubicSplineFitting(spec, mask, order, pieceEdges, params, nClipped, thresClip, nIterClip, true); 3459 res = doSinusoidFitting(spec, mask, nWaves, params, rms, finalChanMask, nClipped); 2754 3460 } else { 2755 throw(AipsError("blfunc must be chebyshev, cspline or sinusoid."));3461 throw(AipsError("blfunc must be poly, chebyshev, cspline or sinusoid.")); 2756 3462 } 2757 3463 … … 2777 3483 double aic = nusedchan * (log(2.0 * PI * msq) + 1.0) + 2.0 * nparam; 2778 3484 2779 // Corrected AIC by Sugiura(1978) 3485 // Corrected AIC by Sugiura(1978) (AICc) 2780 3486 if (valname == "aicc") { 2781 3487 if (nusedchan - nparam - 1 <= 0) { … … 2803 3509 } 2804 3510 2805 void Scantable::autoChebyshevBaseline(const std::vector<bool>& mask, int order, 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) 2806 { 2807 try { 2808 ofstream ofs; 2809 String coordInfo = ""; 2810 bool hasSameNchan = true; 2811 bool outTextFile = false; 2812 bool csvFormat = false; 2813 2814 if (blfile != "") { 2815 csvFormat = (blfile.substr(0, 1) == "T"); 2816 ofs.open(blfile.substr(1).c_str(), ios::out | ios::app); 2817 if (ofs) outTextFile = true; 2818 } 2819 2820 if (outLogger || outTextFile) { 2821 coordInfo = getCoordInfo()[0]; 2822 if (coordInfo == "") coordInfo = "channel"; 2823 hasSameNchan = hasSameNchanOverIFs(); 2824 } 2825 2826 int nRow = nrow(); 2827 std::vector<bool> chanMask; 2828 int minEdgeSize = getIFNos().size()*2; 2829 STLineFinder lineFinder = STLineFinder(); 2830 lineFinder.setOptions(threshold, 3, chanAvgLimit); 2831 2832 bool showProgress; 2833 int minNRow; 2834 parseProgressInfo(progressInfo, showProgress, minNRow); 2835 2836 std::vector<bool> finalChanMask; 2837 float rms; 2838 2839 for (int whichrow = 0; whichrow < nRow; ++whichrow) { 2840 std::vector<float> sp = getSpectrum(whichrow); 2841 2842 //------------------------------------------------------- 2843 //chanMask = getCompositeChanMask(whichrow, mask, edge, minEdgeSize, lineFinder); 2844 //------------------------------------------------------- 2845 int edgeSize = edge.size(); 2846 std::vector<int> currentEdge; 2847 if (edgeSize >= 2) { 2848 int idx = 0; 2849 if (edgeSize > 2) { 2850 if (edgeSize < minEdgeSize) { 2851 throw(AipsError("Length of edge element info is less than that of IFs")); 2852 } 2853 idx = 2 * getIF(whichrow); 2854 } 2855 currentEdge.push_back(edge[idx]); 2856 currentEdge.push_back(edge[idx+1]); 2857 } else { 2858 throw(AipsError("Wrong length of edge element")); 2859 } 2860 //lineFinder.setData(getSpectrum(whichrow)); 2861 lineFinder.setData(sp); 2862 lineFinder.findLines(getCompositeChanMask(whichrow, mask), currentEdge, whichrow); 2863 chanMask = lineFinder.getMask(); 2864 //------------------------------------------------------- 2865 2866 2867 //fitBaseline(chanMask, whichrow, fitter); 2868 //setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow); 2869 std::vector<float> params(order+1); 2870 int nClipped = 0; 2871 std::vector<float> res = doChebyshevFitting(sp, chanMask, order, params, finalChanMask, rms, nClipped, thresClip, nIterClip, getResidual); 2872 setSpectrum(res, whichrow); 2873 2874 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoChebyshevBaseline()", params, nClipped); 2875 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 2876 } 2877 2878 if (outTextFile) ofs.close(); 2879 2880 } catch (...) { 2881 throw; 2882 } 2883 } 2884 2885 /* 2886 double Scantable::getChebyshevPolynomial(int n, double x) { 2887 if ((x < -1.0)||(x > 1.0)) { 2888 throw(AipsError("out of definition range (-1 <= x <= 1).")); 2889 } else if (n < 0) { 2890 throw(AipsError("the order must be zero or positive.")); 2891 } else if (n == 0) { 3511 double Scantable::getNormalPolynomial(int n, double x) { 3512 if (n == 0) { 2892 3513 return 1.0; 2893 } else if (n == 1) { 2894 return x; 3514 } else if (n > 0) { 3515 double res = 1.0; 3516 for (int i = 0; i < n; ++i) { 3517 res *= x; 3518 } 3519 return res; 2895 3520 } else { 2896 return 2.0*x*getChebyshevPolynomial(n-1, x) - getChebyshevPolynomial(n-2, x); 2897 } 2898 } 2899 */ 3521 if (x == 0.0) { 3522 throw(AipsError("infinity result: x=0 given for negative power.")); 3523 } else { 3524 return pow(x, (double)n); 3525 } 3526 } 3527 } 3528 2900 3529 double Scantable::getChebyshevPolynomial(int n, double x) { 2901 3530 if ((x < -1.0)||(x > 1.0)) { … … 2939 3568 } 2940 3569 2941 std::vector<float> Scantable::doChebyshevFitting(const std::vector<float>& data, const std::vector<bool>& mask, int order, std::vector<float>& params, std::vector<bool>& finalMask, float& rms, int& nClipped, float thresClip, int nIterClip, bool getResidual) 3570 std::vector<float> Scantable::doPolynomialFitting(const std::vector<float>& data, const std::vector<bool>& mask, int order, std::vector<float>& params, float& rms, std::vector<bool>& finalmask, float clipth, int clipn) 3571 { 3572 int nClipped = 0; 3573 return doPolynomialFitting(data, mask, order, params, rms, finalmask, nClipped, clipth, clipn); 3574 } 3575 3576 std::vector<float> Scantable::doPolynomialFitting(const std::vector<float>& data, const std::vector<bool>& mask, int order, std::vector<float>& params, float& rms, std::vector<bool>& finalMask, int& nClipped, float thresClip, int nIterClip, bool getResidual) 3577 { 3578 return doLeastSquareFitting(data, mask, &Scantable::getNormalPolynomial, order, params, rms, finalMask, nClipped, thresClip, nIterClip, getResidual); 3579 } 3580 3581 std::vector<float> Scantable::doChebyshevFitting(const std::vector<float>& data, const std::vector<bool>& mask, int order, std::vector<float>& params, float& rms, std::vector<bool>& finalmask, float clipth, int clipn) 3582 { 3583 int nClipped = 0; 3584 return doChebyshevFitting(data, mask, order, params, rms, finalmask, nClipped, clipth, clipn); 3585 } 3586 3587 std::vector<float> Scantable::doChebyshevFitting(const std::vector<float>& data, const std::vector<bool>& mask, int order, std::vector<float>& params, float& rms, std::vector<bool>& finalMask, int& nClipped, float thresClip, int nIterClip, bool getResidual) 3588 { 3589 return doLeastSquareFitting(data, mask, &Scantable::getChebyshevPolynomial, order, params, rms, finalMask, nClipped, thresClip, nIterClip, getResidual); 3590 } 3591 3592 std::vector<float> Scantable::doLeastSquareFitting(const std::vector<float>& data, const std::vector<bool>& mask, double (Scantable::*pfunc)(int, double), int order, std::vector<float>& params, float& rms, std::vector<bool>& finalMask, int& nClipped, float thresClip, int nIterClip, bool getResidual) 2942 3593 { 2943 3594 if (data.size() != mask.size()) { … … 2945 3596 } 2946 3597 if (order < 0) { 2947 throw(AipsError("maximum order of Chebyshevpolynomial must not be negative."));3598 throw(AipsError("maximum order of polynomial must not be negative.")); 2948 3599 } 2949 3600 … … 2971 3622 // xArray.size() is nDOF and xArray[*].size() is nChan. 2972 3623 // Each xArray element are as follows: 3624 // 3625 // (for normal polynomials) 3626 // xArray[0] = {1.0, 1.0, 1.0, ..., 1.0}, 3627 // xArray[1] = {0.0, 1.0, 2.0, ..., (nChan-1)} 3628 // xArray[n-1] = ..., 3629 // xArray[n] = {0.0^n, 1.0^n, 2.0^n, ..., (nChan-1)^n} 3630 // where (0 <= n <= order) 3631 // 3632 // (for Chebyshev polynomials) 2973 3633 // xArray[0] = {T0(-1), T0(2/(nChan-1)-1), T0(4/(nChan-1)-1), ..., T0(1)}, 2974 3634 // xArray[n-1] = ..., … … 2976 3636 // where (0 <= n <= order), 2977 3637 std::vector<std::vector<double> > xArray; 3638 double xFactor, xShift; 3639 if (pfunc == &Scantable::getChebyshevPolynomial) { 3640 xFactor = 2.0/(double)(nChan - 1); 3641 xShift = -1.0; 3642 } else { 3643 xFactor = 1.0; 3644 xShift = 0.0; 3645 } 2978 3646 for (int i = 0; i < nDOF; ++i) { 2979 double xFactor = 2.0/(double)(nChan - 1);2980 3647 std::vector<double> xs; 2981 3648 xs.clear(); 2982 3649 for (int j = 0; j < nChan; ++j) { 2983 xs.push_back( getChebyshevPolynomial(i, xFactor*(double)j-1.0));3650 xs.push_back((this->*pfunc)(i, xFactor*(double)j + xShift)); 2984 3651 } 2985 3652 xArray.push_back(xs); … … 3063 3730 } 3064 3731 } 3065 //compute a vector y which consists of the coefficients of the sinusoids forming the 3066 //best-fit curves (a0,s1,c1,s2,c2,...), where a0 is constant and s* and c* are of sine 3067 //and cosine functions, respectively. 3732 //compute a vector y which consists of the coefficients of Chebyshev polynomials. 3068 3733 std::vector<double> y; 3069 3734 params.clear(); … … 3118 3783 3119 3784 std::vector<float> result; 3785 result.clear(); 3120 3786 if (getResidual) { 3121 3787 for (int i = 0; i < nChan; ++i) { … … 3131 3797 } 3132 3798 3133 void Scantable::cubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile) 3134 { 3135 /************* 3136 double totTimeStart, totTimeEnd, blTimeStart, blTimeEnd, ioTimeStart, ioTimeEnd, msTimeStart, msTimeEnd, seTimeStart, seTimeEnd, otTimeStart, otTimeEnd, prTimeStart, prTimeEnd; 3137 double elapseMs = 0.0; 3138 double elapseSe = 0.0; 3139 double elapseOt = 0.0; 3140 double elapsePr = 0.0; 3141 double elapseBl = 0.0; 3142 double elapseIo = 0.0; 3143 totTimeStart = mathutil::gettimeofday_sec(); 3144 *************/ 3145 3799 void Scantable::cubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile, const std::string& bltable) 3800 { 3146 3801 try { 3147 3802 ofstream ofs; … … 3163 3818 } 3164 3819 3165 //Fitter fitter = Fitter();3166 //fitter.setExpression("cspline", nPiece);3167 //fitter.setIterClipping(thresClip, nIterClip);3168 3169 3820 bool showProgress; 3170 3821 int minNRow; … … 3173 3824 int nRow = nrow(); 3174 3825 std::vector<bool> chanMask; 3175 3176 //-------------------------------- 3826 std::vector<bool> finalChanMask; 3827 float rms; 3828 3829 //--- 3830 bool outBaselintTable = (bltable != ""); 3831 STBaselineTable* bt = new STBaselineTable(*this); 3832 ROScalarColumn<Double> *tcol = new ROScalarColumn<Double>(table_, "TIME"); 3833 Vector<Double> timeSecCol = tcol->getColumn(); 3834 //--- 3835 3836 3177 3837 for (int whichrow = 0; whichrow < nRow; ++whichrow) { 3178 /******************3179 ioTimeStart = mathutil::gettimeofday_sec();3180 **/3181 3838 std::vector<float> sp = getSpectrum(whichrow); 3182 /**3183 ioTimeEnd = mathutil::gettimeofday_sec();3184 elapseIo += (double)(ioTimeEnd - ioTimeStart);3185 msTimeStart = mathutil::gettimeofday_sec();3186 ******************/3187 3188 3839 chanMask = getCompositeChanMask(whichrow, mask); 3189 3190 /** 3191 msTimeEnd = mathutil::gettimeofday_sec(); 3192 elapseMs += (double)(msTimeEnd - msTimeStart); 3193 blTimeStart = mathutil::gettimeofday_sec(); 3194 **/ 3195 3196 //fitBaseline(chanMask, whichrow, fitter); 3197 //setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow); 3198 std::vector<int> pieceEdges(nPiece+1); 3199 std::vector<float> params(nPiece*4); 3840 std::vector<int> pieceEdges;//(nPiece+1); 3841 std::vector<float> params;//(nPiece*4); 3200 3842 int nClipped = 0; 3201 std::vector<float> res = doCubicSplineFitting(sp, chanMask, nPiece, pieceEdges, params, nClipped, thresClip, nIterClip, getResidual); 3202 3203 /** 3204 blTimeEnd = mathutil::gettimeofday_sec(); 3205 elapseBl += (double)(blTimeEnd - blTimeStart); 3206 seTimeStart = mathutil::gettimeofday_sec(); 3207 **/ 3208 3209 3210 setSpectrum(res, whichrow); 3211 // 3212 3213 /** 3214 seTimeEnd = mathutil::gettimeofday_sec(); 3215 elapseSe += (double)(seTimeEnd - seTimeStart); 3216 otTimeStart = mathutil::gettimeofday_sec(); 3217 **/ 3843 std::vector<float> res = doCubicSplineFitting(sp, chanMask, nPiece, false, pieceEdges, params, rms, finalChanMask, nClipped, thresClip, nIterClip, getResidual); 3844 3845 //--- 3846 if (outBaselintTable) { 3847 Vector<Int> fparam(nPiece); 3848 for (uInt i = 0; i < fparam.size(); ++i) { 3849 fparam[i] = pieceEdges[i]; 3850 } 3851 std::vector<int> finalMaskList0; 3852 finalMaskList0.clear(); 3853 for (uInt i = 0; i < finalChanMask.size(); ++i) { 3854 if (finalChanMask[i]) { 3855 if ((i == 0)||(i == finalChanMask.size()-1)) { 3856 finalMaskList0.push_back(i); 3857 } else { 3858 if ((finalChanMask[i])&&(!finalChanMask[i-1])) { 3859 finalMaskList0.push_back(i); 3860 } 3861 if ((finalChanMask[i])&&(!finalChanMask[i+1])) { 3862 finalMaskList0.push_back(i); 3863 } 3864 } 3865 } 3866 } 3867 Vector<uInt> finalMaskList(finalMaskList0.size()); 3868 for (uInt i = 0; i < finalMaskList0.size(); ++i) { 3869 finalMaskList[i] = (uInt)finalMaskList0[i]; 3870 } 3871 3872 bt->appenddata(uInt(getScan(whichrow)), uInt(getCycle(whichrow)), uInt(getBeam(whichrow)), uInt(getIF(whichrow)), uInt(getPol(whichrow)), 3873 uInt(0), 3874 timeSecCol[whichrow], 3875 Bool(true), 3876 STBaselineFunc::CSpline, 3877 fparam, 3878 Vector<Float>(), 3879 finalMaskList, 3880 Vector<Float>(params), 3881 Float(rms), 3882 uInt(sp.size()), 3883 Float(thresClip), 3884 uInt(nIterClip), 3885 Float(0.0), 3886 uInt(0), 3887 Vector<uInt>()); 3888 } else { 3889 setSpectrum(res, whichrow); 3890 } 3891 //--- 3218 3892 3219 3893 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "cubicSplineBaseline()", pieceEdges, params, nClipped); 3220 3221 /**3222 otTimeEnd = mathutil::gettimeofday_sec();3223 elapseOt += (double)(otTimeEnd - otTimeStart);3224 prTimeStart = mathutil::gettimeofday_sec();3225 **/3226 3227 3894 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 3228 3229 /****************** 3230 prTimeEnd = mathutil::gettimeofday_sec(); 3231 elapsePr += (double)(prTimeEnd - prTimeStart); 3232 ******************/ 3233 } 3234 //-------------------------------- 3895 } 3235 3896 3897 //--- 3898 if (outBaselintTable) { 3899 bt->save(bltable); 3900 } 3901 //--- 3902 delete bt; 3903 3236 3904 if (outTextFile) ofs.close(); 3237 3905 … … 3239 3907 throw; 3240 3908 } 3241 /*************** 3242 totTimeEnd = mathutil::gettimeofday_sec(); 3243 std::cout << "io : " << elapseIo << " (sec.)" << endl; 3244 std::cout << "ms : " << elapseMs << " (sec.)" << endl; 3245 std::cout << "bl : " << elapseBl << " (sec.)" << endl; 3246 std::cout << "se : " << elapseSe << " (sec.)" << endl; 3247 std::cout << "ot : " << elapseOt << " (sec.)" << endl; 3248 std::cout << "pr : " << elapsePr << " (sec.)" << endl; 3249 std::cout << "total : " << (double)(totTimeEnd - totTimeStart) << " (sec.)" << endl; 3250 ***************/ 3251 } 3252 3253 void Scantable::autoCubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile) 3909 } 3910 3911 void Scantable::autoCubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile, const std::string& bltable) 3254 3912 { 3255 3913 try { … … 3272 3930 } 3273 3931 3274 //Fitter fitter = Fitter(); 3275 //fitter.setExpression("cspline", nPiece); 3276 //fitter.setIterClipping(thresClip, nIterClip); 3277 3278 int nRow = nrow(); 3279 std::vector<bool> chanMask; 3932 bool showProgress; 3933 int minNRow; 3934 parseProgressInfo(progressInfo, showProgress, minNRow); 3935 3280 3936 int minEdgeSize = getIFNos().size()*2; 3281 3937 STLineFinder lineFinder = STLineFinder(); 3282 3938 lineFinder.setOptions(threshold, 3, chanAvgLimit); 3283 3939 3284 bool showProgress; 3285 int minNRow; 3286 parseProgressInfo(progressInfo, showProgress, minNRow); 3940 int nRow = nrow(); 3941 std::vector<bool> chanMask; 3942 std::vector<bool> finalChanMask; 3943 float rms; 3944 3945 //--- 3946 bool outBaselintTable = (bltable != ""); 3947 STBaselineTable* bt = new STBaselineTable(*this); 3948 ROScalarColumn<Double> *tcol = new ROScalarColumn<Double>(table_, "TIME"); 3949 Vector<Double> timeSecCol = tcol->getColumn(); 3950 //--- 3287 3951 3288 3952 for (int whichrow = 0; whichrow < nRow; ++whichrow) { 3289 3953 std::vector<float> sp = getSpectrum(whichrow); 3290 3291 //------------------------------------------------------- 3292 //chanMask = getCompositeChanMask(whichrow, mask, edge, minEdgeSize, lineFinder); 3293 //------------------------------------------------------- 3954 //-- composote given channel mask and flagtra -------- 3294 3955 int edgeSize = edge.size(); 3295 3956 std::vector<int> currentEdge; 3957 currentEdge.clear(); 3296 3958 if (edgeSize >= 2) { 3297 3959 int idx = 0; … … 3307 3969 throw(AipsError("Wrong length of edge element")); 3308 3970 } 3309 //lineFinder.setData(getSpectrum(whichrow));3310 3971 lineFinder.setData(sp); 3311 3972 lineFinder.findLines(getCompositeChanMask(whichrow, mask), currentEdge, whichrow); 3312 3973 chanMask = lineFinder.getMask(); 3313 //------------------------------------------------------- 3314 3315 3316 //fitBaseline(chanMask, whichrow, fitter); 3317 //setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow); 3318 std::vector<int> pieceEdges(nPiece+1); 3319 std::vector<float> params(nPiece*4); 3974 //-- composote given channel mask and flagtra END -------- 3975 3976 std::vector<int> pieceEdges;//(nPiece+1); 3977 std::vector<float> params;//(nPiece*4); 3320 3978 int nClipped = 0; 3321 std::vector<float> res = doCubicSplineFitting(sp, chanMask, nPiece, pieceEdges, params, nClipped, thresClip, nIterClip, getResidual); 3322 setSpectrum(res, whichrow); 3323 // 3979 std::vector<float> res = doCubicSplineFitting(sp, chanMask, nPiece, false, pieceEdges, params, rms, finalChanMask, nClipped, thresClip, nIterClip, getResidual); 3980 3981 if (outBaselintTable) { 3982 Vector<Int> fparam(nPiece); 3983 for (uInt i = 0; i < fparam.size(); ++i) { 3984 fparam[i] = pieceEdges[i]; 3985 } 3986 std::vector<int> finalMaskList0; 3987 finalMaskList0.clear(); 3988 for (uInt i = 0; i < finalChanMask.size(); ++i) { 3989 if (finalChanMask[i]) { 3990 if ((i == 0)||(i == finalChanMask.size()-1)) { 3991 finalMaskList0.push_back(i); 3992 } else { 3993 if ((finalChanMask[i])&&(!finalChanMask[i-1])) { 3994 finalMaskList0.push_back(i); 3995 } 3996 if ((finalChanMask[i])&&(!finalChanMask[i+1])) { 3997 finalMaskList0.push_back(i); 3998 } 3999 } 4000 } 4001 } 4002 Vector<uInt> finalMaskList(finalMaskList0.size()); 4003 for (uInt i = 0; i < finalMaskList0.size(); ++i) { 4004 finalMaskList[i] = (uInt)finalMaskList0[i]; 4005 } 4006 4007 Vector<uInt> cEdge(currentEdge.size()); 4008 for (uInt i = 0; i < currentEdge.size(); ++i) { 4009 cEdge[i] = currentEdge[i]; 4010 } 4011 4012 bt->appenddata(uInt(getScan(whichrow)), uInt(getCycle(whichrow)), uInt(getBeam(whichrow)), uInt(getIF(whichrow)), uInt(getPol(whichrow)), 4013 uInt(0), 4014 timeSecCol[whichrow], 4015 Bool(true), 4016 STBaselineFunc::CSpline, 4017 fparam, 4018 Vector<Float>(), 4019 finalMaskList, 4020 Vector<Float>(params), 4021 Float(rms), 4022 uInt(sp.size()), 4023 Float(thresClip), 4024 uInt(nIterClip), 4025 Float(threshold), 4026 uInt(chanAvgLimit), 4027 cEdge); 4028 } else { 4029 setSpectrum(res, whichrow); 4030 } 3324 4031 3325 4032 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoCubicSplineBaseline()", pieceEdges, params, nClipped); … … 3327 4034 } 3328 4035 4036 //--- 4037 if (outBaselintTable) { 4038 bt->save(bltable); 4039 } 4040 //--- 4041 delete bt; 4042 3329 4043 if (outTextFile) ofs.close(); 3330 4044 … … 3334 4048 } 3335 4049 3336 std::vector<float> Scantable::doCubicSplineFitting(const std::vector<float>& data, const std::vector<bool>& mask, int nPiece, std::vector<int>& idxEdge, std::vector<float>& params, int& nClipped, float thresClip, int nIterClip, bool getResidual) 4050 std::vector<float> Scantable::doCubicSplineFitting(const std::vector<float>& data, const std::vector<bool>& mask, std::vector<int>& idxEdge, std::vector<float>& params, float& rms, std::vector<bool>& finalmask, float clipth, int clipn) 4051 { 4052 int nClipped = 0; 4053 return doCubicSplineFitting(data, mask, idxEdge.size()-1, true, idxEdge, params, rms, finalmask, nClipped, clipth, clipn); 4054 } 4055 4056 std::vector<float> Scantable::doCubicSplineFitting(const std::vector<float>& data, const std::vector<bool>& mask, int nPiece, std::vector<int>& idxEdge, std::vector<float>& params, float& rms, std::vector<bool>& finalmask, float clipth, int clipn) 4057 { 4058 int nClipped = 0; 4059 return doCubicSplineFitting(data, mask, nPiece, false, idxEdge, params, rms, finalmask, nClipped, clipth, clipn); 4060 } 4061 4062 std::vector<float> Scantable::doCubicSplineFitting(const std::vector<float>& data, const std::vector<bool>& mask, int nPiece, bool useGivenPieceBoundary, std::vector<int>& idxEdge, std::vector<float>& params, float& rms, std::vector<bool>& finalMask, int& nClipped, float thresClip, int nIterClip, bool getResidual) 3337 4063 { 3338 4064 if (data.size() != mask.size()) { … … 3344 4070 3345 4071 int nChan = data.size(); 4072 4073 finalMask.clear(); 4074 finalMask.resize(nChan); 4075 3346 4076 std::vector<int> maskArray(nChan); 3347 4077 std::vector<int> x(nChan); … … 3353 4083 j++; 3354 4084 } 4085 finalMask[i] = mask[i]; 3355 4086 } 3356 4087 int initNData = j; … … 3362 4093 int nElement = (int)(floor(floor((double)(initNData/nPiece))+0.5)); 3363 4094 std::vector<double> invEdge(nPiece-1); 3364 idxEdge[0] = x[0]; 4095 4096 if (useGivenPieceBoundary) { 4097 if ((int)idxEdge.size() != nPiece+1) { 4098 throw(AipsError("pieceEdge.size() must be equal to nPiece+1.")); 4099 } 4100 } else { 4101 idxEdge.clear(); 4102 idxEdge.resize(nPiece+1); 4103 idxEdge[0] = x[0]; 4104 } 3365 4105 for (int i = 1; i < nPiece; ++i) { 3366 4106 int valX = x[nElement*i]; 3367 idxEdge[i] = valX; 4107 if (!useGivenPieceBoundary) { 4108 idxEdge[i] = valX; 4109 } 3368 4110 invEdge[i-1] = 1.0/(double)valX; 3369 4111 } 3370 idxEdge[nPiece] = x[initNData-1]+1; 4112 if (!useGivenPieceBoundary) { 4113 idxEdge[nPiece] = x[initNData-1]+1; 4114 } 4115 4116 params.clear(); 4117 params.resize(nPiece*4); 3371 4118 3372 4119 int nData = initNData; … … 3395 4142 // identity matrix (right). 3396 4143 // the right part is used to calculate the inverse matrix of the left part. 4144 3397 4145 double xMatrix[nDOF][2*nDOF]; 3398 4146 double zMatrix[nDOF]; … … 3496 4244 } 3497 4245 } 4246 3498 4247 //compute a vector y which consists of the coefficients of the best-fit spline curves 3499 4248 //(a0,a1,a2,a3(,b3,c3,...)), namely, the ones for the leftmost piece and the ones of … … 3545 4294 } 3546 4295 } 4296 3547 4297 if (idxEdge[nPiece] < nChan) { 3548 4298 int n = idxEdge[nPiece]-1; … … 3562 4312 } 3563 4313 4314 double stdDev = 0.0; 4315 for (int i = 0; i < nChan; ++i) { 4316 stdDev += residual[i]*residual[i]*(double)maskArray[i]; 4317 } 4318 stdDev = sqrt(stdDev/(double)nData); 4319 rms = (float)stdDev; 4320 3564 4321 if ((nClip == nIterClip) || (thresClip <= 0.0)) { 3565 4322 break; 3566 4323 } else { 3567 double stdDev = 0.0;3568 for (int i = 0; i < nChan; ++i) {3569 stdDev += residual[i]*residual[i]*(double)maskArray[i];3570 }3571 stdDev = sqrt(stdDev/(double)nData);3572 4324 3573 4325 double thres = stdDev * thresClip; … … 3576 4328 if (abs(residual[i]) >= thres) { 3577 4329 maskArray[i] = 0; 4330 finalMask[i] = false; 3578 4331 } 3579 4332 if (maskArray[i] > 0) { … … 3586 4339 nData = newNData; 3587 4340 } 4341 3588 4342 } 3589 4343 } … … 3605 4359 } 3606 4360 3607 void Scantable::selectWaveNumbers(const int whichrow, const std::vector<bool>& chanMask, const bool applyFFT, const std::string& fftMethod, const std::string& fftThresh, const std::vector<int>& addNWaves, const std::vector<int>& rejectNWaves, std::vector<int>& nWaves) 3608 { 4361 void Scantable::selectWaveNumbers(const int whichrow, const std::vector<bool>& chanMask, const std::string& fftInfo, const std::vector<int>& addNWaves, const std::vector<int>& rejectNWaves, std::vector<int>& nWaves) 4362 //void Scantable::selectWaveNumbers(const int whichrow, const std::vector<bool>& chanMask, const bool applyFFT, const std::string& fftMethod, const std::string& fftThresh, const std::vector<int>& addNWaves, const std::vector<int>& rejectNWaves, std::vector<int>& nWaves) 4363 { 4364 bool applyFFT; 4365 std::string fftMethod; 4366 std::string fftThresh; 4367 3609 4368 nWaves.clear(); 3610 4369 4370 parseFFTInfo(fftInfo, applyFFT, fftMethod, fftThresh); 3611 4371 if (applyFFT) { 3612 4372 string fftThAttr; … … 3618 4378 3619 4379 addAuxWaveNumbers(whichrow, addNWaves, rejectNWaves, nWaves); 4380 } 4381 4382 void Scantable::parseFFTInfo(const std::string& fftInfo, bool& applyFFT, std::string& fftMethod, std::string& fftThresh) 4383 { 4384 istringstream iss(fftInfo); 4385 std::string tmp; 4386 std::vector<string> res; 4387 while (getline(iss, tmp, ',')) { 4388 res.push_back(tmp); 4389 } 4390 if (res.size() < 3) { 4391 throw(AipsError("wrong value in 'fftinfo' parameter")) ; 4392 } 4393 applyFFT = (res[0] == "true"); 4394 fftMethod = res[1]; 4395 fftThresh = res[2]; 3620 4396 } 3621 4397 … … 3702 4478 { 3703 4479 std::vector<int> tempAddNWaves, tempRejectNWaves; 4480 tempAddNWaves.clear(); 4481 tempRejectNWaves.clear(); 4482 3704 4483 for (uInt i = 0; i < addNWaves.size(); ++i) { 3705 4484 tempAddNWaves.push_back(addNWaves[i]); … … 3745 4524 void Scantable::setWaveNumberListUptoNyquistFreq(const int whichrow, std::vector<int>& nWaves) 3746 4525 { 3747 if ((nWaves.size() == 2)&&(nWaves[1] == -999)) { 3748 int val = nWaves[0]; 3749 int nyquistFreq = nchan(getIF(whichrow))/2+1; 3750 nWaves.clear(); 3751 if (val > nyquistFreq) { // for safety, at least nWaves contains a constant; CAS-3759 3752 nWaves.push_back(0); 3753 } 3754 while (val <= nyquistFreq) { 3755 nWaves.push_back(val); 3756 val++; 3757 } 3758 } 3759 } 3760 3761 void Scantable::sinusoidBaseline(const std::vector<bool>& mask, const bool applyFFT, const std::string& fftMethod, const std::string& fftThresh, const std::vector<int>& addNWaves, const std::vector<int>& rejectNWaves, float thresClip, int nIterClip, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile) 4526 int val = nWaves[0]; 4527 int nyquistFreq = nchan(getIF(whichrow))/2+1; 4528 nWaves.clear(); 4529 if (val > nyquistFreq) { // for safety, at least nWaves contains a constant; CAS-3759 4530 nWaves.push_back(0); 4531 } 4532 while (val <= nyquistFreq) { 4533 nWaves.push_back(val); 4534 val++; 4535 } 4536 } 4537 4538 void Scantable::sinusoidBaseline(const std::vector<bool>& mask, const std::string& fftInfo, 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, const std::string& bltable) 3762 4539 { 3763 4540 try { … … 3780 4557 } 3781 4558 3782 //Fitter fitter = Fitter();3783 //fitter.setExpression("sinusoid", nWaves);3784 //fitter.setIterClipping(thresClip, nIterClip);4559 bool showProgress; 4560 int minNRow; 4561 parseProgressInfo(progressInfo, showProgress, minNRow); 3785 4562 3786 4563 int nRow = nrow(); 3787 4564 std::vector<bool> chanMask; 3788 4565 std::vector<int> nWaves; 3789 3790 bool showProgress; 3791 int minNRow; 3792 parseProgressInfo(progressInfo, showProgress, minNRow); 4566 std::vector<bool> finalChanMask; 4567 float rms; 4568 4569 //--- 4570 bool outBaselintTable = (bltable != ""); 4571 STBaselineTable* bt = new STBaselineTable(*this); 4572 ROScalarColumn<Double> *tcol = new ROScalarColumn<Double>(table_, "TIME"); 4573 Vector<Double> timeSecCol = tcol->getColumn(); 4574 //--- 3793 4575 3794 4576 for (int whichrow = 0; whichrow < nRow; ++whichrow) { 4577 std::vector<float> sp = getSpectrum(whichrow); 3795 4578 chanMask = getCompositeChanMask(whichrow, mask); 3796 selectWaveNumbers(whichrow, chanMask, applyFFT, fftMethod, fftThresh, addNWaves, rejectNWaves, nWaves); 3797 3798 //FOR DEBUGGING------------ 3799 /* 3800 if (whichrow < 0) {// == nRow -1) { 3801 cout << "+++ i=" << setw(3) << whichrow << ", IF=" << setw(2) << getIF(whichrow); 3802 if (applyFFT) { 3803 cout << "[ "; 3804 for (uInt j = 0; j < nWaves.size(); ++j) { 3805 cout << nWaves[j] << ", "; 3806 } 3807 cout << " ] " << endl; 3808 } 3809 cout << flush; 3810 } 3811 */ 3812 //------------------------- 3813 3814 //fitBaseline(chanMask, whichrow, fitter); 3815 //setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow); 4579 selectWaveNumbers(whichrow, chanMask, fftInfo, addNWaves, rejectNWaves, nWaves); 4580 3816 4581 std::vector<float> params; 3817 4582 int nClipped = 0; 3818 std::vector<float> res = doSinusoidFitting(getSpectrum(whichrow), chanMask, nWaves, params, nClipped, thresClip, nIterClip, getResidual); 3819 setSpectrum(res, whichrow); 3820 // 4583 std::vector<float> res = doSinusoidFitting(sp, chanMask, nWaves, params, rms, finalChanMask, nClipped, thresClip, nIterClip, getResidual); 4584 4585 //--- 4586 if (outBaselintTable) { 4587 uInt nparam = nWaves.size(); 4588 Vector<Int> fparam(nparam); 4589 for (uInt i = 0; i < nparam; ++i) { 4590 fparam[i] = nWaves[i]; 4591 } 4592 std::vector<int> finalMaskList0; 4593 finalMaskList0.clear(); 4594 for (uInt i = 0; i < finalChanMask.size(); ++i) { 4595 if (finalChanMask[i]) { 4596 if ((i == 0)||(i == finalChanMask.size()-1)) { 4597 finalMaskList0.push_back(i); 4598 } else { 4599 if ((finalChanMask[i])&&(!finalChanMask[i-1])) { 4600 finalMaskList0.push_back(i); 4601 } 4602 if ((finalChanMask[i])&&(!finalChanMask[i+1])) { 4603 finalMaskList0.push_back(i); 4604 } 4605 } 4606 } 4607 } 4608 Vector<uInt> finalMaskList(finalMaskList0.size()); 4609 for (uInt i = 0; i < finalMaskList0.size(); ++i) { 4610 finalMaskList[i] = (uInt)finalMaskList0[i]; 4611 } 4612 4613 bt->appenddata(uInt(getScan(whichrow)), uInt(getCycle(whichrow)), uInt(getBeam(whichrow)), uInt(getIF(whichrow)), uInt(getPol(whichrow)), 4614 uInt(0), 4615 timeSecCol[whichrow], 4616 Bool(true), 4617 STBaselineFunc::Sinusoid, 4618 fparam, 4619 Vector<Float>(), 4620 finalMaskList, 4621 Vector<Float>(params), 4622 Float(rms), 4623 uInt(sp.size()), 4624 Float(thresClip), 4625 uInt(nIterClip), 4626 Float(0.0), 4627 uInt(0), 4628 Vector<uInt>()); 4629 } else { 4630 setSpectrum(res, whichrow); 4631 } 4632 //--- 3821 4633 3822 4634 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "sinusoidBaseline()", params, nClipped); … … 3824 4636 } 3825 4637 4638 //--- 4639 if (outBaselintTable) { 4640 bt->save(bltable); 4641 } 4642 //--- 4643 delete bt; 4644 3826 4645 if (outTextFile) ofs.close(); 3827 4646 … … 3831 4650 } 3832 4651 3833 void Scantable::autoSinusoidBaseline(const std::vector<bool>& mask, const bool applyFFT, const std::string& fftMethod, const std::string& fftThresh, const std::vector<int>& addNWaves, const std::vector<int>& rejectNWaves, float thresClip, int nIterClip, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile) 4652 void Scantable::autoSinusoidBaseline(const std::vector<bool>& mask, const std::string& fftInfo, 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, const std::string& bltable) 4653 //void Scantable::autoSinusoidBaseline(const std::vector<bool>& mask, const bool applyFFT, const std::string& fftMethod, const std::string& fftThresh, const std::vector<int>& addNWaves, const std::vector<int>& rejectNWaves, float thresClip, int nIterClip, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool getResidual, const std::string& progressInfo, const bool outLogger, const std::string& blfile, const std::string& bltable) 3834 4654 { 3835 4655 try { … … 3852 4672 } 3853 4673 3854 //Fitter fitter = Fitter(); 3855 //fitter.setExpression("sinusoid", nWaves); 3856 //fitter.setIterClipping(thresClip, nIterClip); 4674 bool showProgress; 4675 int minNRow; 4676 parseProgressInfo(progressInfo, showProgress, minNRow); 4677 4678 int minEdgeSize = getIFNos().size()*2; 4679 STLineFinder lineFinder = STLineFinder(); 4680 lineFinder.setOptions(threshold, 3, chanAvgLimit); 3857 4681 3858 4682 int nRow = nrow(); 3859 4683 std::vector<bool> chanMask; 3860 4684 std::vector<int> nWaves; 3861 3862 int minEdgeSize = getIFNos().size()*2; 3863 STLineFinder lineFinder = STLineFinder(); 3864 lineFinder.setOptions(threshold, 3, chanAvgLimit); 3865 3866 bool showProgress; 3867 int minNRow; 3868 parseProgressInfo(progressInfo, showProgress, minNRow); 4685 std::vector<bool> finalChanMask; 4686 float rms; 4687 4688 //--- 4689 bool outBaselintTable = (bltable != ""); 4690 STBaselineTable* bt = new STBaselineTable(*this); 4691 ROScalarColumn<Double> *tcol = new ROScalarColumn<Double>(table_, "TIME"); 4692 Vector<Double> timeSecCol = tcol->getColumn(); 4693 //--- 3869 4694 3870 4695 for (int whichrow = 0; whichrow < nRow; ++whichrow) { 3871 3872 //------------------------------------------------------- 3873 //chanMask = getCompositeChanMask(whichrow, mask, edge, minEdgeSize, lineFinder); 3874 //------------------------------------------------------- 4696 std::vector<float> sp = getSpectrum(whichrow); 4697 //-- composote given channel mask and flagtra -------- 3875 4698 int edgeSize = edge.size(); 3876 4699 std::vector<int> currentEdge; 4700 currentEdge.clear(); 3877 4701 if (edgeSize >= 2) { 3878 4702 int idx = 0; … … 3888 4712 throw(AipsError("Wrong length of edge element")); 3889 4713 } 3890 lineFinder.setData( getSpectrum(whichrow));4714 lineFinder.setData(sp); 3891 4715 lineFinder.findLines(getCompositeChanMask(whichrow, mask), currentEdge, whichrow); 3892 4716 chanMask = lineFinder.getMask(); 3893 //------------------------------------------------------- 3894 3895 selectWaveNumbers(whichrow, chanMask, applyFFT, fftMethod, fftThresh, addNWaves, rejectNWaves, nWaves); 3896 3897 //fitBaseline(chanMask, whichrow, fitter); 3898 //setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow); 4717 //-- composote given channel mask and flagtra END -------- 4718 selectWaveNumbers(whichrow, chanMask, fftInfo, addNWaves, rejectNWaves, nWaves); 4719 3899 4720 std::vector<float> params; 3900 4721 int nClipped = 0; 3901 std::vector<float> res = doSinusoidFitting(getSpectrum(whichrow), chanMask, nWaves, params, nClipped, thresClip, nIterClip, getResidual); 3902 setSpectrum(res, whichrow); 3903 // 4722 std::vector<float> res = doSinusoidFitting(sp, chanMask, nWaves, params, rms, finalChanMask, nClipped, thresClip, nIterClip, getResidual); 4723 4724 //--- 4725 if (outBaselintTable) { 4726 uInt nparam = nWaves.size(); 4727 Vector<Int> fparam(nparam); 4728 for (uInt i = 0; i < nparam; ++i) { 4729 fparam[i] = nWaves[i]; 4730 } 4731 std::vector<int> finalMaskList0; 4732 finalMaskList0.clear(); 4733 for (uInt i = 0; i < finalChanMask.size(); ++i) { 4734 if (finalChanMask[i]) { 4735 if ((i == 0)||(i == finalChanMask.size()-1)) { 4736 finalMaskList0.push_back(i); 4737 } else { 4738 if ((finalChanMask[i])&&(!finalChanMask[i-1])) { 4739 finalMaskList0.push_back(i); 4740 } 4741 if ((finalChanMask[i])&&(!finalChanMask[i+1])) { 4742 finalMaskList0.push_back(i); 4743 } 4744 } 4745 } 4746 } 4747 Vector<uInt> finalMaskList(finalMaskList0.size()); 4748 for (uInt i = 0; i < finalMaskList0.size(); ++i) { 4749 finalMaskList[i] = (uInt)finalMaskList0[i]; 4750 } 4751 4752 Vector<uInt> cEdge(currentEdge.size()); 4753 for (uInt i = 0; i < currentEdge.size(); ++i) { 4754 cEdge[i] = currentEdge[i]; 4755 } 4756 4757 bt->appenddata(uInt(getScan(whichrow)), uInt(getCycle(whichrow)), uInt(getBeam(whichrow)), uInt(getIF(whichrow)), uInt(getPol(whichrow)), 4758 uInt(0), 4759 timeSecCol[whichrow], 4760 Bool(true), 4761 STBaselineFunc::Sinusoid, 4762 fparam, 4763 Vector<Float>(), 4764 finalMaskList, 4765 Vector<Float>(params), 4766 Float(rms), 4767 uInt(sp.size()), 4768 Float(thresClip), 4769 uInt(nIterClip), 4770 Float(threshold), 4771 uInt(chanAvgLimit), 4772 cEdge); 4773 } else { 4774 setSpectrum(res, whichrow); 4775 } 4776 //--- 3904 4777 3905 4778 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoSinusoidBaseline()", params, nClipped); … … 3907 4780 } 3908 4781 4782 //--- 4783 if (outBaselintTable) { 4784 bt->save(bltable); 4785 } 4786 //--- 4787 delete bt; 4788 3909 4789 if (outTextFile) ofs.close(); 3910 4790 … … 3914 4794 } 3915 4795 3916 std::vector<float> Scantable::doSinusoidFitting(const std::vector<float>& data, const std::vector<bool>& mask, const std::vector<int>& waveNumbers, std::vector<float>& params, int& nClipped, float thresClip, int nIterClip, bool getResidual) 4796 std::vector<float> Scantable::doSinusoidFitting(const std::vector<float>& data, const std::vector<bool>& mask, const std::vector<int>& waveNumbers, std::vector<float>& params, float& rms, std::vector<bool>& finalmask, float clipth, int clipn) 4797 { 4798 int nClipped = 0; 4799 return doSinusoidFitting(data, mask, waveNumbers, params, rms, finalmask, nClipped, clipth, clipn); 4800 } 4801 4802 std::vector<float> Scantable::doSinusoidFitting(const std::vector<float>& data, const std::vector<bool>& mask, const std::vector<int>& waveNumbers, std::vector<float>& params, float& rms, std::vector<bool>& finalMask, int& nClipped, float thresClip, int nIterClip, bool getResidual) 3917 4803 { 3918 4804 if (data.size() != mask.size()) { … … 3939 4825 3940 4826 int nChan = data.size(); 4827 4828 finalMask.clear(); 4829 finalMask.resize(nChan); 4830 3941 4831 std::vector<int> maskArray; 3942 4832 std::vector<int> x; … … 3946 4836 x.push_back(i); 3947 4837 } 4838 finalMask[i] = mask[i]; 3948 4839 } 3949 4840 … … 4086 4977 } 4087 4978 4979 double stdDev = 0.0; 4980 for (int i = 0; i < nChan; ++i) { 4981 stdDev += residual[i]*residual[i]*(double)maskArray[i]; 4982 } 4983 stdDev = sqrt(stdDev/(double)nData); 4984 rms = (float)stdDev; 4985 4088 4986 if ((nClip == nIterClip) || (thresClip <= 0.0)) { 4089 4987 break; 4090 4988 } else { 4091 double stdDev = 0.0; 4092 for (int i = 0; i < nChan; ++i) { 4093 stdDev += residual[i]*residual[i]*(double)maskArray[i]; 4094 } 4095 stdDev = sqrt(stdDev/(double)nData); 4096 4989 4097 4990 double thres = stdDev * thresClip; 4098 4991 int newNData = 0; … … 4100 4993 if (abs(residual[i]) >= thres) { 4101 4994 maskArray[i] = 0; 4995 finalMask[i] = false; 4102 4996 } 4103 4997 if (maskArray[i] > 0) { … … 4110 5004 nData = newNData; 4111 5005 } 5006 4112 5007 } 4113 5008 } -
trunk/src/Scantable.h
r2737 r2767 28 28 #include <casa/Quanta/Quantum.h> 29 29 #include <casa/Utilities/CountedPtr.h> 30 31 30 #include <coordinates/Coordinates/SpectralCoordinate.h> 32 33 31 #include <measures/TableMeasures/ScalarMeasColumn.h> 34 35 32 #include <scimath/Mathematics/FFTServer.h> 36 37 33 #include <tables/Tables/ArrayColumn.h> 38 34 #include <tables/Tables/ScalarColumn.h> 39 35 #include <tables/Tables/Table.h> 40 36 41 42 37 #include "MathUtils.h" 38 #include "STBaselineEnum.h" 43 39 #include "STFit.h" 44 40 #include "STFitEntry.h" … … 507 503 void regridChannel( int nchan, double dnu, int irow ) ; 508 504 void regridChannel( int nchan, double dnu, double fmin, int irow ) ; 509 510 505 void regridSpecChannel( double dnu, int nchan=-1 ) ; 511 506 512 507 bool getFlagtraFast(casa::uInt whichrow); 513 508 514 void polyBaseline(const std::vector<bool>& mask, 515 int order, 509 std::vector<std::string> applyBaselineTable(const std::string& bltable, const std::string& outbltable, const bool outbltableexists, const bool overwrite); 510 std::vector<std::string> subBaseline(const std::vector<std::string>& blInfoList, const std::string& outbltable, const bool outbltableexists, const bool overwrite); 511 void polyBaseline(const std::vector<bool>& mask, 512 int order, 513 float thresClip, 514 int nIterClip, 516 515 bool getResidual=true, 517 516 const std::string& progressInfo="true,1000", 518 const bool outLogger=false, 519 const std::string& blfile=""); 517 const bool outLogger=false, 518 const std::string& blfile="", 519 const std::string& bltable=""); 520 520 void autoPolyBaseline(const std::vector<bool>& mask, 521 int order, 522 const std::vector<int>& edge, 523 float threshold=3.0, 524 int chanAvgLimit=1, 525 bool getResidual=true, 526 const std::string& progressInfo="true,1000", 527 const bool outLogger=false, 528 const std::string& blfile=""); 521 int order, 522 float thresClip, 523 int nIterClip, 524 const std::vector<int>& edge, 525 float threshold=3.0, 526 int chanAvgLimit=1, 527 bool getResidual=true, 528 const std::string& progressInfo="true,1000", 529 const bool outLogger=false, 530 const std::string& blfile="", 531 const std::string& bltable=""); 529 532 void chebyshevBaseline(const std::vector<bool>& mask, 530 533 int order, … … 534 537 const std::string& progressInfo="true,1000", 535 538 const bool outLogger=false, 536 const std::string& blfile=""); 539 const std::string& blfile="", 540 const std::string& bltable=""); 537 541 void autoChebyshevBaseline(const std::vector<bool>& mask, 538 542 int order, … … 545 549 const std::string& progressInfo="true,1000", 546 550 const bool outLogger=false, 547 const std::string& blfile=""); 551 const std::string& blfile="", 552 const std::string& bltable=""); 548 553 void cubicSplineBaseline(const std::vector<bool>& mask, 549 554 int nPiece, … … 553 558 const std::string& progressInfo="true,1000", 554 559 const bool outLogger=false, 555 const std::string& blfile=""); 560 const std::string& blfile="", 561 const std::string& bltable=""); 556 562 void autoCubicSplineBaseline(const std::vector<bool>& mask, 557 563 int nPiece, … … 564 570 const std::string& progressInfo="true,1000", 565 571 const bool outLogger=false, 566 const std::string& blfile=""); 572 const std::string& blfile="", 573 const std::string& bltable=""); 567 574 void sinusoidBaseline(const std::vector<bool>& mask, 568 const bool applyFFT, 569 const std::string& fftMethod, 570 const std::string& fftThresh, 575 const std::string& fftInfo, 571 576 const std::vector<int>& addNWaves, 572 577 const std::vector<int>& rejectNWaves, … … 576 581 const std::string& progressInfo="true,1000", 577 582 const bool outLogger=false, 578 const std::string& blfile=""); 583 const std::string& blfile="", 584 const std::string& bltable=""); 579 585 void autoSinusoidBaseline(const std::vector<bool>& mask, 580 const bool applyFFT, 581 const std::string& fftMethod, 582 const std::string& fftThresh, 586 const std::string& fftInfo, 583 587 const std::vector<int>& addNWaves, 584 588 const std::vector<int>& rejectNWaves, … … 591 595 const std::string& progressInfo="true,1000", 592 596 const bool outLogger=false, 593 const std::string& blfile=""); 597 const std::string& blfile="", 598 const std::string& bltable=""); 594 599 std::vector<float> execFFT(const int whichrow, 595 600 const std::vector<bool>& inMask, … … 628 633 float threshold, 629 634 int chanAvgLimit); 635 static std::vector<bool> getMaskFromMaskList(const int nchan, 636 const std::vector<int>& masklist); 637 static std::vector<int> splitToIntList(const std::string& str, const char delim); 638 static std::vector<string> splitToStringList(const std::string& str, const char delim); 639 630 640 631 641 … … 743 753 744 754 void fitBaseline(const std::vector<bool>& mask, int whichrow, Fitter& fitter); 755 double getNormalPolynomial(int n, double x); 745 756 double getChebyshevPolynomial(int n, double x); 757 std::vector<float> doPolynomialFitting(const std::vector<float>& data, 758 const std::vector<bool>& mask, 759 int order, 760 std::vector<float>& params, 761 float& rms, 762 std::vector<bool>& finalMask, 763 float clipth, 764 int clipn); 765 std::vector<float> doPolynomialFitting(const std::vector<float>& data, 766 const std::vector<bool>& mask, 767 int order, 768 std::vector<float>& params, 769 float& rms, 770 std::vector<bool>& finalMask, 771 int& nClipped, 772 float thresClip=3.0, 773 int nIterClip=0, 774 bool getResidual=true); 746 775 std::vector<float> doChebyshevFitting(const std::vector<float>& data, 776 const std::vector<bool>& mask, 777 int order, 778 std::vector<float>& params, 779 float& rms, 780 std::vector<bool>& finalMask, 781 float clipth, 782 int clipn); 783 std::vector<float> doChebyshevFitting(const std::vector<float>& data, 784 const std::vector<bool>& mask, 785 int order, 786 std::vector<float>& params, 787 float& rms, 788 std::vector<bool>& finalMask, 789 int& nClipped, 790 float thresClip=3.0, 791 int nIterClip=0, 792 bool getResidual=true); 793 std::vector<float> doLeastSquareFitting(const std::vector<float>& data, 794 const std::vector<bool>& mask, 795 double (Scantable::*pfunc)(int, double), 796 int order, 797 std::vector<float>& params, 798 float& rms, 799 std::vector<bool>& finalMask, 800 int& nClipped, 801 float thresClip=3.0, 802 int nIterClip=0, 803 bool getResidual=true); 804 std::vector<float> doCubicSplineFitting(const std::vector<float>& data, 747 805 const std::vector<bool>& mask, 748 int order,806 std::vector<int>& idxEdge, 749 807 std::vector<float>& params, 808 float& rms, 750 809 std::vector<bool>& finalMask, 751 float& rms, 752 int& nClipped, 753 float thresClip=3.0, 754 int nIterClip=1, 755 bool getResidual=true); 810 float clipth, 811 int clipn); 756 812 std::vector<float> doCubicSplineFitting(const std::vector<float>& data, 757 813 const std::vector<bool>& mask, … … 759 815 std::vector<int>& idxEdge, 760 816 std::vector<float>& params, 817 float& rms, 818 std::vector<bool>& finalMask, 819 float clipth, 820 int clipn); 821 std::vector<float> doCubicSplineFitting(const std::vector<float>& data, 822 const std::vector<bool>& mask, 823 int nPiece, 824 bool useGivenPieceBoundary, 825 std::vector<int>& idxEdge, 826 std::vector<float>& params, 827 float& rms, 828 std::vector<bool>& finalMask, 761 829 int& nClipped, 762 830 float thresClip=3.0, 763 int nIterClip= 1,831 int nIterClip=0, 764 832 bool getResidual=true); 765 833 std::vector<float> doSinusoidFitting(const std::vector<float>& data, … … 767 835 const std::vector<int>& waveNumbers, 768 836 std::vector<float>& params, 837 float& rms, 838 std::vector<bool>& finalMask, 839 float clipth, 840 int clipn); 841 std::vector<float> doSinusoidFitting(const std::vector<float>& data, 842 const std::vector<bool>& mask, 843 const std::vector<int>& waveNumbers, 844 std::vector<float>& params, 845 float& rms, 846 std::vector<bool>& finalMask, 769 847 int& nClipped, 770 848 float thresClip=3.0, 771 int nIterClip= 1,849 int nIterClip=0, 772 850 bool getResidual=true); 773 851 void selectWaveNumbers(const int whichrow, 774 852 const std::vector<bool>& chanMask, 775 const bool applyFFT, 776 const std::string& fftMethod, 777 const std::string& fftThresh, 853 const std::string& fftInfo, 854 //const bool applyFFT, 855 //const std::string& fftMethod, 856 //const std::string& fftThresh, 778 857 const std::vector<int>& addNWaves, 779 858 const std::vector<int>& rejectNWaves, 780 859 std::vector<int>& nWaves); 860 void parseFFTInfo(const std::string& fftInfo, 861 bool& applyFFT, 862 std::string& fftMethod, 863 std::string& fftThresh); 781 864 void parseThresholdExpression(const std::string& fftThresh, 782 865 std::string& fftThAttr, … … 821 904 int order); 822 905 double doGetRms(const std::vector<bool>& mask, const casa::Vector<casa::Float>& spec); 906 std::string packFittingResults(const int irow, const std::vector<float>& params, const float rms); 907 void parseBlInfo(const std::string& blInfo, int& whichrow, STBaselineFunc::FuncName& ftype, std::vector<int>& fpar, std::vector<bool>& mask, float& thresClip, int& nIterClip, bool& useLineFinder, float& thresLF, std::vector<int>& edgeLF, int& avgLF); 908 std::vector<float> doApplyBaselineTable(std::vector<float>& spec, std::vector<bool>& mask, const STBaselineFunc::FuncName ftype, std::vector<int>& fpar, std::vector<float>& params, float&rms); 909 std::vector<float> doSubtractBaseline(std::vector<float>& spec, std::vector<bool>& mask, const STBaselineFunc::FuncName ftype, std::vector<int>& fpar, std::vector<float>& params, float&rms, std::vector<bool>& finalmask, float clipth, int clipn, bool uself, int irow, float lfth, std::vector<int>& lfedge, int lfavg); 823 910 824 911 }; 825 826 912 } // namespace 827 913 -
trunk/src/ScantableWrapper.h
r2713 r2767 278 278 { table_->regridSpecChannel( dnu, nchan ); } 279 279 280 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="") 281 { table_->polyBaseline(mask, order, getresidual, showprogress, outlog, blfile); } 282 283 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="") 284 { table_->autoPolyBaseline(mask, order, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile); } 285 286 void chebyshevBaseline(const std::vector<bool>& mask, int order, float clipthresh, int clipniter, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="") 287 { table_->chebyshevBaseline(mask, order, clipthresh, clipniter, getresidual, showprogress, outlog, blfile); } 288 289 void autoChebyshevBaseline(const std::vector<bool>& mask, int order, 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="") 290 { table_->autoChebyshevBaseline(mask, order, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile); } 291 292 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="") 293 { table_->cubicSplineBaseline(mask, npiece, clipthresh, clipniter, getresidual, showprogress, outlog, blfile); } 294 295 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="") 296 { table_->autoCubicSplineBaseline(mask, npiece, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile); } 297 298 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="") 299 { table_->sinusoidBaseline(mask, applyfft, fftmethod, fftthresh, addwn, rejwn, clipthresh, clipniter, getresidual, showprogress, outlog, blfile); } 300 301 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="") 302 { table_->autoSinusoidBaseline(mask, applyfft, fftmethod, fftthresh, addwn, rejwn, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile); } 280 std::vector<std::string> applyBaselineTable(const std::string& bltable, const std::string& outbltable, const bool outbltableexists, const bool overwrite) 281 { return table_->applyBaselineTable(bltable, outbltable, outbltableexists, overwrite); } 282 std::vector<std::string> subBaseline(const std::vector<std::string>& blinfo, const std::string& outbltable, const bool outbltableexists, const bool overwrite) 283 { return table_->subBaseline(blinfo, outbltable, outbltableexists, overwrite); } 284 void polyBaseline(const std::vector<bool>& mask, int order, float clipthresh, int clipniter, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="", const std::string& bltable="") 285 { table_->polyBaseline(mask, order, clipthresh, clipniter, getresidual, showprogress, outlog, blfile, bltable); } 286 287 void autoPolyBaseline(const std::vector<bool>& mask, int order, 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="", const std::string& bltable="") 288 { table_->autoPolyBaseline(mask, order, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile, bltable); } 289 290 void chebyshevBaseline(const std::vector<bool>& mask, int order, float clipthresh, int clipniter, bool getresidual=true, const std::string& showprogress="true,1000", const bool outlog=false, const std::string& blfile="", const std::string& bltable="") 291 { table_->chebyshevBaseline(mask, order, clipthresh, clipniter, getresidual, showprogress, outlog, blfile, bltable); } 292 293 void autoChebyshevBaseline(const std::vector<bool>& mask, int order, 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="", const std::string& bltable="") 294 { table_->autoChebyshevBaseline(mask, order, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile, bltable); } 295 296 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="", const std::string& bltable="") 297 { table_->cubicSplineBaseline(mask, npiece, clipthresh, clipniter, getresidual, showprogress, outlog, blfile, bltable); } 298 299 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="", const std::string& bltable="") 300 { table_->autoCubicSplineBaseline(mask, npiece, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile, bltable); } 301 302 void sinusoidBaseline(const std::vector<bool>& mask, const std::string& fftinfo, 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="", const std::string& bltable="") 303 { table_->sinusoidBaseline(mask, fftinfo, addwn, rejwn, clipthresh, clipniter, getresidual, showprogress, outlog, blfile, bltable); } 304 305 void autoSinusoidBaseline(const std::vector<bool>& mask, const std::string& fftinfo, 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="", const std::string& bltable="") 306 { table_->autoSinusoidBaseline(mask, fftinfo, addwn, rejwn, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, showprogress, outlog, blfile, bltable); } 303 307 304 308 float getRms(const std::vector<bool>& mask, int whichrow) -
trunk/src/python_Scantable.cpp
r2713 r2767 145 145 .def("_regrid_specchan", &ScantableWrapper::regridSpecChannel, 146 146 (boost::python::arg("nchan")=-1) ) 147 .def("_apply_bltable", &ScantableWrapper::applyBaselineTable) 148 .def("_sub_baseline", &ScantableWrapper::subBaseline) 147 149 .def("_poly_baseline", &ScantableWrapper::polyBaseline) 148 150 .def("_auto_poly_baseline", &ScantableWrapper::autoPolyBaseline)
Note:
See TracChangeset
for help on using the changeset viewer.