Changeset 294


Ignore:
Timestamp:
01/25/05 14:56:37 (19 years ago)
Author:
kil064
Message:

move some code into function generateVelocityAligners
add arg. doTSys to binaryOperate and unaryOperate

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/SDMath.cc

    r292 r294  
    114114
    115115   std::vector<std::string> info = in.getCoordInfo();
     116
     117// Parse unit ("" means channels)
     118
    116119   String velUnit(info[0]);
    117120   if (velUnit.length()==0) {
     
    123126      }
    124127   }
    125 //
     128
     129// Parse doppler
     130
    126131   String dopplerStr(info[2]);
    127132   String velSystemStr(info[1]);
     
    130135      throw(AipsError("You have not set a velocity frame different from the initial - use function set_freqframe"));
    131136   }
    132 //
     137
     138// Parse frequency system
     139
    133140   MFrequency::Types velSystem;
    134141   MFrequency::getType(velSystem, velSystemStr);
     
    377384CountedPtr<SDMemTable> SDMath::binaryOperate (const CountedPtr<SDMemTable>& left,
    378385                                              const CountedPtr<SDMemTable>& right,
    379                                               const String& op, Bool preserve)  const
     386                                              const String& op, Bool preserve,
     387                                              Bool doTSys)  const
    380388{
    381389
     
    395403  } else if (op2=="QUOTIENT") {
    396404     what = 4;
     405     doTSys = True;
    397406  } else {
    398407    throw( AipsError("Unrecognized operation"));
     
    416425// TSys columns
    417426
    418   ROArrayColumn<Float> tSysLeft(tLeft, "TSYS");
    419   ROArrayColumn<Float> tSysRight(tRight, "TSYS");
     427  ROArrayColumn<Float> tSysLeftCol, tSysRightCol;
     428  if (doTSys) {
     429     tSysLeftCol.attach(tLeft, "TSYS");
     430     tSysRightCol.attach(tRight, "TSYS");
     431  }
    420432
    421433// First row for right
    422434
    423435  Array<Float> tSysLeftArr, tSysRightArr;
    424   tSysRight.get(0, tSysRightArr);
     436  if (doTSys) tSysRightCol.get(0, tSysRightArr);
    425437  MaskedArray<Float>* pMRight = new MaskedArray<Float>(right->rowAsMaskedArray(0));
    426438  IPosition shpRight = pMRight->shape();
     
    438450     MaskedArray<Float> mLeft(left->rowAsMaskedArray(i));
    439451     IPosition shpLeft = mLeft.shape();
    440      tSysLeft.get(i, tSysLeftArr);
     452     if (doTSys) tSysLeftCol.get(i, tSysLeftArr);
    441453//
    442454     if (nRowRight>1) {
     
    444456        pMRight = new MaskedArray<Float>(right->rowAsMaskedArray(i));
    445457        shpRight = pMRight->shape();
    446         tSysRight.get(i, tSysRightArr);
     458        if (doTSys) tSysRightCol.get(i, tSysRightArr);
    447459     }
    448460//
     
    450462        throw(AipsError("left and right scan tables are not conformant"));
    451463     }
    452      if (!tSysRightArr.shape().isEqual(tSysRightArr.shape())) {
    453         throw(AipsError("left and right Tsys data are not conformant"));
    454      }
    455      if (!shpRight.isEqual(tSysRightArr.shape())) {
    456         throw(AipsError("left and right scan tables are not conformant"));
     464     if (doTSys) {
     465        if (!tSysRightArr.shape().isEqual(tSysRightArr.shape())) {
     466           throw(AipsError("left and right Tsys data are not conformant"));
     467        }
     468        if (!shpRight.isEqual(tSysRightArr.shape())) {
     469           throw(AipsError("left and right scan tables are not conformant"));
     470        }
    457471     }
    458472
     
    466480        MaskedArray<Float> tmp = mLeft + *pMRight;
    467481        putDataInSDC(sc, tmp.getArray(), tmp.getMask());
    468         sc.putTsys(tSysLeftArr+tSysRightArr);
     482        if (doTSys) sc.putTsys(tSysLeftArr+tSysRightArr);
    469483     } else if (what==1) {
    470484        MaskedArray<Float> tmp = mLeft - *pMRight;
    471485        putDataInSDC(sc, tmp.getArray(), tmp.getMask());
    472         sc.putTsys(tSysLeftArr-tSysRightArr);
     486        if (doTSys) sc.putTsys(tSysLeftArr-tSysRightArr);
    473487     } else if (what==2) {
    474488        MaskedArray<Float> tmp = mLeft * *pMRight;
    475489        putDataInSDC(sc, tmp.getArray(), tmp.getMask());
    476         sc.putTsys(tSysLeftArr*tSysRightArr);
     490        if (doTSys) sc.putTsys(tSysLeftArr*tSysRightArr);
    477491     } else if (what==3) {
    478492        MaskedArray<Float> tmp = mLeft / *pMRight;
    479493        putDataInSDC(sc, tmp.getArray(), tmp.getMask());
    480         sc.putTsys(tSysLeftArr/tSysRightArr);
     494        if (doTSys) sc.putTsys(tSysLeftArr/tSysRightArr);
    481495     } else if (what==4) {
    482496        if (preserve) {     
     
    621635
    622636SDMemTable* SDMath::unaryOperate(const SDMemTable& in, Float val, Bool doAll,
    623                                  uInt what) const
     637                                 uInt what, Bool doTSys) const
    624638//
    625639// what = 0   Multiply
     
    628642   SDMemTable* pOut = new SDMemTable(in,False);
    629643   const Table& tOut = pOut->table();
    630    ArrayColumn<Float> spec(tOut,"SPECTRA"); 
     644   ArrayColumn<Float> specCol(tOut,"SPECTRA"); 
     645   ArrayColumn<Float> tSysCol(tOut,"TSYS"); 
     646   Array<Float> tSysArr;
    631647//
    632648   if (doAll) {
    633649      for (uInt i=0; i < tOut.nrow(); i++) {
     650
     651// Modify data
     652
    634653         MaskedArray<Float> dataIn(pOut->rowAsMaskedArray(i));
    635 //
    636654         if (what==0) {
    637655            dataIn  *= val;
     
    639657            dataIn += val;
    640658         }
    641 //
    642          spec.put(i, dataIn.getArray());
     659         specCol.put(i, dataIn.getArray());
     660
     661// Modify Tsys
     662
     663         if (doTSys) {
     664            tSysCol.get(i, tSysArr);
     665            if (what==0) {
     666               tSysArr *= val;
     667            } else if (what==1) {
     668               tSysArr += val;
     669            }
     670            tSysCol.put(i, tSysArr);
     671         }
    643672      }
    644673   } else {
     
    650679//
    651680      for (uInt i=0; i < tOut.nrow(); i++) {
     681
     682// Modify data
     683
    652684         MaskedArray<Float> dataIn(pOut->rowAsMaskedArray(i));
    653685         MaskedArray<Float> dataIn2 = dataIn(start,end);    // Reference
    654 //
    655686         if (what==0) {
    656687            dataIn2 *= val;
     
    658689            dataIn2 += val;
    659690         }
    660 //
    661          spec.put(i, dataIn.getArray());
     691         specCol.put(i, dataIn.getArray());
     692
     693// Modify Tsys
     694
     695         if (doTSys) {
     696            tSysCol.get(i, tSysArr);
     697            Array<Float> tSysArr2 = tSysArr(start,end);     // Reference
     698            if (what==0) {
     699               tSysArr2 *= val;
     700            } else if (what==1) {
     701               tSysArr2 += val;
     702            }
     703            tSysCol.put(i, tSysArr);
     704         }
    662705      }
    663706   }
     
    11181161// Get Columns from Table
    11191162
    1120   ROScalarColumn<Double> mjdCol(tabIn, "TIME");
    1121   ROScalarColumn<String> srcCol(tabIn, "SRCNAME");
    1122   ROArrayColumn<uInt> fqIDCol(tabIn, "FREQID");
    1123 //
    1124   Vector<Double> times = mjdCol.getColumn();
    1125   Vector<String> srcNames = srcCol.getColumn();
    1126   Vector<uInt> freqID;
     1163   ROScalarColumn<Double> mjdCol(tabIn, "TIME");
     1164   ROScalarColumn<String> srcCol(tabIn, "SRCNAME");
     1165   ROArrayColumn<uInt> fqIDCol(tabIn, "FREQID");
     1166//
     1167   Vector<Double> times = mjdCol.getColumn();
     1168   Vector<String> srcNames = srcCol.getColumn();
     1169   Vector<uInt> freqID;
    11271170
    11281171// Generate Source table
     
    11341177   cerr << "Found " << srcTab.nelements() << " sources to align " << endl;
    11351178
    1136 // Set reference Epoch to time of first row or given String
     1179// Get reference Epoch to time of first row or given String
    11371180
    11381181   Unit DAY(String("d"));
     
    11461189   cerr << "Aligning at reference Epoch " << formatEpoch(refEpoch) << endl;
    11471190
    1148 // Set Reference Position
     1191// Get Reference Position
    11491192
    11501193   MPosition refPos = in.getAntennaPosition();
     
    11591202
    11601203   PtrBlock<VelocityAligner<Float>* > vA(nFreqIDs*nSrcTab);
    1161    for (uInt fqID=0; fqID<nFreqIDs; fqID++) {
    1162       SpectralCoordinate sC = in.getSpectralCoordinate(fqID);
    1163       for (uInt iSrc=0; iSrc<nSrcTab; iSrc++) {
    1164          MDirection refDir = in.getDirection(firstRow[iSrc]);
    1165          uInt idx = (iSrc*nFreqIDs) + fqID;
    1166          vA[idx] = new VelocityAligner<Float>(sC, nChan, refEpoch, refDir, refPos,
    1167                                               velUnit, doppler, velSystem);
     1204   generateVelocityAligners (vA, in, nChan, nFreqIDs, nSrcTab, firstRow,
     1205                             velSystem, velUnit, doppler,  refPos, refEpoch);
     1206
     1207// New output Table
     1208
     1209   SDMemTable* pTabOut = new SDMemTable(in,True);
     1210
     1211// Loop over rows in Table
     1212
     1213   const IPosition polChanAxes(2, asap::PolAxis, asap::ChanAxis);
     1214   VelocityAligner<Float>::Method method = VelocityAligner<Float>::LINEAR;
     1215   Bool extrapolate=False;
     1216   Bool useCachedAbcissa = False;
     1217   Bool first = True;
     1218   Bool ok;
     1219   Vector<Float> yOut;
     1220   Vector<Bool> maskOut;
     1221   uInt ifIdx, vaIdx;
     1222//
     1223   for (uInt iRow=0; iRow<nRows; ++iRow) {
     1224      if (iRow%10==0) {
     1225         cerr << "Processing row " << iRow << endl;
    11681226      }
    1169    }
    1170 
    1171 // New output Table
    1172 
    1173    SDMemTable* pTabOut = new SDMemTable(in,True);
    1174 
    1175 // Loop over rows in Table
    1176 
    1177   const IPosition polChanAxes(2, asap::PolAxis, asap::ChanAxis);
    1178   VelocityAligner<Float>::Method method = VelocityAligner<Float>::LINEAR;
    1179   Bool extrapolate=False;
    1180   Bool useCachedAbcissa = False;
    1181   Bool first = True;
    1182   Bool ok;
    1183   Vector<Float> yOut;
    1184   Vector<Bool> maskOut;
    1185   uInt ifIdx, vaIdx;
    1186 //
    1187   for (uInt iRow=0; iRow<nRows; ++iRow) {
    1188      if (iRow%10==0) {
    1189         cerr << "Processing row " << iRow << endl;
    1190      }
    11911227
    11921228// Get EPoch
    11931229
    1194     Quantum<Double> tQ2(times[iRow],DAY);
    1195     MVEpoch mv2(tQ2);
    1196     MEpoch epoch(mv2, epochRef);
     1230     Quantum<Double> tQ2(times[iRow],DAY);
     1231     MVEpoch mv2(tQ2);
     1232     MEpoch epoch(mv2, epochRef);
    11971233
    11981234// Get FreqID vector.  One freqID per IF
    11991235
    1200     fqIDCol.get(iRow, freqID);
     1236     fqIDCol.get(iRow, freqID);
    12011237
    12021238// Get copy of data
    12031239   
    1204     const MaskedArray<Float>& mArrIn(in.rowAsMaskedArray(iRow));
    1205     Array<Float> values = mArrIn.getArray();
    1206     Array<Bool> mask = mArrIn.getMask();
     1240     const MaskedArray<Float>& mArrIn(in.rowAsMaskedArray(iRow));
     1241     Array<Float> values = mArrIn.getArray();
     1242     Array<Bool> mask = mArrIn.getMask();
    12071243
    12081244// cerr << "values in = " << values(IPosition(4,0,0,0,0),IPosition(4,0,0,0,9)) << endl;
     
    12161252// all beams get same position and velocoity abcissa.
    12171253
    1218     ArrayIterator<Float> itValuesPlane(values, polChanAxes);
    1219     ArrayIterator<Bool> itMaskPlane(mask, polChanAxes);
    1220     while (!itValuesPlane.pastEnd()) {
     1254     ArrayIterator<Float> itValuesPlane(values, polChanAxes);
     1255     ArrayIterator<Bool> itMaskPlane(mask, polChanAxes);
     1256     while (!itValuesPlane.pastEnd()) {
    12211257
    12221258// Find the IF index and then the VA PtrBlock index
    12231259
    1224        const IPosition& pos = itValuesPlane.pos();
    1225        ifIdx = pos(asap::IFAxis);
    1226        vaIdx = (srcIdx[iRow]*nFreqIDs) + freqID[ifIdx];
    1227 //
    1228        VectorIterator<Float> itValuesVec(itValuesPlane.array(), 1);
    1229        VectorIterator<Bool> itMaskVec(itMaskPlane.array(), 1);
    1230 //
    1231        first = True;
    1232        useCachedAbcissa=False;
    1233        while (!itValuesVec.pastEnd()) {     
    1234           ok = vA[vaIdx]->align (yOut, maskOut, itValuesVec.vector(),
    1235                                  itMaskVec.vector(), epoch, useCachedAbcissa,
    1236                                  method, extrapolate);
    1237           itValuesVec.vector() = yOut;
    1238           itMaskVec.vector() = maskOut;
    1239 //
    1240           itValuesVec.next();
    1241           itMaskVec.next();
    1242 //
    1243           if (first) {
    1244              useCachedAbcissa = True;
    1245              first = False;
    1246           }
    1247        }
     1260        const IPosition& pos = itValuesPlane.pos();
     1261        ifIdx = pos(asap::IFAxis);
     1262        vaIdx = (srcIdx[iRow]*nFreqIDs) + freqID[ifIdx];
     1263//
     1264        VectorIterator<Float> itValuesVec(itValuesPlane.array(), 1);
     1265        VectorIterator<Bool> itMaskVec(itMaskPlane.array(), 1);
     1266//
     1267        first = True;
     1268        useCachedAbcissa=False;
     1269        while (!itValuesVec.pastEnd()) {     
     1270           ok = vA[vaIdx]->align (yOut, maskOut, itValuesVec.vector(),
     1271                                  itMaskVec.vector(), epoch, useCachedAbcissa,
     1272                                  method, extrapolate);
     1273           itValuesVec.vector() = yOut;
     1274           itMaskVec.vector() = maskOut;
     1275//
     1276           itValuesVec.next();
     1277           itMaskVec.next();
     1278//
     1279           if (first) {
     1280              useCachedAbcissa = True;
     1281              first = False;
     1282           }
     1283        }
    12481284//
    12491285       itValuesPlane.next();
    12501286       itMaskPlane.next();
    1251     }
     1287     }
    12521288
    12531289// cerr << "values out = " << values(IPosition(4,0,0,0,0),IPosition(4,0,0,0,9)) << endl;
     
    12591295//
    12601296    pTabOut->putSDContainer(sc);
    1261   }
     1297   }
    12621298
    12631299// Clean up PointerBlock
     
    16281664}
    16291665
     1666
     1667void SDMath::generateVelocityAligners (PtrBlock<VelocityAligner<Float>* >& vA,
     1668                                       const SDMemTable& in, uInt nChan,
     1669                                       uInt nFreqIDs, uInt nSrcTab,
     1670                                       const Vector<uInt>& firstRow,
     1671                                       MFrequency::Types velSystem,
     1672                                       const String& velUnit,
     1673                                       MDoppler::Types doppler,
     1674                                       const MPosition& refPos,
     1675                                       const MEpoch& refEpoch) const
     1676{
     1677   for (uInt fqID=0; fqID<nFreqIDs; fqID++) {
     1678      SpectralCoordinate sC = in.getSpectralCoordinate(fqID);
     1679      for (uInt iSrc=0; iSrc<nSrcTab; iSrc++) {
     1680         MDirection refDir = in.getDirection(firstRow[iSrc]);
     1681         uInt idx = (iSrc*nFreqIDs) + fqID;
     1682         vA[idx] = new VelocityAligner<Float>(sC, nChan, refEpoch, refDir, refPos,
     1683                                              velUnit, doppler, velSystem);
     1684      }
     1685   }
     1686}
     1687
  • trunk/src/SDMath.h

    r272 r294  
    3636#include <casa/aips.h>
    3737#include <casa/Utilities/CountedPtr.h>
     38#include <coordinates/Coordinates/VelocityAligner.h>
     39
    3840#include "SDDefs.h"
    3941
    4042class casa::Table;
    4143class casa::MEpoch;
     44class casa::MPosition;
     45template<class T> class casa::PtrBlock;
     46//template<class T> class casa::VelocityAligner;
    4247
    4348
     
    6570   casa::CountedPtr<SDMemTable> binaryOperate (const casa::CountedPtr<SDMemTable>& left,
    6671                                               const casa::CountedPtr<SDMemTable>& right,
    67                                                const casa::String& op, casa::Bool preserve) const;
     72                                               const casa::String& op, casa::Bool preserve,
     73                                               casa::Bool tSys) const;
    6874
    6975// Average in time
     
    104110// Simple unary mathematical operations.  what=0 (mul) or 1 (add)
    105111   SDMemTable* unaryOperate(const SDMemTable& in, casa::Float offset,
    106                             casa::Bool doAll, casa::uInt what) const;
     112                            casa::Bool doAll, casa::uInt what, casa::Bool tSys) const;
    107113
    108114// Average polarizations
     
    184190                             const casa::Vector<casa::String>& srcNames) const;
    185191
     192// Generate velocity aligners
     193   void generateVelocityAligners (casa::PtrBlock<casa::VelocityAligner<casa::Float>* >& vA,
     194                                  const SDMemTable& in, casa::uInt nChan,
     195                                  casa::uInt nFreqIDs, casa::uInt nSrcTab,
     196                                  const casa::Vector<casa::uInt>& firstRow,
     197                                  casa::MFrequency::Types velSystem,
     198                                  const casa::String& velUnit,
     199                                  casa::MDoppler::Types doppler,
     200                                  const casa::MPosition& refPos,
     201                                  const casa::MEpoch& refEpoch) const;
     202
    186203// Align in Velocity
    187204   SDMemTable* velocityAlign (const SDMemTable& in,
Note: See TracChangeset for help on using the changeset viewer.