Changeset 2640 for branches/hpc34/src


Ignore:
Timestamp:
08/10/12 20:18:03 (12 years ago)
Author:
WataruKawasaki
Message:

added a new parameter 'csvformat' to sd.scantable.*baseline() and the relevant functions in the C++ side. (2012/08/10 WK)

Location:
branches/hpc34/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/hpc34/src/Scantable.cpp

    r2575 r2640  
    23332333    bool hasSameNchan = true;
    23342334    bool outTextFile = false;
     2335    bool csvFormat = false;
    23352336
    23362337    if (blfile != "") {
    2337       ofs.open(blfile.c_str(), ios::out | ios::app);
     2338      csvFormat = (blfile.substr(0, 1) == "T");
     2339      ofs.open(blfile.substr(1).c_str(), ios::out | ios::app);
    23382340      if (ofs) outTextFile = true;
    23392341    }
     
    23592361      fitBaseline(chanMask, whichrow, fitter);
    23602362      setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow);
    2361       outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "polyBaseline()", fitter);
     2363      outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "polyBaseline()", fitter);
    23622364      showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    23632365    }
     
    23772379    bool hasSameNchan = true;
    23782380    bool outTextFile = false;
     2381    bool csvFormat = false;
    23792382
    23802383    if (blfile != "") {
    2381       ofs.open(blfile.c_str(), ios::out | ios::app);
     2384      csvFormat = (blfile.substr(0, 1) == "T");
     2385      ofs.open(blfile.substr(1).c_str(), ios::out | ios::app);
    23822386      if (ofs) outTextFile = true;
    23832387    }
     
    24312435      setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow);
    24322436
    2433       outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoPolyBaseline()", fitter);
     2437      outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoPolyBaseline()", fitter);
    24342438      showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    24352439    }
     
    24492453    bool hasSameNchan = true;
    24502454    bool outTextFile = false;
     2455    bool csvFormat = false;
    24512456
    24522457    if (blfile != "") {
    2453       ofs.open(blfile.c_str(), ios::out | ios::app);
     2458      csvFormat = (blfile.substr(0, 1) == "T");
     2459      ofs.open(blfile.substr(1).c_str(), ios::out | ios::app);
    24542460      if (ofs) outTextFile = true;
    24552461    }
     
    24842490      //
    24852491
    2486       outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "cubicSplineBaseline()", pieceEdges, params, nClipped);
     2492      outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "cubicSplineBaseline()", pieceEdges, params, nClipped);
    24872493      showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    24882494    }
     
    25032509    bool hasSameNchan = true;
    25042510    bool outTextFile = false;
     2511    bool csvFormat = false;
    25052512
    25062513    if (blfile != "") {
    2507       ofs.open(blfile.c_str(), ios::out | ios::app);
     2514      csvFormat = (blfile.substr(0, 1) == "T");
     2515      ofs.open(blfile.substr(1).c_str(), ios::out | ios::app);
    25082516      if (ofs) outTextFile = true;
    25092517    }
     
    25642572      //
    25652573
    2566       outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoCubicSplineBaseline()", pieceEdges, params, nClipped);
     2574      outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoCubicSplineBaseline()", pieceEdges, params, nClipped);
    25672575      showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    25682576    }
     
    30073015    bool hasSameNchan = true;
    30083016    bool outTextFile = false;
     3017    bool csvFormat = false;
    30093018
    30103019    if (blfile != "") {
    3011       ofs.open(blfile.c_str(), ios::out | ios::app);
     3020      csvFormat = (blfile.substr(0, 1) == "T");
     3021      ofs.open(blfile.substr(1).c_str(), ios::out | ios::app);
    30123022      if (ofs) outTextFile = true;
    30133023    }
     
    30593069      //
    30603070
    3061       outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "sinusoidBaseline()", params, nClipped);
     3071      outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "sinusoidBaseline()", params, nClipped);
    30623072      showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    30633073    }
     
    30773087    bool hasSameNchan = true;
    30783088    bool outTextFile = false;
     3089    bool csvFormat = false;
    30793090
    30803091    if (blfile != "") {
    3081       ofs.open(blfile.c_str(), ios::out | ios::app);
     3092      csvFormat = (blfile.substr(0, 1) == "T");
     3093      ofs.open(blfile.substr(1).c_str(), ios::out | ios::app);
    30823094      if (ofs) outTextFile = true;
    30833095    }
     
    31403152      //
    31413153
    3142       outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoSinusoidBaseline()", params, nClipped);
     3154      outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoSinusoidBaseline()", params, nClipped);
    31433155      showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    31443156    }
     
    34223434
    34233435/* for poly. the variations of outputFittingResult() should be merged into one eventually (2011/3/10 WK)  */
    3424 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)
     3436void 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)
    34253437{
    34263438  if (outLogger || outTextFile) {
     
    34323444    if (outLogger) {
    34333445      LogIO ols(LogOrigin("Scantable", funcName, WHERE));
    3434       ols << formatBaselineParams(params, fixed, rms, -1, masklist, whichrow, false) << LogIO::POST ;
     3446      ols << formatBaselineParams(params, fixed, rms, -1, masklist, whichrow, false, csvFormat) << LogIO::POST ;
    34353447    }
    34363448    if (outTextFile) {
    3437       ofs << formatBaselineParams(params, fixed, rms, -1, masklist, whichrow, true) << flush;
     3449      ofs << formatBaselineParams(params, fixed, rms, -1, masklist, whichrow, true, csvFormat) << flush;
    34383450    }
    34393451  }
     
    34413453
    34423454/* for cspline. will be merged once cspline is available in fitter (2011/3/10 WK) */
    3443 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)
     3455void 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)
    34443456{
    34453457  if (outLogger || outTextFile) {
     
    34513463    if (outLogger) {
    34523464      LogIO ols(LogOrigin("Scantable", funcName, WHERE));
    3453       ols << formatPiecewiseBaselineParams(edge, params, fixed, rms, nClipped, masklist, whichrow, false) << LogIO::POST ;
     3465      ols << formatPiecewiseBaselineParams(edge, params, fixed, rms, nClipped, masklist, whichrow, false, csvFormat) << LogIO::POST ;
    34543466    }
    34553467    if (outTextFile) {
    3456       ofs << formatPiecewiseBaselineParams(edge, params, fixed, rms, nClipped, masklist, whichrow, true) << flush;
     3468      ofs << formatPiecewiseBaselineParams(edge, params, fixed, rms, nClipped, masklist, whichrow, true, csvFormat) << flush;
    34573469    }
    34583470  }
     
    34603472
    34613473/* for sinusoid. will be merged once sinusoid is available in fitter (2011/3/10 WK) */
    3462 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)
     3474void 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)
    34633475{
    34643476  if (outLogger || outTextFile) {
     
    34703482    if (outLogger) {
    34713483      LogIO ols(LogOrigin("Scantable", funcName, WHERE));
    3472       ols << formatBaselineParams(params, fixed, rms, nClipped, masklist, whichrow, false) << LogIO::POST ;
     3484      ols << formatBaselineParams(params, fixed, rms, nClipped, masklist, whichrow, false, csvFormat) << LogIO::POST ;
    34733485    }
    34743486    if (outTextFile) {
    3475       ofs << formatBaselineParams(params, fixed, rms, nClipped, masklist, whichrow, true) << flush;
     3487      ofs << formatBaselineParams(params, fixed, rms, nClipped, masklist, whichrow, true, csvFormat) << flush;
    34763488    }
    34773489  }
     
    35743586
    35753587
    3576 std::string Scantable::formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose) const
    3577 {
    3578   ostringstream oss;
    3579 
     3588std::string Scantable::formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose, bool csvformat) const
     3589{
    35803590  if (verbose) {
    3581     oss <<  " Scan[" << getScan(whichrow)  << "]";
    3582     oss <<  " Beam[" << getBeam(whichrow)  << "]";
    3583     oss <<    " IF[" << getIF(whichrow)    << "]";
    3584     oss <<   " Pol[" << getPol(whichrow)   << "]";
    3585     oss << " Cycle[" << getCycle(whichrow) << "]: " << endl;
    3586     oss << "Fitter range = " << masklist << endl;
    3587     oss << "Baseline parameters" << endl;
     3591    ostringstream oss;
     3592
     3593    if (csvformat) {
     3594      oss << getScan(whichrow)  << ",";
     3595      oss << getBeam(whichrow)  << ",";
     3596      oss << getIF(whichrow)    << ",";
     3597      oss << getPol(whichrow)   << ",";
     3598      oss << getCycle(whichrow) << ",";
     3599      String commaReplacedMasklist = masklist;
     3600      string::size_type pos = 0;
     3601      while (pos = commaReplacedMasklist.find(","), pos != string::npos) {
     3602        commaReplacedMasklist.replace(pos, 1, ";");
     3603        pos++;
     3604      }
     3605      oss << commaReplacedMasklist << ",";
     3606    } else {
     3607      oss <<  " Scan[" << getScan(whichrow)  << "]";
     3608      oss <<  " Beam[" << getBeam(whichrow)  << "]";
     3609      oss <<    " IF[" << getIF(whichrow)    << "]";
     3610      oss <<   " Pol[" << getPol(whichrow)   << "]";
     3611      oss << " Cycle[" << getCycle(whichrow) << "]: " << endl;
     3612      oss << "Fitter range = " << masklist << endl;
     3613      oss << "Baseline parameters" << endl;
     3614    }
    35883615    oss << flush;
    3589   }
    3590 
    3591   return String(oss);
    3592 }
    3593 
    3594 std::string Scantable::formatBaselineParamsFooter(float rms, int nClipped, bool verbose) const
    3595 {
    3596   ostringstream oss;
    3597 
     3616
     3617    return String(oss);
     3618  }
     3619
     3620  return "";
     3621}
     3622
     3623std::string Scantable::formatBaselineParamsFooter(float rms, int nClipped, bool verbose, bool csvformat) const
     3624{
    35983625  if (verbose) {
    3599     oss << "Results of baseline fit" << endl;
    3600     oss << "  rms = " << setprecision(6) << rms << endl;
    3601     if (nClipped >= 0) {
    3602       oss << "  Number of clipped channels = " << nClipped << endl;
    3603     }
    3604     for (int i = 0; i < 60; ++i) {
    3605       oss << "-";
     3626    ostringstream oss;
     3627
     3628    if (csvformat) {
     3629      oss << rms << ",";
     3630      if (nClipped >= 0) {
     3631        oss << nClipped;
     3632      }
     3633    } else {
     3634      oss << endl;
     3635      oss << "Results of baseline fit" << endl;
     3636      oss << "  rms = " << setprecision(6) << rms << endl;
     3637      if (nClipped >= 0) {
     3638        oss << "  Number of clipped channels = " << nClipped << endl;
     3639      }
     3640      for (int i = 0; i < 60; ++i) {
     3641        oss << "-";
     3642      }
    36063643    }
    36073644    oss << endl;
    36083645    oss << flush;
    3609   }
    3610 
    3611   return String(oss);
     3646
     3647    return String(oss);
     3648  }
     3649
     3650  return "";
    36123651}
    36133652
     
    36193658                                            int whichrow,
    36203659                                            bool verbose,
     3660                                            bool csvformat,
    36213661                                            int start, int count,
    36223662                                            bool resetparamid) const
     
    36293669
    36303670    ostringstream oss;
    3631     oss << formatBaselineParamsHeader(whichrow, masklist, verbose);
     3671    oss << formatBaselineParamsHeader(whichrow, masklist, verbose, csvformat);
    36323672
    36333673    if (start < 0) start = 0;
     
    36423682      }
    36433683      std::string sFix = ((fixed.size() > 0) && (fixed[i]) && verbose) ? "(fixed)" : "";
    3644       oss << "  p" << (i+paramidoffset) << sFix << "= " << right << setw(13) << setprecision(6) << params[i];
    3645     }
    3646 
    3647     oss << endl;
    3648     oss << formatBaselineParamsFooter(rms, nClipped, verbose);
     3684      if (csvformat) {
     3685        oss << params[i] << sFix;
     3686      } else {
     3687        oss << "  p" << (i+paramidoffset) << sFix << "= " << right << setw(13) << setprecision(6) << params[i];
     3688      }
     3689    }
     3690
     3691    if (csvformat) {
     3692      oss << ",";
     3693    }
     3694    oss << formatBaselineParamsFooter(rms, nClipped, verbose, csvformat);
    36493695
    36503696    return String(oss);
     
    36533699}
    36543700
    3655   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
     3701std::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
    36563702{
    36573703  int nOutParam = (int)(params.size());
     
    36613707    return("  Not fitted");
    36623708  } else if (nPiece < 0) {
    3663     return formatBaselineParams(params, fixed, rms, nClipped, masklist, whichrow, verbose);
     3709    return formatBaselineParams(params, fixed, rms, nClipped, masklist, whichrow, verbose, csvformat);
    36643710  } else if (nPiece < 1) {
    36653711    return("  Bad count of the piece edge info");
     
    36713717
    36723718    ostringstream oss;
    3673     oss << formatBaselineParamsHeader(whichrow, masklist, verbose);
    3674 
    3675     stringstream ss;
    3676     ss << ranges[nPiece] << flush;
    3677     int wRange = ss.str().size() * 2 + 5;
    3678 
    3679     for (int i = 0; i < nPiece; ++i) {
    3680       ss.str("");
    3681       ss << "  [" << ranges[i] << "," << (ranges[i+1]-1) << "]";
    3682       oss << left << setw(wRange) << ss.str();
    3683       oss << formatBaselineParams(params, fixed, rms, 0, masklist, whichrow, false, i*nParam, nParam, true);
    3684     }
    3685 
    3686     oss << formatBaselineParamsFooter(rms, nClipped, verbose);
     3719    oss << formatBaselineParamsHeader(whichrow, masklist, verbose, csvformat);
     3720
     3721    if (csvformat) {
     3722      for (int i = 0; i < nPiece; ++i) {
     3723        oss << ranges[i] << "," << (ranges[i+1]-1) << ",";
     3724        oss << formatBaselineParams(params, fixed, rms, 0, masklist, whichrow, false, csvformat, i*nParam, nParam, true);
     3725      }
     3726    } else {
     3727      stringstream ss;
     3728      ss << ranges[nPiece] << flush;
     3729      int wRange = ss.str().size() * 2 + 5;
     3730
     3731      for (int i = 0; i < nPiece; ++i) {
     3732        ss.str("");
     3733        ss << "  [" << ranges[i] << "," << (ranges[i+1]-1) << "]";
     3734        oss << left << setw(wRange) << ss.str();
     3735        oss << formatBaselineParams(params, fixed, rms, 0, masklist, whichrow, false, csvformat, i*nParam, nParam, true);
     3736        oss << endl;
     3737      }
     3738    }
     3739
     3740    oss << formatBaselineParamsFooter(rms, nClipped, verbose, csvformat);
    36873741
    36883742    return String(oss);
  • branches/hpc34/src/Scantable.h

    r2435 r2640  
    579579                                   int whichrow,
    580580                                   bool verbose=false,
     581                                   bool csvformat=false,
    581582                                   int start=-1,
    582583                                   int count=-1,
     
    589590                                            const std::string& masklist,
    590591                                            int whichrow,
    591                                             bool verbose=false) const;
     592                                            bool verbose=false,
     593                                            bool csvformat=false) const;
    592594
    593595
     
    754756                                bool verbose=false);
    755757  std::vector<int> getMaskEdgeIndices(const std::vector<bool>& mask);
    756   std::string formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose) const;
    757   std::string formatBaselineParamsFooter(float rms, int nClipped, bool verbose) const;
     758  std::string formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose, bool csvformat) const;
     759  std::string formatBaselineParamsFooter(float rms, int nClipped, bool verbose, bool csvformat) const;
    758760  std::vector<bool> getCompositeChanMask(int whichrow, const std::vector<bool>& inMask);
    759761  //std::vector<bool> getCompositeChanMask(int whichrow, const std::vector<bool>& inMask, const std::vector<int>& edge, const int minEdgeSize, STLineFinder& lineFinder);
    760   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);
    761   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);
    762   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);
     762  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);
     763  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);
     764  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);
    763765  void parseProgressInfo(const std::string& progressInfo, bool& showProgress, int& minNRow);
    764766  void showProgressOnTerminal(const int nProcessed, const int nTotal, const bool showProgress=true, const int nTotalThreshold=1000);
  • branches/hpc34/src/ScantableWrapper.h

    r2435 r2640  
    292292  { return table_->getRms(mask, whichrow); }
    293293
    294   std::string formatBaselineParams(const std::vector<float>& params, const std::vector<bool>& fixed, float rms, const std::string& masklist, int whichrow, bool verbose=false)
    295   { return table_->formatBaselineParams(params, fixed, rms, -1, masklist, whichrow, verbose); }
    296 
    297   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)
    298   { return table_->formatPiecewiseBaselineParams(ranges, params, fixed, rms, -1, masklist, whichrow, verbose); }
     294  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)
     295    { return table_->formatBaselineParams(params, fixed, rms, -1, masklist, whichrow, verbose, csvformat); }
     296
     297  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)
     298  { return table_->formatPiecewiseBaselineParams(ranges, params, fixed, rms, -1, masklist, whichrow, verbose, csvformat); }
    299299
    300300  bool getFlagtraFast(int whichrow=0) const
Note: See TracChangeset for help on using the changeset viewer.