diff --git a/CMakeLists.txt b/CMakeLists.txt index 9137a821002b82ec3095bbad4c52783a0b811267..85da5cac46e7853c0a5da354c743e09d20b5778d 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 0000000000000000000000000000000000000000..fde636c4e1cb3c40a279e51f9a3d87784331fb29 --- /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 0000000000000000000000000000000000000000..444a8773797cb124d5009a8814d847931e219f83 --- /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 8681f0c3ce3ad0343983a245170e9929191e67d6..55ab207e52e55213d22e205861b75f508d9db292 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 ab87e567f8acbc787b640bd0016f63f7fb6da92e..c73bd97e2627428b3ea531331f0e6d2da08fafb7 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 420ec8fdb8d923cd3fff3e5e290a969d49933f7c..034a6d92624b7182c1cf8e67d3b7935365d06eab 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 06f24dd8d62b74ba72a6ee29acace1e9646c7be5..aaaa3df98e0e4cc03f9649edfee515f3f0f75832 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; }; // @}