Changeset 330


Ignore:
Timestamp:
01/31/05 12:11:36 (19 years ago)
Author:
kil064
Message:

reqork frequency alignment to

  • only make the required numnber of aligners
  • write out a correct frequency table with new FreqIDs
Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMath.cc

    r317 r330  
    3232
    3333#include <casa/aips.h>
     34#include <casa/iostream.h>
     35#include <casa/iomanip.h>
    3436#include <casa/BasicSL/String.h>
    3537#include <casa/Arrays/IPosition.h>
     
    4244#include <casa/Arrays/MaskArrMath.h>
    4345#include <casa/Arrays/MaskArrLogi.h>
     46#include <casa/Arrays/Matrix.h>
    4447#include <casa/BasicMath/Math.h>
    4548#include <casa/Containers/Block.h>
     
    12601263   const uInt nChan = sh.nchan;
    12611264   const uInt nRows = in.nRow();
     1265   const uInt nIF = sh.nif;
    12621266
    12631267// Get Table reference
     
    12701274   ROScalarColumn<String> srcCol(tabIn, "SRCNAME");
    12711275   ROArrayColumn<uInt> fqIDCol(tabIn, "FREQID");
    1272 //
    12731276   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);
    12841283
    12851284// Get reference Epoch to time of first row or given String
     
    13001299   MPosition refPos = in.getAntennaPosition();
    13011300
    1302 // Get Frequency Table
    1303 
    1304    SDFrequencyTable fTab = in.getSDFreqTable();
    1305    const uInt nFreqIDs = fTab.length();
    1306 
    13071301// Create FrequencyAligner Block. One VA for each possible
    13081302// source/freqID combination
    13091303
    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   }
    13131328
    13141329// Interpolation method
     
    13201335
    13211336   SDMemTable* pTabOut = new SDMemTable(in,True);
     1337   pTabOut->putSDFreqTable(freqTabOut);
    13221338
    13231339// Loop over rows in Table
    13241340
     1341   Bool extrapolate=False;
    13251342   const IPosition polChanAxes(2, asap::PolAxis, asap::ChanAxis);
    1326 
    1327    Bool extrapolate=False;
    13281343   Bool useCachedAbcissa = False;
    13291344   Bool first = True;
     
    13311346   Vector<Float> yOut;
    13321347   Vector<Bool> maskOut;
     1348   Vector<uInt> freqID(nIF);
    13331349   uInt ifIdx, faIdx;
    13341350//
     
    13431359     MVEpoch mv2(tQ2);
    13441360     MEpoch epoch(mv2, epochRef);
    1345 
    1346 // Get FreqID vector.  One freqID per IF
    1347 
    1348      fqIDCol.get(iRow, freqID);
    13491361
    13501362// Get copy of data
     
    13591371// of polarization.  For all other axes (IF and BEAM) the abcissa
    13601372// 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.
    13651375
    13661376     ArrayIterator<Float> itValuesPlane(values, polChanAxes);
     
    13721382        const IPosition& pos = itValuesPlane.pos();
    13731383        ifIdx = pos(asap::IFAxis);
    1374         faIdx = (srcIdx[iRow]*nFreqIDs) + freqID[ifIdx];
     1384        faIdx = ddIdx(iRow,ifIdx);
    13751385//
    13761386        VectorIterator<Float> itValuesVec(itValuesPlane.array(), 1);
    13771387        VectorIterator<Bool> itMaskVec(itMaskPlane.array(), 1);
    1378 //
     1388
     1389// Iterate through the plane by vector and align
     1390
    13791391        first = True;
    13801392        useCachedAbcissa=False;
     
    13831395                                 itMaskVec.vector(), epoch, useCachedAbcissa,
    13841396                                 interp, extrapolate);
     1397//
    13851398           itValuesVec.vector() = yOut;
    13861399           itMaskVec.vector() = maskOut;
     
    14011414// cerr << "values out = " << values(IPosition(4,0,0,0,0),IPosition(4,0,0,0,9)) << endl;
    14021415
    1403 // Create and put back
     1416// Create SDContainer and put back
    14041417
    14051418    SDContainer sc = in.getSDContainer(iRow);
    14061419    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);
    14071425//
    14081426    pTabOut->putSDContainer(sc);
    14091427   }
    1410 
    1411 
    1412 // Write out correct frequency table information for output.
    1413 // CLone from input and overwrite
    1414 
    1415    SDFrequencyTable freqTab = in.getSDFreqTable();
    1416    freqTab.setLength(0);
    1417 
    1418 // Note that we don't have anyway to hold frequency table information
    1419 // in the SDMemTable which is source dependent.  Each FrequencyAligner
    1420 // is generated for an freqID/Source combination.  Don't know what to
    1421 // do about this apart from to pick the aligned SC from the first source
    1422 // at the moment.  ASAP really needs to handle data description id
    1423 // like in aips++ which is a combination of source and freqid. Otherwise
    1424 // all else I can do in this function is disallow multiple sources
    1425 
    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 Hz
    1434 
    1435          if (iSrc==0) {
    1436             SpectralCoordinate sC = a[idx]->alignedSpectralCoordinate(linear);
    1437             sC.setWorldAxisUnits(units);
    1438 
    1439 // Write out frequency table information to SDMemTable
    1440 
    1441             Int idx = freqTab.addFrequency(sC.referencePixel()[0],
    1442                                            sC.referenceValue()[0],
    1443                                            sC.increment()[0]);
    1444          }
    1445       }
    1446    }
    1447    pTabOut->putSDFreqTable(freqTab);
    14481428
    14491429// Now we must set the base and extra frames to the
     
    17571737
    17581738
    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
     1741void 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;
    17881762      }
    1789 
    1790 // Add new entry if not found
    1791 
    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 occurs
    1800       }
    1801 
    1802 // Set index for this row
    1803 
    1804       srcIdx[i] = idx;
    18051763   }
    18061764}
     
    18281786
    18291787void 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);
    18441800   }
    18451801}
  • trunk/src/SDMath.h

    r317 r330  
    4444class casa::MPosition;
    4545template<class T> class casa::PtrBlock;
     46template<class T> class casa::Matrix;
     47template<class T> class casa::ROScalarColumn;
     48template<class T> class casa::ROArrayColumn;
     49
    4650
    4751
     
    4953
    5054class SDMemTable;
     55class SDDataDesc;
    5156
    5257class SDMath {
     
    191196   casa::Table readAsciiFile (const casa::String& fileName) const;
    192197
    193 // Generate source table
    194    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 
    199198// Generate frequency aligners
    200199   void generateFrequencyAligners (casa::PtrBlock<casa::FrequencyAligner<casa::Float>* >& a,
     200                                   const SDDataDesc& dDesc,
    201201                                   const SDMemTable& in, casa::uInt nChan,
    202                                    casa::uInt nFreqIDs, casa::uInt nSrcTab,
    203                                    const casa::Vector<casa::uInt>& firstRow,
    204202                                   casa::MFrequency::Types system,
    205203                                   const casa::MPosition& refPos,
    206204                                   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;
    207214
    208215// Align in Frequency
     
    219226};
    220227
     228
     229
     230
    221231} // namespace
    222232
Note: See TracChangeset for help on using the changeset viewer.