diff --git a/CEP/Calibration/BBSKernel/src/MeasurementExprLOFAR.cc b/CEP/Calibration/BBSKernel/src/MeasurementExprLOFAR.cc index 45434335d7b970690e1ac57f56138834ae8a8aaf..eee7d97cc59a176eef6634bff47034dfb5ecdc07 100644 --- a/CEP/Calibration/BBSKernel/src/MeasurementExprLOFAR.cc +++ b/CEP/Calibration/BBSKernel/src/MeasurementExprLOFAR.cc @@ -377,16 +377,12 @@ void MeasurementExprLOFAR::makeInverseExpr(SourceDB &sourceDB, if(haveDDE) { // Position of interest on the sky (given as patch name). - if(config.getSources().size() != 1) + if(config.getSources().size() > 1) { - THROW(BBSKernelException, "No patch, or more than one patch" - " selected, yet corrections can only be applied for a single" - " direction on the sky"); + THROW(BBSKernelException, "Multiple patches selected, yet a" + " correction can only be applied for a single direction on the" + " sky."); } - const string &patch = config.getSources().front(); - - PatchExprBase::Ptr exprPatch = makePatchExpr(patch, - buffer->getPhaseReference(), sourceDB, buffers); // Beam reference position on the sky. Expr<Vector<2> >::Ptr exprRefDelay = @@ -400,10 +396,6 @@ void MeasurementExprLOFAR::makeInverseExpr(SourceDB &sourceDB, Expr<Vector<3> >::Ptr exprRefTileITRF = makeITRFExpr(instrument->position(), exprRefTile); - // Patch position (ITRF direction vector). - Expr<Vector<3> >::Ptr exprPatchPositionITRF = - makeITRFExpr(instrument->position(), exprPatch->position()); - HamakerBeamCoeff coeffLBA, coeffHBA; if(config.useBeam()) { @@ -427,54 +419,114 @@ void MeasurementExprLOFAR::makeInverseExpr(SourceDB &sourceDB, IonosphereExpr::create(config.getIonosphereConfig(), itsScope); } - for(size_t i = 0; i < stationExpr.size(); ++i) + if(config.getSources().empty()) { - // Directional gain. - if(config.useDirectionalGain()) - { - stationExpr[i] = compose(stationExpr[i], - makeDirectionalGainExpr(itsScope, instrument->station(i), - patch, config.usePhasors())); - } + LOG_DEBUG_STR("Applying a correction for the phase reference of the" + " observation."); - // Beam. - if(config.useBeam()) + if(config.useDirectionalGain() || config.useDirectionalTEC() + || config.useFaradayRotation()) { - stationExpr[i] = compose(stationExpr[i], - makeBeamExpr(itsScope, instrument->station(i), - buffer->getReferenceFreq(), exprPatchPositionITRF, - exprRefDelayITRF, exprRefTileITRF, config.getBeamConfig(), - coeffLBA, coeffHBA)); + THROW(BBSKernelException, "Cannot correct for DirectionalGain," + " DirectionalTEC, and/or FaradayRotation when correcting" + " for the (unnamed) phase reference direction."); } - // Directional TEC. - if(config.useDirectionalTEC()) - { - stationExpr[i] = compose(stationExpr[i], - makeDirectionalTECExpr(itsScope, instrument->station(i), - patch)); - } + // Phase reference position on the sky. + Expr<Vector<2> >::Ptr exprRefPhase = + makeDirectionExpr(buffer->getPhaseReference()); + Expr<Vector<3> >::Ptr exprRefPhaseITRF = + makeITRFExpr(instrument->position(), exprRefPhase); - // Faraday rotation. - if(config.useFaradayRotation()) + for(size_t i = 0; i < stationExpr.size(); ++i) { - stationExpr[i] = compose(stationExpr[i], - makeFaradayRotationExpr(itsScope, instrument->station(i), - patch)); + // Beam. + if(config.useBeam()) + { + stationExpr[i] = compose(stationExpr[i], + makeBeamExpr(itsScope, instrument->station(i), + buffer->getReferenceFreq(), exprRefPhaseITRF, + exprRefDelayITRF, exprRefTileITRF, + config.getBeamConfig(), coeffLBA, coeffHBA)); + } + + // Ionosphere. + if(config.useIonosphere()) + { + // Create an AZ, EL expression for the phase reference + // direction. + Expr<Vector<2> >::Ptr exprAzEl = + makeAzElExpr(instrument->station(i)->position(), + exprRefPhase); + + stationExpr[i] = compose(stationExpr[i], + makeIonosphereExpr(itsScope, instrument->station(i), + instrument->position(), exprAzEl, exprIonosphere)); + } } + } + else + { + const string &patch = config.getSources().front(); + LOG_DEBUG_STR("Applying a correction for the centroid of patch: " + << patch); - // Ionosphere. - if(config.useIonosphere()) - { - // Create an AZ, EL expression for the centroid direction of the - // patch. - Expr<Vector<2> >::Ptr exprAzEl = - makeAzElExpr(instrument->station(i)->position(), - exprPatch->position()); + PatchExprBase::Ptr exprPatch = makePatchExpr(patch, + buffer->getPhaseReference(), sourceDB, buffers); - stationExpr[i] = compose(stationExpr[i], - makeIonosphereExpr(itsScope, instrument->station(i), - instrument->position(), exprAzEl, exprIonosphere)); + // Patch position (ITRF direction vector). + Expr<Vector<3> >::Ptr exprPatchPositionITRF = + makeITRFExpr(instrument->position(), exprPatch->position()); + + for(size_t i = 0; i < stationExpr.size(); ++i) + { + // Directional gain. + if(config.useDirectionalGain()) + { + stationExpr[i] = compose(stationExpr[i], + makeDirectionalGainExpr(itsScope, + instrument->station(i), patch, config.usePhasors())); + } + + // Beam. + if(config.useBeam()) + { + stationExpr[i] = compose(stationExpr[i], + makeBeamExpr(itsScope, instrument->station(i), + buffer->getReferenceFreq(), exprPatchPositionITRF, + exprRefDelayITRF, exprRefTileITRF, + config.getBeamConfig(), coeffLBA, coeffHBA)); + } + + // Directional TEC. + if(config.useDirectionalTEC()) + { + stationExpr[i] = compose(stationExpr[i], + makeDirectionalTECExpr(itsScope, instrument->station(i), + patch)); + } + + // Faraday rotation. + if(config.useFaradayRotation()) + { + stationExpr[i] = compose(stationExpr[i], + makeFaradayRotationExpr(itsScope, + instrument->station(i), patch)); + } + + // Ionosphere. + if(config.useIonosphere()) + { + // Create an AZ, EL expression for the centroid direction of + // the patch. + Expr<Vector<2> >::Ptr exprAzEl = + makeAzElExpr(instrument->station(i)->position(), + exprPatch->position()); + + stationExpr[i] = compose(stationExpr[i], + makeIonosphereExpr(itsScope, instrument->station(i), + instrument->position(), exprAzEl, exprIonosphere)); + } } } } diff --git a/CEP/Calibration/BBSKernel/src/StationExprLOFAR.cc b/CEP/Calibration/BBSKernel/src/StationExprLOFAR.cc index 0e9151a0c4d7b71367627a1e858106bf54c84396..2bef1f6840c4e70ed05fee9468e609f10db93d1d 100644 --- a/CEP/Calibration/BBSKernel/src/StationExprLOFAR.cc +++ b/CEP/Calibration/BBSKernel/src/StationExprLOFAR.cc @@ -111,15 +111,12 @@ void StationExprLOFAR::initialize(SourceDB &sourceDB, const BufferMap &buffers, || config.useIonosphere()) { // Position of interest on the sky (given as patch name). - if(config.getSources().size() != 1) + if(config.getSources().size() > 1) { - THROW(BBSKernelException, "No patch, or more than one patch" - " selected, yet corrections can only be applied for a single" - " direction on the sky"); + THROW(BBSKernelException, "Multiple patches selected, yet a" + " correction can only be applied for a single direction on the" + " sky."); } - string patch = config.getSources().front(); - PatchExprBase::Ptr exprPatch = makePatchExpr(patch, refPhase, sourceDB, - buffers); // Beam reference position on the sky. Expr<Vector<2> >::Ptr exprRefDelay = makeDirectionExpr(refDelay); @@ -131,10 +128,6 @@ void StationExprLOFAR::initialize(SourceDB &sourceDB, const BufferMap &buffers, Expr<Vector<3> >::Ptr exprRefTileITRF = makeITRFExpr(instrument->position(), exprRefTile); - // Patch position (ITRF direction vector). - Expr<Vector<3> >::Ptr exprPatchPositionITRF = - makeITRFExpr(instrument->position(), exprPatch->position()); - HamakerBeamCoeff coeffLBA, coeffHBA; if(config.useBeam()) { @@ -158,54 +151,113 @@ void StationExprLOFAR::initialize(SourceDB &sourceDB, const BufferMap &buffers, IonosphereExpr::create(config.getIonosphereConfig(), itsScope); } - for(size_t i = 0; i < itsExpr.size(); ++i) + if(config.getSources().empty()) { - // Directional gain. - if(config.useDirectionalGain()) - { - itsExpr[i] = compose(itsExpr[i], - makeDirectionalGainExpr(itsScope, instrument->station(i), - patch, config.usePhasors())); - } + LOG_DEBUG_STR("Applying a correction for the phase reference of the" + " observation."); - // Beam. - if(config.useBeam()) + if(config.useDirectionalGain() || config.useDirectionalTEC() + || config.useFaradayRotation()) { - // Create beam expression. - itsExpr[i] = compose(itsExpr[i], - makeBeamExpr(itsScope, instrument->station(i), refFreq, - exprPatchPositionITRF, exprRefDelayITRF, exprRefTileITRF, - config.getBeamConfig(), coeffLBA, coeffHBA)); + THROW(BBSKernelException, "Cannot correct for DirectionalGain," + " DirectionalTEC, and/or FaradayRotation when correcting" + " for the (unnamed) phase reference direction."); } - // Directional TEC. - if(config.useDirectionalTEC()) - { - itsExpr[i] = compose(itsExpr[i], - makeDirectionalTECExpr(itsScope, instrument->station(i), - patch)); - } + // Phase reference position on the sky. + Expr<Vector<2> >::Ptr exprRefPhase = makeDirectionExpr(refPhase); + Expr<Vector<3> >::Ptr exprRefPhaseITRF = + makeITRFExpr(instrument->position(), exprRefPhase); - // Faraday rotation. - if(config.useFaradayRotation()) + for(size_t i = 0; i < itsExpr.size(); ++i) { - itsExpr[i] = compose(itsExpr[i], - makeFaradayRotationExpr(itsScope, instrument->station(i), - patch)); + // Beam. + if(config.useBeam()) + { + itsExpr[i] = compose(itsExpr[i], + makeBeamExpr(itsScope, instrument->station(i), + refFreq, exprRefPhaseITRF, exprRefDelayITRF, + exprRefTileITRF, config.getBeamConfig(), coeffLBA, + coeffHBA)); + } + + // Ionosphere. + if(config.useIonosphere()) + { + // Create an AZ, EL expression for the phase reference + // direction. + Expr<Vector<2> >::Ptr exprAzEl = + makeAzElExpr(instrument->station(i)->position(), + exprRefPhase); + + itsExpr[i] = compose(itsExpr[i], + makeIonosphereExpr(itsScope, instrument->station(i), + instrument->position(), exprAzEl, exprIonosphere)); + } } + } + else + { + const string &patch = config.getSources().front(); + LOG_DEBUG_STR("Applying a correction for the centroid of patch: " + << patch); + + PatchExprBase::Ptr exprPatch = makePatchExpr(patch, refPhase, + sourceDB, buffers); + + // Patch position (ITRF direction vector). + Expr<Vector<3> >::Ptr exprPatchPositionITRF = + makeITRFExpr(instrument->position(), exprPatch->position()); - // Ionosphere. - if(config.useIonosphere()) + for(size_t i = 0; i < itsExpr.size(); ++i) { - // Create an AZ, EL expression per station for the centroid - // direction of the patch. - Expr<Vector<2> >::Ptr exprAzEl = - makeAzElExpr(instrument->station(i)->position(), - exprPatch->position()); - - itsExpr[i] = compose(itsExpr[i], - makeIonosphereExpr(itsScope, instrument->station(i), - instrument->position(), exprAzEl, exprIonosphere)); + // Directional gain. + if(config.useDirectionalGain()) + { + itsExpr[i] = compose(itsExpr[i], + makeDirectionalGainExpr(itsScope, + instrument->station(i), patch, config.usePhasors())); + } + + // Beam. + if(config.useBeam()) + { + itsExpr[i] = compose(itsExpr[i], + makeBeamExpr(itsScope, instrument->station(i), refFreq, + exprPatchPositionITRF, exprRefDelayITRF, + exprRefTileITRF, config.getBeamConfig(), coeffLBA, + coeffHBA)); + } + + // Directional TEC. + if(config.useDirectionalTEC()) + { + itsExpr[i] = compose(itsExpr[i], + makeDirectionalTECExpr(itsScope, instrument->station(i), + patch)); + } + + // Faraday rotation. + if(config.useFaradayRotation()) + { + itsExpr[i] = compose(itsExpr[i], + makeFaradayRotationExpr(itsScope, + instrument->station(i), patch)); + } + + // Ionosphere. + if(config.useIonosphere()) + { + // Create an AZ, EL expression for the centroid direction of + // the patch. + Expr<Vector<2> >::Ptr exprAzEl = + makeAzElExpr(instrument->station(i)->position(), + exprPatch->position()); + + itsExpr[i] = compose(itsExpr[i], + makeIonosphereExpr(itsScope, instrument->station(i), + instrument->position(), exprAzEl, exprIonosphere)); + } } } }