Skip to content
Snippets Groups Projects
Commit 794ab501 authored by Bas van der Tol's avatar Bas van der Tol
Browse files

WIP

parent 88a89abc
No related tags found
No related merge requests found
Pipeline #102803 failed
......@@ -196,6 +196,14 @@ class SolTab : private H5::Group {
const std::vector<double>& freqs,
size_t pol, size_t dir,
bool nearest) const;
std::tuple<int, int, int, int, int> GetValuesOrWeights(
const std::string& val_or_weight,
unsigned int startantenna, unsigned int nantenna, unsigned int antennastep,
unsigned int starttimeslot, unsigned int ntime, unsigned int timestep,
unsigned int startfreq, unsigned int nfreq, unsigned int freqstep,
unsigned int startpol, unsigned int npol, unsigned int polstep,
unsigned int startdir, unsigned int ndir, unsigned int dirstep,
std::vector<double> &buffer) 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.
......
......@@ -362,6 +362,104 @@ std::vector<double> SolTab::GetValuesOrWeights(
frequencies, sub_array, mem_layout, nearest);
}
std::tuple<int, int, int, int, int> SolTab::GetValuesOrWeights(
const std::string& val_or_weight,
unsigned int startantenna, unsigned int nantenna, unsigned int antennastep,
unsigned int starttimeslot, unsigned int ntime, unsigned int timestep,
unsigned int startfreq, unsigned int nfreq, unsigned int freqstep,
unsigned int startpol, unsigned int npol, unsigned int polstep,
unsigned int startdir, unsigned int ndir, unsigned int dirstep,
std::vector<double> &buffer) const {
H5::DataSet val = openDataSet(val_or_weight);
// Set offsets and strides
std::vector<hsize_t> memdims;
std::vector<hsize_t> offsets;
std::vector<hsize_t> counts;
std::vector<hsize_t> strides;
memdims.reserve(axes_.size());
offsets.reserve(axes_.size());
counts.reserve(axes_.size());
strides.reserve(axes_.size());
for (const AxisInfo& axis_info : axes_) {
hsize_t stride = 1;
hsize_t count = 1;
hsize_t offset = 0;
if (axis_info.name == "time") {
offset = starttimeslot;
stride = timestep;
count = ntime;
} else if (axis_info.name == "freq") {
offset = startfreq;
stride = freqstep;
count = nfreq;
} else if (axis_info.name == "ant") {
offset = startantenna;
stride = antennastep;
count = nantenna;
} else if (axis_info.name == "dir") {
offset = startdir;
stride = dirstep;
count = ndir;
} else if (axis_info.name == "pol") {
offset = startpol;
stride = polstep;
count = npol;
} else if (axis_info.size != 1) {
throw std::runtime_error("Axis \"" + axis_info.name +
"\" in H5Parm is not understood");
}
memdims.push_back(count);
offsets.push_back(offset);
counts.push_back(count);
strides.push_back(stride);
}
int ant_stride = 0;
int time_stride = 0;
int freq_stride = 0;
int pol_stride = 0;
int dir_stride = 0;
int stride = 1;
for (auto axis_info = axes_.rbegin(); axis_info != axes_.rend(); ++axis_info) {
if (axis_info->name == "time") {
time_stride = stride;
stride *= ntime;
} else if (axis_info->name == "freq") {
freq_stride = stride;
stride *= nfreq;
} else if (axis_info->name == "ant") {
ant_stride = stride;
stride *= nantenna;
} else if (axis_info->name == "dir") {
dir_stride = stride;
stride *= ndir;
} else if (axis_info->name == "pol") {
pol_stride = stride;
stride *= npol;
}
}
buffer.resize(stride);
H5::DataSpace dataspace = val.getSpace();
dataspace.selectHyperslab(H5S_SELECT_SET, counts.data(), offsets.data(),
strides.data());
// Setup memory dataspace
H5::DataSpace memspace(axes_.size(), memdims.data());
try {
val.read(buffer.data(), H5::PredType::NATIVE_DOUBLE, memspace, dataspace);
} catch (H5::DataSetIException& e) {
e.printErrorStack();
throw std::runtime_error("Could not read data");
}
return {ant_stride, time_stride, freq_stride,
pol_stride, dir_stride};
}
void SolTab::ApplyFlags(std::vector<double>& values,
const std::vector<double>& weights) {
assert(values.size() == weights.size());
......
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