Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMath.cc
r292 r294 114 114 115 115 std::vector<std::string> info = in.getCoordInfo(); 116 117 // Parse unit ("" means channels) 118 116 119 String velUnit(info[0]); 117 120 if (velUnit.length()==0) { … … 123 126 } 124 127 } 125 // 128 129 // Parse doppler 130 126 131 String dopplerStr(info[2]); 127 132 String velSystemStr(info[1]); … … 130 135 throw(AipsError("You have not set a velocity frame different from the initial - use function set_freqframe")); 131 136 } 132 // 137 138 // Parse frequency system 139 133 140 MFrequency::Types velSystem; 134 141 MFrequency::getType(velSystem, velSystemStr); … … 377 384 CountedPtr<SDMemTable> SDMath::binaryOperate (const CountedPtr<SDMemTable>& left, 378 385 const CountedPtr<SDMemTable>& right, 379 const String& op, Bool preserve) const 386 const String& op, Bool preserve, 387 Bool doTSys) const 380 388 { 381 389 … … 395 403 } else if (op2=="QUOTIENT") { 396 404 what = 4; 405 doTSys = True; 397 406 } else { 398 407 throw( AipsError("Unrecognized operation")); … … 416 425 // TSys columns 417 426 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 } 420 432 421 433 // First row for right 422 434 423 435 Array<Float> tSysLeftArr, tSysRightArr; 424 tSysRight.get(0, tSysRightArr);436 if (doTSys) tSysRightCol.get(0, tSysRightArr); 425 437 MaskedArray<Float>* pMRight = new MaskedArray<Float>(right->rowAsMaskedArray(0)); 426 438 IPosition shpRight = pMRight->shape(); … … 438 450 MaskedArray<Float> mLeft(left->rowAsMaskedArray(i)); 439 451 IPosition shpLeft = mLeft.shape(); 440 tSysLeft.get(i, tSysLeftArr);452 if (doTSys) tSysLeftCol.get(i, tSysLeftArr); 441 453 // 442 454 if (nRowRight>1) { … … 444 456 pMRight = new MaskedArray<Float>(right->rowAsMaskedArray(i)); 445 457 shpRight = pMRight->shape(); 446 tSysRight.get(i, tSysRightArr);458 if (doTSys) tSysRightCol.get(i, tSysRightArr); 447 459 } 448 460 // … … 450 462 throw(AipsError("left and right scan tables are not conformant")); 451 463 } 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 } 457 471 } 458 472 … … 466 480 MaskedArray<Float> tmp = mLeft + *pMRight; 467 481 putDataInSDC(sc, tmp.getArray(), tmp.getMask()); 468 sc.putTsys(tSysLeftArr+tSysRightArr);482 if (doTSys) sc.putTsys(tSysLeftArr+tSysRightArr); 469 483 } else if (what==1) { 470 484 MaskedArray<Float> tmp = mLeft - *pMRight; 471 485 putDataInSDC(sc, tmp.getArray(), tmp.getMask()); 472 sc.putTsys(tSysLeftArr-tSysRightArr);486 if (doTSys) sc.putTsys(tSysLeftArr-tSysRightArr); 473 487 } else if (what==2) { 474 488 MaskedArray<Float> tmp = mLeft * *pMRight; 475 489 putDataInSDC(sc, tmp.getArray(), tmp.getMask()); 476 sc.putTsys(tSysLeftArr*tSysRightArr);490 if (doTSys) sc.putTsys(tSysLeftArr*tSysRightArr); 477 491 } else if (what==3) { 478 492 MaskedArray<Float> tmp = mLeft / *pMRight; 479 493 putDataInSDC(sc, tmp.getArray(), tmp.getMask()); 480 sc.putTsys(tSysLeftArr/tSysRightArr);494 if (doTSys) sc.putTsys(tSysLeftArr/tSysRightArr); 481 495 } else if (what==4) { 482 496 if (preserve) { … … 621 635 622 636 SDMemTable* SDMath::unaryOperate(const SDMemTable& in, Float val, Bool doAll, 623 uInt what ) const637 uInt what, Bool doTSys) const 624 638 // 625 639 // what = 0 Multiply … … 628 642 SDMemTable* pOut = new SDMemTable(in,False); 629 643 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; 631 647 // 632 648 if (doAll) { 633 649 for (uInt i=0; i < tOut.nrow(); i++) { 650 651 // Modify data 652 634 653 MaskedArray<Float> dataIn(pOut->rowAsMaskedArray(i)); 635 //636 654 if (what==0) { 637 655 dataIn *= val; … … 639 657 dataIn += val; 640 658 } 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 } 643 672 } 644 673 } else { … … 650 679 // 651 680 for (uInt i=0; i < tOut.nrow(); i++) { 681 682 // Modify data 683 652 684 MaskedArray<Float> dataIn(pOut->rowAsMaskedArray(i)); 653 685 MaskedArray<Float> dataIn2 = dataIn(start,end); // Reference 654 //655 686 if (what==0) { 656 687 dataIn2 *= val; … … 658 689 dataIn2 += val; 659 690 } 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 } 662 705 } 663 706 } … … 1118 1161 // Get Columns from Table 1119 1162 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; 1127 1170 1128 1171 // Generate Source table … … 1134 1177 cerr << "Found " << srcTab.nelements() << " sources to align " << endl; 1135 1178 1136 // Set reference Epoch to time of first row or given String1179 // Get reference Epoch to time of first row or given String 1137 1180 1138 1181 Unit DAY(String("d")); … … 1146 1189 cerr << "Aligning at reference Epoch " << formatEpoch(refEpoch) << endl; 1147 1190 1148 // Set Reference Position1191 // Get Reference Position 1149 1192 1150 1193 MPosition refPos = in.getAntennaPosition(); … … 1159 1202 1160 1203 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; 1168 1226 } 1169 }1170 1171 // New output Table1172 1173 SDMemTable* pTabOut = new SDMemTable(in,True);1174 1175 // Loop over rows in Table1176 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 }1191 1227 1192 1228 // Get EPoch 1193 1229 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); 1197 1233 1198 1234 // Get FreqID vector. One freqID per IF 1199 1235 1200 fqIDCol.get(iRow, freqID);1236 fqIDCol.get(iRow, freqID); 1201 1237 1202 1238 // Get copy of data 1203 1239 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(); 1207 1243 1208 1244 // cerr << "values in = " << values(IPosition(4,0,0,0,0),IPosition(4,0,0,0,9)) << endl; … … 1216 1252 // all beams get same position and velocoity abcissa. 1217 1253 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()) { 1221 1257 1222 1258 // Find the IF index and then the VA PtrBlock index 1223 1259 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 } 1248 1284 // 1249 1285 itValuesPlane.next(); 1250 1286 itMaskPlane.next(); 1251 }1287 } 1252 1288 1253 1289 // cerr << "values out = " << values(IPosition(4,0,0,0,0),IPosition(4,0,0,0,9)) << endl; … … 1259 1295 // 1260 1296 pTabOut->putSDContainer(sc); 1261 }1297 } 1262 1298 1263 1299 // Clean up PointerBlock … … 1628 1664 } 1629 1665 1666 1667 void 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 36 36 #include <casa/aips.h> 37 37 #include <casa/Utilities/CountedPtr.h> 38 #include <coordinates/Coordinates/VelocityAligner.h> 39 38 40 #include "SDDefs.h" 39 41 40 42 class casa::Table; 41 43 class casa::MEpoch; 44 class casa::MPosition; 45 template<class T> class casa::PtrBlock; 46 //template<class T> class casa::VelocityAligner; 42 47 43 48 … … 65 70 casa::CountedPtr<SDMemTable> binaryOperate (const casa::CountedPtr<SDMemTable>& left, 66 71 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; 68 74 69 75 // Average in time … … 104 110 // Simple unary mathematical operations. what=0 (mul) or 1 (add) 105 111 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; 107 113 108 114 // Average polarizations … … 184 190 const casa::Vector<casa::String>& srcNames) const; 185 191 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 186 203 // Align in Velocity 187 204 SDMemTable* velocityAlign (const SDMemTable& in,
Note:
See TracChangeset
for help on using the changeset viewer.