using namespace casacore;
using namespace casa::vi;
using namespace casacore;
namespace casa { //# NAMESPACE CASA - BEGIN
SolveDataBuffer::SolveDataBuffer() :
SolveDataBuffer::SolveDataBuffer(const vi::VisBuffer2& vb) :
vb_= vi::VisBuffer2::factory(VbRekeyable);
SolveDataBuffer::SolveDataBuffer(const SolveDataBuffer& sdb) :
// Copy from the other's VB2
// NB: that VB2 won't be attached!!
// copy over freqs_, corrs_,feedPa
// copy over freqs_, corrs_,feedPa, nAnt_
// (things that normally require being attached)
freqs_.assign(sdb.freqs_);
corrs_.assign(sdb.corrs_);
feedPa_.assign(sdb.feedPa_);
SolveDataBuffer::~SolveDataBuffer()
//SolveDataBuffer& SolveDataBuffer::operator=(const VisBuffer& other)
void SolveDataBuffer::finalizeResiduals()
// Subtract in-focus obs data from residuals workspace
residuals_p -= infocusVisCube_p;
// TBD: zero flagged samples here?
void SolveDataBuffer::reportData()
Slice corrs(0,2,3), sl; // p-hands only
Vector<Int> a1(this->antenna1()), a2(this->antenna2());
Cube<Complex> vCC(this->visCubeCorrected()(corrs,sl,sl));
Cube<Complex> vCM(this->visCubeModel()(corrs,sl,sl));
Cube<Float> wtS(this->weightSpectrum()(corrs,sl,sl));
Cube<Bool> flg(this->flagCube()(corrs,sl,sl));
// Set weights for flagged data to zero
Cube<Float> wtsp(vb_->weightSpectrum());
wtsp(vb_->flagCube())=0.0;
// Store the frequeny info
// TBD: also need bandwidth info....
freqs_.assign(vb.getFrequencies(0));
corrs_.assign(vb.correlationTypes());
// Probably only needed in testing.... (gmoellen, 2016Aug04, 2019Jan07)
cout << "The supplied VisBuffer2 is not attached to a ViImplementation2," << endl
<< " which is necessary to generate accurate frequency info." << endl
<< " This is probably just a test with a naked VisBuffer2." << endl
<< " Spoofing freq axis with 1 MHz channels at 100 GHz." << endl
<< " Spoofing corr axis with [5,6,7,8] (circulars)" << endl;
freqs_.resize(vb.nChannels());
String polBas(SDB_[0]->polBasis());
// Trap non-uniformity, for now
for (Int isdb=1;isdb<nSDB_;++isdb)
AlwaysAssert((SDB_[isdb]->polBasis()==polBas),AipsError);
// Currently, this insists on uniformity over all SDBs
Int SDBList::nAntennas() const {
Int nAnt=SDB_[0]->nAntennas();
// Trap non-uniformity, for now
for (Int isdb=1;isdb<nSDB_;++isdb)
AlwaysAssert((SDB_[isdb]->nAntennas()==nAnt),AipsError);
// How many correlations?
// Currently, this insists on uniformity over all SDBs
Int SDBList::nCorrelations() const {
Int nCorr=SDB_[0]->nCorrelations();
// Trap non-uniformity, for now
for (Int isdb=1;isdb<nSDB_;++isdb)
AlwaysAssert((SDB_[isdb]->nCorrelations()==nCorr),AipsError);
void SDBList::reportData()
cout << "nSDB=" << nSDB_ << endl;
for (Int i=0;i<nSDB_;++i) {
cout << "isdb=" << i << endl;
void SDBList::extendBaselineFlags()
// This enforces uniform nAnt in all SDBs
Int nAnt(this->nAntennas());
// channelized flags per baseline, cross-corr pair
Cube<Bool> aggFlag(nChannels(),nAnt,nAnt,true);
// Initialize aggregate flags to those in first SDB
// If an antenna pair is not avail here, it won't be used (default flagged)
// Subsequent SDBs might flag more baselines
Cube<Bool>& flc(SDB_[0]->flagCube());
const Vector<Int>& a1(SDB_[0]->antenna1());
const Vector<Int>& a2(SDB_[0]->antenna2());
Int nRows(SDB_[0]->nRows());
Int nChan(SDB_[0]->nChannels());
for (Int irow=0;irow<nRows;++irow) {
for (Int ichan=0;ichan<nChan;++ichan) {
aggFlag(ichan,a1(irow),a2(irow))=(flc(1,ichan,irow)||flc(2,ichan,irow)); // Either cross-hand flagged
// Accumulate from other SDBs
for (Int isdb=1;isdb<nSDB_;++isdb) {
Cube<Bool>& flc(SDB_[isdb]->flagCube());
const Vector<Int>& a1(SDB_[isdb]->antenna1());
const Vector<Int>& a2(SDB_[isdb]->antenna2());
Int nRows(SDB_[isdb]->nRows());
Int nChan(SDB_[isdb]->nChannels());
for (Int irow=0;irow<nRows;++irow) {
for (Int ichan=0;ichan<nChan;++ichan) {
aggFlag(ichan,a1(irow),a2(irow))|=(flc(1,ichan,irow)||flc(2,ichan,irow)); // Either cross-hand flagged
// cout << "aggFlag: " << ntrue(aggFlag) << "/" << nfalse(aggFlag) << " sh=" << aggFlag.shape() << endl;
// Apply aggregate flags to each SDB
for (Int isdb=0;isdb<nSDB_;++isdb) {
Cube<Bool>& flc(SDB_[isdb]->flagCube());
const Vector<Int>& a1(SDB_[isdb]->antenna1());
const Vector<Int>& a2(SDB_[isdb]->antenna2());
Int nRows(SDB_[isdb]->nRows());
Int nChan(SDB_[isdb]->nChannels());
for (Int irow=0;irow<nRows;++irow) {
for (Int ichan=0;ichan<nChan;++ichan) {
if (aggFlag(ichan,a1(irow),a2(irow))) {
flc(Slice(1,2,1),Slice(ichan),Slice(irow))=true;
//cout << ntrue(flc) << " ";
} //# NAMESPACE CASA - END