- Timestamp:
- 01/18/13 19:09:41 (12 years ago)
- Location:
- trunk/src
- Files:
-
- 2 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/STBaselineEnum.h
r2728 r2737 26 26 @version $Revision:$ 27 27 */ 28 class STBaseline Enum{28 class STBaselineFunc { 29 29 public: 30 enum BaselineType {Polynomial = 0,31 32 33 30 enum FuncName {Polynomial = 0, 31 CSpline, 32 Sinusoid, 33 Chebyshev}; 34 34 }; 35 35 -
trunk/src/Scantable.cpp
r2713 r2737 66 66 #include "MathUtils.h" 67 67 #include "STAttr.h" 68 #include "STBaselineTable.h" 68 69 #include "STLineFinder.h" 69 70 #include "STPolCircular.h" … … 2637 2638 std::vector<bool> chanMask; 2638 2639 2640 std::vector<float> sect(0); 2641 std::vector<bool> finalChanMask; 2642 float rms; 2643 2644 //--- 2645 bool outBaselineParamTable = true; 2646 STBaselineTable* bt = new STBaselineTable(*this); 2647 //--- 2648 2639 2649 for (int whichrow = 0; whichrow < nRow; ++whichrow) { 2640 2650 std::vector<float> sp = getSpectrum(whichrow); … … 2642 2652 std::vector<float> params(order+1); 2643 2653 int nClipped = 0; 2644 std::vector<float> res = doChebyshevFitting(sp, chanMask, order, params, nClipped, thresClip, nIterClip, getResidual); 2645 2646 setSpectrum(res, whichrow); 2654 std::vector<float> res = doChebyshevFitting(sp, chanMask, order, params, finalChanMask, rms, nClipped, thresClip, nIterClip, getResidual); 2655 2656 //--- 2657 if (outBaselineParamTable) { 2658 bt->appenddata(uInt(getScan(whichrow)), uInt(getCycle(whichrow)), uInt(getBeam(whichrow)), uInt(getIF(whichrow)), uInt(getPol(whichrow)), 2659 uInt(0), 2660 Double(0.0), // <-- Double(getTime(whichrow, false)), 2661 uInt(nchan(whichrow)), STBaselineFunc::Chebyshev, 2662 uInt(order), uInt(nIterClip), Float(thresClip), Vector<Float>(sect), Vector<Float>(params), 2663 Vector<Float>(params), // <-- Vector<Float>(finalChanMask), 2664 Float(rms)); 2665 } else { 2666 setSpectrum(res, whichrow); 2667 } 2668 //--- 2669 2647 2670 outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "chebyshevBaseline()", params, nClipped); 2648 2671 showProgressOnTerminal(whichrow, nRow, showProgress, minNRow); 2649 2672 } 2650 2673 2674 //--- 2675 if (outBaselineParamTable) { 2676 bt->save("chebyparamtable"); 2677 } 2678 //--- 2679 delete bt; 2680 2651 2681 if (outTextFile) ofs.close(); 2652 2682 … … 2697 2727 int nparam; 2698 2728 std::vector<float> params; 2729 std::vector<bool> finalChanMask; 2730 float rms; 2699 2731 int nClipped = 0; 2700 2732 float thresClip = 0.0; … … 2703 2735 if (blfunc == "chebyshev") { 2704 2736 nparam = order + 1; 2705 res = doChebyshevFitting(spec, mask, order, params, nClipped, thresClip, nIterClip, true);2737 res = doChebyshevFitting(spec, mask, order, params, finalChanMask, rms, nClipped, thresClip, nIterClip, true); 2706 2738 } else if (blfunc == "sinusoid") { 2707 2739 std::vector<int> nWaves; … … 2798 2830 int minNRow; 2799 2831 parseProgressInfo(progressInfo, showProgress, minNRow); 2832 2833 std::vector<bool> finalChanMask; 2834 float rms; 2800 2835 2801 2836 for (int whichrow = 0; whichrow < nRow; ++whichrow) { … … 2831 2866 std::vector<float> params(order+1); 2832 2867 int nClipped = 0; 2833 std::vector<float> res = doChebyshevFitting(sp, chanMask, order, params, nClipped, thresClip, nIterClip, getResidual);2868 std::vector<float> res = doChebyshevFitting(sp, chanMask, order, params, finalChanMask, rms, nClipped, thresClip, nIterClip, getResidual); 2834 2869 setSpectrum(res, whichrow); 2835 2870 … … 2901 2936 } 2902 2937 2903 std::vector<float> Scantable::doChebyshevFitting(const std::vector<float>& data, const std::vector<bool>& mask, int order, std::vector<float>& params, int& nClipped, float thresClip, int nIterClip, bool getResidual)2938 std::vector<float> Scantable::doChebyshevFitting(const std::vector<float>& data, const std::vector<bool>& mask, int order, std::vector<float>& params, std::vector<bool>& finalMask, float& rms, int& nClipped, float thresClip, int nIterClip, bool getResidual) 2904 2939 { 2905 2940 if (data.size() != mask.size()) { … … 2911 2946 2912 2947 int nChan = data.size(); 2948 2949 finalMask.clear(); 2950 finalMask.resize(nChan); 2951 2913 2952 std::vector<int> maskArray; 2914 2953 std::vector<int> x; … … 2918 2957 x.push_back(i); 2919 2958 } 2959 finalMask[i] = mask[i]; 2920 2960 } 2921 2961 … … 3041 3081 } 3042 3082 3083 double stdDev = 0.0; 3084 for (int i = 0; i < nChan; ++i) { 3085 stdDev += residual[i]*residual[i]*(double)maskArray[i]; 3086 } 3087 stdDev = sqrt(stdDev/(double)nData); 3088 rms = (float)stdDev; 3089 3043 3090 if ((nClip == nIterClip) || (thresClip <= 0.0)) { 3044 3091 break; 3045 3092 } else { 3046 double stdDev = 0.0; 3047 for (int i = 0; i < nChan; ++i) { 3048 stdDev += residual[i]*residual[i]*(double)maskArray[i]; 3049 } 3050 stdDev = sqrt(stdDev/(double)nData); 3051 3093 3052 3094 double thres = stdDev * thresClip; 3053 3095 int newNData = 0; … … 3055 3097 if (abs(residual[i]) >= thres) { 3056 3098 maskArray[i] = 0; 3099 finalMask[i] = false; 3057 3100 } 3058 3101 if (maskArray[i] > 0) { … … 3065 3108 nData = newNData; 3066 3109 } 3110 3067 3111 } 3068 3112 } … … 4315 4359 { 4316 4360 /**** 4317 double ms1TimeStart, ms1TimeEnd , ms2TimeStart, ms2TimeEnd;4361 double ms1TimeStart, ms1TimeEnd; 4318 4362 double elapse1 = 0.0; 4319 double elapse2 = 0.0;4320 4321 4363 ms1TimeStart = mathutil::gettimeofday_sec(); 4322 4364 ****/ 4323 4365 4324 4366 Vector<Float> spec; 4325 4326 4367 specCol_.get(whichrow, spec); 4327 4368 … … 4330 4371 elapse1 = ms1TimeEnd - ms1TimeStart; 4331 4372 std::cout << "rm1 : " << elapse1 << " (sec.)" << endl; 4332 ms2TimeStart = mathutil::gettimeofday_sec();4333 4373 ****/ 4334 4374 4335 float mean = 0.0; 4336 float smean = 0.0; 4375 return (float)doGetRms(mask, spec); 4376 } 4377 4378 double Scantable::doGetRms(const std::vector<bool>& mask, const Vector<Float>& spec) 4379 { 4380 double mean = 0.0; 4381 double smean = 0.0; 4337 4382 int n = 0; 4338 4383 for (uInt i = 0; i < spec.nelements(); ++i) { 4339 4384 if (mask[i]) { 4340 mean += spec[i]; 4341 smean += spec[i]*spec[i]; 4385 double val = (double)spec[i]; 4386 mean += val; 4387 smean += val*val; 4342 4388 n++; 4343 4389 } 4344 4390 } 4345 4391 4346 mean /= (float)n; 4347 smean /= (float)n; 4348 4349 /**** 4350 ms2TimeEnd = mathutil::gettimeofday_sec(); 4351 elapse2 = ms2TimeEnd - ms2TimeStart; 4352 std::cout << "rm2 : " << elapse2 << " (sec.)" << endl; 4353 ****/ 4392 mean /= (double)n; 4393 smean /= (double)n; 4354 4394 4355 4395 return sqrt(smean - mean*mean); 4356 4396 } 4357 4358 4397 4359 4398 std::string Scantable::formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose, bool csvformat) const -
trunk/src/Scantable.h
r2713 r2737 748 748 int order, 749 749 std::vector<float>& params, 750 std::vector<bool>& finalMask, 751 float& rms, 750 752 int& nClipped, 751 753 float thresClip=3.0, … … 818 820 const std::string& blfunc, 819 821 int order); 822 double doGetRms(const std::vector<bool>& mask, const casa::Vector<casa::Float>& spec); 820 823 821 824 };
Note:
See TracChangeset
for help on using the changeset viewer.