Changeset 262
- Timestamp:
- 01/22/05 17:37:42 (20 years ago)
- Location:
- trunk/src
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMath.cc
r248 r262 44 44 #include <casa/BasicMath/Math.h> 45 45 #include <casa/Containers/Block.h> 46 #include <casa/Exceptions.h> 47 #include <casa/Quanta/Quantum.h> 48 #include <casa/Quanta/Unit.h> 49 #include <casa/Quanta/MVEpoch.h> 46 50 #include <casa/Quanta/QC.h> 47 51 #include <casa/Utilities/Assert.h> 48 #include <casa/Exceptions.h> 52 53 #include <coordinates/Coordinates/SpectralCoordinate.h> 54 #include <coordinates/Coordinates/CoordinateSystem.h> 55 #include <coordinates/Coordinates/CoordinateUtil.h> 56 #include <coordinates/Coordinates/VelocityAligner.h> 57 58 #include <lattices/Lattices/LatticeUtilities.h> 59 #include <lattices/Lattices/RebinLattice.h> 60 61 #include <measures/Measures/MEpoch.h> 62 #include <measures/Measures/MDirection.h> 63 #include <measures/Measures/MPosition.h> 49 64 50 65 #include <scimath/Mathematics/VectorKernel.h> … … 58 73 #include <tables/Tables/ReadAsciiTable.h> 59 74 60 #include <lattices/Lattices/LatticeUtilities.h>61 #include <lattices/Lattices/RebinLattice.h>62 #include <coordinates/Coordinates/SpectralCoordinate.h>63 #include <coordinates/Coordinates/CoordinateSystem.h>64 #include <coordinates/Coordinates/CoordinateUtil.h>65 #include <coordinates/Coordinates/VelocityAligner.h>66 67 75 #include "MathUtils.h" 68 76 #include "SDDefs.h" … … 96 104 SDMath::~SDMath() 97 105 {;} 106 107 108 109 SDMemTable* SDMath::velocityAlignment (const SDMemTable& in) const 110 { 111 112 // Get velocity/frame info 113 114 std::vector<std::string> info = in.getCoordInfo(); 115 String velUnit(info[0]); 116 if (velUnit.length()==0) { 117 throw(AipsError("You have not set a velocity abcissa unit - use function set_unit")); 118 } else { 119 Unit velUnitU(velUnit); 120 if (velUnitU!=Unit(String("m/s"))) { 121 throw(AipsError("Specified abcissa unit is not consistent with km/s - use function set_unit")); 122 } 123 } 124 // 125 String dopplerStr(info[2]); 126 String velSystemStr(info[1]); 127 String velBaseSystemStr(info[3]); 128 if (velBaseSystemStr==velSystemStr) { 129 throw(AipsError("You have not set a velocity frame different from the initial - use function set_frame")); 130 } 131 132 cerr << "unit, frame, doppler, baseframe = " << velUnit << ", " << velSystemStr << ", " << 133 dopplerStr << ", " << velBaseSystemStr << endl; 134 // 135 MFrequency::Types velSystem; 136 MFrequency::getType(velSystem, velSystemStr); 137 MDoppler::Types doppler; 138 MDoppler::getType(doppler, dopplerStr); 139 140 // Get Header 141 142 SDHeader sh = in.getSDHeader(); 143 const uInt nChan = sh.nchan; 144 const uInt nRows = in.nRow(); 145 146 // Get Table reference 147 148 const Table& tabIn = in.table(); 149 150 // Get Columns from Table 151 152 ROScalarColumn<Double> mjdCol(tabIn, "TIME"); 153 ROScalarColumn<String> srcCol(tabIn, "SRCNAME"); 154 ROArrayColumn<uInt> fqIDCol(tabIn, "FREQID"); 155 // 156 Vector<Double> times = mjdCol.getColumn(); 157 Vector<String> srcNames = srcCol.getColumn(); 158 Vector<uInt> freqID; 159 160 // Generate Source table 161 162 Vector<String> srcTab; 163 Vector<uInt> srcIdx, firstRow; 164 generateSourceTable (srcTab, srcIdx, firstRow, srcNames); 165 const uInt nSrcTab = srcTab.nelements(); 166 /* 167 cerr << "source table = " << srcTab << endl; 168 cerr << "source idx = " << srcIdx << endl; 169 cerr << "first row = " << firstRow << endl; 170 */ 171 172 // Set reference Epoch to time of first row 173 174 MEpoch::Ref timeRef = MEpoch::Ref(in.getTimeReference()); 175 Unit DAY(String("d")); 176 Quantum<Double> tQ(times[0], DAY); 177 MVEpoch mve(tQ); 178 MEpoch refTime(mve, timeRef); 179 180 // Set Reference Position 181 182 Vector<Double> antPos = sh.antennaposition; 183 MVPosition mvpos(antPos[0], antPos[1], antPos[2]); 184 MPosition refPos(mvpos); 185 186 // Get Frequency Table 187 188 SDFrequencyTable fTab = in.getSDFreqTable(); 189 const uInt nFreqIDs = fTab.length(); 190 191 // Create VelocityAligner Block. One VA for each possible 192 // source/freqID combination 193 194 PtrBlock<VelocityAligner<Float>* > vA(nFreqIDs*nSrcTab); 195 for (uInt fqID=0; fqID<nFreqIDs; fqID++) { 196 SpectralCoordinate sC = in.getCoordinate(fqID); 197 for (uInt iSrc=0; iSrc<nSrcTab; iSrc++) { 198 MDirection refDir = in.getDirection(firstRow[iSrc]); 199 uInt idx = (iSrc*nFreqIDs) + fqID; 200 vA[idx] = new VelocityAligner<Float>(sC, nChan, refTime, refDir, refPos, 201 velUnit, doppler, velSystem); 202 } 203 } 204 205 // New output Table 206 207 SDMemTable* pTabOut = new SDMemTable(in,True); 208 209 // Loop over rows in Table 210 211 const IPosition polChanAxes(2, asap::PolAxis, asap::ChanAxis); 212 VelocityAligner<Float>::Method method = VelocityAligner<Float>::LINEAR; 213 Bool extrapolate=False; 214 Bool useCachedAbcissa = False; 215 Bool first = True; 216 Vector<Float> yOut; 217 Vector<Bool> maskOut; 218 // 219 for (uInt iRow=0; iRow<nRows; ++iRow) { 220 221 // Get EPoch 222 223 Quantum<Double> tQ2(times[iRow],DAY); 224 MVEpoch mv2(tQ2); 225 MEpoch epoch(mv2, timeRef); 226 227 // Get FreqID vector. One freqID per IF 228 229 fqIDCol.get(iRow, freqID); 230 231 // Get copy of data 232 233 const MaskedArray<Float>& mArrIn(in.rowAsMaskedArray(iRow)); 234 Array<Float> values = mArrIn.getArray(); 235 Array<Bool> mask = mArrIn.getMask(); 236 237 // cerr << "values in = " << values(IPosition(4,0,0,0,0),IPosition(4,0,0,0,9)) << endl; 238 239 // For each row, the Velocity abcissa will be the same regardless 240 // of polarization. For all other axes (IF and BEAM) the abcissa 241 // will change. So we iterate through the data by pol-chan planes 242 // to mimimize the work. At this point, I think the Direction 243 // is stored as the same for each beam. DOn't know where the 244 // offsets are or what to do about them right now. For now 245 // all beams get same position and velocoity abcissa. 246 247 ArrayIterator<Float> itValuesPlane(values, polChanAxes); 248 ArrayIterator<Bool> itMaskPlane(mask, polChanAxes); 249 while (!itValuesPlane.pastEnd()) { 250 251 // Find the IF index and then the VA PtrBlock index 252 253 const IPosition& pos = itValuesPlane.pos(); 254 uInt ifIdx = pos(asap::IFAxis); 255 uInt vaIdx = (srcIdx[iRow]*nFreqIDs) + freqID[ifIdx]; 256 //cerr << "VA idx = " << vaIdx << endl; 257 // 258 VectorIterator<Float> itValuesVec(itValuesPlane.array(), 1); 259 VectorIterator<Bool> itMaskVec(itMaskPlane.array(), 1); 260 // 261 first = True; 262 useCachedAbcissa=False; 263 while (!itValuesVec.pastEnd()) { 264 Bool ok = vA[vaIdx]->align (yOut, maskOut, itValuesVec.vector(), 265 itMaskVec.vector(), epoch, useCachedAbcissa, 266 method, extrapolate); 267 itValuesVec.vector() = yOut; 268 itMaskVec.vector() = maskOut; 269 // 270 itValuesVec.next(); 271 itMaskVec.next(); 272 // 273 if (first) { 274 useCachedAbcissa = True; 275 first = False; 276 } 277 } 278 // 279 itValuesPlane.next(); 280 itMaskPlane.next(); 281 } 282 283 // cerr << "values out = " << values(IPosition(4,0,0,0,0),IPosition(4,0,0,0,9)) << endl; 284 285 // Create and put back 286 287 SDContainer sc = in.getSDContainer(iRow); 288 putDataInSDC(sc, values, mask); 289 // 290 pTabOut->putSDContainer(sc); 291 } 292 293 // Clean up PointerBlock 294 295 for (uInt i=0; i<vA.nelements(); i++) delete vA[i]; 296 // 297 return pTabOut; 298 } 98 299 99 300 … … 197 398 String sourceName, oldSourceName, sourceNameStart; 198 399 Vector<uInt> freqID, freqIDStart, oldFreqID; 199 200 // Velocity Aligner. We need an aligner for each Direction and FreqID201 // combination. I don't think there is anyway to know how many202 // directions there are.203 // For now, assume all Tables have the same Frequency Table204 205 /*206 {207 MEpoch::Ref timeRef(MEpoch::UTC); // Should be in header208 MDirection::Types dirRef(MDirection::J2000); // Should be in header209 //210 SDHeader sh = in[0].getSDHeader();211 const uInt nChan = sh.nchan;212 //213 const SDFrequencyTable freqTab = in[0]->getSDFreqTable();214 const uInt nFreqID = freqTab.length();215 PtrBlock<const VelocityAligner<Float>* > vA(nFreqID);216 217 // Get first time from first table218 219 const Table& tabIn0 = in[0]->table();220 mjdCol.attach(tabIn0, "TIME");221 Double dTmp;222 mjdCol.get(0, dTmp);223 MVEpoch tmp2(Quantum<Double>(dTmp, Unit(String("d"))));224 MEpoch epoch(tmp2, timeRef);225 //226 for (uInt freqID=0; freqID<nFreqID; freqID++) {227 SpectralCoordinate sC = in[0]->getCoordinate(freqID);228 vA[freqID] = new VelocityAligner<Float>(sC, nChan, epoch, const MDirection& dir,229 const MPosition& pos, const String& velUnit,230 MDoppler::Types velType, MFrequency::Types velFreqSystem)231 }232 }233 */234 400 235 401 // Loop over tables … … 686 852 687 853 const uInt nRows = in.nRow(); 688 const uInt polAxis = asap::PolAxis; // Polarization axis689 const uInt chanAxis = asap::ChanAxis; // Spectrum axis690 854 691 855 // Create output Table and reshape number of polarizations … … 701 865 const IPosition& shapeIn = in.rowAsMaskedArray(0u, False).shape(); 702 866 IPosition shapeOut(shapeIn); 703 shapeOut( polAxis) = 1; // Average all polarizations704 // 705 const uInt nChan = shapeIn( chanAxis);867 shapeOut(asap::PolAxis) = 1; // Average all polarizations 868 // 869 const uInt nChan = shapeIn(asap::ChanAxis); 706 870 const IPosition vecShapeOut(4,1,1,1,nChan); // A multi-dim form of a Vector shape 707 871 IPosition start(4), end(4); … … 711 875 Array<Float> outData(shapeOut, 0.0); 712 876 Array<Bool> outMask(shapeOut, True); 713 const IPosition axes(2, 2, 3); // pol-channel plane877 const IPosition axes(2, asap::PolAxis, asap::ChanAxis); // pol-channel plane 714 878 // 715 const Bool useMask = (mask.nelements() == shapeIn( chanAxis));879 const Bool useMask = (mask.nelements() == shapeIn(asap::ChanAxis)); 716 880 717 881 // Loop over rows … … 787 951 start = pos; 788 952 end = pos; 789 end( chanAxis) = nChan-1;953 end(asap::ChanAxis) = nChan-1; 790 954 outData(start,end) = vecSum.getArray().reform(vecShapeOut); 791 955 outMask(start,end) = vecSum.getMask().reform(vecShapeOut); … … 854 1018 855 1019 const MaskedArray<Float>& dataIn(in.rowAsMaskedArray(ri)); 856 AlwaysAssert(dataIn.shape()( chanAxis)==nChan, AipsError);1020 AlwaysAssert(dataIn.shape()(asap::ChanAxis)==nChan, AipsError); 857 1021 // 858 1022 Array<Float> valuesIn = dataIn.getArray(); … … 886 1050 // Set multi-dim Vector shape 887 1051 888 shapeOut( chanAxis) = valuesIn.shape()(chanAxis);1052 shapeOut(asap::ChanAxis) = valuesIn.shape()(chanAxis); 889 1053 890 1054 // Stuff about with shapes so that we don't have conformance run-time errors … … 916 1080 return pTabOut; 917 1081 } 1082 918 1083 919 1084 … … 1438 1603 1439 1604 1605 void SDMath::generateSourceTable (Vector<String>& srcTab, 1606 Vector<uInt>& srcIdx, 1607 Vector<uInt>& firstRow, 1608 const Vector<String>& srcNames) const 1609 // 1610 // This algorithm assumes that if there are multiple beams 1611 // that the source names are diffent. Oterwise we would need 1612 // to look atthe direction for each beam... 1613 // 1614 { 1615 const uInt nRow = srcNames.nelements(); 1616 srcTab.resize(0); 1617 srcIdx.resize(nRow); 1618 firstRow.resize(0); 1619 // 1620 uInt nSrc = 0; 1621 for (uInt i=0; i<nRow; i++) { 1622 String srcName = srcNames[i]; 1623 1624 // Do we have this source already ? 1625 1626 Int idx = -1; 1627 if (nSrc>0) { 1628 for (uInt j=0; j<nSrc; j++) { 1629 if (srcName==srcTab[j]) { 1630 idx = j; 1631 break; 1632 } 1633 } 1634 } 1635 1636 // Add new entry if not found 1637 1638 if (idx==-1) { 1639 nSrc++; 1640 srcTab.resize(nSrc,True); 1641 srcTab(nSrc-1) = srcName; 1642 idx = nSrc-1; 1643 // 1644 firstRow.resize(nSrc,True); 1645 firstRow(nSrc-1) = i; // First row for which this source occurs 1646 } 1647 1648 // Set index for this row 1649 1650 srcIdx[i] = idx; 1651 } 1652 } -
trunk/src/SDMath.h
r248 r262 94 94 const casa::String& method, casa::Bool doAll) const; 95 95 96 // Velocity Alignment 97 SDMemTable* velocityAlignment (const SDMemTable& in) const; 98 96 99 // Opacity correction 97 100 SDMemTable* opacity (const SDMemTable& in, casa::Float tau, casa::Bool doAll) const; … … 169 172 casa::Bool doAll, const casa::Vector<casa::Float>& factor) const; 170 173 171 172 173 174 // Read ascii file into a Table 174 175 175 176 casa::Table readAsciiFile (const casa::String& fileName) const; 177 178 // Generate source table 179 void generateSourceTable (casa::Vector<casa::String>& srcTab, 180 casa::Vector<casa::uInt>& srcIdx, 181 casa::Vector<casa::uInt>& firstRow, 182 const casa::Vector<casa::String>& srcNames) const; 183 176 184 }; 177 185 -
trunk/src/SDMathWrapper.cc
r249 r262 228 228 } 229 229 230 SDMemTableWrapper SDMathWrapper::velocityAlignment (const SDMemTableWrapper& in) 231 { 232 const CountedPtr<SDMemTable>& pIn = in.getCP(); 233 SDMath sdm; 234 return CountedPtr<SDMemTable>(sdm.velocityAlignment(*pIn)); 235 } 236 230 237 void SDMathWrapper::opacityInSitu(SDMemTableWrapper& in, float tau, bool doAll) 231 238 { -
trunk/src/SDMathWrapper.h
r249 r262 84 84 const std::string& method, bool doAll); 85 85 86 // Apply velocity alignment 87 SDMemTableWrapper velocityAlignment(const SDMemTableWrapper& in); 88 86 89 // Apply opacity correction 87 90 void opacityInSitu (SDMemTableWrapper& in, float tau, bool doAll);
Note:
See TracChangeset
for help on using the changeset viewer.