Skip to content

Commit

Permalink
Merge pull request #779 from kettenis/weather
Browse files Browse the repository at this point in the history
Concatenate WEATHER tables
  • Loading branch information
gervandiepen committed Sep 18, 2018
2 parents ba5f5dc + d130b34 commit 1c22f8e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
71 changes: 71 additions & 0 deletions ms/MSOper/MSConcat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ IPosition MSConcat::isFixedShape(const TableDesc& td) {
// SYSCAL
copySysCal(otherMS.sysCal(), newAntIndices);

// WEATHER
copyWeather(otherMS.weather(), newAntIndices);

/////////////////////////////////////////////////////

// copying all subtables over to otherMS
Expand Down Expand Up @@ -1058,6 +1061,11 @@ IPosition MSConcat::isFixedShape(const TableDesc& td) {
log << LogIO::WARN << "Could not merge SysCal subtables " << LogIO::POST ;
}

// WEATHER
if(!copyWeather(otherMS.weather(), newAntIndices)){
log << LogIO::WARN << "Could not merge Weather subtables " << LogIO::POST ;
}


//////////////////////////////////////////////////////

Expand Down Expand Up @@ -1802,6 +1810,69 @@ Bool MSConcat::copySysCal(const MSSysCal& otherSysCal,
return True;
}

Bool MSConcat::copyWeather(const MSWeather& otherWeather,
const Block<uInt>& newAntIndices){

LogIO os(LogOrigin("MSConcat", "copyWeather"));

Bool itsWeatherNull = (itsMS.weather().isNull() || (itsMS.weather().nrow() == 0));
Bool otherWeatherNull = (otherWeather.isNull() || (otherWeather.nrow() == 0));

if(itsWeatherNull && otherWeatherNull){ // neither of the two MSs do have valid syscal tables
os << LogIO::NORMAL << "No valid weather tables present. Result won't have one either." << LogIO::POST;
return True;
}
else if(itsWeatherNull && !otherWeatherNull){
os << LogIO::WARN << itsMS.tableName() << " does not have a valid weather table," << endl
<< " the MS to be appended, however, has one. Result won't have one."
<< LogIO::POST;
return False;
}

MSWeather& weather=itsMS.weather();
Int actualRow=weather.nrow()-1;
Int origNRow=actualRow+1;
Int rowToBeAdded=otherWeather.nrow();
TableRow weatherRow(weather);
const ROTableRow otherWeatherRow(otherWeather);
for (Int k=0; k < rowToBeAdded; ++k){
++actualRow;
weather.addRow();
weatherRow.put(actualRow, otherWeatherRow.get(k, True));
}

//Now reassigning antennas to the new indices of the ANTENNA table

if(rowToBeAdded > 0){
MSWeatherColumns weatherCol(weather);
// check antenna IDs
Vector<Int> antennaIDs=weatherCol.antennaId().getColumn();
Bool idsOK = True;
Int maxID = static_cast<Int>(newAntIndices.nelements()) - 1;
for (Int k=origNRow; k < (origNRow+rowToBeAdded); ++k){
if(antennaIDs[k] < 0 || antennaIDs[k] > maxID){
idsOK = False;
break;
}
}
if(!idsOK){
os << LogIO::WARN
<< "Found invalid antenna ids in the WEATHER table; the WEATHER table will be emptied as it is inconsistent"
<< LogIO::POST;
Vector<uInt> rowtodel(weather.nrow());
indgen(rowtodel);
weather.removeRow(rowtodel);
return False;
}

for (Int k=origNRow; k < (origNRow+rowToBeAdded); ++k){
weatherCol.antennaId().put(k, newAntIndices[antennaIDs[k]]);
}
}

return True;
}


Int MSConcat::copyObservation(const MSObservation& otherObs,
const Bool remRedunObsId){
Expand Down
1 change: 1 addition & 0 deletions ms/MSOper/MSConcat.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ class MSConcat: public MSColumns
Bool copyPointing(const MSPointing& otherPoint, const Block<uInt>& newAntIndices);
Bool copyPointingB(MSPointing& otherPoint, const Block<uInt>& newAntIndices);
Bool copySysCal(const MSSysCal& otherSysCal, const Block<uInt>& newAndIndices);
Bool copyWeather(const MSWeather& otherWeather, const Block<uInt>& newAndIndices);
Int copyObservation(const MSObservation& otherObs, const Bool remRedunObsId=True);
// by default remove redundant observation table rows
Block<uInt> copyAntennaAndFeed(const MSAntenna& otherAnt,
Expand Down

0 comments on commit 1c22f8e

Please sign in to comment.