Changeset 330
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMath.cc
r317 r330 32 32 33 33 #include <casa/aips.h> 34 #include <casa/iostream.h> 35 #include <casa/iomanip.h> 34 36 #include <casa/BasicSL/String.h> 35 37 #include <casa/Arrays/IPosition.h> … … 42 44 #include <casa/Arrays/MaskArrMath.h> 43 45 #include <casa/Arrays/MaskArrLogi.h> 46 #include <casa/Arrays/Matrix.h> 44 47 #include <casa/BasicMath/Math.h> 45 48 #include <casa/Containers/Block.h> … … 1260 1263 const uInt nChan = sh.nchan; 1261 1264 const uInt nRows = in.nRow(); 1265 const uInt nIF = sh.nif; 1262 1266 1263 1267 // Get Table reference … … 1270 1274 ROScalarColumn<String> srcCol(tabIn, "SRCNAME"); 1271 1275 ROArrayColumn<uInt> fqIDCol(tabIn, "FREQID"); 1272 //1273 1276 Vector<Double> times = mjdCol.getColumn(); 1274 Vector<String> srcNames = srcCol.getColumn(); 1275 Vector<uInt> freqID; 1276 1277 // Generate Source table 1278 1279 Vector<String> srcTab; 1280 Vector<uInt> srcIdx, firstRow; 1281 generateSourceTable (srcTab, srcIdx, firstRow, srcNames); 1282 const uInt nSrcTab = srcTab.nelements(); 1283 cerr << "Found " << srcTab.nelements() << " sources to align " << endl; 1277 1278 // Generate DataDesc table 1279 1280 Matrix<uInt> ddIdx; 1281 SDDataDesc dDesc; 1282 generateDataDescTable (ddIdx, dDesc, nIF, in, tabIn, srcCol, fqIDCol); 1284 1283 1285 1284 // Get reference Epoch to time of first row or given String … … 1300 1299 MPosition refPos = in.getAntennaPosition(); 1301 1300 1302 // Get Frequency Table1303 1304 SDFrequencyTable fTab = in.getSDFreqTable();1305 const uInt nFreqIDs = fTab.length();1306 1307 1301 // Create FrequencyAligner Block. One VA for each possible 1308 1302 // source/freqID combination 1309 1303 1310 PtrBlock<FrequencyAligner<Float>* > a(nFreqIDs*nSrcTab); 1311 generateFrequencyAligners (a, in, nChan, nFreqIDs, nSrcTab, firstRow, 1312 freqSystem, refPos, refEpoch); 1304 PtrBlock<FrequencyAligner<Float>* > a(dDesc.length()); 1305 generateFrequencyAligners (a, dDesc, in, nChan, freqSystem, refPos, refEpoch); 1306 1307 // Generate and fill output Frequency Tabke 1308 1309 SDFrequencyTable freqTabOut = in.getSDFreqTable(); 1310 freqTabOut.setLength(0); 1311 Vector<String> units(1); 1312 units = String("Hz"); 1313 Bool linear=True; 1314 // 1315 for (uInt i=0; i<dDesc.length(); i++) { 1316 1317 // Get Aligned SC in Hz 1318 1319 SpectralCoordinate sC = a[i]->alignedSpectralCoordinate(linear); 1320 sC.setWorldAxisUnits(units); 1321 1322 // Add FreqID 1323 1324 freqTabOut.addFrequency(sC.referencePixel()[0], 1325 sC.referenceValue()[0], 1326 sC.increment()[0]); 1327 } 1313 1328 1314 1329 // Interpolation method … … 1320 1335 1321 1336 SDMemTable* pTabOut = new SDMemTable(in,True); 1337 pTabOut->putSDFreqTable(freqTabOut); 1322 1338 1323 1339 // Loop over rows in Table 1324 1340 1341 Bool extrapolate=False; 1325 1342 const IPosition polChanAxes(2, asap::PolAxis, asap::ChanAxis); 1326 1327 Bool extrapolate=False;1328 1343 Bool useCachedAbcissa = False; 1329 1344 Bool first = True; … … 1331 1346 Vector<Float> yOut; 1332 1347 Vector<Bool> maskOut; 1348 Vector<uInt> freqID(nIF); 1333 1349 uInt ifIdx, faIdx; 1334 1350 // … … 1343 1359 MVEpoch mv2(tQ2); 1344 1360 MEpoch epoch(mv2, epochRef); 1345 1346 // Get FreqID vector. One freqID per IF1347 1348 fqIDCol.get(iRow, freqID);1349 1361 1350 1362 // Get copy of data … … 1359 1371 // of polarization. For all other axes (IF and BEAM) the abcissa 1360 1372 // will change. So we iterate through the data by pol-chan planes 1361 // to mimimize the work. At this point, I think the Direction 1362 // is stored as the same for each beam. DOn't know where the 1363 // offsets are or what to do about them right now. For now 1364 // all beams get same position and velocoity abcissa. 1373 // to mimimize the work. Probably won't work for multiple beams 1374 // at this point. 1365 1375 1366 1376 ArrayIterator<Float> itValuesPlane(values, polChanAxes); … … 1372 1382 const IPosition& pos = itValuesPlane.pos(); 1373 1383 ifIdx = pos(asap::IFAxis); 1374 faIdx = (srcIdx[iRow]*nFreqIDs) + freqID[ifIdx];1384 faIdx = ddIdx(iRow,ifIdx); 1375 1385 // 1376 1386 VectorIterator<Float> itValuesVec(itValuesPlane.array(), 1); 1377 1387 VectorIterator<Bool> itMaskVec(itMaskPlane.array(), 1); 1378 // 1388 1389 // Iterate through the plane by vector and align 1390 1379 1391 first = True; 1380 1392 useCachedAbcissa=False; … … 1383 1395 itMaskVec.vector(), epoch, useCachedAbcissa, 1384 1396 interp, extrapolate); 1397 // 1385 1398 itValuesVec.vector() = yOut; 1386 1399 itMaskVec.vector() = maskOut; … … 1401 1414 // cerr << "values out = " << values(IPosition(4,0,0,0,0),IPosition(4,0,0,0,9)) << endl; 1402 1415 1403 // Create and put back1416 // Create SDContainer and put back 1404 1417 1405 1418 SDContainer sc = in.getSDContainer(iRow); 1406 1419 putDataInSDC(sc, values, mask); 1420 for (uInt i=0; i<nIF; i++) { 1421 uInt idx = ddIdx(iRow,i); 1422 freqID(i) = dDesc.freqID(idx); 1423 } 1424 sc.putFreqMap(freqID); 1407 1425 // 1408 1426 pTabOut->putSDContainer(sc); 1409 1427 } 1410 1411 1412 // Write out correct frequency table information for output.1413 // CLone from input and overwrite1414 1415 SDFrequencyTable freqTab = in.getSDFreqTable();1416 freqTab.setLength(0);1417 1418 // Note that we don't have anyway to hold frequency table information1419 // in the SDMemTable which is source dependent. Each FrequencyAligner1420 // is generated for an freqID/Source combination. Don't know what to1421 // do about this apart from to pick the aligned SC from the first source1422 // at the moment. ASAP really needs to handle data description id1423 // like in aips++ which is a combination of source and freqid. Otherwise1424 // all else I can do in this function is disallow multiple sources1425 1426 Bool linear=True;1427 Vector<String> units(1);1428 units = String("Hz");1429 for (uInt fqID=0; fqID<nFreqIDs; fqID++) {1430 for (uInt iSrc=0; iSrc<nSrcTab; iSrc++) {1431 uInt idx = (iSrc*nFreqIDs) + fqID;1432 1433 // Get Aligned SC in Hz1434 1435 if (iSrc==0) {1436 SpectralCoordinate sC = a[idx]->alignedSpectralCoordinate(linear);1437 sC.setWorldAxisUnits(units);1438 1439 // Write out frequency table information to SDMemTable1440 1441 Int idx = freqTab.addFrequency(sC.referencePixel()[0],1442 sC.referenceValue()[0],1443 sC.increment()[0]);1444 }1445 }1446 }1447 pTabOut->putSDFreqTable(freqTab);1448 1428 1449 1429 // Now we must set the base and extra frames to the … … 1757 1737 1758 1738 1759 void SDMath::generateSourceTable (Vector<String>& srcTab, 1760 Vector<uInt>& srcIdx, 1761 Vector<uInt>& firstRow, 1762 const Vector<String>& srcNames) const 1763 // 1764 // This algorithm assumes that if there are multiple beams 1765 // that the source names are diffent. Oterwise we would need 1766 // to look atthe direction for each beam... 1767 // 1768 { 1769 const uInt nRow = srcNames.nelements(); 1770 srcTab.resize(0); 1771 srcIdx.resize(nRow); 1772 firstRow.resize(0); 1773 // 1774 uInt nSrc = 0; 1775 for (uInt i=0; i<nRow; i++) { 1776 String srcName = srcNames[i]; 1777 1778 // Do we have this source already ? 1779 1780 Int idx = -1; 1781 if (nSrc>0) { 1782 for (uInt j=0; j<nSrc; j++) { 1783 if (srcName==srcTab[j]) { 1784 idx = j; 1785 break; 1786 } 1787 } 1739 1740 1741 void SDMath::generateDataDescTable (Matrix<uInt>& ddIdx, 1742 SDDataDesc& dDesc, 1743 uInt nIF, 1744 const SDMemTable& in, 1745 const Table& tabIn, 1746 const ROScalarColumn<String>& srcCol, 1747 const ROArrayColumn<uInt>& fqIDCol) const 1748 { 1749 const uInt nRows = tabIn.nrow(); 1750 ddIdx.resize(nRows,nIF); 1751 // 1752 String srcName; 1753 Vector<uInt> freqIDs; 1754 for (uInt iRow=0; iRow<nRows; iRow++) { 1755 srcCol.get(iRow, srcName); 1756 fqIDCol.get(iRow, freqIDs); 1757 const MDirection& dir = in.getDirection(iRow); 1758 // 1759 for (uInt iIF=0; iIF<nIF; iIF++) { 1760 uInt idx = dDesc.addEntry(srcName, freqIDs[iIF], dir); 1761 ddIdx(iRow,iIF) = idx; 1788 1762 } 1789 1790 // Add new entry if not found1791 1792 if (idx==-1) {1793 nSrc++;1794 srcTab.resize(nSrc,True);1795 srcTab(nSrc-1) = srcName;1796 idx = nSrc-1;1797 //1798 firstRow.resize(nSrc,True);1799 firstRow(nSrc-1) = i; // First row for which this source occurs1800 }1801 1802 // Set index for this row1803 1804 srcIdx[i] = idx;1805 1763 } 1806 1764 } … … 1828 1786 1829 1787 void SDMath::generateFrequencyAligners (PtrBlock<FrequencyAligner<Float>* >& a, 1830 const SDMemTable& in, uInt nChan, 1831 uInt nFreqIDs, uInt nSrcTab, 1832 const Vector<uInt>& firstRow, 1833 MFrequency::Types system, 1834 const MPosition& refPos, 1835 const MEpoch& refEpoch) const 1836 { 1837 for (uInt fqID=0; fqID<nFreqIDs; fqID++) { 1838 SpectralCoordinate sC = in.getSpectralCoordinate(fqID); 1839 for (uInt iSrc=0; iSrc<nSrcTab; iSrc++) { 1840 MDirection refDir = in.getDirection(firstRow[iSrc]); 1841 uInt idx = (iSrc*nFreqIDs) + fqID; 1842 a[idx] = new FrequencyAligner<Float>(sC, nChan, refEpoch, refDir, refPos, system); 1843 } 1788 const SDDataDesc& dDesc, 1789 const SDMemTable& in, uInt nChan, 1790 MFrequency::Types system, 1791 const MPosition& refPos, 1792 const MEpoch& refEpoch) const 1793 { 1794 for (uInt i=0; i<dDesc.length(); i++) { 1795 uInt freqID = dDesc.freqID(i); 1796 const MDirection& refDir = dDesc.direction(i); 1797 // 1798 SpectralCoordinate sC = in.getSpectralCoordinate(freqID); 1799 a[i] = new FrequencyAligner<Float>(sC, nChan, refEpoch, refDir, refPos, system); 1844 1800 } 1845 1801 } -
trunk/src/SDMath.h
r317 r330 44 44 class casa::MPosition; 45 45 template<class T> class casa::PtrBlock; 46 template<class T> class casa::Matrix; 47 template<class T> class casa::ROScalarColumn; 48 template<class T> class casa::ROArrayColumn; 49 46 50 47 51 … … 49 53 50 54 class SDMemTable; 55 class SDDataDesc; 51 56 52 57 class SDMath { … … 191 196 casa::Table readAsciiFile (const casa::String& fileName) const; 192 197 193 // Generate source table194 void generateSourceTable (casa::Vector<casa::String>& srcTab,195 casa::Vector<casa::uInt>& srcIdx,196 casa::Vector<casa::uInt>& firstRow,197 const casa::Vector<casa::String>& srcNames) const;198 199 198 // Generate frequency aligners 200 199 void generateFrequencyAligners (casa::PtrBlock<casa::FrequencyAligner<casa::Float>* >& a, 200 const SDDataDesc& dDesc, 201 201 const SDMemTable& in, casa::uInt nChan, 202 casa::uInt nFreqIDs, casa::uInt nSrcTab,203 const casa::Vector<casa::uInt>& firstRow,204 202 casa::MFrequency::Types system, 205 203 const casa::MPosition& refPos, 206 204 const casa::MEpoch& refEpoch) const; 205 206 // Generate data description table (combines source and freqID) 207 void generateDataDescTable (casa::Matrix<casa::uInt>& ddIdx, 208 SDDataDesc& dDesc, 209 casa::uInt nIF, 210 const SDMemTable& in, 211 const casa::Table& tabIn, 212 const casa::ROScalarColumn<casa::String>& srcCol, 213 const casa::ROArrayColumn<casa::uInt>& fqIDCol) const; 207 214 208 215 // Align in Frequency … … 219 226 }; 220 227 228 229 230 221 231 } // namespace 222 232
Note:
See TracChangeset
for help on using the changeset viewer.