Changeset 2063


Ignore:
Timestamp:
03/24/11 17:43:46 (14 years ago)
Author:
WataruKawasaki
Message:

merged from trunk (r2057)

Location:
branches/casa-prerelease/pre-asap
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • branches/casa-prerelease/pre-asap

    • Property svn:mergeinfo changed
      /trunkmerged: 2058
  • branches/casa-prerelease/pre-asap/Makefile

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/casa-prerelease/pre-asap/SConstruct

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/casa-prerelease/pre-asap/apps

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/casa-prerelease/pre-asap/external-alma

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/casa-prerelease/pre-asap/external-alma/atnf/pks/pks_maths.cc

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/casa-prerelease/pre-asap/getsvnrev.sh

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/casa-prerelease/pre-asap/python

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/casa-prerelease/pre-asap/src

  • branches/casa-prerelease/pre-asap/src/SConscript

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/casa-prerelease/pre-asap/src/Scantable.cpp

    r2047 r2063  
    18851885    std::vector<int> pieceRanges;
    18861886    std::vector<float> params;
    1887     std::vector<float> res = doCubicSplineFitting(getSpectrum(whichrow), chanMask, pieceRanges, params, nPiece, thresClip, nIterClip);
     1887    std::vector<float> res = doCubicSplineFitting(getSpectrum(whichrow), chanMask, pieceRanges, params, nPiece, thresClip, nIterClip, true);
    18881888    setSpectrum(res, whichrow);
    18891889    //
     
    19541954    std::vector<int> pieceRanges;
    19551955    std::vector<float> params;
    1956     std::vector<float> res = doCubicSplineFitting(getSpectrum(whichrow), chanMask, pieceRanges, params, nPiece, thresClip, nIterClip);
     1956    std::vector<float> res = doCubicSplineFitting(getSpectrum(whichrow), chanMask, pieceRanges, params, nPiece, thresClip, nIterClip, true);
    19571957    setSpectrum(res, whichrow);
    19581958    //
     
    19661966}
    19671967
    1968 std::vector<float> Scantable::doCubicSplineFitting(const std::vector<float>& data, const std::vector<bool>& mask, std::vector<int>& sectionRanges, std::vector<float>& params, int nPiece, float thresClip, int nIterClip) {
     1968std::vector<float> Scantable::doCubicSplineFitting(const std::vector<float>& data, const std::vector<bool>& mask, std::vector<int>& sectionRanges, std::vector<float>& params, int nPiece, float thresClip, int nIterClip, bool getResidual) {
    19691969  if (nPiece < 1) {
    19701970    throw(AipsError("wrong number of the sections for fitting"));
     
    20042004  sectionRanges.push_back(x[x.size()-1]);
    20052005
    2006   std::vector<double> x1, x2, x3, z1, x1z1, x2z1, x3z1, r1;
     2006  std::vector<double> x1, z1, r1;
    20072007  for (int i = 0; i < nChan; ++i) {
    20082008    x1.push_back((double)i);
    2009     x2.push_back((double)(i*i));
    2010     x3.push_back((double)(i*i*i));
    20112009    z1.push_back((double)data[i]);
    2012     x1z1.push_back(((double)i)*(double)data[i]);
    2013     x2z1.push_back(((double)(i*i))*(double)data[i]);
    2014     x3z1.push_back(((double)(i*i*i))*(double)data[i]);
    20152010    r1.push_back(0.0);
    20162011  }
     
    20362031      for (int i = sectionList0[n]; i < sectionList1[n]; ++i) {
    20372032        if (maskArray[i] == 0) continue;
     2033        double xp1 = x1[i];
     2034        double xp2 = xp1*xp1;
     2035        double xp3 = xp2*xp1;
     2036        double xp4 = xp3*xp1;
     2037        double xp5 = xp4*xp1;
     2038        double xp6 = xp5*xp1;
    20382039        xMatrix[0][0] += 1.0;
    2039         xMatrix[0][1] += x1[i];
    2040         xMatrix[0][2] += x2[i];
    2041         xMatrix[0][3] += x3[i];
    2042         xMatrix[1][1] += x2[i];
    2043         xMatrix[1][2] += x3[i];
    2044         xMatrix[1][3] += x2[i]*x2[i];
    2045         xMatrix[2][2] += x2[i]*x2[i];
    2046         xMatrix[2][3] += x3[i]*x2[i];
    2047         xMatrix[3][3] += x3[i]*x3[i];
     2040        xMatrix[0][1] += xp1;
     2041        xMatrix[0][2] += xp2;
     2042        xMatrix[0][3] += xp3;
     2043        xMatrix[1][1] += xp2;
     2044        xMatrix[1][2] += xp3;
     2045        xMatrix[1][3] += xp4;
     2046        xMatrix[2][2] += xp4;
     2047        xMatrix[2][3] += xp5;
     2048        xMatrix[3][3] += xp6;
    20482049        zMatrix[0] += z1[i];
    2049         zMatrix[1] += x1z1[i];
    2050         zMatrix[2] += x2z1[i];
    2051         zMatrix[3] += x3z1[i];
     2050        zMatrix[1] += xp1*z1[i];
     2051        zMatrix[2] += xp2*z1[i];
     2052        zMatrix[3] += xp3*z1[i];
    20522053        for (int j = 0; j < n; ++j) {
    2053           double q = 1.0 - x1[i]*sectionListR[j];
     2054          double q = 1.0 - xp1*sectionListR[j];
    20542055          q = q*q*q;
    20552056          xMatrix[0][j+4] += q;
    2056           xMatrix[1][j+4] += q*x1[i];
    2057           xMatrix[2][j+4] += q*x2[i];
    2058           xMatrix[3][j+4] += q*x3[i];
     2057          xMatrix[1][j+4] += q*xp1;
     2058          xMatrix[2][j+4] += q*xp2;
     2059          xMatrix[3][j+4] += q*xp3;
    20592060          for (int k = 0; k < j; ++k) {
    2060             double r = 1.0 - x1[i]*sectionListR[k];
     2061            double r = 1.0 - xp1*sectionListR[k];
    20612062            r = r*r*r;
    20622063            xMatrix[k+4][j+4] += r*q;
     
    21092110    //cubic terms for the other pieces (in case nPiece>1).
    21102111    std::vector<double> y;
     2112    y.clear();
    21112113    for (int i = 0; i < nDOF; ++i) {
    21122114      y.push_back(0.0);
     
    21242126    for (int n = 0; n < nPiece; ++n) {
    21252127      for (int i = sectionList0[n]; i < sectionList1[n]; ++i) {
    2126         r1[i] = a0 + a1*x1[i] + a2*x2[i] + a3*x3[i];
     2128        r1[i] = a0 + a1*x1[i] + a2*x1[i]*x1[i] + a3*x1[i]*x1[i]*x1[i];
    21272129      }
    21282130      params.push_back(a0);
     
    21702172  }
    21712173
    2172   std::vector<float> residual;
    2173   for (int i = 0; i < nChan; ++i) {
    2174     residual.push_back((float)(z1[i] - r1[i]));
    2175   }
    2176   return residual;
    2177 
     2174  std::vector<float> result;
     2175  if (getResidual) {
     2176    for (int i = 0; i < nChan; ++i) {
     2177      result.push_back((float)(z1[i] - r1[i]));
     2178    }
     2179  } else {
     2180    for (int i = 0; i < nChan; ++i) {
     2181      result.push_back((float)r1[i]);
     2182    }
     2183  }
     2184
     2185  return result;
    21782186}
    21792187
     
    22072215    std::vector<int> pieceRanges;
    22082216    std::vector<float> params;
    2209     std::vector<float> res = doSinusoidFitting(getSpectrum(whichrow), chanMask, nMinWavesInSW, nMaxWavesInSW, params, thresClip, nIterClip);
     2217    std::vector<float> res = doSinusoidFitting(getSpectrum(whichrow), chanMask, nMinWavesInSW, nMaxWavesInSW, params, thresClip, nIterClip, true);
    22102218    setSpectrum(res, whichrow);
    22112219    //
     
    22762284    std::vector<int> pieceRanges;
    22772285    std::vector<float> params;
    2278     std::vector<float> res = doSinusoidFitting(getSpectrum(whichrow), chanMask, nMinWavesInSW, nMaxWavesInSW, params, thresClip, nIterClip);
     2286    std::vector<float> res = doSinusoidFitting(getSpectrum(whichrow), chanMask, nMinWavesInSW, nMaxWavesInSW, params, thresClip, nIterClip, true);
    22792287    setSpectrum(res, whichrow);
    22802288    //
     
    22882296}
    22892297
    2290 std::vector<float> Scantable::doSinusoidFitting(const std::vector<float>& data, const std::vector<bool>& mask, int nMinWavesInSW, int nMaxWavesInSW, std::vector<float>& params, float thresClip, int nIterClip) {
    2291   if (nMaxWavesInSW < 1) {
    2292     throw(AipsError("maximum wave number must be a positive value"));
    2293   }
     2298std::vector<float> Scantable::doSinusoidFitting(const std::vector<float>& data, const std::vector<bool>& mask, int nMinWavesInSW, int nMaxWavesInSW, std::vector<float>& params, float thresClip, int nIterClip, bool getResidual) {
    22942299  if (data.size() != mask.size()) {
    22952300    throw(AipsError("data and mask have different size"));
     2301  }
     2302  if ((nMinWavesInSW < 0) || (nMaxWavesInSW < 0)) {
     2303    throw(AipsError("wave number must be positive or zero (i.e. constant)"));
     2304  } else {
     2305    if (nMaxWavesInSW < nMinWavesInSW) {
     2306      int temp = nMaxWavesInSW;
     2307      nMaxWavesInSW = nMinWavesInSW;
     2308      nMinWavesInSW = temp;
     2309    }
    22962310  }
    22972311
     
    24482462  }
    24492463
    2450   std::vector<float> residual;
    2451   for (int i = 0; i < nChan; ++i) {
    2452     residual.push_back((float)(z1[i] - r1[i]));
    2453   }
    2454   return residual;
    2455 
     2464  std::vector<float> result;
     2465  if (getResidual) {
     2466    for (int i = 0; i < nChan; ++i) {
     2467      result.push_back((float)(z1[i] - r1[i]));
     2468    }
     2469  } else {
     2470    for (int i = 0; i < nChan; ++i) {
     2471      result.push_back((float)r1[i]);
     2472    }
     2473  }
     2474
     2475  return result;
    24562476}
    24572477
  • branches/casa-prerelease/pre-asap/src/Scantable.h

    r2047 r2063  
    673673                                          int nPiece=2,
    674674                                          float thresClip=3.0,
    675                                           int nIterClip=1);
     675                                          int nIterClip=1,
     676                                          bool getResidual=false);
    676677  std::vector<float> doSinusoidFitting(const std::vector<float>& data,
    677678                                       const std::vector<bool>& mask,
     
    680681                                       std::vector<float>& params,
    681682                                       float thresClip=3.0,
    682                                        int nIterClip=1);
     683                                       int nIterClip=1,
     684                                       bool getResidual=false);
    683685  bool hasSameNchanOverIFs();
    684686  std::string getMaskRangeList(const std::vector<bool>& mask,
Note: See TracChangeset for help on using the changeset viewer.