- Timestamp:
- 08/10/12 20:49:54 (12 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/python/scantable.py
r2611 r2641 2524 2524 clipniter=None, plot=None, 2525 2525 getresidual=None, showprogress=None, 2526 minnrow=None, outlog=None, blfile=None ):2526 minnrow=None, outlog=None, blfile=None, csvformat=None): 2527 2527 """\ 2528 2528 Return a scan which has been baselined (all rows) with sinusoidal … … 2582 2582 parameter values to be written 2583 2583 (default is '': no file/logger output) 2584 csvformat: if True blfile is csv-formatted, default is False. 2584 2585 2585 2586 Example: … … 2618 2619 if outlog is None: outlog = False 2619 2620 if blfile is None: blfile = '' 2621 if csvformat is None: csvformat = False 2622 2623 if csvformat: 2624 scsvformat = "T" 2625 else: 2626 scsvformat = "F" 2620 2627 2621 2628 #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method. … … 2626 2633 clipniter, getresidual, 2627 2634 pack_progress_params(showprogress, 2628 minnrow), outlog,2629 blfile)2635 minnrow), 2636 outlog, scsvformat+blfile) 2630 2637 workscan._add_history('sinusoid_baseline', varlist) 2631 2638 … … 2646 2653 chan_avg_limit=None, plot=None, 2647 2654 getresidual=None, showprogress=None, 2648 minnrow=None, outlog=None, blfile=None ):2655 minnrow=None, outlog=None, blfile=None, csvformat=None): 2649 2656 """\ 2650 2657 Return a scan which has been baselined (all rows) with sinusoidal … … 2726 2733 parameter values to be written 2727 2734 (default is "": no file/logger output) 2735 csvformat: if True blfile is csv-formatted, default is False. 2728 2736 2729 2737 Example: … … 2762 2770 if outlog is None: outlog = False 2763 2771 if blfile is None: blfile = '' 2772 if csvformat is None: csvformat = False 2773 2774 if csvformat: 2775 scsvformat = "T" 2776 else: 2777 scsvformat = "F" 2764 2778 2765 2779 #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method. … … 2775 2789 pack_progress_params(showprogress, 2776 2790 minnrow), 2777 outlog, blfile)2791 outlog, scsvformat+blfile) 2778 2792 workscan._add_history("auto_sinusoid_baseline", varlist) 2779 2793 … … 2790 2804 clipthresh=None, clipniter=None, plot=None, 2791 2805 getresidual=None, showprogress=None, minnrow=None, 2792 outlog=None, blfile=None ):2806 outlog=None, blfile=None, csvformat=None): 2793 2807 """\ 2794 2808 Return a scan which has been baselined (all rows) by cubic spline … … 2819 2833 parameter values to be written 2820 2834 (default is "": no file/logger output) 2835 csvformat: if True blfile is csv-formatted, default is False. 2821 2836 2822 2837 Example: … … 2851 2866 if outlog is None: outlog = False 2852 2867 if blfile is None: blfile = '' 2868 if csvformat is None: csvformat = False 2869 2870 if csvformat: 2871 scsvformat = "T" 2872 else: 2873 scsvformat = "F" 2853 2874 2854 2875 #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method. … … 2856 2877 getresidual, 2857 2878 pack_progress_params(showprogress, 2858 minnrow), outlog,2859 blfile)2879 minnrow), 2880 outlog, scsvformat+blfile) 2860 2881 workscan._add_history("cspline_baseline", varlist) 2861 2882 … … 2874 2895 getresidual=None, plot=None, 2875 2896 showprogress=None, minnrow=None, outlog=None, 2876 blfile=None ):2897 blfile=None, csvformat=None): 2877 2898 """\ 2878 2899 Return a scan which has been baselined (all rows) by cubic spline … … 2925 2946 parameter values to be written 2926 2947 (default is "": no file/logger output) 2948 csvformat: if True blfile is csv-formatted, default is False. 2927 2949 2928 2950 Example: … … 2957 2979 if outlog is None: outlog = False 2958 2980 if blfile is None: blfile = '' 2981 if csvformat is None: csvformat = False 2982 2983 if csvformat: 2984 scsvformat = "T" 2985 else: 2986 scsvformat = "F" 2959 2987 2960 2988 #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method. … … 2966 2994 pack_progress_params(showprogress, 2967 2995 minnrow), 2968 outlog, blfile)2996 outlog, scsvformat+blfile) 2969 2997 workscan._add_history("auto_cspline_baseline", varlist) 2970 2998 … … 2980 3008 def poly_baseline(self, mask=None, order=None, insitu=None, plot=None, 2981 3009 getresidual=None, showprogress=None, minnrow=None, 2982 outlog=None, blfile=None ):3010 outlog=None, blfile=None, csvformat=None): 2983 3011 """\ 2984 3012 Return a scan which has been baselined (all rows) by a polynomial. … … 3003 3031 parameter values to be written 3004 3032 (default is "": no file/logger output) 3033 csvformat: if True blfile is csv-formatted, default is False. 3005 3034 3006 3035 Example: … … 3030 3059 if outlog is None: outlog = False 3031 3060 if blfile is None: blfile = "" 3061 if csvformat is None: csvformat = False 3062 3063 if csvformat: 3064 scsvformat = "T" 3065 else: 3066 scsvformat = "F" 3032 3067 3033 3068 if plot: … … 3084 3119 blpars["fixed"], 3085 3120 rms, str(masklist), 3086 r, True )3121 r, True, csvformat) 3087 3122 blf.write(dataout) 3088 3123 … … 3096 3131 pack_progress_params(showprogress, 3097 3132 minnrow), 3098 outlog, blfile)3133 outlog, scsvformat+blfile) 3099 3134 3100 3135 workscan._add_history("poly_baseline", varlist) … … 3113 3148 plot=None, insitu=None, 3114 3149 getresidual=None, showprogress=None, 3115 minnrow=None, outlog=None, blfile=None ):3150 minnrow=None, outlog=None, blfile=None, csvformat=None): 3116 3151 """\ 3117 3152 Return a scan which has been baselined (all rows) by a polynomial. … … 3159 3194 parameter values to be written 3160 3195 (default is "": no file/logger output) 3196 csvformat: if True blfile is csv-formatted, default is False. 3161 3197 3162 3198 Example: … … 3186 3222 if outlog is None: outlog = False 3187 3223 if blfile is None: blfile = '' 3224 if csvformat is None: csvformat = False 3225 3226 if csvformat: 3227 scsvformat = "T" 3228 else: 3229 scsvformat = "F" 3188 3230 3189 3231 edge = normalise_edge_param(edge) … … 3247 3289 blpars["fixed"], 3248 3290 rms, str(masklist), 3249 r, True )3291 r, True, csvformat) 3250 3292 blf.write(dataout) 3251 3293 … … 3259 3301 pack_progress_params(showprogress, 3260 3302 minnrow), 3261 outlog, blfile)3303 outlog, scsvformat+blfile) 3262 3304 3263 3305 workscan._add_history("auto_poly_baseline", varlist) -
trunk/src/Scantable.cpp
r2595 r2641 2489 2489 bool hasSameNchan = true; 2490 2490 bool outTextFile = false; 2491 bool csvFormat = false; 2491 2492 2492 2493 if (blfile != "") { 2493 ofs.open(blfile.c_str(), ios::out | ios::app); 2494 csvFormat = (blfile.substr(0, 1) == "T"); 2495 ofs.open(blfile.substr(1).c_str(), ios::out | ios::app); 2494 2496 if (ofs) outTextFile = true; 2495 2497 } … … 2515 2517 fitBaseline(chanMask, whichrow, fitter); 2516 2518 setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow); 2517 outputFittingResult(outLogger, outTextFile, c hanMask, whichrow, coordInfo, hasSameNchan, ofs, "polyBaseline()", fitter);2519 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "polyBaseline()", fitter); 2518 2520 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 2519 2521 } … … 2533 2535 bool hasSameNchan = true; 2534 2536 bool outTextFile = false; 2537 bool csvFormat = false; 2535 2538 2536 2539 if (blfile != "") { 2537 ofs.open(blfile.c_str(), ios::out | ios::app); 2540 csvFormat = (blfile.substr(0, 1) == "T"); 2541 ofs.open(blfile.substr(1).c_str(), ios::out | ios::app); 2538 2542 if (ofs) outTextFile = true; 2539 2543 } … … 2587 2591 setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow); 2588 2592 2589 outputFittingResult(outLogger, outTextFile, c hanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoPolyBaseline()", fitter);2593 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoPolyBaseline()", fitter); 2590 2594 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 2591 2595 } … … 2600 2604 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) 2601 2605 { 2602 /*************/ 2603 //clock_t totTimeStart, totTimeEnd, blTimeStart, blTimeEnd, ioTimeStart, ioTimeEnd; 2606 /************* 2604 2607 double totTimeStart, totTimeEnd, blTimeStart, blTimeEnd, ioTimeStart, ioTimeEnd, msTimeStart, msTimeEnd, seTimeStart, seTimeEnd, otTimeStart, otTimeEnd, prTimeStart, prTimeEnd; 2605 2608 double elapseMs = 0.0; … … 2609 2612 double elapseBl = 0.0; 2610 2613 double elapseIo = 0.0; 2611 //totTimeStart = clock();2612 2614 totTimeStart = mathutil::gettimeofday_sec(); 2613 /*************/2615 *************/ 2614 2616 2615 2617 try { … … 2618 2620 bool hasSameNchan = true; 2619 2621 bool outTextFile = false; 2622 bool csvFormat = false; 2620 2623 2621 2624 if (blfile != "") { 2622 ofs.open(blfile.c_str(), ios::out | ios::app); 2625 csvFormat = (blfile.substr(0, 1) == "T"); 2626 ofs.open(blfile.substr(1).c_str(), ios::out | ios::app); 2623 2627 if (ofs) outTextFile = true; 2624 2628 } … … 2643 2647 //-------------------------------- 2644 2648 for (int whichrow = 0; whichrow < nRow; ++whichrow) { 2645 /******************/ 2646 //ioTimeStart = clock(); 2649 /****************** 2647 2650 ioTimeStart = mathutil::gettimeofday_sec(); 2648 /**/2651 **/ 2649 2652 std::vector<float> sp = getSpectrum(whichrow); 2650 /**/ 2651 //ioTimeEnd = clock(); 2653 /** 2652 2654 ioTimeEnd = mathutil::gettimeofday_sec(); 2653 2655 elapseIo += (double)(ioTimeEnd - ioTimeStart); 2654 2655 //blTimeStart = clock();2656 2656 msTimeStart = mathutil::gettimeofday_sec(); 2657 /******************/2657 ******************/ 2658 2658 2659 2659 chanMask = getCompositeChanMask(whichrow, mask); 2660 2660 2661 /** /2661 /** 2662 2662 msTimeEnd = mathutil::gettimeofday_sec(); 2663 2663 elapseMs += (double)(msTimeEnd - msTimeStart); 2664 2664 blTimeStart = mathutil::gettimeofday_sec(); 2665 /**/2665 **/ 2666 2666 2667 2667 //fitBaseline(chanMask, whichrow, fitter); … … 2672 2672 std::vector<float> res = doCubicSplineFitting(sp, chanMask, nPiece, pieceEdges, params, nClipped, thresClip, nIterClip, getResidual); 2673 2673 2674 /** /2674 /** 2675 2675 blTimeEnd = mathutil::gettimeofday_sec(); 2676 2676 elapseBl += (double)(blTimeEnd - blTimeStart); 2677 2677 seTimeStart = mathutil::gettimeofday_sec(); 2678 /**/2678 **/ 2679 2679 2680 2680 … … 2682 2682 // 2683 2683 2684 /** /2684 /** 2685 2685 seTimeEnd = mathutil::gettimeofday_sec(); 2686 2686 elapseSe += (double)(seTimeEnd - seTimeStart); 2687 2687 otTimeStart = mathutil::gettimeofday_sec(); 2688 /**/2689 2690 outputFittingResult(outLogger, outTextFile, c hanMask, whichrow, coordInfo, hasSameNchan, ofs, "cubicSplineBaseline()", pieceEdges, params, nClipped);2691 2692 /** /2688 **/ 2689 2690 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "cubicSplineBaseline()", pieceEdges, params, nClipped); 2691 2692 /** 2693 2693 otTimeEnd = mathutil::gettimeofday_sec(); 2694 2694 elapseOt += (double)(otTimeEnd - otTimeStart); 2695 2695 prTimeStart = mathutil::gettimeofday_sec(); 2696 /**/2696 **/ 2697 2697 2698 2698 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 2699 2699 2700 /******************/ 2701 //blTimeEnd = clock(); 2700 /****************** 2702 2701 prTimeEnd = mathutil::gettimeofday_sec(); 2703 2702 elapsePr += (double)(prTimeEnd - prTimeStart); 2704 /******************/2703 ******************/ 2705 2704 } 2706 2705 //-------------------------------- … … 2711 2710 throw; 2712 2711 } 2713 /***************/ 2714 //totTimeEnd = clock(); 2712 /*************** 2715 2713 totTimeEnd = mathutil::gettimeofday_sec(); 2716 //std::cout << "io : " << elapseIo/CLOCKS_PER_SEC << " (sec.)" << endl;2717 //std::cout << "bl : " << elapseBl/CLOCKS_PER_SEC << " (sec.)" << endl;2718 //std::cout << "total : " << (double)(totTimeEnd - totTimeStart)/CLOCKS_PER_SEC << " (sec.)" << endl;2719 2714 std::cout << "io : " << elapseIo << " (sec.)" << endl; 2720 2715 std::cout << "ms : " << elapseMs << " (sec.)" << endl; … … 2724 2719 std::cout << "pr : " << elapsePr << " (sec.)" << endl; 2725 2720 std::cout << "total : " << (double)(totTimeEnd - totTimeStart) << " (sec.)" << endl; 2726 /***************/2721 ***************/ 2727 2722 } 2728 2723 2729 2724 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) 2730 2725 { 2731 /*************2732 clock_t totTimeStart, totTimeEnd, blTimeStart, blTimeEnd, ioTimeStart, ioTimeEnd;2733 double elapseBl = 0.0;2734 double elapseIo = 0.0;2735 totTimeStart = clock();2736 *************/2737 2738 2726 try { 2739 2727 ofstream ofs; … … 2741 2729 bool hasSameNchan = true; 2742 2730 bool outTextFile = false; 2731 bool csvFormat = false; 2743 2732 2744 2733 if (blfile != "") { 2745 ofs.open(blfile.c_str(), ios::out | ios::app); 2734 csvFormat = (blfile.substr(0, 1) == "T"); 2735 ofs.open(blfile.substr(1).c_str(), ios::out | ios::app); 2746 2736 if (ofs) outTextFile = true; 2747 2737 } … … 2768 2758 2769 2759 for (int whichrow = 0; whichrow < nRow; ++whichrow) { 2770 /******************2771 ioTimeStart = clock();2772 */2773 2760 std::vector<float> sp = getSpectrum(whichrow); 2774 /*2775 ioTimeEnd = clock();2776 elapseIo += (double)(ioTimeEnd - ioTimeStart);2777 2778 blTimeStart = clock();2779 ******************/2780 2761 2781 2762 //------------------------------------------------------- … … 2797 2778 throw(AipsError("Wrong length of edge element")); 2798 2779 } 2799 lineFinder.setData(getSpectrum(whichrow)); 2780 //lineFinder.setData(getSpectrum(whichrow)); 2781 lineFinder.setData(sp); 2800 2782 lineFinder.findLines(getCompositeChanMask(whichrow, mask), currentEdge, whichrow); 2801 2783 chanMask = lineFinder.getMask(); … … 2812 2794 // 2813 2795 2814 outputFittingResult(outLogger, outTextFile, c hanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoCubicSplineBaseline()", pieceEdges, params, nClipped);2796 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoCubicSplineBaseline()", pieceEdges, params, nClipped); 2815 2797 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 2816 2817 /******************2818 blTimeEnd = clock();2819 elapseBl += (double)(blTimeEnd - blTimeStart);2820 ******************/2821 2822 2798 } 2823 2799 … … 2827 2803 throw; 2828 2804 } 2829 2830 /***************2831 totTimeEnd = clock();2832 std::cout << "io : " << elapseIo/CLOCKS_PER_SEC << " (sec.)" << endl;2833 std::cout << "bl : " << elapseBl/CLOCKS_PER_SEC << " (sec.)" << endl;2834 std::cout << "total : " << (double)(totTimeEnd - totTimeStart)/CLOCKS_PER_SEC << " (sec.)" << endl;2835 ***************/2836 2805 } 2837 2806 … … 3268 3237 bool hasSameNchan = true; 3269 3238 bool outTextFile = false; 3239 bool csvFormat = false; 3270 3240 3271 3241 if (blfile != "") { 3272 ofs.open(blfile.c_str(), ios::out | ios::app); 3242 csvFormat = (blfile.substr(0, 1) == "T"); 3243 ofs.open(blfile.substr(1).c_str(), ios::out | ios::app); 3273 3244 if (ofs) outTextFile = true; 3274 3245 } … … 3320 3291 // 3321 3292 3322 outputFittingResult(outLogger, outTextFile, c hanMask, whichrow, coordInfo, hasSameNchan, ofs, "sinusoidBaseline()", params, nClipped);3293 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "sinusoidBaseline()", params, nClipped); 3323 3294 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 3324 3295 } … … 3338 3309 bool hasSameNchan = true; 3339 3310 bool outTextFile = false; 3311 bool csvFormat = false; 3340 3312 3341 3313 if (blfile != "") { 3342 ofs.open(blfile.c_str(), ios::out | ios::app); 3314 csvFormat = (blfile.substr(0, 1) == "T"); 3315 ofs.open(blfile.substr(1).c_str(), ios::out | ios::app); 3343 3316 if (ofs) outTextFile = true; 3344 3317 } … … 3401 3374 // 3402 3375 3403 outputFittingResult(outLogger, outTextFile, c hanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoSinusoidBaseline()", params, nClipped);3376 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoSinusoidBaseline()", params, nClipped); 3404 3377 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 3405 3378 } … … 3705 3678 3706 3679 /* for poly. the variations of outputFittingResult() should be merged into one eventually (2011/3/10 WK) */ 3707 void Scantable::outputFittingResult(bool outLogger, bool outTextFile, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, ofstream& ofs, const casa::String& funcName, Fitter& fitter)3680 void Scantable::outputFittingResult(bool outLogger, bool outTextFile, bool csvFormat, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, ofstream& ofs, const casa::String& funcName, Fitter& fitter) 3708 3681 { 3709 3682 if (outLogger || outTextFile) { … … 3715 3688 if (outLogger) { 3716 3689 LogIO ols(LogOrigin("Scantable", funcName, WHERE)); 3717 ols << formatBaselineParams(params, fixed, rms, -1, masklist, whichrow, false ) << LogIO::POST ;3690 ols << formatBaselineParams(params, fixed, rms, -1, masklist, whichrow, false, csvFormat) << LogIO::POST ; 3718 3691 } 3719 3692 if (outTextFile) { 3720 ofs << formatBaselineParams(params, fixed, rms, -1, masklist, whichrow, true ) << flush;3693 ofs << formatBaselineParams(params, fixed, rms, -1, masklist, whichrow, true, csvFormat) << flush; 3721 3694 } 3722 3695 } … … 3724 3697 3725 3698 /* for cspline. will be merged once cspline is available in fitter (2011/3/10 WK) */ 3726 void Scantable::outputFittingResult(bool outLogger, bool outTextFile, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, ofstream& ofs, const casa::String& funcName, const std::vector<int>& edge, const std::vector<float>& params, const int nClipped)3699 void Scantable::outputFittingResult(bool outLogger, bool outTextFile, bool csvFormat, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, ofstream& ofs, const casa::String& funcName, const std::vector<int>& edge, const std::vector<float>& params, const int nClipped) 3727 3700 { 3728 3701 if (outLogger || outTextFile) { … … 3750 3723 if (outLogger) { 3751 3724 LogIO ols(LogOrigin("Scantable", funcName, WHERE)); 3752 ols << formatPiecewiseBaselineParams(edge, params, fixed, rms, nClipped, masklist, whichrow, false ) << LogIO::POST ;3725 ols << formatPiecewiseBaselineParams(edge, params, fixed, rms, nClipped, masklist, whichrow, false, csvFormat) << LogIO::POST ; 3753 3726 } 3754 3727 if (outTextFile) { 3755 ofs << formatPiecewiseBaselineParams(edge, params, fixed, rms, nClipped, masklist, whichrow, true );//<< flush;3728 ofs << formatPiecewiseBaselineParams(edge, params, fixed, rms, nClipped, masklist, whichrow, true, csvFormat) << flush; 3756 3729 } 3757 3730 … … 3766 3739 3767 3740 /* for sinusoid. will be merged once sinusoid is available in fitter (2011/3/10 WK) */ 3768 void Scantable::outputFittingResult(bool outLogger, bool outTextFile, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, ofstream& ofs, const casa::String& funcName, const std::vector<float>& params, const int nClipped)3741 void Scantable::outputFittingResult(bool outLogger, bool outTextFile, bool csvFormat, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, ofstream& ofs, const casa::String& funcName, const std::vector<float>& params, const int nClipped) 3769 3742 { 3770 3743 if (outLogger || outTextFile) { … … 3776 3749 if (outLogger) { 3777 3750 LogIO ols(LogOrigin("Scantable", funcName, WHERE)); 3778 ols << formatBaselineParams(params, fixed, rms, nClipped, masklist, whichrow, false ) << LogIO::POST ;3751 ols << formatBaselineParams(params, fixed, rms, nClipped, masklist, whichrow, false, csvFormat) << LogIO::POST ; 3779 3752 } 3780 3753 if (outTextFile) { 3781 ofs << formatBaselineParams(params, fixed, rms, nClipped, masklist, whichrow, true ) << flush;3754 ofs << formatBaselineParams(params, fixed, rms, nClipped, masklist, whichrow, true, csvFormat) << flush; 3782 3755 } 3783 3756 } … … 3902 3875 3903 3876 3904 std::string Scantable::formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose) const 3905 { 3906 ostringstream oss; 3907 3877 std::string Scantable::formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose, bool csvformat) const 3878 { 3908 3879 if (verbose) { 3909 oss << " Scan[" << getScan(whichrow) << "]"; 3910 oss << " Beam[" << getBeam(whichrow) << "]"; 3911 oss << " IF[" << getIF(whichrow) << "]"; 3912 oss << " Pol[" << getPol(whichrow) << "]"; 3913 oss << " Cycle[" << getCycle(whichrow) << "]: " << endl; 3914 oss << "Fitter range = " << masklist << endl; 3915 oss << "Baseline parameters" << endl; 3880 ostringstream oss; 3881 3882 if (csvformat) { 3883 oss << getScan(whichrow) << ","; 3884 oss << getBeam(whichrow) << ","; 3885 oss << getIF(whichrow) << ","; 3886 oss << getPol(whichrow) << ","; 3887 oss << getCycle(whichrow) << ","; 3888 String commaReplacedMasklist = masklist; 3889 string::size_type pos = 0; 3890 while (pos = commaReplacedMasklist.find(","), pos != string::npos) { 3891 commaReplacedMasklist.replace(pos, 1, ";"); 3892 pos++; 3893 } 3894 oss << commaReplacedMasklist << ","; 3895 } else { 3896 oss << " Scan[" << getScan(whichrow) << "]"; 3897 oss << " Beam[" << getBeam(whichrow) << "]"; 3898 oss << " IF[" << getIF(whichrow) << "]"; 3899 oss << " Pol[" << getPol(whichrow) << "]"; 3900 oss << " Cycle[" << getCycle(whichrow) << "]: " << endl; 3901 oss << "Fitter range = " << masklist << endl; 3902 oss << "Baseline parameters" << endl; 3903 } 3916 3904 oss << flush; 3917 } 3918 3919 return String(oss);3920 } 3921 3922 std::string Scantable::formatBaselineParamsFooter(float rms, int nClipped, bool verbose) const 3923 { 3924 ostringstream oss; 3925 3905 3906 return String(oss); 3907 } 3908 3909 return ""; 3910 } 3911 3912 std::string Scantable::formatBaselineParamsFooter(float rms, int nClipped, bool verbose, bool csvformat) const 3913 { 3926 3914 if (verbose) { 3927 oss << "Results of baseline fit" << endl; 3928 oss << " rms = " << setprecision(6) << rms << endl; 3929 if (nClipped >= 0) { 3930 oss << " Number of clipped channels = " << nClipped << endl; 3931 } 3932 for (int i = 0; i < 60; ++i) { 3933 oss << "-"; 3915 ostringstream oss; 3916 3917 if (csvformat) { 3918 oss << rms << ","; 3919 if (nClipped >= 0) { 3920 oss << nClipped; 3921 } 3922 } else { 3923 oss << endl; 3924 oss << "Results of baseline fit" << endl; 3925 oss << " rms = " << setprecision(6) << rms << endl; 3926 if (nClipped >= 0) { 3927 oss << " Number of clipped channels = " << nClipped << endl; 3928 } 3929 for (int i = 0; i < 60; ++i) { 3930 oss << "-"; 3931 } 3934 3932 } 3935 3933 oss << endl; 3936 3934 oss << flush; 3937 } 3938 3939 return String(oss); 3935 3936 return String(oss); 3937 } 3938 3939 return ""; 3940 3940 } 3941 3941 … … 3947 3947 int whichrow, 3948 3948 bool verbose, 3949 bool csvformat, 3949 3950 int start, int count, 3950 3951 bool resetparamid) const … … 3957 3958 3958 3959 ostringstream oss; 3959 oss << formatBaselineParamsHeader(whichrow, masklist, verbose );3960 oss << formatBaselineParamsHeader(whichrow, masklist, verbose, csvformat); 3960 3961 3961 3962 if (start < 0) start = 0; … … 3970 3971 } 3971 3972 std::string sFix = ((fixed.size() > 0) && (fixed[i]) && verbose) ? "(fixed)" : ""; 3972 oss << " p" << (i+paramidoffset) << sFix << "= " << right << setw(13) << setprecision(6) << params[i]; 3973 } 3974 3975 oss << endl; 3976 oss << formatBaselineParamsFooter(rms, nClipped, verbose); 3973 if (csvformat) { 3974 oss << params[i] << sFix; 3975 } else { 3976 oss << " p" << (i+paramidoffset) << sFix << "= " << right << setw(13) << setprecision(6) << params[i]; 3977 } 3978 } 3979 3980 if (csvformat) { 3981 oss << ","; 3982 } 3983 oss << formatBaselineParamsFooter(rms, nClipped, verbose, csvformat); 3977 3984 3978 3985 return String(oss); … … 3981 3988 } 3982 3989 3983 std::string Scantable::formatPiecewiseBaselineParams(const std::vector<int>& ranges, const std::vector<float>& params, const std::vector<bool>& fixed, float rms, int nClipped, const std::string& masklist, int whichrow, bool verbose) const3990 std::string Scantable::formatPiecewiseBaselineParams(const std::vector<int>& ranges, const std::vector<float>& params, const std::vector<bool>& fixed, float rms, int nClipped, const std::string& masklist, int whichrow, bool verbose, bool csvformat) const 3984 3991 { 3985 3992 int nOutParam = (int)(params.size()); … … 3989 3996 return(" Not fitted"); 3990 3997 } else if (nPiece < 0) { 3991 return formatBaselineParams(params, fixed, rms, nClipped, masklist, whichrow, verbose );3998 return formatBaselineParams(params, fixed, rms, nClipped, masklist, whichrow, verbose, csvformat); 3992 3999 } else if (nPiece < 1) { 3993 4000 return(" Bad count of the piece edge info"); … … 3999 4006 4000 4007 ostringstream oss; 4001 oss << formatBaselineParamsHeader(whichrow, masklist, verbose); 4002 4003 stringstream ss; 4004 ss << ranges[nPiece] << flush; 4005 int wRange = ss.str().size() * 2 + 5; 4006 4007 for (int i = 0; i < nPiece; ++i) { 4008 ss.str(""); 4009 ss << " [" << ranges[i] << "," << (ranges[i+1]-1) << "]"; 4010 oss << left << setw(wRange) << ss.str(); 4011 oss << formatBaselineParams(params, fixed, rms, 0, masklist, whichrow, false, i*nParam, nParam, true); 4012 } 4013 4014 oss << formatBaselineParamsFooter(rms, nClipped, verbose); 4008 oss << formatBaselineParamsHeader(whichrow, masklist, verbose, csvformat); 4009 4010 if (csvformat) { 4011 for (int i = 0; i < nPiece; ++i) { 4012 oss << ranges[i] << "," << (ranges[i+1]-1) << ","; 4013 oss << formatBaselineParams(params, fixed, rms, 0, masklist, whichrow, false, csvformat, i*nParam, nParam, true); 4014 } 4015 } else { 4016 stringstream ss; 4017 ss << ranges[nPiece] << flush; 4018 int wRange = ss.str().size() * 2 + 5; 4019 4020 for (int i = 0; i < nPiece; ++i) { 4021 ss.str(""); 4022 ss << " [" << ranges[i] << "," << (ranges[i+1]-1) << "]"; 4023 oss << left << setw(wRange) << ss.str(); 4024 oss << formatBaselineParams(params, fixed, rms, 0, masklist, whichrow, false, csvformat, i*nParam, nParam, true); 4025 oss << endl; 4026 } 4027 } 4028 4029 oss << formatBaselineParamsFooter(rms, nClipped, verbose, csvformat); 4015 4030 4016 4031 return String(oss); -
trunk/src/Scantable.h
r2595 r2641 580 580 int whichrow, 581 581 bool verbose=false, 582 bool csvformat=false, 582 583 int start=-1, 583 584 int count=-1, … … 590 591 const std::string& masklist, 591 592 int whichrow, 592 bool verbose=false) const; 593 bool verbose=false, 594 bool csvformat=false) const; 593 595 std::vector<uint> getMoleculeIdColumnData() const; 594 596 void setMoleculeIdColumnData(const std::vector<uint>& molids); … … 757 759 bool verbose=false); 758 760 std::vector<int> getMaskEdgeIndices(const std::vector<bool>& mask); 759 std::string formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose ) const;760 std::string formatBaselineParamsFooter(float rms, int nClipped, bool verbose ) const;761 std::string formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose, bool csvformat) const; 762 std::string formatBaselineParamsFooter(float rms, int nClipped, bool verbose, bool csvformat) const; 761 763 std::vector<bool> getCompositeChanMask(int whichrow, const std::vector<bool>& inMask); 762 764 //std::vector<bool> getCompositeChanMask(int whichrow, const std::vector<bool>& inMask, const std::vector<int>& edge, const int minEdgeSize, STLineFinder& lineFinder); 763 void outputFittingResult(bool outLogger, bool outTextFile, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, std::ofstream& ofs, const casa::String& funcName, Fitter& fitter);764 void outputFittingResult(bool outLogger, bool outTextFile, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, std::ofstream& ofs, const casa::String& funcName, const std::vector<int>& edge, const std::vector<float>& params, const int nClipped);765 void outputFittingResult(bool outLogger, bool outTextFile, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, std::ofstream& ofs, const casa::String& funcName, const std::vector<float>& params, const int nClipped);765 void outputFittingResult(bool outLogger, bool outTextFile, bool csvFormat, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, std::ofstream& ofs, const casa::String& funcName, Fitter& fitter); 766 void outputFittingResult(bool outLogger, bool outTextFile, bool csvFormat, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, std::ofstream& ofs, const casa::String& funcName, const std::vector<int>& edge, const std::vector<float>& params, const int nClipped); 767 void outputFittingResult(bool outLogger, bool outTextFile, bool csvFormat, const std::vector<bool>& chanMask, int whichrow, const casa::String& coordInfo, bool hasSameNchan, std::ofstream& ofs, const casa::String& funcName, const std::vector<float>& params, const int nClipped); 766 768 void parseProgressInfo(const std::string& progressInfo, bool& showProgress, int& minNRow); 767 769 void showProgressOnTerminal(const int nProcessed, const int nTotal, const bool showProgress=true, const int nTotalThreshold=1000); -
trunk/src/ScantableWrapper.h
r2591 r2641 298 298 { return table_->getRms(mask, whichrow); } 299 299 300 std::string formatBaselineParams(const std::vector<float>& params, const std::vector<bool>& fixed, float rms, const std::string& masklist, int whichrow, bool verbose=false )301 { return table_->formatBaselineParams(params, fixed, rms, -1, masklist, whichrow, verbose ); }302 303 std::string formatPiecewiseBaselineParams(const std::vector<int>& ranges, const std::vector<float>& params, const std::vector<bool>& fixed, float rms, const std::string& masklist, int whichrow, bool verbose=false )304 { return table_->formatPiecewiseBaselineParams(ranges, params, fixed, rms, -1, masklist, whichrow, verbose ); }300 std::string formatBaselineParams(const std::vector<float>& params, const std::vector<bool>& fixed, float rms, const std::string& masklist, int whichrow, bool verbose=false, bool csvformat=false) 301 { return table_->formatBaselineParams(params, fixed, rms, -1, masklist, whichrow, verbose, csvformat); } 302 303 std::string formatPiecewiseBaselineParams(const std::vector<int>& ranges, const std::vector<float>& params, const std::vector<bool>& fixed, float rms, const std::string& masklist, int whichrow, bool verbose=false, bool csvformat=false) 304 { return table_->formatPiecewiseBaselineParams(ranges, params, fixed, rms, -1, masklist, whichrow, verbose, csvformat); } 305 305 306 306 bool getFlagtraFast(int whichrow=0) const
Note:
See TracChangeset
for help on using the changeset viewer.