Changeset 2737 for trunk


Ignore:
Timestamp:
01/18/13 19:09:41 (12 years ago)
Author:
WataruKawasaki
Message:

New Development: No

JIRA Issue: Yes CAS-4794

Ready for Test: No

Interface Changes: No

What Interface Changed:

Test Programs:

Put in Release Notes: No

Module(s): sd

Description:


Location:
trunk/src
Files:
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STBaselineEnum.h

    r2728 r2737  
    2626@version $Revision:$
    2727*/
    28 class STBaselineEnum  {
     28class STBaselineFunc  {
    2929public:
    30   enum BaselineType {Polynomial = 0,
    31                      CSpline,
    32                      Sinusoid,
    33                      Chebyshev};
     30  enum FuncName {Polynomial = 0,
     31                 CSpline,
     32                 Sinusoid,
     33                 Chebyshev};
    3434};
    3535
  • trunk/src/Scantable.cpp

    r2713 r2737  
    6666#include "MathUtils.h"
    6767#include "STAttr.h"
     68#include "STBaselineTable.h"
    6869#include "STLineFinder.h"
    6970#include "STPolCircular.h"
     
    26372638    std::vector<bool> chanMask;
    26382639
     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
    26392649    for (int whichrow = 0; whichrow < nRow; ++whichrow) {
    26402650      std::vector<float> sp = getSpectrum(whichrow);
     
    26422652      std::vector<float> params(order+1);
    26432653      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
    26472670      outputFittingResult(outLogger, outTextFile, csvFormat, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "chebyshevBaseline()", params, nClipped);
    26482671      showProgressOnTerminal(whichrow, nRow, showProgress, minNRow);
    26492672    }
    26502673   
     2674    //---
     2675    if (outBaselineParamTable) {
     2676      bt->save("chebyparamtable");
     2677    }
     2678    //---
     2679    delete bt;
     2680
    26512681    if (outTextFile) ofs.close();
    26522682
     
    26972727  int nparam;
    26982728  std::vector<float> params;
     2729  std::vector<bool> finalChanMask;
     2730  float rms;
    26992731  int nClipped = 0;
    27002732  float thresClip = 0.0;
     
    27032735  if (blfunc == "chebyshev") {
    27042736    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);
    27062738  } else if (blfunc == "sinusoid") {
    27072739    std::vector<int> nWaves;
     
    27982830    int minNRow;
    27992831    parseProgressInfo(progressInfo, showProgress, minNRow);
     2832
     2833    std::vector<bool> finalChanMask;
     2834    float rms;
    28002835
    28012836    for (int whichrow = 0; whichrow < nRow; ++whichrow) {
     
    28312866      std::vector<float> params(order+1);
    28322867      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);
    28342869      setSpectrum(res, whichrow);
    28352870
     
    29012936}
    29022937
    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)
     2938std::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)
    29042939{
    29052940  if (data.size() != mask.size()) {
     
    29112946
    29122947  int nChan = data.size();
     2948
     2949  finalMask.clear();
     2950  finalMask.resize(nChan);
     2951
    29132952  std::vector<int> maskArray;
    29142953  std::vector<int> x;
     
    29182957      x.push_back(i);
    29192958    }
     2959    finalMask[i] = mask[i];
    29202960  }
    29212961
     
    30413081    }
    30423082
     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
    30433090    if ((nClip == nIterClip) || (thresClip <= 0.0)) {
    30443091      break;
    30453092    } 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
    30523094      double thres = stdDev * thresClip;
    30533095      int newNData = 0;
     
    30553097        if (abs(residual[i]) >= thres) {
    30563098          maskArray[i] = 0;
     3099          finalMask[i] = false;
    30573100        }
    30583101        if (maskArray[i] > 0) {
     
    30653108        nData = newNData;
    30663109      }
     3110
    30673111    }
    30683112  }
     
    43154359{
    43164360  /****
    4317   double ms1TimeStart, ms1TimeEnd, ms2TimeStart, ms2TimeEnd;
     4361  double ms1TimeStart, ms1TimeEnd;
    43184362  double elapse1 = 0.0;
    4319   double elapse2 = 0.0;
    4320 
    43214363  ms1TimeStart = mathutil::gettimeofday_sec();
    43224364  ****/
    43234365
    43244366  Vector<Float> spec;
    4325 
    43264367  specCol_.get(whichrow, spec);
    43274368
     
    43304371  elapse1 = ms1TimeEnd - ms1TimeStart;
    43314372  std::cout << "rm1   : " << elapse1 << " (sec.)" << endl;
    4332   ms2TimeStart = mathutil::gettimeofday_sec();
    43334373  ****/
    43344374
    4335   float mean = 0.0;
    4336   float smean = 0.0;
     4375  return (float)doGetRms(mask, spec);
     4376}
     4377
     4378double Scantable::doGetRms(const std::vector<bool>& mask, const Vector<Float>& spec)
     4379{
     4380  double mean = 0.0;
     4381  double smean = 0.0;
    43374382  int n = 0;
    43384383  for (uInt i = 0; i < spec.nelements(); ++i) {
    43394384    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;
    43424388      n++;
    43434389    }
    43444390  }
    43454391
    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;
    43544394
    43554395  return sqrt(smean - mean*mean);
    43564396}
    4357 
    43584397
    43594398std::string Scantable::formatBaselineParamsHeader(int whichrow, const std::string& masklist, bool verbose, bool csvformat) const
  • trunk/src/Scantable.h

    r2713 r2737  
    748748                                          int order,
    749749                                          std::vector<float>& params,
     750                                          std::vector<bool>& finalMask,
     751                                          float& rms,
    750752                                          int& nClipped,
    751753                                          float thresClip=3.0,
     
    818820                                           const std::string& blfunc,
    819821                                           int order);
     822  double doGetRms(const std::vector<bool>& mask, const casa::Vector<casa::Float>& spec);
    820823
    821824};
Note: See TracChangeset for help on using the changeset viewer.