diff --git a/include/schaapcommon/h5parm/h5cache.h b/include/schaapcommon/h5parm/h5cache.h index 13369775bbe55c8ca4a971c2efd02d50f5482524..114580a6422d63c50c7328b3758007fc8d1d7a5b 100644 --- a/include/schaapcommon/h5parm/h5cache.h +++ b/include/schaapcommon/h5parm/h5cache.h @@ -52,8 +52,7 @@ class H5Cache : public SolTab { std::vector<double> GetValues(const std::string& antenna_name, const std::vector<double>& times, const std::vector<double>& frequencies, - unsigned int polarization, - unsigned int direction, + size_t polarization, size_t direction, bool nearest) const override; private: @@ -70,12 +69,10 @@ class H5Cache : public SolTab { * the weights were read and applied. */ std::vector<double> GetSubArray(const std::string& antenna_name, - unsigned int start_time, unsigned int n_times, - unsigned int time_step, - unsigned int start_freq, unsigned int n_freqs, - unsigned int freq_step, - unsigned int polarization, - unsigned int direction) const; + size_t start_time, size_t n_times, + size_t time_step, size_t start_freq, + size_t n_freqs, size_t freq_step, + size_t polarization, size_t direction) const; /** * In-memory array to keep all flagged values of the H5 diff --git a/include/schaapcommon/h5parm/jonesparameters.h b/include/schaapcommon/h5parm/jonesparameters.h index f63c862e11dbce58034529566f1415b3e7ca2424..54345038a6810d3b621f414a4b0a1ecdf1812acc 100644 --- a/include/schaapcommon/h5parm/jonesparameters.h +++ b/include/schaapcommon/h5parm/jonesparameters.h @@ -127,7 +127,7 @@ class JonesParameters { 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, + size_t parm_size = 0, MissingAntennaBehavior missing_antenna_behavior = MissingAntennaBehavior::kError); @@ -180,13 +180,13 @@ class JonesParameters { /** * Get the number of parameters for a given @param correct_type. */ - static unsigned int GetNParms(GainType correct_type); + static size_t GetNParms(GainType correct_type); /** * Get the dimension for parm_values, i.e. the number of parameter names in * the H5Parm. */ - static unsigned int GetNParmValues(GainType correct_type); + static size_t GetNParmValues(GainType correct_type); /** * Fill the JonesParameters parameter values from the solution tables diff --git a/include/schaapcommon/h5parm/soltab.h b/include/schaapcommon/h5parm/soltab.h index b8aa428c4be612ad0d72cd643d9424c8c98f4988..7edac7b2b700f797d4038b90db02b40102fd2f27 100644 --- a/include/schaapcommon/h5parm/soltab.h +++ b/include/schaapcommon/h5parm/soltab.h @@ -17,16 +17,16 @@ namespace h5parm { /// A name and the length of an exis, e.g. ('freq', 800) for 800 frequencies struct AxisInfo { std::string name; - unsigned int size; + size_t size; }; struct TimesAndFrequencies { std::vector<double> time_axis; - unsigned int start_time_index; - unsigned int num_times; + size_t start_time_index; + size_t num_times; std::vector<double> freq_axis; - unsigned int start_freq_index; - unsigned int num_freqs; + size_t start_freq_index; + size_t num_freqs; }; /// @brief SolTab is a solution table as defined in the H5Parm standard. It @@ -54,7 +54,7 @@ class SolTab : private H5::Group { const std::vector<AxisInfo>& GetAxes() const { return axes_; } - AxisInfo GetAxis(unsigned int i) const; + AxisInfo GetAxis(size_t i) const; /// Get an axis, throw an exception if it does not exist AxisInfo GetAxis(const std::string& axis_name) const; @@ -140,20 +140,19 @@ class SolTab : private H5::Group { /// Get the values of this SolTab for a given antenna. std::vector<double> GetValues(const std::string& ant_name, - unsigned int starttimeslot, unsigned int ntime, - unsigned int timestep, unsigned int startfreq, - unsigned int nfreq, unsigned int freqstep, - unsigned int pol, unsigned int dir) const { + size_t starttimeslot, size_t ntime, + size_t timestep, size_t startfreq, size_t nfreq, + size_t freqstep, size_t pol, size_t dir) const { return GetSubArray("val", ant_name, starttimeslot, ntime, timestep, startfreq, nfreq, freqstep, pol, dir); } /// Get the weights of this SolTab for a given antenna. std::vector<double> GetWeights(const std::string& ant_name, - unsigned int starttimeslot, unsigned int ntime, - unsigned int timestep, unsigned int startfreq, - unsigned int nfreq, unsigned int freqstep, - unsigned int pol, unsigned int dir) const { + size_t starttimeslot, size_t ntime, + size_t timestep, size_t startfreq, + size_t nfreq, size_t freqstep, size_t pol, + size_t dir) const { return GetSubArray("weight", ant_name, starttimeslot, ntime, timestep, startfreq, nfreq, freqstep, pol, dir); } @@ -164,32 +163,33 @@ class SolTab : private H5::Group { virtual std::vector<double> GetValues(const std::string& antenna_name, const std::vector<double>& times, const std::vector<double>& frequencies, - unsigned int polarization, - unsigned int direction, + size_t polarization, size_t direction, bool nearest) const; // Find the nearest time and frequency indices from H5 file for the // time and frequencies in the arguments. TimesAndFrequencies GetTimesAndFrequencies(const std::vector<double>& times, const std::vector<double>& freqs, - unsigned int pol, unsigned int dir, + size_t pol, size_t dir, bool nearest) const; /// Get the values or weights of this SolTab for a given antenna given an /// antenna name, a direction index, and a (range of) times and frequencies. /// In the returned vector, the freq will be the fastest changing index, /// irrespective of the axis ordering in the underlying h5 data structure. - std::vector<double> GetSubArray( - const std::string& val_or_weight, const std::string& antenna_name, - const unsigned int start_time_index, const unsigned int n_times, - const unsigned int time_step, const unsigned int start_freq_index, - const unsigned int n_freqs, const unsigned int freq_step, - const unsigned int pol, const unsigned int dir) const; - - std::vector<double> GetValuesOrWeights( - const std::string& val_or_weight, const std::string& antenna_name, - const std::vector<double>& times, const std::vector<double>& frequencies, - unsigned int polarization, unsigned int direction, bool nearest) const; + std::vector<double> GetSubArray(const std::string& val_or_weight, + const std::string& antenna_name, + size_t start_time_index, size_t n_times, + size_t time_step, size_t start_freq_index, + size_t n_freqs, size_t freq_step, size_t pol, + size_t dir) const; + + std::vector<double> GetValuesOrWeights(const std::string& val_or_weight, + const std::string& antenna_name, + const std::vector<double>& times, + const std::vector<double>& frequencies, + size_t polarization, size_t direction, + bool nearest) const; /** * Depending on 'weights' some 'values' are discarded, diff --git a/src/h5parm/h5cache.cc b/src/h5parm/h5cache.cc index ba137ce62f918658820955bb681b73eef4230ea8..291622705fb50a28228ba4142b8e13eb1a0995f0 100644 --- a/src/h5parm/h5cache.cc +++ b/src/h5parm/h5cache.cc @@ -25,8 +25,7 @@ H5Cache::H5Cache(H5::Group group) : SolTab(group) { FillFlaggedValues(); } std::vector<double> H5Cache::GetValues(const std::string& antenna_name, const std::vector<double>& times, const std::vector<double>& frequencies, - unsigned int polarization, - unsigned int direction, + size_t polarization, size_t direction, bool nearest) const { TimesAndFrequencies times_and_frequencies = GetTimesAndFrequencies( times, frequencies, polarization, direction, nearest); @@ -51,11 +50,12 @@ std::vector<double> H5Cache::GetValues(const std::string& antenna_name, frequencies, values, mem_layout, nearest); } -std::vector<double> H5Cache::GetSubArray( - const std::string& antenna_name, unsigned int start_time, - unsigned int n_times, unsigned int time_step, unsigned int start_freq, - unsigned int n_freqs, unsigned int freq_step, unsigned int polarization, - unsigned int direction) const { +std::vector<double> H5Cache::GetSubArray(const std::string& antenna_name, + size_t start_time, size_t n_times, + size_t time_step, size_t start_freq, + size_t n_freqs, size_t freq_step, + size_t polarization, + size_t direction) const { assert(time_step >= 1); assert(freq_step >= 1); diff --git a/src/h5parm/h5parm.cc b/src/h5parm/h5parm.cc index a27359dd4c4e32af2d5550864c808f7f4b0319e3..986024514e65f63326f86a43b9ceebfab6aab6a2 100644 --- a/src/h5parm/h5parm.cc +++ b/src/h5parm/h5parm.cc @@ -33,7 +33,7 @@ H5Parm::H5Parm(const std::string& filename, bool force_new, // Get the name of first non-existing solset std::stringstream new_sol_set_name; H5::Group try_group; - for (unsigned int sol_set_idx = 0; sol_set_idx < 100; ++sol_set_idx) { + for (size_t sol_set_idx = 0; sol_set_idx < 100; ++sol_set_idx) { try { H5::Exception::dontPrint(); new_sol_set_name << "sol" << std::setfill('0') << std::setw(3) @@ -67,7 +67,7 @@ H5Parm::H5Parm(const std::string& filename, bool force_new, sol_set_ = openGroup(sol_set_name_to_open); std::vector<std::string> sol_tab_names; - for (unsigned int i = 0; i < sol_set_.getNumObjs(); ++i) { + for (size_t i = 0; i < sol_set_.getNumObjs(); ++i) { if (sol_set_.getObjTypeByIdx(i) == H5G_GROUP) { sol_tab_names.push_back(sol_set_.getObjnameByIdx(i)); } @@ -171,7 +171,7 @@ void H5Parm::AddSources(const std::vector<std::string>& names, // Prepare data std::vector<source_t> sources(names.size()); - for (unsigned int src = 0; src < sources.size(); ++src) { + for (size_t src = 0; src < sources.size(); ++src) { std::strncpy(sources[src].name, names[src].c_str(), 127); sources[src].name[127] = 0; sources[src].dir[0] = dirs[src].first; @@ -202,7 +202,7 @@ void H5Parm::AddAntennas(const std::vector<std::string>& names, // Prepare data std::vector<antenna_t> ants(names.size()); - for (unsigned int ant = 0; ant < ants.size(); ++ant) { + for (size_t ant = 0; ant < ants.size(); ++ant) { std::strncpy(ants[ant].name, names[ant].c_str(), 15); ants[ant].name[15] = 0; const std::array<double, 3>& pos = positions[ant]; diff --git a/src/h5parm/jonesparameters.cc b/src/h5parm/jonesparameters.cc index 907e84b154d1a0504365aef9c3dc5c1485951839..438f94f0aca2327048c562ec289d52fba2cfd81b 100644 --- a/src/h5parm/jonesparameters.cc +++ b/src/h5parm/jonesparameters.cc @@ -29,7 +29,7 @@ JonesParameters::JonesParameters( InterpolationType interpolation_type, hsize_t direction, std::vector<std::vector<std::vector<double>>>&& parm_values, bool invert, float sigma_mmse) { - const unsigned int num_parms = GetNParms(gain_type); + const size_t num_parms = GetNParms(gain_type); parms_.resize(num_parms, antenna_names.size(), freqs.size() * times.size()); for (size_t ant = 0; ant < antenna_names.size(); ++ant) { MakeComplex(parm_values, ant, freqs, gain_type, invert); @@ -49,7 +49,7 @@ JonesParameters::JonesParameters( * Expected format of the parm_values is [n_chans, n_ants, n_pols] * So we reorder the matrices below */ - const unsigned int num_parms = GetNParms(gain_type); + const size_t num_parms = GetNParms(gain_type); parms_.resize(num_parms, antenna_names.size(), freqs.size() * times.size()); for (uint i = 0; i < solution.size(); i++) { @@ -72,8 +72,8 @@ JonesParameters::JonesParameters( InterpolationType interpolation_type, hsize_t direction, schaapcommon::h5parm::SolTab* sol_tab, schaapcommon::h5parm::SolTab* sol_tab2, bool invert, float sigma_mmse, - unsigned int parm_size, MissingAntennaBehavior missing_antenna_behavior) { - const unsigned int num_parms = GetNParms(gain_type); + size_t parm_size, MissingAntennaBehavior missing_antenna_behavior) { + const size_t num_parms = GetNParms(gain_type); parms_.resize(num_parms, antenna_names.size(), freqs.size() * times.size()); if (parm_size == 0U) { @@ -131,7 +131,8 @@ void JonesParameters::MakeComplex( const std::vector<std::vector<std::vector<double>>>& parm_values, size_t ant, const std::vector<double>& freqs, GainType gain_type, bool invert) { - for (unsigned int tf = 0; tf < parms_.shape()[2]; ++tf) { + const size_t tf_size = parms_.shape()[2]; + for (size_t tf = 0; tf < tf_size; ++tf) { const double freq = freqs[tf % freqs.size()]; switch (gain_type) { @@ -242,7 +243,7 @@ void JonesParameters::MakeComplex( } } -unsigned int JonesParameters::GetNParms(GainType gain_type) { +size_t JonesParameters::GetNParms(GainType gain_type) { switch (gain_type) { case GainType::kFullJones: case GainType::kRotationAngle: @@ -254,7 +255,7 @@ unsigned int JonesParameters::GetNParms(GainType gain_type) { } } -unsigned int JonesParameters::GetNParmValues(GainType gain_type) { +size_t JonesParameters::GetNParmValues(GainType gain_type) { switch (gain_type) { case GainType::kFullJones: case GainType::kFullJonesRealImaginary: @@ -314,11 +315,13 @@ void JonesParameters::FillParmValues( void JonesParameters::Invert(casacore::Cube<casacore::Complex>& parms, float sigma_mmse, GainType gain_type) { - for (unsigned int tf = 0; tf < parms.shape()[2]; ++tf) { - for (unsigned int ant = 0; ant < parms.shape()[1]; ++ant) { + const size_t tf_size = parms.shape()[2]; + const size_t ant_size = parms.shape()[1]; + for (size_t tf = 0; tf < tf_size; ++tf) { + for (size_t ant = 0; ant < ant_size; ++ant) { if (parms.shape()[0] == 2) { - parms(0, ant, tf) = 1.f / parms(0, ant, tf); - parms(1, ant, tf) = 1.f / parms(1, ant, tf); + parms(0, ant, tf) = 1.0f / parms(0, ant, tf); + parms(1, ant, tf) = 1.0f / parms(1, ant, tf); } else if (gain_type == GainType::kFullJones || gain_type == GainType::kFullJonesRealImaginary) { aocommon::MC2x2F v(&parms(0, ant, tf)); diff --git a/src/h5parm/soltab.cc b/src/h5parm/soltab.cc index 7008b75e06af7af25266acb4f668751cb85a2e81..043f1e5dd3c47d7b27f2bedfc68ccba9ef439a75 100644 --- a/src/h5parm/soltab.cc +++ b/src/h5parm/soltab.cc @@ -75,7 +75,7 @@ void SolTab::AddVersionStamp(H5::Group& node) { attr.write(H5::StrType(H5::PredType::C_S1, 3), "1.0"); } -AxisInfo SolTab::GetAxis(unsigned int i) const { return axes_[i]; } +AxisInfo SolTab::GetAxis(size_t i) const { return axes_[i]; } AxisInfo SolTab::GetAxis(const std::string& axis_name) const { for (const AxisInfo& axis_info : axes_) { @@ -109,7 +109,7 @@ void SolTab::SetValues(const std::vector<double>& vals, size_t expectedsize = 1; std::string axesstr = axes_.front().name; std::vector<hsize_t> dims(axes_.size()); - for (unsigned int i = 0; i < axes_.size(); ++i) { + for (size_t i = 0; i < axes_.size(); ++i) { dims[i] = axes_[i].size; expectedsize *= dims[i]; if (i > 0) { @@ -232,7 +232,7 @@ void SolTab::ReadAxes() { axesattr.read(axesattr.getDataType(), axes_chars.data()); std::vector<std::string> axesnames = Tokenize(axes_chars.data(), ","); - unsigned int ndims = axesnames.size(); + const size_t ndims = axesnames.size(); // Get number of dimensions and size of all dimensions H5::DataSpace ds = val.getSpace(); @@ -246,9 +246,8 @@ void SolTab::ReadAxes() { std::vector<hsize_t> dims_out(ndims, 0); ds.getSimpleExtentDims(dims_out.data()); - for (unsigned int i = 0; i < axesnames.size(); ++i) { - AxisInfo a{axesnames[i], static_cast<unsigned int>(dims_out[i])}; - axes_.push_back(a); + for (size_t i = 0; i < axesnames.size(); ++i) { + axes_.push_back(AxisInfo{axesnames[i], dims_out[i]}); } if (HasAxis("time")) { @@ -276,8 +275,7 @@ std::string SolTab::GetName() const { std::vector<double> SolTab::GetValues(const std::string& antenna_name, const std::vector<double>& times, const std::vector<double>& frequencies, - unsigned int polarization, - unsigned int direction, + size_t polarization, size_t direction, bool nearest) const { std::vector<double> values = GetValuesOrWeights("val", antenna_name, times, frequencies, polarization, @@ -295,7 +293,7 @@ std::vector<double> SolTab::GetValues(const std::string& antenna_name, std::vector<double> SolTab::GetValuesOrWeights( const std::string& val_or_weight, const std::string& antenna_name, const std::vector<double>& times, const std::vector<double>& frequencies, - unsigned int polarization, unsigned int direction, bool nearest) const { + size_t polarization, size_t direction, bool nearest) const { TimesAndFrequencies times_and_frequencies = GetTimesAndFrequencies( times, frequencies, polarization, direction, nearest); @@ -331,7 +329,7 @@ void SolTab::ApplyFlags(std::vector<double>& values, TimesAndFrequencies SolTab::GetTimesAndFrequencies( const std::vector<double>& times, const std::vector<double>& frequencies, - unsigned int pol, unsigned int dir, bool nearest) const { + size_t pol, size_t dir, bool nearest) const { assert(!times.empty()); assert(!frequencies.empty()); @@ -395,7 +393,7 @@ TimesAndFrequencies SolTab::GetTimesAndFrequencies( times_and_frequencies.num_freqs); } if (HasAxis("pol")) { - unsigned int num_pol_h5 = GetAxis("pol").size; + const size_t num_pol_h5 = GetAxis("pol").size; if (pol > num_pol_h5 - 1) { throw std::runtime_error("Polarization " + std::to_string(pol) + " requested from H5Parm, but only " + @@ -409,10 +407,9 @@ TimesAndFrequencies SolTab::GetTimesAndFrequencies( std::vector<double> SolTab::GetSubArray( const std::string& val_or_weight, const std::string& antenna_name, - const unsigned int start_time_index, const unsigned int n_times, - const unsigned int time_step, const unsigned int start_freq_index, - const unsigned int n_freqs, const unsigned int freq_step, - const unsigned int polarization, const unsigned int direction) const { + const size_t start_time_index, const size_t n_times, const size_t time_step, + const size_t start_freq_index, const size_t n_freqs, const size_t freq_step, + const size_t polarization, const size_t direction) const { std::vector<double> res(n_times * n_freqs); H5::DataSet val = openDataSet(val_or_weight); diff --git a/src/h5parm/test/th5parm.cc b/src/h5parm/test/th5parm.cc index ab3c58e7511cdf48a9863c3fbd0e17e27b0fa75c..ceb30f4e36390379a847821e2df59e9dea6ac96e 100644 --- a/src/h5parm/test/th5parm.cc +++ b/src/h5parm/test/th5parm.cc @@ -47,7 +47,7 @@ void InitializeH5(H5Parm& h5parm) { // Add some metadata std::vector<std::string> antNames; std::vector<std::array<double, 3>> antPositions; - for (unsigned int i = 0; i < 5; ++i) { + for (size_t i = 0; i < 5; ++i) { std::stringstream antNameStr; antNameStr << "Antenna" << i; antNames.push_back(antNameStr.str()); diff --git a/src/h5parm/test/tjonesparameters.cc b/src/h5parm/test/tjonesparameters.cc index beab094c9ce93db03451267a7922d70d73d52d03..19decd9f41f8716cd2f9dd281a6b7144ef648e3e 100644 --- a/src/h5parm/test/tjonesparameters.cc +++ b/src/h5parm/test/tjonesparameters.cc @@ -14,7 +14,7 @@ using schaapcommon::h5parm::SolTab; const std::vector<double> kFreqs{130e6, 131e6}; const std::vector<double> kTimes{0., 1.}; -const unsigned int kNAnts = 4; +const size_t kNAnts = 4; const JonesParameters::InterpolationType kInterpolationType = JonesParameters::InterpolationType::LINEAR; const hsize_t kDirection = 42; @@ -25,8 +25,7 @@ class SolTabMock : public SolTab { std::vector<double> GetValues(const std::string& ant_name, const std::vector<double>& times, const std::vector<double>& frequencies, - unsigned int polarization, - unsigned int direction, + size_t polarization, size_t direction, bool nearest) const override { ++called; auto res = std::vector<double>(kNAnts, 200.); @@ -48,9 +47,9 @@ class SolTabMock : public SolTab { JonesParameters PrepareJonesParameters(GainType ct, bool invert = false, float sigma_mmse = 0., - unsigned int parm_size = 0) { + size_t parm_size = 0) { std::vector<std::string> antNames; - for (unsigned int i = 0; i < kNAnts; ++i) { + for (size_t i = 0; i < kNAnts; ++i) { std::stringstream antNameStr; antNameStr << "Antenna" << i; antNames.push_back(antNameStr.str()); @@ -231,7 +230,7 @@ BOOST_AUTO_TEST_CASE(make_complex_fulljones_re_im) { BOOST_AUTO_TEST_CASE(fulljones_with_nullptr) { std::vector<std::string> antNames; - for (unsigned int i = 0; i < kNAnts; ++i) { + for (size_t i = 0; i < kNAnts; ++i) { std::stringstream antNameStr; antNameStr << "Antenna" << i; antNames.push_back(antNameStr.str()); @@ -247,7 +246,7 @@ BOOST_AUTO_TEST_CASE(fulljones_with_nullptr) { BOOST_AUTO_TEST_CASE(missing_antenna_error) { std::vector<std::string> antNames; - for (unsigned int i = 0; i < kNAnts + 1; ++i) { + for (size_t i = 0; i < kNAnts + 1; ++i) { std::stringstream antNameStr; antNameStr << "Antenna" << i; antNames.push_back(antNameStr.str()); @@ -263,7 +262,7 @@ BOOST_AUTO_TEST_CASE(missing_antenna_error) { BOOST_AUTO_TEST_CASE(missing_antenna_flag) { std::vector<std::string> antNames; - for (unsigned int i = 0; i < kNAnts + 1; ++i) { + for (size_t i = 0; i < kNAnts + 1; ++i) { std::stringstream antNameStr; antNameStr << "Antenna" << i; antNames.push_back(antNameStr.str()); @@ -283,7 +282,7 @@ BOOST_AUTO_TEST_CASE(missing_antenna_flag) { BOOST_AUTO_TEST_CASE(missing_antenna_unit_diag) { std::vector<std::string> antNames; - for (unsigned int i = 0; i < kNAnts + 1; ++i) { + for (size_t i = 0; i < kNAnts + 1; ++i) { std::stringstream antNameStr; antNameStr << "Antenna" << i; antNames.push_back(antNameStr.str()); @@ -305,7 +304,7 @@ BOOST_AUTO_TEST_CASE(missing_antenna_unit_diag) { BOOST_AUTO_TEST_CASE(missing_antenna_unit_full) { std::vector<std::string> antNames; - for (unsigned int i = 0; i < kNAnts + 1; ++i) { + for (size_t i = 0; i < kNAnts + 1; ++i) { std::stringstream antNameStr; antNameStr << "Antenna" << i; antNames.push_back(antNameStr.str());