Changeset 2082 for branches/casa-prerelease/pre-asap/src
- Timestamp:
- 03/30/11 21:43:43 (14 years ago)
- Location:
- branches/casa-prerelease/pre-asap
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/casa-prerelease/pre-asap
-
branches/casa-prerelease/pre-asap/src
- Property svn:mergeinfo changed
/trunk/src merged: 2081
- 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/STLineFinder.cpp
r2012 r2082 1203 1203 vel = scan->getAbcissa(last_row_used); 1204 1204 } else { 1205 for ( int i = 0; i < spectrum.nelements(); ++i)1205 for (uInt i = 0; i < spectrum.nelements(); ++i) 1206 1206 vel.push_back((double)i); 1207 1207 } -
branches/casa-prerelease/pre-asap/src/Scantable.cpp
r2065 r2082 1764 1764 { 1765 1765 ofstream ofs; 1766 String coordInfo ;1766 String coordInfo = ""; 1767 1767 bool hasSameNchan = true; 1768 1768 bool outTextFile = false; … … 1781 1781 Fitter fitter = Fitter(); 1782 1782 fitter.setExpression("poly", order); 1783 //fitter.setIterClipping(thresClip, nIterClip); 1783 1784 1784 1785 int nRow = nrow(); … … 1798 1799 { 1799 1800 ofstream ofs; 1800 String coordInfo ;1801 String coordInfo = ""; 1801 1802 bool hasSameNchan = true; 1802 1803 bool outTextFile = false; … … 1815 1816 Fitter fitter = Fitter(); 1816 1817 fitter.setExpression("poly", order); 1818 //fitter.setIterClipping(thresClip, nIterClip); 1817 1819 1818 1820 int nRow = nrow(); … … 1856 1858 } 1857 1859 1858 void Scantable::cubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, bool outLogger, const std::string& blfile) { 1860 void Scantable::cubicSplineBaseline(const std::vector<bool>& mask, int nPiece, float thresClip, int nIterClip, bool outLogger, const std::string& blfile) 1861 { 1859 1862 ofstream ofs; 1860 String coordInfo ;1863 String coordInfo = ""; 1861 1864 bool hasSameNchan = true; 1862 1865 bool outTextFile = false; … … 1875 1878 //Fitter fitter = Fitter(); 1876 1879 //fitter.setExpression("cspline", nPiece); 1880 //fitter.setIterClipping(thresClip, nIterClip); 1877 1881 1878 1882 int nRow = nrow(); … … 1881 1885 for (int whichrow = 0; whichrow < nRow; ++whichrow) { 1882 1886 chanMask = getCompositeChanMask(whichrow, mask); 1883 //fitBaseline(chanMask, whichrow, fitter , thresClip, nIterClip);1887 //fitBaseline(chanMask, whichrow, fitter); 1884 1888 //setSpectrum(fitter.getResidual(), whichrow); 1885 std::vector<int> piece Ranges;1889 std::vector<int> pieceEdges; 1886 1890 std::vector<float> params; 1887 std::vector<float> res = doCubicSplineFitting(getSpectrum(whichrow), chanMask, pieceRanges, params, nPiece, thresClip, nIterClip, true);1891 std::vector<float> res = doCubicSplineFitting(getSpectrum(whichrow), chanMask, nPiece, pieceEdges, params, thresClip, nIterClip, true); 1888 1892 setSpectrum(res, whichrow); 1889 1893 // 1890 1894 1891 std::vector<bool> fixed; 1892 fixed.clear(); 1893 outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "cubicSplineBaseline()", pieceRanges, params, fixed); 1895 outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "cubicSplineBaseline()", pieceEdges, params); 1894 1896 } 1895 1897 … … 1900 1902 { 1901 1903 ofstream ofs; 1902 String coordInfo ;1904 String coordInfo = ""; 1903 1905 bool hasSameNchan = true; 1904 1906 bool outTextFile = false; … … 1917 1919 //Fitter fitter = Fitter(); 1918 1920 //fitter.setExpression("cspline", nPiece); 1921 //fitter.setIterClipping(thresClip, nIterClip); 1919 1922 1920 1923 int nRow = nrow(); … … 1950 1953 1951 1954 1952 //fitBaseline(chanMask, whichrow, fitter , thresClip, nIterClip);1955 //fitBaseline(chanMask, whichrow, fitter); 1953 1956 //setSpectrum(fitter.getResidual(), whichrow); 1954 std::vector<int> piece Ranges;1957 std::vector<int> pieceEdges; 1955 1958 std::vector<float> params; 1956 std::vector<float> res = doCubicSplineFitting(getSpectrum(whichrow), chanMask, pieceRanges, params, nPiece, thresClip, nIterClip, true);1959 std::vector<float> res = doCubicSplineFitting(getSpectrum(whichrow), chanMask, nPiece, pieceEdges, params, thresClip, nIterClip, true); 1957 1960 setSpectrum(res, whichrow); 1958 1961 // 1959 1962 1960 std::vector<bool> fixed; 1961 fixed.clear(); 1962 outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoCubicSplineBaseline()", pieceRanges, params, fixed); 1963 outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoCubicSplineBaseline()", pieceEdges, params); 1963 1964 } 1964 1965 … … 1966 1967 } 1967 1968 1968 std::vector<float> Scantable::doCubicSplineFitting(const std::vector<float>& data, const std::vector<bool>& mask, std::vector<int>& idxEdge, std::vector<float>& params, int nPiece, float thresClip, int nIterClip, bool getResidual) { 1969 std::vector<float> Scantable::doCubicSplineFitting(const std::vector<float>& data, const std::vector<bool>& mask, int nPiece, std::vector<int>& idxEdge, std::vector<float>& params, float thresClip, int nIterClip, bool getResidual) 1970 { 1971 if (data.size() != mask.size()) { 1972 throw(AipsError("data and mask sizes are not identical")); 1973 } 1969 1974 if (nPiece < 1) { 1970 1975 throw(AipsError("wrong number of the sections for fitting")); 1971 }1972 if (data.size() != mask.size()) {1973 throw(AipsError("data and mask have different size"));1974 1976 } 1975 1977 … … 1984 1986 } 1985 1987 1986 int nData = x.size(); 1987 int nElement = (int)(floor(floor((double)(nData/nPiece))+0.5)); 1988 int initNData = x.size(); 1989 1990 int nElement = (int)(floor(floor((double)(initNData/nPiece))+0.5)); 1988 1991 std::vector<double> invEdge; 1989 1990 1992 idxEdge.clear(); 1991 1993 idxEdge.push_back(x[0]); 1992 1993 1994 for (int i = 1; i < nPiece; ++i) { 1994 1995 int valX = x[nElement*i]; … … 1996 1997 invEdge.push_back(1.0/(double)valX); 1997 1998 } 1998 1999 1999 idxEdge.push_back(x[x.size()-1]+1); 2000 2000 2001 std::vector<double> x1, x2, x3, z1, x1z1, x2z1, x3z1, r1; 2001 int nData = initNData; 2002 int nDOF = nPiece + 3; //number of parameters to solve, namely, 4+(nPiece-1). 2003 2004 std::vector<double> x1, x2, x3, z1, x1z1, x2z1, x3z1, r1, residual; 2002 2005 for (int i = 0; i < nChan; ++i) { 2003 2006 double di = (double)i; … … 2011 2014 x3z1.push_back(dD*di*di*di); 2012 2015 r1.push_back(0.0); 2013 } 2014 2015 int currentNData = nData; 2016 int nDOF = nPiece + 3; //number of parameters to solve, namely, 4+(nPiece-1). 2016 residual.push_back(0.0); 2017 } 2017 2018 2018 2019 for (int nClip = 0; nClip < nIterClip+1; ++nClip) { … … 2128 2129 for (int i = idxEdge[n]; i < idxEdge[n+1]; ++i) { 2129 2130 r1[i] = a0 + a1*x1[i] + a2*x2[i] + a3*x3[i]; 2131 residual[i] = z1[i] - r1[i]; 2130 2132 } 2131 2133 params.push_back(a0); … … 2147 2149 break; 2148 2150 } else { 2149 std::vector<double> rz;2150 2151 double stdDev = 0.0; 2151 2152 for (int i = 0; i < nChan; ++i) { 2152 double val = abs(r1[i] - z1[i]); 2153 rz.push_back(val); 2154 stdDev += val*val*(double)maskArray[i]; 2153 stdDev += residual[i]*residual[i]*(double)maskArray[i]; 2155 2154 } 2156 2155 stdDev = sqrt(stdDev/(double)nData); … … 2159 2158 int newNData = 0; 2160 2159 for (int i = 0; i < nChan; ++i) { 2161 if ( rz[i]>= thres) {2160 if (abs(residual[i]) >= thres) { 2162 2161 maskArray[i] = 0; 2163 2162 } … … 2166 2165 } 2167 2166 } 2168 if (newNData == currentNData) {2167 if (newNData == nData) { 2169 2168 break; //no more flag to add. iteration stops. 2170 2169 } else { 2171 currentNData = newNData;2170 nData = newNData; 2172 2171 } 2173 2172 } … … 2177 2176 if (getResidual) { 2178 2177 for (int i = 0; i < nChan; ++i) { 2179 result.push_back((float) (z1[i] - r1[i]));2178 result.push_back((float)residual[i]); 2180 2179 } 2181 2180 } else { … … 2188 2187 } 2189 2188 2190 void Scantable::sinusoidBaseline(const std::vector<bool>& mask, int nMinWavesInSW, int nMaxWavesInSW, float thresClip, int nIterClip, bool outLogger, const std::string& blfile) { 2189 void Scantable::sinusoidBaseline(const std::vector<bool>& mask, const std::vector<int>& nWaves, float maxWaveLength, float thresClip, int nIterClip, bool getResidual, bool outLogger, const std::string& blfile) 2190 { 2191 2191 ofstream ofs; 2192 String coordInfo ;2192 String coordInfo = ""; 2193 2193 bool hasSameNchan = true; 2194 2194 bool outTextFile = false; … … 2206 2206 2207 2207 //Fitter fitter = Fitter(); 2208 //fitter.setExpression("sinusoid", nMaxWavesInSW); 2208 //fitter.setExpression("sinusoid", nWaves); 2209 //fitter.setIterClipping(thresClip, nIterClip); 2209 2210 2210 2211 int nRow = nrow(); … … 2213 2214 for (int whichrow = 0; whichrow < nRow; ++whichrow) { 2214 2215 chanMask = getCompositeChanMask(whichrow, mask); 2215 //fitBaseline(chanMask, whichrow, fitter , thresClip, nIterClip);2216 //fitBaseline(chanMask, whichrow, fitter); 2216 2217 //setSpectrum(fitter.getResidual(), whichrow); 2217 std::vector<int> pieceRanges;2218 2218 std::vector<float> params; 2219 std::vector<float> res = doSinusoidFitting(getSpectrum(whichrow), chanMask, nMinWavesInSW, nMaxWavesInSW, params, thresClip, nIterClip, true); 2219 //std::vector<float> res = doSinusoidFitting(getSpectrum(whichrow), chanMask, nWaves, params, thresClip, nIterClip, true); 2220 std::vector<float> res = doSinusoidFitting(getSpectrum(whichrow), chanMask, nWaves, maxWaveLength, params, thresClip, nIterClip, getResidual); 2220 2221 setSpectrum(res, whichrow); 2221 2222 // 2222 2223 2223 std::vector<bool> fixed; 2224 fixed.clear(); 2225 outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "sinusoidBaseline()", pieceRanges, params, fixed); 2224 outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "sinusoidBaseline()", params); 2226 2225 } 2227 2226 … … 2229 2228 } 2230 2229 2231 void Scantable::autoSinusoidBaseline(const std::vector<bool>& mask, int nMinWavesInSW, int nMaxWavesInSW, float thresClip, int nIterClip, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool outLogger, const std::string& blfile)2230 void Scantable::autoSinusoidBaseline(const std::vector<bool>& mask, const std::vector<int>& nWaves, float maxWaveLength, float thresClip, int nIterClip, const std::vector<int>& edge, float threshold, int chanAvgLimit, bool getResidual, bool outLogger, const std::string& blfile) 2232 2231 { 2233 2232 ofstream ofs; 2234 String coordInfo ;2233 String coordInfo = ""; 2235 2234 bool hasSameNchan = true; 2236 2235 bool outTextFile = false; … … 2248 2247 2249 2248 //Fitter fitter = Fitter(); 2250 //fitter.setExpression("sinusoid", nMaxWavesInSW); 2249 //fitter.setExpression("sinusoid", nWaves); 2250 //fitter.setIterClipping(thresClip, nIterClip); 2251 2251 2252 2252 int nRow = nrow(); … … 2282 2282 2283 2283 2284 //fitBaseline(chanMask, whichrow, fitter , thresClip, nIterClip);2284 //fitBaseline(chanMask, whichrow, fitter); 2285 2285 //setSpectrum(fitter.getResidual(), whichrow); 2286 std::vector<int> pieceRanges;2287 2286 std::vector<float> params; 2288 std::vector<float> res = doSinusoidFitting(getSpectrum(whichrow), chanMask, n MinWavesInSW, nMaxWavesInSW, params, thresClip, nIterClip, true);2287 std::vector<float> res = doSinusoidFitting(getSpectrum(whichrow), chanMask, nWaves, maxWaveLength, params, thresClip, nIterClip, getResidual); 2289 2288 setSpectrum(res, whichrow); 2290 2289 // 2291 2290 2292 std::vector<bool> fixed; 2293 fixed.clear(); 2294 outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoSinusoidBaseline()", pieceRanges, params, fixed); 2291 outputFittingResult(outLogger, outTextFile, chanMask, whichrow, coordInfo, hasSameNchan, ofs, "autoSinusoidBaseline()", params); 2295 2292 } 2296 2293 … … 2298 2295 } 2299 2296 2300 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) { 2297 std::vector<float> Scantable::doSinusoidFitting(const std::vector<float>& data, const std::vector<bool>& mask, const std::vector<int>& waveNumbers, float maxWaveLength, std::vector<float>& params, float thresClip, int nIterClip, bool getResidual) 2298 { 2301 2299 if (data.size() != mask.size()) { 2302 throw(AipsError("data and mask have different size")); 2303 } 2304 if ((nMinWavesInSW < 0) || (nMaxWavesInSW < 0)) { 2300 throw(AipsError("data and mask sizes are not identical")); 2301 } 2302 if (data.size() < 2) { 2303 throw(AipsError("data size is too short")); 2304 } 2305 if (waveNumbers.size() == 0) { 2306 throw(AipsError("missing wave number info")); 2307 } 2308 std::vector<int> nWaves; // sorted and uniqued array of wave numbers 2309 nWaves.reserve(waveNumbers.size()); 2310 copy(waveNumbers.begin(), waveNumbers.end(), back_inserter(nWaves)); 2311 sort(nWaves.begin(), nWaves.end()); 2312 std::vector<int>::iterator end_it = unique(nWaves.begin(), nWaves.end()); 2313 nWaves.erase(end_it, nWaves.end()); 2314 2315 int minNWaves = nWaves[0]; 2316 if (minNWaves < 0) { 2305 2317 throw(AipsError("wave number must be positive or zero (i.e. constant)")); 2306 } else { 2307 if (nMaxWavesInSW < nMinWavesInSW) { 2308 int temp = nMaxWavesInSW; 2309 nMaxWavesInSW = nMinWavesInSW; 2310 nMinWavesInSW = temp; 2311 } 2312 } 2318 } 2319 bool hasConstantTerm = (minNWaves == 0); 2313 2320 2314 2321 int nChan = data.size(); … … 2322 2329 } 2323 2330 2324 int nData = x.size(); 2325 2326 std::vector<double> x1, x2, x3, z1, x1z1, x2z1, x3z1, r1; 2331 int initNData = x.size(); 2332 2333 int nData = initNData; 2334 int nDOF = nWaves.size() * 2 - (hasConstantTerm ? 1 : 0); //number of parameters to solve. 2335 2336 const double PI = 6.0 * asin(0.5); // PI (= 3.141592653...) 2337 double baseXFactor = 2.0*PI/(double)maxWaveLength/(double)(nChan-1); //the denominator (nChan-1) should be changed to (xdata[nChan-1]-xdata[0]) for accepting x-values given in velocity or frequency when this function is moved to fitter. 2338 2339 // xArray : contains elemental values for computing the least-square matrix. 2340 // xArray.size() is nDOF and xArray[*].size() is nChan. 2341 // Each xArray element are as follows: 2342 // xArray[0] = {1.0, 1.0, 1.0, ..., 1.0}, 2343 // xArray[2n-1] = {sin(nPI/L*x[0]), sin(nPI/L*x[1]), ..., sin(nPI/L*x[nChan])}, 2344 // xArray[2n] = {cos(nPI/L*x[0]), cos(nPI/L*x[1]), ..., cos(nPI/L*x[nChan])}, 2345 // where (1 <= n <= nMaxWavesInSW), 2346 // or, 2347 // xArray[2n-1] = {sin(wn[n]PI/L*x[0]), sin(wn[n]PI/L*x[1]), ..., sin(wn[n]PI/L*x[nChan])}, 2348 // xArray[2n] = {cos(wn[n]PI/L*x[0]), cos(wn[n]PI/L*x[1]), ..., cos(wn[n]PI/L*x[nChan])}, 2349 // where wn[n] denotes waveNumbers[n] (1 <= n <= waveNumbers.size()). 2350 std::vector<std::vector<double> > xArray; 2351 if (hasConstantTerm) { 2352 std::vector<double> xu; 2353 for (int j = 0; j < nChan; ++j) { 2354 xu.push_back(1.0); 2355 } 2356 xArray.push_back(xu); 2357 } 2358 for (uInt i = (hasConstantTerm ? 1 : 0); i < nWaves.size(); ++i) { 2359 double xFactor = baseXFactor*(double)nWaves[i]; 2360 std::vector<double> xs, xc; 2361 xs.clear(); 2362 xc.clear(); 2363 for (int j = 0; j < nChan; ++j) { 2364 xs.push_back(sin(xFactor*(double)j)); 2365 xc.push_back(cos(xFactor*(double)j)); 2366 } 2367 xArray.push_back(xs); 2368 xArray.push_back(xc); 2369 } 2370 2371 std::vector<double> z1, r1, residual; 2327 2372 for (int i = 0; i < nChan; ++i) { 2328 double di = (double)i; 2329 double dD = (double)data[i]; 2330 x1.push_back(di); 2331 x2.push_back(di*di); 2332 x3.push_back(di*di*di); 2333 z1.push_back(dD); 2334 x1z1.push_back(di*dD); 2335 x2z1.push_back(di*di*dD); 2336 x3z1.push_back(di*di*di*dD); 2373 z1.push_back((double)data[i]); 2337 2374 r1.push_back(0.0); 2338 } 2339 2340 int currentNData = nData; 2341 int nDOF = nMaxWavesInSW + 1; //number of parameters to solve. 2375 residual.push_back(0.0); 2376 } 2342 2377 2343 2378 for (int nClip = 0; nClip < nIterClip+1; ++nClip) { 2344 //xMatrix : horizontal concatenation of the least-sq. matrix (left) and an 2345 //identity matrix (right). 2346 //the right part is used to calculate the inverse matrix of the left part. 2379 // xMatrix : horizontal concatenation of 2380 // the least-sq. matrix (left) and an 2381 // identity matrix (right). 2382 // the right part is used to calculate the inverse matrix of the left part. 2347 2383 double xMatrix[nDOF][2*nDOF]; 2348 2384 double zMatrix[nDOF]; … … 2355 2391 } 2356 2392 2357 for (int i = 0; i < currentNData; ++i) { 2358 if (maskArray[i] == 0) continue; 2359 xMatrix[0][0] += 1.0; 2360 xMatrix[0][1] += x1[i]; 2361 xMatrix[0][2] += x2[i]; 2362 xMatrix[0][3] += x3[i]; 2363 xMatrix[1][1] += x2[i]; 2364 xMatrix[1][2] += x3[i]; 2365 xMatrix[1][3] += x2[i]*x2[i]; 2366 xMatrix[2][2] += x2[i]*x2[i]; 2367 xMatrix[2][3] += x3[i]*x2[i]; 2368 xMatrix[3][3] += x3[i]*x3[i]; 2369 zMatrix[0] += z1[i]; 2370 zMatrix[1] += x1z1[i]; 2371 zMatrix[2] += x2z1[i]; 2372 zMatrix[3] += x3z1[i]; 2393 for (int k = 0; k < nChan; ++k) { 2394 if (maskArray[k] == 0) continue; 2395 2396 for (int i = 0; i < nDOF; ++i) { 2397 for (int j = i; j < nDOF; ++j) { 2398 xMatrix[i][j] += xArray[i][k] * xArray[j][k]; 2399 } 2400 zMatrix[i] += z1[k] * xArray[i][k]; 2401 } 2373 2402 } 2374 2403 … … 2411 2440 } 2412 2441 //compute a vector y which consists of the coefficients of the sinusoids forming the 2413 //best-fit curves (a0, b0,a1,b1,...), namely, a* and b* are of sine and cosine functions,2414 // respectively.2442 //best-fit curves (a0,s1,c1,s2,c2,...), where a0 is constant and s* and c* are of sine 2443 //and cosine functions, respectively. 2415 2444 std::vector<double> y; 2445 params.clear(); 2416 2446 for (int i = 0; i < nDOF; ++i) { 2417 2447 y.push_back(0.0); … … 2419 2449 y[i] += xMatrix[i][nDOF+j]*zMatrix[j]; 2420 2450 } 2421 } 2422 2423 double a0 = y[0]; 2424 double a1 = y[1]; 2425 double a2 = y[2]; 2426 double a3 = y[3]; 2427 params.clear(); 2451 params.push_back(y[i]); 2452 } 2428 2453 2429 2454 for (int i = 0; i < nChan; ++i) { 2430 r1[i] = a0 + a1*x1[i] + a2*x2[i] + a3*x3[i]; 2431 } 2432 params.push_back(a0); 2433 params.push_back(a1); 2434 params.push_back(a2); 2435 params.push_back(a3); 2436 2455 r1[i] = y[0]; 2456 for (int j = 1; j < nDOF; ++j) { 2457 r1[i] += y[j]*xArray[j][i]; 2458 } 2459 residual[i] = z1[i] - r1[i]; 2460 } 2437 2461 2438 2462 if ((nClip == nIterClip) || (thresClip <= 0.0)) { 2439 2463 break; 2440 2464 } else { 2441 std::vector<double> rz;2442 2465 double stdDev = 0.0; 2443 2466 for (int i = 0; i < nChan; ++i) { 2444 double val = abs(r1[i] - z1[i]); 2445 rz.push_back(val); 2446 stdDev += val*val*(double)maskArray[i]; 2467 stdDev += residual[i]*residual[i]*(double)maskArray[i]; 2447 2468 } 2448 2469 stdDev = sqrt(stdDev/(double)nData); … … 2451 2472 int newNData = 0; 2452 2473 for (int i = 0; i < nChan; ++i) { 2453 if ( rz[i]>= thres) {2474 if (abs(residual[i]) >= thres) { 2454 2475 maskArray[i] = 0; 2455 2476 } … … 2458 2479 } 2459 2480 } 2460 if (newNData == currentNData) {2461 break; //no additional flag. finish iteration.2481 if (newNData == nData) { 2482 break; //no more flag to add. iteration stops. 2462 2483 } else { 2463 currentNData = newNData;2484 nData = newNData; 2464 2485 } 2465 2486 } … … 2469 2490 if (getResidual) { 2470 2491 for (int i = 0; i < nChan; ++i) { 2471 result.push_back((float) (z1[i] - r1[i]));2492 result.push_back((float)residual[i]); 2472 2493 } 2473 2494 } else { … … 2482 2503 void Scantable::fitBaseline(const std::vector<bool>& mask, int whichrow, Fitter& fitter) 2483 2504 { 2484 std::vector<double> abcsd= getAbcissa(whichrow);2485 std::vector<float> abc s;2486 for (uInt i = 0; i < abcsd.size(); ++i) {2487 abc s.push_back((float)abcsd[i]);2505 std::vector<double> dAbcissa = getAbcissa(whichrow); 2506 std::vector<float> abcissa; 2507 for (uInt i = 0; i < dAbcissa.size(); ++i) { 2508 abcissa.push_back((float)dAbcissa[i]); 2488 2509 } 2489 2510 std::vector<float> spec = getSpectrum(whichrow); 2490 2511 2491 fitter.setData(abc s, spec, mask);2512 fitter.setData(abcissa, spec, mask); 2492 2513 fitter.lfit(); 2493 2514 } … … 2552 2573 2553 2574 /* for cspline. will be merged once cspline is available in fitter (2011/3/10 WK) */ 2554 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 std::vector<bool>& fixed) {2575 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) { 2555 2576 if (outLogger || outTextFile) { 2556 2577 float rms = getRms(chanMask, whichrow); 2557 2578 String masklist = getMaskRangeList(chanMask, whichrow, coordInfo, hasSameNchan); 2579 std::vector<bool> fixed; 2580 fixed.clear(); 2558 2581 2559 2582 if (outLogger) { … … 2568 2591 2569 2592 /* for sinusoid. will be merged once sinusoid is available in fitter (2011/3/10 WK) */ 2570 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 std::vector<bool>& fixed) {2593 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) { 2571 2594 if (outLogger || outTextFile) { 2572 2595 float rms = getRms(chanMask, whichrow); 2573 2596 String masklist = getMaskRangeList(chanMask, whichrow, coordInfo, hasSameNchan); 2597 std::vector<bool> fixed; 2598 fixed.clear(); 2574 2599 2575 2600 if (outLogger) { -
branches/casa-prerelease/pre-asap/src/Scantable.h
r2065 r2082 522 522 const std::string& blfile=""); 523 523 void sinusoidBaseline(const std::vector<bool>& mask, 524 int nMinWavesInSW,525 int nMaxWavesInSW,524 const std::vector<int>& nWaves, 525 float maxWaveLength, 526 526 float thresClip, 527 527 int nIterClip, 528 bool getResidual=true, 528 529 bool outLogger=false, 529 530 const std::string& blfile=""); 530 531 void autoSinusoidBaseline(const std::vector<bool>& mask, 531 int nMinWavesInSW,532 int nMaxWavesInSW,532 const std::vector<int>& nWaves, 533 float maxWaveLength, 533 534 float thresClip, 534 535 int nIterClip, … … 536 537 float threshold=3.0, 537 538 int chanAvgLimit=1, 539 bool getResidual=true, 538 540 bool outLogger=false, 539 541 const std::string& blfile=""); … … 672 674 std::vector<float> doCubicSplineFitting(const std::vector<float>& data, 673 675 const std::vector<bool>& mask, 676 int nPiece, 674 677 std::vector<int>& idxEdge, 675 678 std::vector<float>& params, 676 int nPiece=2,677 679 float thresClip=3.0, 678 680 int nIterClip=1, … … 680 682 std::vector<float> doSinusoidFitting(const std::vector<float>& data, 681 683 const std::vector<bool>& mask, 682 int nMinWavesInSW,683 int nMaxWavesInSW,684 const std::vector<int>& waveNumbers, 685 float maxWaveLength, 684 686 std::vector<float>& params, 685 687 float thresClip=3.0, … … 698 700 //std::vector<bool> getCompositeChanMask(int whichrow, const std::vector<bool>& inMask, const std::vector<int>& edge, const int minEdgeSize, STLineFinder& lineFinder); 699 701 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); 700 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 std::vector<bool>& fixed);701 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 std::vector<bool>& fixed);702 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); 703 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); 702 704 703 705 void applyChanFlag( casa::uInt whichrow, const std::vector<bool>& msk, casa::uChar flagval); -
branches/casa-prerelease/pre-asap/src/ScantableWrapper.h
r2047 r2082 269 269 { table_->autoCubicSplineBaseline(mask, npiece, clipthresh, clipniter, edge, threshold, chan_avg_limit, outlog, blfile); } 270 270 271 void sinusoidBaseline(const std::vector<bool>& mask, int minnwave, int maxnwave, float clipthresh, int clipniter, bool outlog=false, const std::string& blfile="")272 { table_->sinusoidBaseline(mask, minnwave, maxnwave, clipthresh, clipniter, outlog, blfile); }273 274 void autoSinusoidBaseline(const std::vector<bool>& mask, int minnwave, int maxnwave, float clipthresh, int clipniter, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool outlog=false, const std::string& blfile="")275 { table_->autoSinusoidBaseline(mask, minnwave, maxnwave, clipthresh, clipniter, edge, threshold, chan_avg_limit, outlog, blfile); }271 void sinusoidBaseline(const std::vector<bool>& mask, const std::vector<int>& nwave, float maxwavelength, float clipthresh, int clipniter, bool getresidual=true, bool outlog=false, const std::string& blfile="") 272 { table_->sinusoidBaseline(mask, nwave, maxwavelength, clipthresh, clipniter, getresidual, outlog, blfile); } 273 274 void autoSinusoidBaseline(const std::vector<bool>& mask, const std::vector<int>& nwave, float maxwavelength, float clipthresh, int clipniter, const std::vector<int>& edge, float threshold=5.0, int chan_avg_limit=1, bool getresidual=true, bool outlog=false, const std::string& blfile="") 275 { table_->autoSinusoidBaseline(mask, nwave, maxwavelength, clipthresh, clipniter, edge, threshold, chan_avg_limit, getresidual, outlog, blfile); } 276 276 277 277 float getRms(const std::vector<bool>& mask, int whichrow)
Note:
See TracChangeset
for help on using the changeset viewer.