Changeset 2063 for branches/casa-prerelease
- Timestamp:
- 03/24/11 17:43:46 (14 years ago)
- Location:
- branches/casa-prerelease/pre-asap
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/casa-prerelease/pre-asap
-
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
- Property svn:mergeinfo changed
/trunk/src merged: 2058
- Property svn:mergeinfo changed
-
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 1885 1885 std::vector<int> pieceRanges; 1886 1886 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); 1888 1888 setSpectrum(res, whichrow); 1889 1889 // … … 1954 1954 std::vector<int> pieceRanges; 1955 1955 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); 1957 1957 setSpectrum(res, whichrow); 1958 1958 // … … 1966 1966 } 1967 1967 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 ) {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, bool getResidual) { 1969 1969 if (nPiece < 1) { 1970 1970 throw(AipsError("wrong number of the sections for fitting")); … … 2004 2004 sectionRanges.push_back(x[x.size()-1]); 2005 2005 2006 std::vector<double> x1, x2, x3, z1, x1z1, x2z1, x3z1, r1;2006 std::vector<double> x1, z1, r1; 2007 2007 for (int i = 0; i < nChan; ++i) { 2008 2008 x1.push_back((double)i); 2009 x2.push_back((double)(i*i));2010 x3.push_back((double)(i*i*i));2011 2009 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]);2015 2010 r1.push_back(0.0); 2016 2011 } … … 2036 2031 for (int i = sectionList0[n]; i < sectionList1[n]; ++i) { 2037 2032 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; 2038 2039 xMatrix[0][0] += 1.0; 2039 xMatrix[0][1] += x 1[i];2040 xMatrix[0][2] += x 2[i];2041 xMatrix[0][3] += x 3[i];2042 xMatrix[1][1] += x 2[i];2043 xMatrix[1][2] += x 3[i];2044 xMatrix[1][3] += x 2[i]*x2[i];2045 xMatrix[2][2] += x 2[i]*x2[i];2046 xMatrix[2][3] += x 3[i]*x2[i];2047 xMatrix[3][3] += x 3[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; 2048 2049 zMatrix[0] += z1[i]; 2049 zMatrix[1] += x 1z1[i];2050 zMatrix[2] += x 2z1[i];2051 zMatrix[3] += x 3z1[i];2050 zMatrix[1] += xp1*z1[i]; 2051 zMatrix[2] += xp2*z1[i]; 2052 zMatrix[3] += xp3*z1[i]; 2052 2053 for (int j = 0; j < n; ++j) { 2053 double q = 1.0 - x 1[i]*sectionListR[j];2054 double q = 1.0 - xp1*sectionListR[j]; 2054 2055 q = q*q*q; 2055 2056 xMatrix[0][j+4] += q; 2056 xMatrix[1][j+4] += q*x 1[i];2057 xMatrix[2][j+4] += q*x 2[i];2058 xMatrix[3][j+4] += q*x 3[i];2057 xMatrix[1][j+4] += q*xp1; 2058 xMatrix[2][j+4] += q*xp2; 2059 xMatrix[3][j+4] += q*xp3; 2059 2060 for (int k = 0; k < j; ++k) { 2060 double r = 1.0 - x 1[i]*sectionListR[k];2061 double r = 1.0 - xp1*sectionListR[k]; 2061 2062 r = r*r*r; 2062 2063 xMatrix[k+4][j+4] += r*q; … … 2109 2110 //cubic terms for the other pieces (in case nPiece>1). 2110 2111 std::vector<double> y; 2112 y.clear(); 2111 2113 for (int i = 0; i < nDOF; ++i) { 2112 2114 y.push_back(0.0); … … 2124 2126 for (int n = 0; n < nPiece; ++n) { 2125 2127 for (int i = sectionList0[n]; i < sectionList1[n]; ++i) { 2126 r1[i] = a0 + a1*x1[i] + a2*x 2[i] + a3*x3[i];2128 r1[i] = a0 + a1*x1[i] + a2*x1[i]*x1[i] + a3*x1[i]*x1[i]*x1[i]; 2127 2129 } 2128 2130 params.push_back(a0); … … 2170 2172 } 2171 2173 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; 2178 2186 } 2179 2187 … … 2207 2215 std::vector<int> pieceRanges; 2208 2216 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); 2210 2218 setSpectrum(res, whichrow); 2211 2219 // … … 2276 2284 std::vector<int> pieceRanges; 2277 2285 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); 2279 2287 setSpectrum(res, whichrow); 2280 2288 // … … 2288 2296 } 2289 2297 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 } 2298 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, bool getResidual) { 2294 2299 if (data.size() != mask.size()) { 2295 2300 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 } 2296 2310 } 2297 2311 … … 2448 2462 } 2449 2463 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; 2456 2476 } 2457 2477 -
branches/casa-prerelease/pre-asap/src/Scantable.h
r2047 r2063 673 673 int nPiece=2, 674 674 float thresClip=3.0, 675 int nIterClip=1); 675 int nIterClip=1, 676 bool getResidual=false); 676 677 std::vector<float> doSinusoidFitting(const std::vector<float>& data, 677 678 const std::vector<bool>& mask, … … 680 681 std::vector<float>& params, 681 682 float thresClip=3.0, 682 int nIterClip=1); 683 int nIterClip=1, 684 bool getResidual=false); 683 685 bool hasSameNchanOverIFs(); 684 686 std::string getMaskRangeList(const std::vector<bool>& mask,
Note:
See TracChangeset
for help on using the changeset viewer.