Changeset 2641


Ignore:
Timestamp:
08/10/12 20:49:54 (12 years ago)
Author:
WataruKawasaki
Message:

New Development: No

JIRA Issue: No

Ready for Test: Yes

Interface Changes: Yes

What Interface Changed: parameter of tool functions

Test Programs:

Put in Release Notes: No

Module(s): sd.scantable

Description: added a new parameter csvformat.


Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/python/scantable.py

    r2611 r2641  
    25242524                          clipniter=None, plot=None,
    25252525                          getresidual=None, showprogress=None,
    2526                           minnrow=None, outlog=None, blfile=None):
     2526                          minnrow=None, outlog=None, blfile=None, csvformat=None):
    25272527        """\
    25282528        Return a scan which has been baselined (all rows) with sinusoidal
     
    25822582                           parameter values to be written
    25832583                           (default is '': no file/logger output)
     2584            csvformat:     if True blfile is csv-formatted, default is False.
    25842585
    25852586        Example:
     
    26182619            if outlog        is None: outlog        = False
    26192620            if blfile        is None: blfile        = ''
     2621            if csvformat     is None: csvformat     = False
     2622
     2623            if csvformat:
     2624                scsvformat = "T"
     2625            else:
     2626                scsvformat = "F"
    26202627
    26212628            #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method.
     
    26262633                                        clipniter, getresidual,
    26272634                                        pack_progress_params(showprogress,
    2628                                                              minnrow), outlog,
    2629                                         blfile)
     2635                                                             minnrow),
     2636                                        outlog, scsvformat+blfile)
    26302637            workscan._add_history('sinusoid_baseline', varlist)
    26312638           
     
    26462653                               chan_avg_limit=None, plot=None,
    26472654                               getresidual=None, showprogress=None,
    2648                                minnrow=None, outlog=None, blfile=None):
     2655                               minnrow=None, outlog=None, blfile=None, csvformat=None):
    26492656        """\
    26502657        Return a scan which has been baselined (all rows) with sinusoidal
     
    27262733                            parameter values to be written
    27272734                            (default is "": no file/logger output)
     2735            csvformat:      if True blfile is csv-formatted, default is False.
    27282736
    27292737        Example:
     
    27622770            if outlog         is None: outlog         = False
    27632771            if blfile         is None: blfile         = ''
     2772            if csvformat      is None: csvformat      = False
     2773
     2774            if csvformat:
     2775                scsvformat = "T"
     2776            else:
     2777                scsvformat = "F"
    27642778
    27652779            #CURRENTLY, PLOT=true is UNAVAILABLE UNTIL sinusoidal fitting is implemented as a fitter method.
     
    27752789                                             pack_progress_params(showprogress,
    27762790                                                                  minnrow),
    2777                                              outlog, blfile)
     2791                                             outlog, scsvformat+blfile)
    27782792            workscan._add_history("auto_sinusoid_baseline", varlist)
    27792793           
     
    27902804                         clipthresh=None, clipniter=None, plot=None,
    27912805                         getresidual=None, showprogress=None, minnrow=None,
    2792                          outlog=None, blfile=None):
     2806                         outlog=None, blfile=None, csvformat=None):
    27932807        """\
    27942808        Return a scan which has been baselined (all rows) by cubic spline
     
    28192833                          parameter values to be written
    28202834                          (default is "": no file/logger output)
     2835            csvformat:    if True blfile is csv-formatted, default is False.
    28212836
    28222837        Example:
     
    28512866            if outlog       is None: outlog       = False
    28522867            if blfile       is None: blfile       = ''
     2868            if csvformat     is None: csvformat     = False
     2869
     2870            if csvformat:
     2871                scsvformat = "T"
     2872            else:
     2873                scsvformat = "F"
    28532874
    28542875            #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method.
     
    28562877                                       getresidual,
    28572878                                       pack_progress_params(showprogress,
    2858                                                             minnrow), outlog,
    2859                                        blfile)
     2879                                                            minnrow),
     2880                                       outlog, scsvformat+blfile)
    28602881            workscan._add_history("cspline_baseline", varlist)
    28612882           
     
    28742895                              getresidual=None, plot=None,
    28752896                              showprogress=None, minnrow=None, outlog=None,
    2876                               blfile=None):
     2897                              blfile=None, csvformat=None):
    28772898        """\
    28782899        Return a scan which has been baselined (all rows) by cubic spline
     
    29252946                            parameter values to be written
    29262947                            (default is "": no file/logger output)
     2948            csvformat:      if True blfile is csv-formatted, default is False.
    29272949
    29282950        Example:
     
    29572979            if outlog         is None: outlog         = False
    29582980            if blfile         is None: blfile         = ''
     2981            if csvformat      is None: csvformat      = False
     2982
     2983            if csvformat:
     2984                scsvformat = "T"
     2985            else:
     2986                scsvformat = "F"
    29592987
    29602988            #CURRENTLY, PLOT=true UNAVAILABLE UNTIL cubic spline fitting is implemented as a fitter method.
     
    29662994                                            pack_progress_params(showprogress,
    29672995                                                                 minnrow),
    2968                                             outlog, blfile)
     2996                                            outlog, scsvformat+blfile)
    29692997            workscan._add_history("auto_cspline_baseline", varlist)
    29702998           
     
    29803008    def poly_baseline(self, mask=None, order=None, insitu=None, plot=None,
    29813009                      getresidual=None, showprogress=None, minnrow=None,
    2982                       outlog=None, blfile=None):
     3010                      outlog=None, blfile=None, csvformat=None):
    29833011        """\
    29843012        Return a scan which has been baselined (all rows) by a polynomial.
     
    30033031                          parameter values to be written
    30043032                          (default is "": no file/logger output)
     3033            csvformat:    if True blfile is csv-formatted, default is False.
    30053034
    30063035        Example:
     
    30303059            if outlog       is None: outlog       = False
    30313060            if blfile       is None: blfile       = ""
     3061            if csvformat    is None: csvformat    = False
     3062
     3063            if csvformat:
     3064                scsvformat = "T"
     3065            else:
     3066                scsvformat = "F"
    30323067
    30333068            if plot:
     
    30843119                                                         blpars["fixed"],
    30853120                                                         rms, str(masklist),
    3086                                                          r, True)
     3121                                                         r, True, csvformat)
    30873122                        blf.write(dataout)
    30883123
     
    30963131                                        pack_progress_params(showprogress,
    30973132                                                             minnrow),
    3098                                         outlog, blfile)
     3133                                        outlog, scsvformat+blfile)
    30993134           
    31003135            workscan._add_history("poly_baseline", varlist)
     
    31133148                           plot=None, insitu=None,
    31143149                           getresidual=None, showprogress=None,
    3115                            minnrow=None, outlog=None, blfile=None):
     3150                           minnrow=None, outlog=None, blfile=None, csvformat=None):
    31163151        """\
    31173152        Return a scan which has been baselined (all rows) by a polynomial.
     
    31593194                            parameter values to be written
    31603195                            (default is "": no file/logger output)
     3196            csvformat:      if True blfile is csv-formatted, default is False.
    31613197
    31623198        Example:
     
    31863222            if outlog         is None: outlog         = False
    31873223            if blfile         is None: blfile         = ''
     3224            if csvformat      is None: csvformat      = False
     3225
     3226            if csvformat:
     3227                scsvformat = "T"
     3228            else:
     3229                scsvformat = "F"
    31883230
    31893231            edge = normalise_edge_param(edge)
     
    32473289                                                         blpars["fixed"],
    32483290                                                         rms, str(masklist),
    3249                                                          r, True)
     3291                                                         r, True, csvformat)
    32503292                        blf.write(dataout)
    32513293                   
     
    32593301                                             pack_progress_params(showprogress,
    32603302                                                                  minnrow),
    3261                                              outlog, blfile)
     3303                                             outlog, scsvformat+blfile)
    32623304
    32633305            workscan._add_history("auto_poly_baseline", varlist)
  • trunk/src/Scantable.cpp

    r2595 r2641  
    24892489    bool hasSameNchan = true;
    24902490    bool outTextFile = false;
     2491    bool csvFormat = false;
    24912492
    24922493    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);
    24942496      if (ofs) outTextFile = true;
    24952497    }
     
    25152517      fitBaseline(chanMask, whichrow, fitter);
    25162518      setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow);
    2517       outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "polyBaseline()", fitter);
     2519      outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "polyBaseline()", fitter);
    25182520      showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    25192521    }
     
    25332535    bool hasSameNchan = true;
    25342536    bool outTextFile = false;
     2537    bool csvFormat = false;
    25352538
    25362539    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);
    25382542      if (ofs) outTextFile = true;
    25392543    }
     
    25872591      setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow);
    25882592
    2589       outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoPolyBaseline()", fitter);
     2593      outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoPolyBaseline()", fitter);
    25902594      showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    25912595    }
     
    26002604void 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)
    26012605{
    2602   /*************/
    2603   //clock_t totTimeStart, totTimeEnd, blTimeStart, blTimeEnd, ioTimeStart, ioTimeEnd;
     2606  /*************
    26042607  double totTimeStart, totTimeEnd, blTimeStart, blTimeEnd, ioTimeStart, ioTimeEnd, msTimeStart, msTimeEnd, seTimeStart, seTimeEnd, otTimeStart, otTimeEnd, prTimeStart, prTimeEnd;
    26052608  double elapseMs = 0.0;
     
    26092612  double elapseBl = 0.0;
    26102613  double elapseIo = 0.0;
    2611   //totTimeStart = clock();
    26122614  totTimeStart = mathutil::gettimeofday_sec();
    2613   /*************/
     2615  *************/
    26142616
    26152617  try {
     
    26182620    bool hasSameNchan = true;
    26192621    bool outTextFile = false;
     2622    bool csvFormat = false;
    26202623
    26212624    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);
    26232627      if (ofs) outTextFile = true;
    26242628    }
     
    26432647    //--------------------------------
    26442648    for (int whichrow = 0; whichrow < nRow; ++whichrow) {
    2645       /******************/
    2646       //ioTimeStart = clock();
     2649      /******************
    26472650      ioTimeStart = mathutil::gettimeofday_sec();
    2648       /**/
     2651      **/
    26492652      std::vector<float> sp = getSpectrum(whichrow);
    2650       /**/
    2651       //ioTimeEnd = clock();
     2653      /**
    26522654      ioTimeEnd = mathutil::gettimeofday_sec();
    26532655      elapseIo += (double)(ioTimeEnd - ioTimeStart);
    2654 
    2655       //blTimeStart = clock();
    26562656      msTimeStart = mathutil::gettimeofday_sec();
    2657       /******************/
     2657      ******************/
    26582658
    26592659      chanMask = getCompositeChanMask(whichrow, mask);
    26602660
    2661       /**/
     2661      /**
    26622662      msTimeEnd = mathutil::gettimeofday_sec();
    26632663      elapseMs += (double)(msTimeEnd - msTimeStart);
    26642664      blTimeStart = mathutil::gettimeofday_sec();
    2665       /**/
     2665      **/
    26662666
    26672667      //fitBaseline(chanMask, whichrow, fitter);
     
    26722672      std::vector<float> res = doCubicSplineFitting(sp, chanMask, nPiece, pieceEdges, params, nClipped, thresClip, nIterClip, getResidual);
    26732673
    2674       /**/
     2674      /**
    26752675      blTimeEnd = mathutil::gettimeofday_sec();
    26762676      elapseBl += (double)(blTimeEnd - blTimeStart);
    26772677      seTimeStart = mathutil::gettimeofday_sec();
    2678       /**/
     2678      **/
    26792679
    26802680
     
    26822682      //
    26832683
    2684       /**/
     2684      /**
    26852685      seTimeEnd = mathutil::gettimeofday_sec();
    26862686      elapseSe += (double)(seTimeEnd - seTimeStart);
    26872687      otTimeStart = mathutil::gettimeofday_sec();
    2688       /**/
    2689 
    2690       outputFittingResult(outLogger, outTextFile, chanMask, 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      /**
    26932693      otTimeEnd = mathutil::gettimeofday_sec();
    26942694      elapseOt += (double)(otTimeEnd - otTimeStart);
    26952695      prTimeStart = mathutil::gettimeofday_sec();
    2696       /**/
     2696      **/
    26972697
    26982698      showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    26992699
    2700       /******************/
    2701       //blTimeEnd = clock();
     2700      /******************
    27022701      prTimeEnd = mathutil::gettimeofday_sec();
    27032702      elapsePr += (double)(prTimeEnd - prTimeStart);
    2704       /******************/
     2703      ******************/
    27052704    }
    27062705    //--------------------------------
     
    27112710    throw;
    27122711  }
    2713   /***************/
    2714   //totTimeEnd = clock();
     2712  /***************
    27152713  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;
    27192714  std::cout << "io    : " << elapseIo << " (sec.)" << endl;
    27202715  std::cout << "ms    : " << elapseMs << " (sec.)" << endl;
     
    27242719  std::cout << "pr    : " << elapsePr << " (sec.)" << endl;
    27252720  std::cout << "total : " << (double)(totTimeEnd - totTimeStart) << " (sec.)" << endl;
    2726   /***************/
     2721  ***************/
    27272722}
    27282723
    27292724void 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)
    27302725{
    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 
    27382726  try {
    27392727    ofstream ofs;
     
    27412729    bool hasSameNchan = true;
    27422730    bool outTextFile = false;
     2731    bool csvFormat = false;
    27432732
    27442733    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);
    27462736      if (ofs) outTextFile = true;
    27472737    }
     
    27682758
    27692759    for (int whichrow = 0; whichrow < nRow; ++whichrow) {
    2770       /******************
    2771       ioTimeStart = clock();
    2772       */
    27732760      std::vector<float> sp = getSpectrum(whichrow);
    2774       /*
    2775       ioTimeEnd = clock();
    2776       elapseIo += (double)(ioTimeEnd - ioTimeStart);
    2777 
    2778       blTimeStart = clock();
    2779       ******************/
    27802761
    27812762      //-------------------------------------------------------
     
    27972778        throw(AipsError("Wrong length of edge element"));
    27982779      }
    2799       lineFinder.setData(getSpectrum(whichrow));
     2780      //lineFinder.setData(getSpectrum(whichrow));
     2781      lineFinder.setData(sp);
    28002782      lineFinder.findLines(getCompositeChanMask(whichrow, mask), currentEdge, whichrow);
    28012783      chanMask = lineFinder.getMask();
     
    28122794      //
    28132795
    2814       outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoCubicSplineBaseline()", pieceEdges, params, nClipped);
     2796      outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoCubicSplineBaseline()", pieceEdges, params, nClipped);
    28152797      showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    2816 
    2817       /******************
    2818       blTimeEnd = clock();
    2819       elapseBl += (double)(blTimeEnd - blTimeStart);
    2820       ******************/
    2821 
    28222798    }
    28232799
     
    28272803    throw;
    28282804  }
    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   ***************/
    28362805}
    28372806
     
    32683237    bool hasSameNchan = true;
    32693238    bool outTextFile = false;
     3239    bool csvFormat = false;
    32703240
    32713241    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);
    32733244      if (ofs) outTextFile = true;
    32743245    }
     
    33203291      //
    33213292
    3322       outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "sinusoidBaseline()", params, nClipped);
     3293      outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "sinusoidBaseline()", params, nClipped);
    33233294      showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    33243295    }
     
    33383309    bool hasSameNchan = true;
    33393310    bool outTextFile = false;
     3311    bool csvFormat = false;
    33403312
    33413313    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);
    33433316      if (ofs) outTextFile = true;
    33443317    }
     
    34013374      //
    34023375
    3403       outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoSinusoidBaseline()", params, nClipped);
     3376      outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoSinusoidBaseline()", params, nClipped);
    34043377      showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    34053378    }
     
    37053678
    37063679/* 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)
     3680void 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)
    37083681{
    37093682  if (outLogger || outTextFile) {
     
    37153688    if (outLogger) {
    37163689      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 ;
    37183691    }
    37193692    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;
    37213694    }
    37223695  }
     
    37243697
    37253698/* 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)
     3699void 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)
    37273700{
    37283701  if (outLogger || outTextFile) {
     
    37503723    if (outLogger) {
    37513724      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 ;
    37533726    }
    37543727    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;
    37563729    }
    37573730
     
    37663739
    37673740/* 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)
     3741void 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)
    37693742{
    37703743  if (outLogger || outTextFile) {
     
    37763749    if (outLogger) {
    37773750      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 ;
    37793752    }
    37803753    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;
    37823755    }
    37833756  }
     
    39023875
    39033876
    3904 std::string Scantable::formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose) const
    3905 {
    3906   ostringstream oss;
    3907 
     3877std::string Scantable::formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose, bool csvformat) const
     3878{
    39083879  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    }
    39163904    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
     3912std::string Scantable::formatBaselineParamsFooter(float rms, int nClipped, bool verbose, bool csvformat) const
     3913{
    39263914  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      }
    39343932    }
    39353933    oss << endl;
    39363934    oss << flush;
    3937   }
    3938 
    3939   return String(oss);
     3935
     3936    return String(oss);
     3937  }
     3938
     3939  return "";
    39403940}
    39413941
     
    39473947                                            int whichrow,
    39483948                                            bool verbose,
     3949                                            bool csvformat,
    39493950                                            int start, int count,
    39503951                                            bool resetparamid) const
     
    39573958
    39583959    ostringstream oss;
    3959     oss << formatBaselineParamsHeader(whichrow, masklist, verbose);
     3960    oss << formatBaselineParamsHeader(whichrow, masklist, verbose, csvformat);
    39603961
    39613962    if (start < 0) start = 0;
     
    39703971      }
    39713972      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);
    39773984
    39783985    return String(oss);
     
    39813988}
    39823989
    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) const
     3990std::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
    39843991{
    39853992  int nOutParam = (int)(params.size());
     
    39893996    return("  Not fitted");
    39903997  } 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);
    39923999  } else if (nPiece < 1) {
    39934000    return("  Bad count of the piece edge info");
     
    39994006
    40004007    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);
    40154030
    40164031    return String(oss);
  • trunk/src/Scantable.h

    r2595 r2641  
    580580                                   int whichrow,
    581581                                   bool verbose=false,
     582                                   bool csvformat=false,
    582583                                   int start=-1,
    583584                                   int count=-1,
     
    590591                                            const std::string& masklist,
    591592                                            int whichrow,
    592                                             bool verbose=false) const;
     593                                            bool verbose=false,
     594                                            bool csvformat=false) const;
    593595  std::vector<uint> getMoleculeIdColumnData() const;
    594596  void setMoleculeIdColumnData(const std::vector<uint>& molids);
     
    757759                                bool verbose=false);
    758760  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;
    761763  std::vector<bool> getCompositeChanMask(int whichrow, const std::vector<bool>& inMask);
    762764  //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);
    766768  void parseProgressInfo(const std::string& progressInfo, bool& showProgress, int& minNRow);
    767769  void showProgressOnTerminal(const int nProcessed, const int nTotal, const bool showProgress=true, const int nTotalThreshold=1000);
  • trunk/src/ScantableWrapper.h

    r2591 r2641  
    298298  { return table_->getRms(mask, whichrow); }
    299299
    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); }
    305305
    306306  bool getFlagtraFast(int whichrow=0) const
Note: See TracChangeset for help on using the changeset viewer.