Changeset 267
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/SDMath.cc
r262 r267 110 110 { 111 111 112 // Get velocity/frame info 112 // Get velocity/frame info from Table 113 113 114 114 std::vector<std::string> info = in.getCoordInfo(); … … 127 127 String velBaseSystemStr(info[3]); 128 128 if (velBaseSystemStr==velSystemStr) { 129 throw(AipsError("You have not set a velocity frame different from the initial - use function set_fr ame"));129 throw(AipsError("You have not set a velocity frame different from the initial - use function set_freqframe")); 130 130 } 131 132 cerr << "unit, frame, doppler, baseframe = " << velUnit << ", " << velSystemStr << ", " <<133 dopplerStr << ", " << velBaseSystemStr << endl;134 131 // 135 132 MFrequency::Types velSystem; … … 138 135 MDoppler::getType(doppler, dopplerStr); 139 136 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 } 137 // Decide on alignment Epoch 138 139 // Do it 140 141 return velocityAlign (in, velSystem, velUnit, doppler); 142 } 143 299 144 300 145 … … 1306 1151 // 'private' functions 1307 1152 1153 SDMemTable* SDMath::velocityAlign (const SDMemTable& in, 1154 MFrequency::Types velSystem, 1155 const String& velUnit, 1156 MDoppler::Types doppler) const 1157 { 1158 // Get Header 1159 1160 SDHeader sh = in.getSDHeader(); 1161 const uInt nChan = sh.nchan; 1162 const uInt nRows = in.nRow(); 1163 1164 // Get Table reference 1165 1166 const Table& tabIn = in.table(); 1167 1168 // Get Columns from Table 1169 1170 ROScalarColumn<Double> mjdCol(tabIn, "TIME"); 1171 ROScalarColumn<String> srcCol(tabIn, "SRCNAME"); 1172 ROArrayColumn<uInt> fqIDCol(tabIn, "FREQID"); 1173 // 1174 Vector<Double> times = mjdCol.getColumn(); 1175 Vector<String> srcNames = srcCol.getColumn(); 1176 Vector<uInt> freqID; 1177 1178 // Generate Source table 1179 1180 Vector<String> srcTab; 1181 Vector<uInt> srcIdx, firstRow; 1182 generateSourceTable (srcTab, srcIdx, firstRow, srcNames); 1183 const uInt nSrcTab = srcTab.nelements(); 1184 cerr << "Found " << srcTab.nelements() << " sources to align " << endl; 1185 /* 1186 cerr << "source table = " << srcTab << endl; 1187 cerr << "source idx = " << srcIdx << endl; 1188 cerr << "first row = " << firstRow << endl; 1189 */ 1190 1191 // Set reference Epoch to time of first row 1192 1193 MEpoch::Ref timeRef = MEpoch::Ref(in.getTimeReference()); 1194 Unit DAY(String("d")); 1195 Quantum<Double> tQ(times[0], DAY); 1196 MVEpoch mve(tQ); 1197 MEpoch refTime(mve, timeRef); 1198 1199 // Set Reference Position 1200 1201 Vector<Double> antPos = sh.antennaposition; 1202 MVPosition mvpos(antPos[0], antPos[1], antPos[2]); 1203 MPosition refPos(mvpos); 1204 1205 // Get Frequency Table 1206 1207 SDFrequencyTable fTab = in.getSDFreqTable(); 1208 const uInt nFreqIDs = fTab.length(); 1209 1210 // Create VelocityAligner Block. One VA for each possible 1211 // source/freqID combination 1212 1213 PtrBlock<VelocityAligner<Float>* > vA(nFreqIDs*nSrcTab); 1214 for (uInt fqID=0; fqID<nFreqIDs; fqID++) { 1215 SpectralCoordinate sC = in.getCoordinate(fqID); 1216 for (uInt iSrc=0; iSrc<nSrcTab; iSrc++) { 1217 MDirection refDir = in.getDirection(firstRow[iSrc]); 1218 uInt idx = (iSrc*nFreqIDs) + fqID; 1219 vA[idx] = new VelocityAligner<Float>(sC, nChan, refTime, refDir, refPos, 1220 velUnit, doppler, velSystem); 1221 } 1222 } 1223 1224 // New output Table 1225 1226 SDMemTable* pTabOut = new SDMemTable(in,True); 1227 1228 // Loop over rows in Table 1229 1230 const IPosition polChanAxes(2, asap::PolAxis, asap::ChanAxis); 1231 VelocityAligner<Float>::Method method = VelocityAligner<Float>::LINEAR; 1232 Bool extrapolate=False; 1233 Bool useCachedAbcissa = False; 1234 Bool first = True; 1235 Bool ok; 1236 Vector<Float> yOut; 1237 Vector<Bool> maskOut; 1238 uInt ifIdx, vaIdx; 1239 // 1240 for (uInt iRow=0; iRow<nRows; ++iRow) { 1241 if (iRow%10==0) { 1242 cerr << "Processing row " << iRow << endl; 1243 } 1244 1245 // Get EPoch 1246 1247 Quantum<Double> tQ2(times[iRow],DAY); 1248 MVEpoch mv2(tQ2); 1249 MEpoch epoch(mv2, timeRef); 1250 1251 // Get FreqID vector. One freqID per IF 1252 1253 fqIDCol.get(iRow, freqID); 1254 1255 // Get copy of data 1256 1257 const MaskedArray<Float>& mArrIn(in.rowAsMaskedArray(iRow)); 1258 Array<Float> values = mArrIn.getArray(); 1259 Array<Bool> mask = mArrIn.getMask(); 1260 1261 // cerr << "values in = " << values(IPosition(4,0,0,0,0),IPosition(4,0,0,0,9)) << endl; 1262 1263 // For each row, the Velocity abcissa will be the same regardless 1264 // of polarization. For all other axes (IF and BEAM) the abcissa 1265 // will change. So we iterate through the data by pol-chan planes 1266 // to mimimize the work. At this point, I think the Direction 1267 // is stored as the same for each beam. DOn't know where the 1268 // offsets are or what to do about them right now. For now 1269 // all beams get same position and velocoity abcissa. 1270 1271 ArrayIterator<Float> itValuesPlane(values, polChanAxes); 1272 ArrayIterator<Bool> itMaskPlane(mask, polChanAxes); 1273 while (!itValuesPlane.pastEnd()) { 1274 1275 // Find the IF index and then the VA PtrBlock index 1276 1277 const IPosition& pos = itValuesPlane.pos(); 1278 ifIdx = pos(asap::IFAxis); 1279 vaIdx = (srcIdx[iRow]*nFreqIDs) + freqID[ifIdx]; 1280 // 1281 VectorIterator<Float> itValuesVec(itValuesPlane.array(), 1); 1282 VectorIterator<Bool> itMaskVec(itMaskPlane.array(), 1); 1283 // 1284 first = True; 1285 useCachedAbcissa=False; 1286 while (!itValuesVec.pastEnd()) { 1287 ok = vA[vaIdx]->align (yOut, maskOut, itValuesVec.vector(), 1288 itMaskVec.vector(), epoch, useCachedAbcissa, 1289 method, extrapolate); 1290 itValuesVec.vector() = yOut; 1291 itMaskVec.vector() = maskOut; 1292 // 1293 itValuesVec.next(); 1294 itMaskVec.next(); 1295 // 1296 if (first) { 1297 useCachedAbcissa = True; 1298 first = False; 1299 } 1300 } 1301 // 1302 itValuesPlane.next(); 1303 itMaskPlane.next(); 1304 } 1305 1306 // cerr << "values out = " << values(IPosition(4,0,0,0,0),IPosition(4,0,0,0,9)) << endl; 1307 1308 // Create and put back 1309 1310 SDContainer sc = in.getSDContainer(iRow); 1311 putDataInSDC(sc, values, mask); 1312 // 1313 pTabOut->putSDContainer(sc); 1314 } 1315 1316 // Clean up PointerBlock 1317 1318 for (uInt i=0; i<vA.nelements(); i++) delete vA[i]; 1319 // 1320 return pTabOut; 1321 } 1322 1323 1308 1324 void SDMath::fillSDC(SDContainer& sc, 1309 1325 const Array<Bool>& mask, -
trunk/src/SDMath.h
r262 r267 182 182 const casa::Vector<casa::String>& srcNames) const; 183 183 184 // Align in Velocity 185 SDMemTable* velocityAlign (const SDMemTable& in, 186 casa::MFrequency::Types velSystem, 187 const casa::String& velUnit, 188 casa::MDoppler::Types doppler) const; 184 189 }; 185 190
Note:
See TracChangeset
for help on using the changeset viewer.