From df2465593f5dd26bdad52caf3239862a7be1175a Mon Sep 17 00:00:00 2001 From: Bram Veenboer <bram.veenboer@gmail.com> Date: Fri, 3 Jan 2020 14:44:53 +0100 Subject: [PATCH] Add ElementResponseModel to choose between various element response models The Hamaker model is currently the only supported model. Two other models, LOBES and Oskar are added to the enum of models, but are not implemented yet. To maintain backwards compatability, the default behavior is to use the Hamaker model. --- CMakeLists.txt | 3 +++ ElementResponseModel.cc | 14 ++++++++++++++ ElementResponseModel.h | 15 +++++++++++++++ LofarMetaDataUtil.cc | 7 +++++-- LofarMetaDataUtil.h | 15 ++++++++++++--- Station.cc | 31 ++++++++++++++++++++++++++----- Station.h | 7 ++++++- 7 files changed, 81 insertions(+), 11 deletions(-) create mode 100644 ElementResponseModel.cc create mode 100644 ElementResponseModel.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9137a821..85da5cac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ add_library(stationresponse SHARED AntennaModelHBA.cc AntennaModelLBA.cc DualDipoleAntenna.cc + ElementResponseModel.cc HamakerElementResponse.cc ITRFConverter.cc ITRFDirection.cc @@ -52,10 +53,12 @@ install (FILES Types.h ITRFConverter.h ITRFDirection.h + ElementResponseModel.h DESTINATION include/StationResponse) install (FILES ElementResponse.h + ElementResponseModel.h DESTINATION include/ElementResponse) find_package(Doxygen) diff --git a/ElementResponseModel.cc b/ElementResponseModel.cc new file mode 100644 index 00000000..fde636c4 --- /dev/null +++ b/ElementResponseModel.cc @@ -0,0 +1,14 @@ +#include "ElementResponseModel.h" + +std::ostream& operator<<(std::ostream& os, ElementResponseModel model) +{ + switch (model) + { + case Unknown: os << "Unknown"; break; + case Hamaker: os << "Hamaker"; break; + case LOBES : os << "LOBES"; break; + case OSKAR : os << "OSKAR"; break; + default : os.setstate(std::ios_base::failbit); + } + return os; +} diff --git a/ElementResponseModel.h b/ElementResponseModel.h new file mode 100644 index 00000000..444a8773 --- /dev/null +++ b/ElementResponseModel.h @@ -0,0 +1,15 @@ +#ifndef ELEMENT_RESPONSE_MODEL_H +#define ELEMENT_RESPONSE_MODEL_H + +#include <ostream> + +enum ElementResponseModel { + Unknown, + Hamaker, + LOBES, + OSKAR +}; + +std::ostream& operator<<(std::ostream& os, ElementResponseModel model); + +#endif diff --git a/LofarMetaDataUtil.cc b/LofarMetaDataUtil.cc index 8681f0c3..55ab207e 100644 --- a/LofarMetaDataUtil.cc +++ b/LofarMetaDataUtil.cc @@ -259,7 +259,10 @@ void readStationPhaseReference(const Table &table, unsigned int id, } } -Station::Ptr readStation(const MeasurementSet &ms, unsigned int id) +Station::Ptr readStation( + const MeasurementSet &ms, + unsigned int id, + const ElementResponseModel model) { ROMSAntennaColumns antenna(ms.antenna()); assert(antenna.nrow() > id && !antenna.flagRow()(id)); @@ -274,7 +277,7 @@ Station::Ptr readStation(const MeasurementSet &ms, unsigned int id) const vector3r_t position = {{mvPosition(0), mvPosition(1), mvPosition(2)}}; // Create station. - Station::Ptr station(new Station(name, position)); + Station::Ptr station(new Station(name, position, model)); // Read phase reference position (if available). readStationPhaseReference(ms.antenna(), id, station); diff --git a/LofarMetaDataUtil.h b/LofarMetaDataUtil.h index ab87e567..c73bd97e 100644 --- a/LofarMetaDataUtil.h +++ b/LofarMetaDataUtil.h @@ -29,6 +29,7 @@ // LOFAR observations stored in MS format. #include "Station.h" +#include "ElementResponseModel.h" #include <casacore/ms/MeasurementSets/MeasurementSet.h> #include <casacore/ms/MeasurementSets/MSAntennaColumns.h> @@ -42,15 +43,23 @@ namespace StationResponse // \addtogroup StationResponse // @{ -Station::Ptr readStation(const casacore::MeasurementSet &ms, unsigned int id); +const ElementResponseModel defaultElementResponseModel = ElementResponseModel::Hamaker; + +Station::Ptr readStation( + const casacore::MeasurementSet &ms, + unsigned int id, + const ElementResponseModel model = defaultElementResponseModel); template <typename T> -void readStations(const casacore::MeasurementSet &ms, T out_it) +void readStations( + const casacore::MeasurementSet &ms, + T out_it, + const ElementResponseModel model = defaultElementResponseModel) { casacore::ROMSAntennaColumns antenna(ms.antenna()); for(unsigned int i = 0; i < antenna.nrow(); ++i) { - *out_it++ = readStation(ms, i); + *out_it++ = readStation(ms, i, model); } } diff --git a/Station.cc b/Station.cc index 420ec8fd..034a6d92 100644 --- a/Station.cc +++ b/Station.cc @@ -32,16 +32,37 @@ namespace LOFAR namespace StationResponse { -Station::Station(const string &name, const vector3r_t &position) +Station::Station( + const string &name, + const vector3r_t &position, + const ElementResponseModel model) : itsName(name), itsPosition(position), itsPhaseReference(position) { - if (DualDipoleAntenna::itsElementResponse == nullptr) { - DualDipoleAntenna::itsElementResponse.reset(new HamakerElementResponseLBA); + if (itsModel != ElementResponseModel::Unknown && + itsModel != model) + { + throw std::runtime_error("Every station must have the same element response model."); + } else { + itsModel = model; } - if (TileAntenna::itsElementResponse == nullptr) { - TileAntenna::itsElementResponse.reset(new HamakerElementResponseHBA); + + switch (model) + { + case Hamaker: + if (DualDipoleAntenna::itsElementResponse == nullptr) { + DualDipoleAntenna::itsElementResponse.reset(new HamakerElementResponseLBA); + } + if (TileAntenna::itsElementResponse == nullptr) { + TileAntenna::itsElementResponse.reset(new HamakerElementResponseHBA); + } + break; + default: + std::stringstream message; + message << "The requested element response model '" + << model << "' is not implemented."; + throw std::runtime_error(message.str()); } } diff --git a/Station.h b/Station.h index 06f24dd8..aaaa3df9 100644 --- a/Station.h +++ b/Station.h @@ -28,6 +28,7 @@ #include "AntennaField.h" #include "Types.h" +#include "ElementResponseModel.h" #include <memory> #include <vector> @@ -53,7 +54,10 @@ public: * \param name Name of the station. * \param position Position of the station (ITRF, m). */ - Station(const string &name, const vector3r_t &position); + Station( + const string &name, + const vector3r_t &position, + const ElementResponseModel model); /*! * \brief Return the name of the station. @@ -306,6 +310,7 @@ private: vector3r_t itsPosition; vector3r_t itsPhaseReference; FieldList itsFields; + ElementResponseModel itsModel; }; // @} -- GitLab