Merge branch 'main' into developer

This commit is contained in:
Erik Fröjdh
2024-11-11 18:52:23 +01:00
committed by GitHub
19 changed files with 233 additions and 8 deletions

View File

@ -342,6 +342,7 @@ template <typename T, int64_t Ndim> void NDArray<T, Ndim>::Print() {
Print_some();
}
template <typename T, int64_t Ndim>
std::ostream& operator <<(std::ostream& os, const NDArray<T, Ndim>& arr){
for (auto row = 0; row < arr.shape(0); ++row) {
@ -354,6 +355,7 @@ std::ostream& operator <<(std::ostream& os, const NDArray<T, Ndim>& arr){
return os;
}
template <typename T, int64_t Ndim> void NDArray<T, Ndim>::Print_all() {
for (auto row = 0; row < shape_[0]; ++row) {
for (auto col = 0; col < shape_[1]; ++col) {

View File

@ -156,6 +156,7 @@ template <typename T, int64_t Ndim> void NDView<T, Ndim>::print_all() const {
}
}
template <typename T, int64_t Ndim>
std::ostream& operator <<(std::ostream& os, const NDView<T, Ndim>& arr){
for (auto row = 0; row < arr.shape(0); ++row) {
@ -168,4 +169,5 @@ std::ostream& operator <<(std::ostream& os, const NDView<T, Ndim>& arr){
return os;
}
} // namespace aare

View File

@ -5,6 +5,7 @@
#include "aare/NDArray.hpp" //for pixel map
#include "aare/RawSubFile.hpp"
#include <optional>
namespace aare {
@ -62,6 +63,7 @@ class RawFile : public FileInterface {
//TODO! do we need to adapt the API?
void read_into(std::byte *image_buf, DetectorHeader *header);
size_t frame_number(size_t frame_index) override;
size_t bytes_per_frame() override;
size_t pixels_per_frame() override;
@ -75,6 +77,7 @@ class RawFile : public FileInterface {
xy geometry();
size_t n_mod() const;
DetectorType detector_type() const override;
private:
@ -91,8 +94,10 @@ class RawFile : public FileInterface {
* @param frame_number frame number to read
* @param image_buf buffer to store the frame
*/
void get_frame_into(size_t frame_index, std::byte *frame_buffer, DetectorHeader *header = nullptr);
/**
* @brief get the frame at the given frame index
* @param frame_number frame number to read
@ -111,6 +116,7 @@ class RawFile : public FileInterface {
void update_geometry_with_roi();
int find_number_of_subfiles();
void open_subfiles();
void find_geometry();
};

View File

@ -58,6 +58,7 @@ class ScanParameters {
bool enabled() const;
};
struct ROI{
size_t xmin{};
size_t xmax{};
@ -107,6 +108,7 @@ class RawMasterFile {
std::optional<ROI> m_roi;
public:
RawMasterFile(const std::filesystem::path &fpath);
@ -133,8 +135,10 @@ class RawMasterFile {
std::optional<size_t> number_of_rows() const;
std::optional<uint8_t> quad() const;
std::optional<ROI> roi() const;
ScanParameters scan_parameters() const;
private:

80
include/aare/SubFile.hpp Normal file
View File

@ -0,0 +1,80 @@
#pragma once
#include "aare/Frame.hpp"
#include "aare/defs.hpp"
#include <cstdint>
#include <filesystem>
#include <map>
#include <optional>
namespace aare {
/**
* @brief Class to read a subfile from a RawFile
*/
class SubFile {
public:
size_t write_part(std::byte *buffer, DetectorHeader header, size_t frame_index);
/**
* @brief SubFile constructor
* @param fname path to the subfile
* @param detector detector type
* @param rows number of rows in the subfile
* @param cols number of columns in the subfile
* @param bitdepth bitdepth of the subfile
* @throws std::invalid_argument if the detector,type pair is not supported
*/
SubFile(const std::filesystem::path &fname, DetectorType detector, size_t rows, size_t cols, size_t bitdepth,
const std::string &mode = "r");
/**
* @brief read the subfile into a buffer
* @param buffer pointer to the buffer to read the data into
* @return number of bytes read
*/
size_t read_impl_normal(std::byte *buffer);
/**
* @brief read the subfile into a buffer with the bytes flipped
* @param buffer pointer to the buffer to read the data into
* @return number of bytes read
*/
template <typename DataType> size_t read_impl_flip(std::byte *buffer);
/**
* @brief read the subfile into a buffer with the bytes reordered
* @param buffer pointer to the buffer to read the data into
* @return number of bytes read
*/
template <typename DataType> size_t read_impl_reorder(std::byte *buffer);
/**
* @brief read the subfile into a buffer with the bytes reordered and flipped
* @param buffer pointer to the buffer to read the data into
* @param frame_number frame number to read
* @return number of bytes read
*/
size_t get_part(std::byte *buffer, size_t frame_index);
size_t frame_number(size_t frame_index);
// TODO: define the inlines as variables and assign them in constructor
inline size_t bytes_per_part() const { return (m_bitdepth / 8) * m_rows * m_cols; }
inline size_t pixels_per_part() const { return m_rows * m_cols; }
~SubFile();
protected:
FILE *fp = nullptr;
size_t m_bitdepth;
std::filesystem::path m_fname;
size_t m_rows{};
size_t m_cols{};
std::string m_mode;
size_t n_frames{};
int m_sub_file_index_{};
DetectorType m_detector_type;
std::optional<NDArray<ssize_t, 2>> pixel_map;
};
} // namespace aare

View File

@ -15,10 +15,6 @@
#include <vector>
/**
* @brief LOCATION macro to get the current location in the code
*/
@ -27,6 +23,7 @@
":" + std::string(__func__) + ":"
#ifdef AARE_CUSTOM_ASSERT
#define AARE_ASSERT(expr)\
if (expr)\
@ -43,6 +40,7 @@ namespace aare {
void assert_failed(const std::string &msg);
class Cluster {
public:
int cluster_sizeX;
@ -192,6 +190,7 @@ struct ModuleGeometry{
int width{};
};
using dynamic_shape = std::vector<int64_t>;
//TODO! Can we uniform enums between the libraries?