Commits

Sandra Castro authored d8019f815f2 Merge
Merge pull request #464 in CASA/casa from bugfix/CAS-11269 to master

* commit '87267f55b38ad3063bdcdc359606a88acdfc063f': clarify description of usewtspectrum (add SIGMA_SPECTRUM), re CAS-11269 add test for usewtspectrum on/off when no input WEIGHT_SPECTRUM available, re CAS-11269 update description of parameter usewtspectrum, re CAS-11269 check earlier if input wtspectrum present, fix logic, prevent potential crashes, re CAS-11269 pass create-sigma_spectrum flag to MSTransformDataHandler::setupMS, re CAS-11269

code/mstransform/MSTransform/MSTransformDataHandler.cc

Modified
30 30 using namespace casacore;
31 31 namespace casa { //# NAMESPACE CASA - BEGIN
32 32
33 33 /////////////////////////////////////////////
34 34 /// MSTransformDataHandler implementation ///
35 35 /////////////////////////////////////////////
36 36
37 37 // -----------------------------------------------------------------------
38 38 //
39 39 // -----------------------------------------------------------------------
40 -MSTransformDataHandler::MSTransformDataHandler( String& theMS, Table::TableOption option,
41 - Bool virtualModelCol,Bool virtualCorrectedCol,
42 - Bool reindex) :
40 + MSTransformDataHandler::MSTransformDataHandler(const String& theMS, Table::TableOption option,
41 + Bool virtualModelCol,Bool virtualCorrectedCol,
42 + Bool reindex) :
43 43 ms_p(MeasurementSet(theMS, option)),
44 44 mssel_p(ms_p),
45 45 msc_p(NULL),
46 46 mscIn_p(NULL),
47 47 keepShape_p(true),
48 48 antennaSel_p(false),
49 49 timeBin_p(-1.0),
50 50 scanString_p(""),
51 51 intentString_p(""),
52 52 obsString_p(""),
61 61 virtualModelCol_p(virtualModelCol),
62 62 virtualCorrectedCol_p(virtualCorrectedCol),
63 63 reindex_p(reindex)
64 64 {
65 65 return;
66 66 }
67 67
68 68 // -----------------------------------------------------------------------
69 69 //
70 70 // -----------------------------------------------------------------------
71 -MSTransformDataHandler::MSTransformDataHandler( MeasurementSet& ms,
72 - Bool virtualModelCol,Bool virtualCorrectedCol,
73 - Bool reindex) :
71 +MSTransformDataHandler::MSTransformDataHandler(const MeasurementSet& ms,
72 + Bool virtualModelCol,Bool virtualCorrectedCol,
73 + Bool reindex) :
74 74 ms_p(ms),
75 75 mssel_p(ms_p),
76 76 msc_p(NULL),
77 77 mscIn_p(NULL),
78 78 keepShape_p(true),
79 79 antennaSel_p(false),
80 80 timeBin_p(-1.0),
81 81 scanString_p(""),
82 82 intentString_p(""),
83 83 obsString_p(""),
769 769 // -----------------------------------------------------------------------
770 770 void MSTransformDataHandler::selectTime(Double timeBin, String timerng)
771 771 {
772 772 timeBin_p = timeBin;
773 773 timeRange_p = timerng;
774 774 }
775 775
776 776 // -----------------------------------------------------------------------
777 777 //
778 778 // -----------------------------------------------------------------------
779 -Bool MSTransformDataHandler::makeMSBasicStructure( String& msname,
780 - String& colname,
781 - const Vector<Int>& tileShape,
782 - const String& combine,
783 - Table::TableOption option)
779 +Bool MSTransformDataHandler::makeMSBasicStructure(String& msname,
780 + String& colname,
781 + casacore::Bool createWeightSpectrumCols,
782 + const Vector<Int>& tileShape,
783 + const String& combine,
784 + Table::TableOption option)
784 785 {
785 786 LogIO os(LogOrigin("MSTransformDataHandler", __FUNCTION__));
787 + os << LogIO::DEBUG1 << "Preparing to setup output MS with createWeightSpectrumCols: "
788 + << createWeightSpectrumCols << LogIO::POST;;
786 789
787 790 if ((spw_p.nelements() > 0) && (max(spw_p) >= Int(ms_p.spectralWindow().nrow())))
788 791 {
789 792 os << LogIO::SEVERE << "SpectralWindow selection contains elements that do not exist in this MS" << LogIO::POST;
790 793 ms_p = MeasurementSet();
791 794 return false;
792 795 }
793 796
794 797 // Watch out! This throws an AipsError if ms_p doesn't have the requested columns.
795 798 const Vector<MS::PredefinedColumns> colNamesTok = parseColumnNames(colname,ms_p,virtualModelCol_p,virtualCorrectedCol_p);
802 805 }
803 806
804 807 mscIn_p = new ROMSColumns(mssel_p);
805 808
806 809 // Note again the parseColumnNames() a few lines back that stops setupMS()
807 810 // from being called if the MS doesn't have the requested columns.
808 811 MeasurementSet* outpointer = 0;
809 812
810 813 if (tileShape.nelements() == 3)
811 814 {
812 - outpointer = setupMS(msname, nchan_p[0], ncorr_p[0], colNamesTok,tileShape);
815 + outpointer = setupMS(msname, nchan_p[0], ncorr_p[0], colNamesTok,
816 + createWeightSpectrumCols, tileShape);
813 817 }
814 818
815 819 // the following calls MSTileLayout... disabled for now because it
816 820 // forces tiles to be the full spw bandwidth in width (gmoellen, 2010/11/07)
817 821 else if ((tileShape.nelements() == 1) && (tileShape[0] == 0 || tileShape[0]== 1))
818 822 {
819 - outpointer = setupMS( msname,
820 - nchan_p[0],
821 - ncorr_p[0],
822 - mscIn_p->observation().telescopeName()(0),
823 - colNamesTok,
824 - tileShape[0]);
823 + outpointer = setupMS(msname, nchan_p[0], ncorr_p[0],
824 + mscIn_p->observation().telescopeName()(0),
825 + colNamesTok, createWeightSpectrumCols, tileShape[0]);
825 826 }
826 827 else {
827 828 // Sweep all other cases of bad tileshape to a default one.
828 829 // (this probably never happens)
829 - outpointer = setupMS( msname,
830 - nchan_p[0],
831 - ncorr_p[0],
832 - mscIn_p->observation().telescopeName()(0),
833 - colNamesTok,
834 - 0);
830 + outpointer = setupMS(msname, nchan_p[0], ncorr_p[0],
831 + mscIn_p->observation().telescopeName()(0),
832 + colNamesTok, createWeightSpectrumCols, 0);
835 833 }
836 834
837 835 combine_p = combine;
838 836
839 837 msOut_p = *outpointer;
840 838
841 839 // handle column keywords copy for CORRECTED_DATA -> DATA
842 840 if (colNamesTok.nelements() == 1 && colNamesTok[0] == MS::CORRECTED_DATA && mssel_p.isColumn(MS::CORRECTED_DATA)) {
843 841 TableColumn outCol(msOut_p, "DATA");
844 842 ROTableColumn inCol(mssel_p, "CORRECTED_DATA");
1164 1162 << LogIO::POST;
1165 1163 }
1166 1164
1167 1165 return true;
1168 1166 }
1169 1167
1170 1168
1171 1169 // -----------------------------------------------------------------------
1172 1170 //
1173 1171 // -----------------------------------------------------------------------
1174 -MeasurementSet* MSTransformDataHandler::setupMS( const String& MSFileName, const Int nchan,
1175 - const Int nCorr, const String& telescop,
1176 - const Vector<MS::PredefinedColumns>& colNames,
1177 - const Int obstype,const Bool compress,
1178 - const asdmStManUseAlternatives asdmStManUse,
1179 - Table::TableOption option)
1172 +MeasurementSet* MSTransformDataHandler::setupMS(const String& MSFileName, const Int nchan,
1173 + const Int nCorr, const String& telescop,
1174 + const Vector<MS::PredefinedColumns>& colNames,
1175 + casacore::Bool createWeightSpectrumCols,
1176 + const Int obstype, const Bool compress,
1177 + const asdmStManUseAlternatives asdmStManUse,
1178 + Table::TableOption option)
1180 1179 {
1181 1180 //Choose an appropriate tileshape
1182 1181 IPosition dataShape(2, nCorr, nchan);
1183 1182 IPosition tileShape = MSTileLayout::tileShape(dataShape, obstype, telescop);
1184 - return setupMS(MSFileName, nchan, nCorr, colNames, tileShape.asVector(),compress, asdmStManUse,option);
1183 + return setupMS(MSFileName, nchan, nCorr, colNames, createWeightSpectrumCols,
1184 + tileShape.asVector(),compress, asdmStManUse,option);
1185 1185 }
1186 1186
1187 1187 // -----------------------------------------------------------------------
1188 1188 //
1189 1189 // -----------------------------------------------------------------------
1190 - MeasurementSet* MSTransformDataHandler::setupMS( const String& MSFileName, const Int nchan,
1191 - const Int nCorr,
1192 - const Vector<MS::PredefinedColumns>& colNamesTok,
1193 - const Vector<Int>& tshape, const Bool compress,
1194 - const asdmStManUseAlternatives asdmStManUse,
1195 - Table::TableOption option)
1190 + MeasurementSet* MSTransformDataHandler::setupMS(const String& MSFileName, const Int nchan,
1191 + const Int nCorr,
1192 + const Vector<MS::PredefinedColumns>& colNamesTok,
1193 + casacore::Bool createWeightSpectrumCols,
1194 + const Vector<Int>& tshape, const Bool compress,
1195 + const asdmStManUseAlternatives asdmStManUse,
1196 + Table::TableOption option)
1196 1197 {
1197 1198 if (tshape.nelements() != 3) throw(AipsError("TileShape has to have 3 elements "));
1198 1199
1199 1200 // This is more to shush a compiler warning than to warn users.
1200 1201 LogIO os(LogOrigin("MSTransformDataHandler", __FUNCTION__));
1201 1202 if (tshape[0] != nCorr)
1202 1203 os << LogIO::DEBUG1 << "Warning: using " << tshape[0]
1203 1204 << " from the tileshape instead of " << nCorr
1204 1205 << " for the number of correlations." << LogIO::POST;
1205 1206 if (tshape[1] != nchan)
1283 1284 }
1284 1285 }
1285 1286
1286 1287 //other cols for compression
1287 1288 if (compress && asdmStManUse != USE_FOR_DATA_WEIGHT_SIGMA_FLAG)
1288 1289 {
1289 1290 MS::addColumnCompression(td, MS::WEIGHT, true);
1290 1291 MS::addColumnCompression(td, MS::SIGMA, true);
1291 1292 }
1292 1293
1293 - // Add this optional column because random group fits has a weight per visibility
1294 - MS::addColumnToDesc(td, MS::WEIGHT_SPECTRUM, 2);
1295 - MS::addColumnToDesc(td, MS::SIGMA_SPECTRUM, 2);
1294 + if (createWeightSpectrumCols) {
1295 + MS::addColumnToDesc(td, MS::WEIGHT_SPECTRUM, 2);
1296 + MS::addColumnToDesc(td, MS::SIGMA_SPECTRUM, 2);
1297 +
1298 + td.defineHypercolumn("TiledWgtSpectrum", 3,stringToVector(MS::columnName(MS::WEIGHT_SPECTRUM)));
1299 + td.defineHypercolumn("TiledSigmaSpectrum", 3,stringToVector(MS::columnName(MS::SIGMA_SPECTRUM)));
1300 + }
1296 1301
1297 1302 td.defineHypercolumn("TiledFlagCategory", 4,stringToVector(MS::columnName(MS::FLAG_CATEGORY)));
1298 - td.defineHypercolumn("TiledWgtSpectrum", 3,stringToVector(MS::columnName(MS::WEIGHT_SPECTRUM)));
1299 - td.defineHypercolumn("TiledSigmaSpectrum", 3,stringToVector(MS::columnName(MS::SIGMA_SPECTRUM)));
1300 1303 td.defineHypercolumn("TiledUVW", 2, stringToVector(MS::columnName(MS::UVW)));
1301 1304
1302 1305 if (asdmStManUse != USE_FOR_DATA_WEIGHT_SIGMA_FLAG)
1303 1306 {
1304 1307 td.defineHypercolumn("TiledFlag", 3,stringToVector(MS::columnName(MS::FLAG)));
1305 1308 td.defineHypercolumn("TiledWgt", 2,stringToVector(MS::columnName(MS::WEIGHT)));
1306 1309 td.defineHypercolumn("TiledSigma", 2,stringToVector(MS::columnName(MS::SIGMA)));
1307 1310 }
1308 1311
1309 1312 SetupNewTable newtab(MSFileName, td, option);
1351 1354 // Bind ANTENNA1, ANTENNA2 and DATA_DESC_ID to the standardStMan
1352 1355 // as they may change sufficiently frequently to make the
1353 1356 // incremental storage manager inefficient for these columns.
1354 1357 StandardStMan aipsStMan0("ANTENNA1", cache_val);
1355 1358 newtab.bindColumn(MS::columnName(MS::ANTENNA1), aipsStMan0);
1356 1359 StandardStMan aipsStMan1("ANTENNA2", cache_val);
1357 1360 newtab.bindColumn(MS::columnName(MS::ANTENNA2), aipsStMan1);
1358 1361 StandardStMan aipsStMan2("DATA_DESC_ID", cache_val);
1359 1362 newtab.bindColumn(MS::columnName(MS::DATA_DESC_ID), aipsStMan2);
1360 1363
1361 - TiledShapeStMan tiledStMan1f("TiledFlag", tileShape);
1362 - TiledShapeStMan tiledStMan1fc("TiledFlagCategory",IPosition(4, tileShape(0), tileShape(1), 1, tileShape(2)));
1363 - TiledShapeStMan tiledStMan2("TiledWgtSpectrum", tileShape);
1364 - TiledShapeStMan tiledStMan6("TiledSigmaSpectrum", tileShape);
1365 - TiledColumnStMan tiledStMan3("TiledUVW",IPosition(2, 3, (tileShape(0) * tileShape(1) * tileShape(2)) / 3));
1366 - TiledShapeStMan tiledStMan4("TiledWgt",IPosition(2, tileShape(0), tileShape(1) * tileShape(2)));
1367 - TiledShapeStMan tiledStMan5("TiledSigma",IPosition(2, tileShape(0), tileShape(1) * tileShape(2)));
1368 -
1369 - // Bind the DATA, FLAG & WEIGHT_SPECTRUM columns to the tiled stman or asdmStMan
1364 + // Bind the DATA, FLAG & WEIGHT/SIGMA_SPECTRUM columns to the tiled stman or
1365 + // asdmStMan
1370 1366 AsdmStMan sm;
1371 1367
1372 1368 if (mustWriteOnlyToData)
1373 1369 {
1374 1370 if (asdmStManUse == DONT)
1375 1371 {
1376 1372 TiledShapeStMan tiledStMan1Data("TiledDATA", tileShape);
1377 1373 newtab.bindColumn(MS::columnName(MS::DATA), tiledStMan1Data);
1378 1374 }
1379 1375 else
1386 1382 for (uInt i = 0; i < ncols; ++i)
1387 1383 {
1388 1384 TiledShapeStMan tiledStMan1Data(tiledDataNames[i], tileShape);
1389 1385 newtab.bindColumn(MS::columnName(colNamesTok[i]), tiledStMan1Data);
1390 1386 }
1391 1387 if (asdmStManUse != DONT)
1392 1388 {
1393 1389 newtab.bindColumn(MS::columnName(MS::DATA), sm);
1394 1390 }
1395 1391 }
1392 +
1393 + TiledShapeStMan tiledStMan1fc("TiledFlagCategory",IPosition(4, tileShape(0), tileShape(1), 1, tileShape(2)));
1396 1394 newtab.bindColumn(MS::columnName(MS::FLAG_CATEGORY), tiledStMan1fc);
1397 - newtab.bindColumn(MS::columnName(MS::WEIGHT_SPECTRUM), tiledStMan2);
1398 - newtab.bindColumn(MS::columnName(MS::SIGMA_SPECTRUM), tiledStMan6);
1399 1395
1396 + if (createWeightSpectrumCols) {
1397 + TiledShapeStMan tiledStMan2("TiledWgtSpectrum", tileShape);
1398 + TiledShapeStMan tiledStMan6("TiledSigmaSpectrum", tileShape);
1399 + newtab.bindColumn(MS::columnName(MS::WEIGHT_SPECTRUM), tiledStMan2);
1400 + newtab.bindColumn(MS::columnName(MS::SIGMA_SPECTRUM), tiledStMan6);
1401 + }
1402 +
1403 + TiledColumnStMan tiledStMan3("TiledUVW",IPosition(2, 3, (tileShape(0) * tileShape(1) * tileShape(2)) / 3));
1400 1404 newtab.bindColumn(MS::columnName(MS::UVW), tiledStMan3);
1401 1405 if (asdmStManUse == USE_FOR_DATA_WEIGHT_SIGMA_FLAG)
1402 1406 {
1403 1407 newtab.bindColumn(MS::columnName(MS::FLAG), sm);
1404 1408 newtab.bindColumn(MS::columnName(MS::WEIGHT), sm);
1405 1409 newtab.bindColumn(MS::columnName(MS::SIGMA), sm);
1406 1410 }
1407 1411 else
1408 1412 {
1409 - newtab.bindColumn(MS::columnName(MS::FLAG), tiledStMan1f);
1410 - newtab.bindColumn(MS::columnName(MS::WEIGHT), tiledStMan4);
1411 - newtab.bindColumn(MS::columnName(MS::SIGMA), tiledStMan5);
1413 + TiledShapeStMan tiledStMan1f("TiledFlag", tileShape);
1414 + TiledShapeStMan tiledStMan4("TiledWgt", IPosition(2, tileShape(0),
1415 + tileShape(1) * tileShape(2)));
1416 + TiledShapeStMan tiledStMan5("TiledSigma",IPosition(2, tileShape(0),
1417 + tileShape(1) * tileShape(2)));
1418 +
1419 + newtab.bindColumn(MS::columnName(MS::FLAG), tiledStMan1f);
1420 + newtab.bindColumn(MS::columnName(MS::WEIGHT), tiledStMan4);
1421 + newtab.bindColumn(MS::columnName(MS::SIGMA), tiledStMan5);
1412 1422 }
1413 1423
1414 1424 // Avoid lock overheads by locking the table permanently
1415 1425 TableLock lock(TableLock::AutoLocking);
1416 1426 MeasurementSet *ms = new MeasurementSet(newtab, lock);
1417 1427
1418 1428 // Set up the sub-tables for the UVFITS MS (we make new tables with 0 rows)
1419 1429 // Table::TableOption option = Table::New;
1420 1430 createSubtables(*ms, option);
1421 1431

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut