mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-07-14 04:41:50 +02:00
fixed warnings and removed ambiguous read_frame
This commit is contained in:
@ -49,6 +49,7 @@ class JungfrauDataFile : public FileInterface {
|
|||||||
size_t total_frames() const override;
|
size_t total_frames() const override;
|
||||||
size_t rows() const override;
|
size_t rows() const override;
|
||||||
size_t cols() const override;
|
size_t cols() const override;
|
||||||
|
std::array<ssize_t,2> shape() const;
|
||||||
size_t n_files() const; //!< get the number of files in the series.
|
size_t n_files() const; //!< get the number of files in the series.
|
||||||
|
|
||||||
// Extra functions needed for FileInterface
|
// Extra functions needed for FileInterface
|
||||||
@ -81,13 +82,6 @@ class JungfrauDataFile : public FileInterface {
|
|||||||
*/
|
*/
|
||||||
void read_into(NDArray<uint16_t>* image, JungfrauDataHeader* header = nullptr);
|
void read_into(NDArray<uint16_t>* image, JungfrauDataHeader* header = nullptr);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Read a single frame from the file. Allocated a new NDArray for the output data
|
|
||||||
* @param header pointer to a JungfrauDataHeader or nullptr to skip header)
|
|
||||||
* @return NDArray with the image data
|
|
||||||
*/
|
|
||||||
NDArray<uint16_t> read_frame(JungfrauDataHeader* header = nullptr);
|
|
||||||
|
|
||||||
JungfrauDataHeader read_header();
|
JungfrauDataHeader read_header();
|
||||||
std::filesystem::path current_file() const { return fpath(m_current_file_index+m_offset); }
|
std::filesystem::path current_file() const { return fpath(m_current_file_index+m_offset); }
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ template <typename T, int64_t Ndim = 2> class NDView : public ArrayExpr<NDView<T
|
|||||||
}
|
}
|
||||||
|
|
||||||
size_t size() const { return size_; }
|
size_t size() const { return size_; }
|
||||||
|
ssize_t ssize() const { return static_cast<ssize_t>(size_); }
|
||||||
size_t total_bytes() const { return size_ * sizeof(T); }
|
size_t total_bytes() const { return size_ * sizeof(T); }
|
||||||
std::array<int64_t, Ndim> strides() const noexcept { return strides_; }
|
std::array<int64_t, Ndim> strides() const noexcept { return strides_; }
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@ namespace aare {
|
|||||||
Interpolator::Interpolator(NDView<double, 3> etacube, NDView<double, 1> xbins,
|
Interpolator::Interpolator(NDView<double, 3> etacube, NDView<double, 1> xbins,
|
||||||
NDView<double, 1> ybins, NDView<double, 1> ebins)
|
NDView<double, 1> ybins, NDView<double, 1> ebins)
|
||||||
: m_ietax(etacube), m_ietay(etacube), m_etabinsx(xbins), m_etabinsy(ybins), m_energy_bins(ebins) {
|
: m_ietax(etacube), m_ietay(etacube), m_etabinsx(xbins), m_etabinsy(ybins), m_energy_bins(ebins) {
|
||||||
if (etacube.shape(0) != xbins.size() || etacube.shape(1) != ybins.size() ||
|
if (etacube.shape(0) != xbins.ssize() || etacube.shape(1) != ybins.ssize() ||
|
||||||
etacube.shape(2) != ebins.size()) {
|
etacube.shape(2) != ebins.ssize()) {
|
||||||
throw std::invalid_argument(
|
throw std::invalid_argument(
|
||||||
"The shape of the etacube does not match the shape of the bins");
|
"The shape of the etacube does not match the shape of the bins");
|
||||||
}
|
}
|
||||||
@ -68,19 +68,14 @@ std::vector<Photon> Interpolator::interpolate(const ClusterVector<int32_t>& clus
|
|||||||
photon.y = cluster.y;
|
photon.y = cluster.y;
|
||||||
photon.energy = eta.sum;
|
photon.energy = eta.sum;
|
||||||
|
|
||||||
// auto ie = nearest_index(m_energy_bins, photon.energy)-1;
|
|
||||||
// auto ix = nearest_index(m_etabinsx, eta.x)-1;
|
|
||||||
// auto iy = nearest_index(m_etabinsy, eta.y)-1;
|
|
||||||
//Finding the index of the last element that is smaller
|
//Finding the index of the last element that is smaller
|
||||||
//should work fine as long as we have many bins
|
//should work fine as long as we have many bins
|
||||||
auto ie = last_smaller(m_energy_bins, photon.energy);
|
auto ie = last_smaller(m_energy_bins, photon.energy);
|
||||||
auto ix = last_smaller(m_etabinsx, eta.x);
|
auto ix = last_smaller(m_etabinsx, eta.x);
|
||||||
auto iy = last_smaller(m_etabinsy, eta.y);
|
auto iy = last_smaller(m_etabinsy, eta.y);
|
||||||
|
|
||||||
// fmt::print("ex: {}, ix: {}, iy: {}\n", ie, ix, iy);
|
double dX{}, dY{};
|
||||||
|
|
||||||
double dX, dY;
|
|
||||||
int ex, ey;
|
|
||||||
// cBottomLeft = 0,
|
// cBottomLeft = 0,
|
||||||
// cBottomRight = 1,
|
// cBottomRight = 1,
|
||||||
// cTopLeft = 2,
|
// cTopLeft = 2,
|
||||||
|
@ -37,8 +37,9 @@ Frame JungfrauDataFile::read_frame(size_t frame_number){
|
|||||||
|
|
||||||
std::vector<Frame> JungfrauDataFile::read_n(size_t n_frames) {
|
std::vector<Frame> JungfrauDataFile::read_n(size_t n_frames) {
|
||||||
std::vector<Frame> frames;
|
std::vector<Frame> frames;
|
||||||
throw std::runtime_error(LOCATION +
|
for(size_t i = 0; i < n_frames; ++i){
|
||||||
"Not implemented yet");
|
frames.push_back(read_frame());
|
||||||
|
}
|
||||||
return frames;
|
return frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,6 +55,10 @@ size_t JungfrauDataFile::frame_number(size_t frame_index) {
|
|||||||
return read_header().framenum;
|
return read_header().framenum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::array<ssize_t, 2> JungfrauDataFile::shape() const {
|
||||||
|
return {static_cast<ssize_t>(rows()), static_cast<ssize_t>(cols())};
|
||||||
|
}
|
||||||
|
|
||||||
DetectorType JungfrauDataFile::detector_type() const { return DetectorType::Jungfrau; }
|
DetectorType JungfrauDataFile::detector_type() const { return DetectorType::Jungfrau; }
|
||||||
|
|
||||||
std::string JungfrauDataFile::base_name() const { return m_base_name; }
|
std::string JungfrauDataFile::base_name() const { return m_base_name; }
|
||||||
@ -198,22 +203,13 @@ void JungfrauDataFile::read_into(std::byte *image_buf, size_t n_frames,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void JungfrauDataFile::read_into(NDArray<uint16_t>* image, JungfrauDataHeader* header) {
|
void JungfrauDataFile::read_into(NDArray<uint16_t>* image, JungfrauDataHeader* header) {
|
||||||
if(!(rows() == image->shape(0) && cols() == image->shape(1))){
|
if(image->shape()!=shape()){
|
||||||
throw std::runtime_error(LOCATION +
|
throw std::runtime_error(LOCATION +
|
||||||
"Image shape does not match file size: " + std::to_string(rows()) + "x" + std::to_string(cols()));
|
"Image shape does not match file size: " + std::to_string(rows()) + "x" + std::to_string(cols()));
|
||||||
}
|
}
|
||||||
read_into(reinterpret_cast<std::byte *>(image->data()), header);
|
read_into(reinterpret_cast<std::byte *>(image->data()), header);
|
||||||
}
|
}
|
||||||
|
|
||||||
NDArray<uint16_t> JungfrauDataFile::read_frame(JungfrauDataHeader* header) {
|
|
||||||
Shape<2> shape{rows(), cols()};
|
|
||||||
NDArray<uint16_t> image(shape);
|
|
||||||
|
|
||||||
read_into(reinterpret_cast<std::byte *>(image.data()),
|
|
||||||
header);
|
|
||||||
|
|
||||||
return image;
|
|
||||||
}
|
|
||||||
|
|
||||||
JungfrauDataHeader JungfrauDataFile::read_header() {
|
JungfrauDataHeader JungfrauDataFile::read_header() {
|
||||||
JungfrauDataHeader header;
|
JungfrauDataHeader header;
|
||||||
|
@ -28,7 +28,8 @@ TEST_CASE("Open a Jungfrau data file", "[.files]") {
|
|||||||
//Check that the frame number and buch id is read correctly
|
//Check that the frame number and buch id is read correctly
|
||||||
for (size_t i = 0; i < 24; ++i) {
|
for (size_t i = 0; i < 24; ++i) {
|
||||||
JungfrauDataHeader header;
|
JungfrauDataHeader header;
|
||||||
auto image = f.read_frame(&header);
|
aare::NDArray<uint16_t> image(f.shape());
|
||||||
|
f.read_into(&image, &header);
|
||||||
REQUIRE(header.framenum == i + 1);
|
REQUIRE(header.framenum == i + 1);
|
||||||
REQUIRE(header.bunchid == (i + 1) * (i + 1));
|
REQUIRE(header.bunchid == (i + 1) * (i + 1));
|
||||||
REQUIRE(image.shape(0) == 512);
|
REQUIRE(image.shape(0) == 512);
|
||||||
@ -58,7 +59,8 @@ TEST_CASE("Seek in a JungfrauDataFile", "[.files]"){
|
|||||||
REQUIRE(h3.framenum == 59+1);
|
REQUIRE(h3.framenum == 59+1);
|
||||||
|
|
||||||
JungfrauDataHeader h4;
|
JungfrauDataHeader h4;
|
||||||
auto image = f.read_frame(&h4);
|
aare::NDArray<uint16_t> image(f.shape());
|
||||||
|
f.read_into(&image, &h4);
|
||||||
REQUIRE(h4.framenum == 59+1);
|
REQUIRE(h4.framenum == 59+1);
|
||||||
|
|
||||||
//now we should be on the next frame
|
//now we should be on the next frame
|
||||||
@ -92,3 +94,21 @@ TEST_CASE("Open a Jungfrau data file with non zero file index", "[.files]"){
|
|||||||
REQUIRE(f.current_file().stem() == "AldoJF65k_000003");
|
REQUIRE(f.current_file().stem() == "AldoJF65k_000003");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Read into throws if size doesn't match", "[.files]"){
|
||||||
|
auto fpath = test_data_path() / "dat" / "AldoJF65k_000000.dat";
|
||||||
|
REQUIRE(std::filesystem::exists(fpath));
|
||||||
|
|
||||||
|
JungfrauDataFile f(fpath);
|
||||||
|
|
||||||
|
aare::NDArray<uint16_t> image({39, 85});
|
||||||
|
JungfrauDataHeader header;
|
||||||
|
|
||||||
|
REQUIRE_THROWS(f.read_into(&image, &header));
|
||||||
|
REQUIRE_THROWS(f.read_into(&image, nullptr));
|
||||||
|
REQUIRE_THROWS(f.read_into(&image));
|
||||||
|
|
||||||
|
REQUIRE(f.tell() == 0);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user