Skip to content
Snippets Groups Projects
Commit da0ef2a6 authored by Andre Offringa's avatar Andre Offringa
Browse files

Merge branch 'rename-cor-type' into 'master'

Rename enum CorrectType entries

See merge request !124
parents 30a07292 67c60b80
No related branches found
No related tags found
1 merge request!124Rename enum CorrectType entries
Pipeline #55906 failed
......@@ -16,31 +16,31 @@
namespace schaapcommon {
namespace h5parm {
/**
* Type of Jones matrix.
* NOTE: kScalarPhase, kScalarAmplitude, kRealImaginary and
* kFullJonesRealImaginary are added to be compatible with ParmDB.
*/
enum class GainType {
kDiagonalComplex,
kFullJones,
kScalarComplex,
kTec,
kClock,
kRotationAngle,
kScalarPhase,
kDiagonalPhase,
kRotationMeasure,
kScalarAmplitude,
kDiagonalAmplitude,
kDiagonalRealImaginary,
kFullJonesRealImaginary
};
/// @brief Class to extract Jones matrices from an h5parm.
/// Provides some compatibility with ParmDB.
class JonesParameters {
public:
/**
* Type of Jones matrix.
* NOTE: SCALARPHASE, SCALARAMPLITUDE, GAIN_RE_IM and FULLJONES_RE_IM are
* added to be compatible with ParmDB.
*/
enum CorrectType {
GAIN,
FULLJONES,
SCALARGAIN,
TEC,
CLOCK,
ROTATIONANGLE,
SCALARPHASE,
PHASE,
ROTATIONMEASURE,
SCALARAMPLITUDE,
AMPLITUDE,
GAIN_RE_IM,
FULLJONES_RE_IM
};
/**
* What to do with missing antennas
*/
......@@ -72,8 +72,8 @@ class JonesParameters {
JonesParameters(const std::vector<double>& freqs,
const std::vector<double>& times,
const std::vector<std::string>& antenna_names,
CorrectType correct_type,
InterpolationType interpolation_type, hsize_t direction,
GainType gain_type, InterpolationType interpolation_type,
hsize_t direction,
std::vector<std::vector<std::vector<double>>>&& parm_values,
bool invert = false, float sigma_mmse = 0.);
......@@ -92,7 +92,7 @@ class JonesParameters {
*/
JonesParameters(
const std::vector<double>& freqs, const std::vector<double>& times,
const std::vector<std::string>& antenna_names, CorrectType correct_type,
const std::vector<std::string>& antenna_names, GainType gain_type,
const std::vector<std::vector<std::complex<double>>>& solution,
bool invert = false, float sigma_mmse = 0.);
......@@ -119,9 +119,8 @@ class JonesParameters {
JonesParameters(const std::vector<double>& freqs,
const std::vector<double>& times,
const std::vector<std::string>& antenna_names,
CorrectType correct_type,
InterpolationType interpolation_type, hsize_t direction,
schaapcommon::h5parm::SolTab* sol_tab,
GainType gain_type, InterpolationType interpolation_type,
hsize_t direction, schaapcommon::h5parm::SolTab* sol_tab,
schaapcommon::h5parm::SolTab* sol_tab2 = nullptr,
bool invert = false, float sigma_mmse = 0.,
unsigned int parm_size = 0,
......@@ -136,14 +135,18 @@ class JonesParameters {
const casacore::Cube<std::complex<float>>& GetParms() const { return parms_; }
/**
* Parse a string into an enum value
* Parse a H5Parm type string into an GainType enum value.
* The H5 strings are not equal to the corresponding strings
* that are returned by @ref GainTypeToHumanReadableString().
* @throws std::runtime_error when string is unrecognized
*/
static JonesParameters::CorrectType StringToCorrectType(const std::string&);
static GainType H5ParmTypeStringToGainType(
const std::string& h5parm_type_string);
/**
* Convert CorrectType to string
* Convert GainType to a string suitable for outputting to the user.
*/
static std::string CorrectTypeToString(JonesParameters::CorrectType);
static std::string GainTypeToHumanReadableString(GainType);
/**
* Parse a missing antennabehavior string into an enum value
......@@ -166,18 +169,18 @@ class JonesParameters {
* have to be inverted explicitly by calling Invert()
*/
void MakeComplex(size_t ant, const std::vector<double>& freqs,
CorrectType correct_type, bool invert = false);
GainType correct_type, bool invert = false);
/**
* Get the number of parameters for a given @param correct_type.
*/
static unsigned int GetNParms(CorrectType correct_type);
static unsigned int GetNParms(GainType correct_type);
/**
* Get the dimension for parm_values, i.e. the number of parameter names in
* the H5Parm.
*/
static unsigned int GetNParmValues(CorrectType correct_type);
static unsigned int GetNParmValues(GainType correct_type);
/**
* Fill the JonesParameters parameter values from the solution tables
......@@ -196,8 +199,8 @@ class JonesParameters {
const std::vector<double>& freqs,
const std::vector<double>& times,
const std::vector<std::string>& antenna_names, size_t ant,
CorrectType correct_type,
InterpolationType interpolation_type, hsize_t direction);
GainType gain_type, InterpolationType interpolation_type,
hsize_t direction);
/**
* Replace values by NaN on places where weight is zero
......@@ -215,7 +218,7 @@ class JonesParameters {
* \param correct_type Correction type of the Jones matrix
*/
static void Invert(casacore::Cube<std::complex<float>>& parms,
float sigma_mmse, CorrectType correct_type);
float sigma_mmse, GainType gain_type);
/// Parameter values, inner vector has dimension num_times * num_frequencies,
/// the middle vector has dimension number_antennas, outer vector has
......
This diff is collapsed.
......@@ -7,6 +7,7 @@
#include "h5parm.h"
using schaapcommon::h5parm::AxisInfo;
using schaapcommon::h5parm::GainType;
using schaapcommon::h5parm::H5Parm;
using schaapcommon::h5parm::JonesParameters;
using schaapcommon::h5parm::SolTab;
......@@ -49,8 +50,7 @@ class SolTabMock : public SolTab {
mutable int called;
};
JonesParameters PrepareJonesParameters(JonesParameters::CorrectType ct,
bool invert = false,
JonesParameters PrepareJonesParameters(GainType ct, bool invert = false,
float sigma_mmse = 0.,
unsigned int parm_size = 0) {
std::vector<std::string> antNames;
......@@ -72,8 +72,7 @@ JonesParameters PrepareJonesParameters(JonesParameters::CorrectType ct,
BOOST_AUTO_TEST_SUITE(jonesparameters)
BOOST_AUTO_TEST_CASE(make_complex_gain) {
JonesParameters jones =
PrepareJonesParameters(JonesParameters::CorrectType::GAIN);
JonesParameters jones = PrepareJonesParameters(GainType::kDiagonalComplex);
const auto parms = jones.GetParms();
BOOST_CHECK_EQUAL(parms.shape()[0], 2);
......@@ -85,8 +84,7 @@ BOOST_AUTO_TEST_CASE(make_complex_gain) {
}
BOOST_AUTO_TEST_CASE(make_scalar_gain) {
JonesParameters jones =
PrepareJonesParameters(JonesParameters::CorrectType::SCALARGAIN);
JonesParameters jones = PrepareJonesParameters(GainType::kScalarComplex);
const auto parms = jones.GetParms();
BOOST_CHECK_EQUAL(parms.shape()[0], 2);
......@@ -99,7 +97,7 @@ BOOST_AUTO_TEST_CASE(make_scalar_gain) {
BOOST_AUTO_TEST_CASE(make_complex_fulljones) {
JonesParameters jones =
PrepareJonesParameters(JonesParameters::CorrectType::FULLJONES, true, 1.);
PrepareJonesParameters(GainType::kFullJones, true, 1.);
const auto parms = jones.GetParms();
BOOST_CHECK_EQUAL(parms.shape()[0], 4);
......@@ -108,8 +106,7 @@ BOOST_AUTO_TEST_CASE(make_complex_fulljones) {
}
BOOST_AUTO_TEST_CASE(make_complex_tec) {
JonesParameters jones =
PrepareJonesParameters(JonesParameters::CorrectType::TEC, false, 0., 1U);
JonesParameters jones = PrepareJonesParameters(GainType::kTec, false, 0., 1U);
const auto parms = jones.GetParms();
BOOST_CHECK_EQUAL(parms.shape()[0], 2);
......@@ -118,8 +115,7 @@ BOOST_AUTO_TEST_CASE(make_complex_tec) {
}
BOOST_AUTO_TEST_CASE(make_complex_tec2) {
JonesParameters jones =
PrepareJonesParameters(JonesParameters::CorrectType::TEC, true, 0., 2U);
JonesParameters jones = PrepareJonesParameters(GainType::kTec, true, 0., 2U);
const auto parms = jones.GetParms();
BOOST_CHECK_CLOSE(parms(0, 0, 0).real(), -0.993747, 1e-3);
......@@ -127,8 +123,7 @@ BOOST_AUTO_TEST_CASE(make_complex_tec2) {
}
BOOST_AUTO_TEST_CASE(make_complex_r_angle) {
JonesParameters jones =
PrepareJonesParameters(JonesParameters::CorrectType::ROTATIONANGLE);
JonesParameters jones = PrepareJonesParameters(GainType::kRotationAngle);
const auto parms = jones.GetParms();
BOOST_CHECK_EQUAL(parms.shape()[0], 4);
......@@ -138,7 +133,7 @@ BOOST_AUTO_TEST_CASE(make_complex_r_angle) {
BOOST_AUTO_TEST_CASE(make_complex_r_angle_inverted) {
JonesParameters jones =
PrepareJonesParameters(JonesParameters::CorrectType::ROTATIONANGLE, true);
PrepareJonesParameters(GainType::kRotationAngle, true);
const auto parms = jones.GetParms();
BOOST_CHECK_CLOSE(parms(0, 0, 0).real(), 0.487187, 1e-3);
......@@ -146,8 +141,7 @@ BOOST_AUTO_TEST_CASE(make_complex_r_angle_inverted) {
}
BOOST_AUTO_TEST_CASE(make_complex_r_measure) {
JonesParameters jones =
PrepareJonesParameters(JonesParameters::CorrectType::ROTATIONMEASURE);
JonesParameters jones = PrepareJonesParameters(GainType::kRotationMeasure);
const auto parms = jones.GetParms();
BOOST_CHECK_EQUAL(parms.shape()[0], 4);
......@@ -156,17 +150,16 @@ BOOST_AUTO_TEST_CASE(make_complex_r_measure) {
}
BOOST_AUTO_TEST_CASE(make_complex_r_measure_inverted) {
JonesParameters jones = PrepareJonesParameters(
JonesParameters::CorrectType::ROTATIONMEASURE, true, 0.5, 4);
JonesParameters jones =
PrepareJonesParameters(GainType::kRotationMeasure, true, 0.5, 4);
const auto parms = jones.GetParms();
BOOST_CHECK_CLOSE(parms(0, 0, 0).real(), -0.185403, 1e-3);
BOOST_CHECK_CLOSE(parms(0, 0, 0).imag(), 0.0, 1e-3);
}
BOOST_AUTO_TEST_CASE(make_complex_phase) {
JonesParameters jones =
PrepareJonesParameters(JonesParameters::CorrectType::PHASE);
BOOST_AUTO_TEST_CASE(make_diagonal_phase) {
JonesParameters jones = PrepareJonesParameters(GainType::kDiagonalPhase);
const auto parms = jones.GetParms();
BOOST_CHECK_EQUAL(parms.shape()[0], 2);
......@@ -174,9 +167,8 @@ BOOST_AUTO_TEST_CASE(make_complex_phase) {
BOOST_CHECK_CLOSE(parms(0, 0, 0).imag(), -0.87329, 1e-3);
}
BOOST_AUTO_TEST_CASE(make_complex_scalar_phase) {
JonesParameters jones =
PrepareJonesParameters(JonesParameters::CorrectType::SCALARPHASE);
BOOST_AUTO_TEST_CASE(make_scalar_phase) {
JonesParameters jones = PrepareJonesParameters(GainType::kScalarPhase);
const auto parms = jones.GetParms();
BOOST_CHECK_EQUAL(parms.shape()[0], 2);
......@@ -185,8 +177,7 @@ BOOST_AUTO_TEST_CASE(make_complex_scalar_phase) {
}
BOOST_AUTO_TEST_CASE(make_complex_amplitude) {
JonesParameters jones =
PrepareJonesParameters(JonesParameters::CorrectType::AMPLITUDE);
JonesParameters jones = PrepareJonesParameters(GainType::kDiagonalAmplitude);
const auto parms = jones.GetParms();
BOOST_CHECK_EQUAL(parms.shape()[0], 2);
......@@ -194,9 +185,8 @@ BOOST_AUTO_TEST_CASE(make_complex_amplitude) {
BOOST_CHECK_CLOSE(parms(0, 0, 0).imag(), 0., 1e-3);
}
BOOST_AUTO_TEST_CASE(make_complex_scalar_amplitude) {
JonesParameters jones =
PrepareJonesParameters(JonesParameters::CorrectType::SCALARAMPLITUDE);
BOOST_AUTO_TEST_CASE(make_scalar_amplitude) {
JonesParameters jones = PrepareJonesParameters(GainType::kScalarAmplitude);
const auto parms = jones.GetParms();
BOOST_CHECK_EQUAL(parms.shape()[0], 2);
......@@ -205,8 +195,8 @@ BOOST_AUTO_TEST_CASE(make_complex_scalar_amplitude) {
}
BOOST_AUTO_TEST_CASE(make_complex_clock) {
JonesParameters jones = PrepareJonesParameters(
JonesParameters::CorrectType::CLOCK, false, 0., 1U);
JonesParameters jones =
PrepareJonesParameters(GainType::kClock, false, 0., 1U);
const auto parms = jones.GetParms();
BOOST_CHECK_EQUAL(parms.shape()[0], 2);
......@@ -216,7 +206,7 @@ BOOST_AUTO_TEST_CASE(make_complex_clock) {
BOOST_AUTO_TEST_CASE(make_complex_clock2) {
JonesParameters jones =
PrepareJonesParameters(JonesParameters::CorrectType::CLOCK, true, 50, 2U);
PrepareJonesParameters(GainType::kClock, true, 50, 2U);
const auto parms = jones.GetParms();
BOOST_CHECK_CLOSE(parms(0, 0, 0).real(), 1., 1e-3);
......@@ -225,7 +215,7 @@ BOOST_AUTO_TEST_CASE(make_complex_clock2) {
BOOST_AUTO_TEST_CASE(make_complex_gain_re_im) {
JonesParameters jones =
PrepareJonesParameters(JonesParameters::CorrectType::GAIN_RE_IM);
PrepareJonesParameters(GainType::kDiagonalRealImaginary);
const auto parms = jones.GetParms();
BOOST_CHECK_EQUAL(parms.shape()[0], 2);
......@@ -235,7 +225,7 @@ BOOST_AUTO_TEST_CASE(make_complex_gain_re_im) {
BOOST_AUTO_TEST_CASE(make_complex_fulljones_re_im) {
JonesParameters jones =
PrepareJonesParameters(JonesParameters::CorrectType::FULLJONES_RE_IM);
PrepareJonesParameters(GainType::kFullJonesRealImaginary);
const auto parms = jones.GetParms();
BOOST_CHECK_EQUAL(parms.shape()[0], 4);
......@@ -254,8 +244,7 @@ BOOST_AUTO_TEST_CASE(fulljones_with_nullptr) {
SolTabMock mock = SolTabMock();
BOOST_CHECK_THROW(
JonesParameters jones(kFreqs, kTimes, antNames,
JonesParameters::CorrectType::FULLJONES,
JonesParameters jones(kFreqs, kTimes, antNames, GainType::kFullJones,
kInterpolationType, kDirection, &mock, nullptr),
std::runtime_error);
}
......@@ -270,11 +259,10 @@ BOOST_AUTO_TEST_CASE(missing_antenna_error) {
SolTabMock mock = SolTabMock();
BOOST_CHECK_THROW(
JonesParameters jones(kFreqs, kTimes, antNames,
JonesParameters::CorrectType::AMPLITUDE,
kInterpolationType, kDirection, &mock, nullptr),
std::runtime_error);
BOOST_CHECK_THROW(JonesParameters jones(
kFreqs, kTimes, antNames, GainType::kDiagonalAmplitude,
kInterpolationType, kDirection, &mock, nullptr),
std::runtime_error);
}
BOOST_AUTO_TEST_CASE(missing_antenna_flag) {
......@@ -287,8 +275,7 @@ BOOST_AUTO_TEST_CASE(missing_antenna_flag) {
SolTabMock mock = SolTabMock();
JonesParameters jones(kFreqs, kTimes, antNames,
JonesParameters::CorrectType::AMPLITUDE,
JonesParameters jones(kFreqs, kTimes, antNames, GainType::kDiagonalAmplitude,
kInterpolationType, kDirection, &mock, nullptr, false,
0, 0, JonesParameters::MissingAntennaBehavior::kFlag);
......@@ -308,8 +295,7 @@ BOOST_AUTO_TEST_CASE(missing_antenna_unit_diag) {
SolTabMock mock = SolTabMock();
JonesParameters jones(kFreqs, kTimes, antNames,
JonesParameters::CorrectType::AMPLITUDE,
JonesParameters jones(kFreqs, kTimes, antNames, GainType::kDiagonalAmplitude,
kInterpolationType, kDirection, &mock, nullptr, false,
0, 0, JonesParameters::MissingAntennaBehavior::kUnit);
......@@ -331,8 +317,7 @@ BOOST_AUTO_TEST_CASE(missing_antenna_unit_full) {
SolTabMock mock = SolTabMock();
JonesParameters jones(kFreqs, kTimes, antNames,
JonesParameters::CorrectType::ROTATIONANGLE,
JonesParameters jones(kFreqs, kTimes, antNames, GainType::kRotationAngle,
kInterpolationType, kDirection, &mock, nullptr, false,
0, 0, JonesParameters::MissingAntennaBehavior::kUnit);
......@@ -349,21 +334,66 @@ BOOST_AUTO_TEST_CASE(missing_antenna_unit_full) {
BOOST_CHECK_EQUAL(parms(3, kNAnts, 0).imag(), 0.);
}
BOOST_AUTO_TEST_CASE(correcttype_to_str) {
std::vector<std::string> correction_names = {
BOOST_AUTO_TEST_CASE(gain_type_to_human_readable_str) {
const std::vector<std::string> kGainTypeNames = {
"diagonal complex",
"full-Jones",
"scalar complex",
"TEC",
"clock",
"rotation angle",
"scalar phase",
"diagonal phase",
"rotation measure",
"scalar amplitude",
"diagonal amplitude",
"diagonal complex (real/imaginary)",
"full-Jones (real/imaginary)"};
const std::vector<GainType> kGainTypes = {GainType::kDiagonalComplex,
GainType::kFullJones,
GainType::kScalarComplex,
GainType::kTec,
GainType::kClock,
GainType::kRotationAngle,
GainType::kScalarPhase,
GainType::kDiagonalPhase,
GainType::kRotationMeasure,
GainType::kScalarAmplitude,
GainType::kDiagonalAmplitude,
GainType::kDiagonalRealImaginary,
GainType::kFullJonesRealImaginary};
BOOST_REQUIRE_EQUAL(kGainTypeNames.size(), kGainTypes.size());
for (size_t i = 0; i != kGainTypeNames.size(); ++i) {
const std::string human_string =
JonesParameters::GainTypeToHumanReadableString(kGainTypes[i]);
BOOST_CHECK_EQUAL(kGainTypeNames[i], human_string);
}
}
BOOST_AUTO_TEST_CASE(h5_parm_type_string_to_gain_type) {
const std::vector<std::string> kH5TypeStrings = {
"gain", "fulljones", "tec", "clock",
"scalarphase", "scalaramplitude", "rotationangle", "rotationmeasure",
"phase", "amplitude"};
for (const std::string& correction_name : correction_names) {
JonesParameters::CorrectType correction_type =
JonesParameters::StringToCorrectType(correction_name);
std::string correction_name_back =
JonesParameters::CorrectTypeToString(correction_type);
BOOST_CHECK_EQUAL(correction_name, correction_name_back);
const std::vector<GainType> kGainTypes = {GainType::kDiagonalComplex,
GainType::kFullJones,
GainType::kTec,
GainType::kClock,
GainType::kScalarPhase,
GainType::kScalarAmplitude,
GainType::kRotationAngle,
GainType::kRotationMeasure,
GainType::kDiagonalPhase,
GainType::kDiagonalAmplitude};
BOOST_REQUIRE_EQUAL(kH5TypeStrings.size(), kGainTypes.size());
for (size_t i = 0; i != kH5TypeStrings.size(); ++i) {
const GainType result_gain_type =
JonesParameters::H5ParmTypeStringToGainType(kH5TypeStrings[i]);
BOOST_CHECK(result_gain_type == kGainTypes[i]);
}
BOOST_CHECK_THROW(JonesParameters::StringToCorrectType("nosuchcorrection"),
std::runtime_error);
BOOST_CHECK_THROW(
JonesParameters::H5ParmTypeStringToGainType("nosuchcorrection"),
std::runtime_error);
}
BOOST_AUTO_TEST_SUITE_END()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment