Changeset 2640 for branches/hpc34/src
- Timestamp:
- 08/10/12 20:18:03 (12 years ago)
- Location:
- branches/hpc34/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/hpc34/src/Scantable.cpp
r2575 r2640 2333 2333 bool hasSameNchan = true; 2334 2334 bool outTextFile = false; 2335 bool csvFormat = false; 2335 2336 2336 2337 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); 2338 2340 if (ofs) outTextFile = true; 2339 2341 } … … 2359 2361 fitBaseline(chanMask, whichrow, fitter); 2360 2362 setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow); 2361 outputFittingResult(outLogger, outTextFile, c hanMask, whichrow, coordInfo, hasSameNchan, ofs, "polyBaseline()", fitter);2363 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "polyBaseline()", fitter); 2362 2364 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 2363 2365 } … … 2377 2379 bool hasSameNchan = true; 2378 2380 bool outTextFile = false; 2381 bool csvFormat = false; 2379 2382 2380 2383 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); 2382 2386 if (ofs) outTextFile = true; 2383 2387 } … … 2431 2435 setSpectrum((getResidual ? fitter.getResidual() : fitter.getFit()), whichrow); 2432 2436 2433 outputFittingResult(outLogger, outTextFile, c hanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoPolyBaseline()", fitter);2437 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoPolyBaseline()", fitter); 2434 2438 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 2435 2439 } … … 2449 2453 bool hasSameNchan = true; 2450 2454 bool outTextFile = false; 2455 bool csvFormat = false; 2451 2456 2452 2457 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); 2454 2460 if (ofs) outTextFile = true; 2455 2461 } … … 2484 2490 // 2485 2491 2486 outputFittingResult(outLogger, outTextFile, c hanMask, whichrow, coordInfo, hasSameNchan, ofs, "cubicSplineBaseline()", pieceEdges, params, nClipped);2492 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "cubicSplineBaseline()", pieceEdges, params, nClipped); 2487 2493 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 2488 2494 } … … 2503 2509 bool hasSameNchan = true; 2504 2510 bool outTextFile = false; 2511 bool csvFormat = false; 2505 2512 2506 2513 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); 2508 2516 if (ofs) outTextFile = true; 2509 2517 } … … 2564 2572 // 2565 2573 2566 outputFittingResult(outLogger, outTextFile, c hanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoCubicSplineBaseline()", pieceEdges, params, nClipped);2574 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoCubicSplineBaseline()", pieceEdges, params, nClipped); 2567 2575 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 2568 2576 } … … 3007 3015 bool hasSameNchan = true; 3008 3016 bool outTextFile = false; 3017 bool csvFormat = false; 3009 3018 3010 3019 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); 3012 3022 if (ofs) outTextFile = true; 3013 3023 } … … 3059 3069 // 3060 3070 3061 outputFittingResult(outLogger, outTextFile, c hanMask, whichrow, coordInfo, hasSameNchan, ofs, "sinusoidBaseline()", params, nClipped);3071 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "sinusoidBaseline()", params, nClipped); 3062 3072 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 3063 3073 } … … 3077 3087 bool hasSameNchan = true; 3078 3088 bool outTextFile = false; 3089 bool csvFormat = false; 3079 3090 3080 3091 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); 3082 3094 if (ofs) outTextFile = true; 3083 3095 } … … 3140 3152 // 3141 3153 3142 outputFittingResult(outLogger, outTextFile, c hanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoSinusoidBaseline()", params, nClipped);3154 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoSinusoidBaseline()", params, nClipped); 3143 3155 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 3144 3156 } … … 3422 3434 3423 3435 /* 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)3436 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) 3425 3437 { 3426 3438 if (outLogger || outTextFile) { … … 3432 3444 if (outLogger) { 3433 3445 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 ; 3435 3447 } 3436 3448 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; 3438 3450 } 3439 3451 } … … 3441 3453 3442 3454 /* 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)3455 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) 3444 3456 { 3445 3457 if (outLogger || outTextFile) { … … 3451 3463 if (outLogger) { 3452 3464 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 ; 3454 3466 } 3455 3467 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; 3457 3469 } 3458 3470 } … … 3460 3472 3461 3473 /* 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)3474 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) 3463 3475 { 3464 3476 if (outLogger || outTextFile) { … … 3470 3482 if (outLogger) { 3471 3483 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 ; 3473 3485 } 3474 3486 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; 3476 3488 } 3477 3489 } … … 3574 3586 3575 3587 3576 std::string Scantable::formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose) const 3577 { 3578 ostringstream oss; 3579 3588 std::string Scantable::formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose, bool csvformat) const 3589 { 3580 3590 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 } 3588 3615 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 3623 std::string Scantable::formatBaselineParamsFooter(float rms, int nClipped, bool verbose, bool csvformat) const 3624 { 3598 3625 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 } 3606 3643 } 3607 3644 oss << endl; 3608 3645 oss << flush; 3609 } 3610 3611 return String(oss); 3646 3647 return String(oss); 3648 } 3649 3650 return ""; 3612 3651 } 3613 3652 … … 3619 3658 int whichrow, 3620 3659 bool verbose, 3660 bool csvformat, 3621 3661 int start, int count, 3622 3662 bool resetparamid) const … … 3629 3669 3630 3670 ostringstream oss; 3631 oss << formatBaselineParamsHeader(whichrow, masklist, verbose );3671 oss << formatBaselineParamsHeader(whichrow, masklist, verbose, csvformat); 3632 3672 3633 3673 if (start < 0) start = 0; … … 3642 3682 } 3643 3683 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); 3649 3695 3650 3696 return String(oss); … … 3653 3699 } 3654 3700 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) const3701 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 3656 3702 { 3657 3703 int nOutParam = (int)(params.size()); … … 3661 3707 return(" Not fitted"); 3662 3708 } 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); 3664 3710 } else if (nPiece < 1) { 3665 3711 return(" Bad count of the piece edge info"); … … 3671 3717 3672 3718 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); 3687 3741 3688 3742 return String(oss); -
branches/hpc34/src/Scantable.h
r2435 r2640 579 579 int whichrow, 580 580 bool verbose=false, 581 bool csvformat=false, 581 582 int start=-1, 582 583 int count=-1, … … 589 590 const std::string& masklist, 590 591 int whichrow, 591 bool verbose=false) const; 592 bool verbose=false, 593 bool csvformat=false) const; 592 594 593 595 … … 754 756 bool verbose=false); 755 757 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; 758 760 std::vector<bool> getCompositeChanMask(int whichrow, const std::vector<bool>& inMask); 759 761 //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); 763 765 void parseProgressInfo(const std::string& progressInfo, bool& showProgress, int& minNRow); 764 766 void showProgressOnTerminal(const int nProcessed, const int nTotal, const bool showProgress=true, const int nTotalThreshold=1000); -
branches/hpc34/src/ScantableWrapper.h
r2435 r2640 292 292 { return table_->getRms(mask, whichrow); } 293 293 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); } 299 299 300 300 bool getFlagtraFast(int whichrow=0) const
Note:
See TracChangeset
for help on using the changeset viewer.