mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2025-07-11 19:31:50 +02:00
WIP
This commit is contained in:
@ -13,6 +13,12 @@ class JungfrauDataFile {
|
|||||||
size_t m_rows{};
|
size_t m_rows{};
|
||||||
size_t m_cols{};
|
size_t m_cols{};
|
||||||
size_t m_total_frames{};
|
size_t m_total_frames{};
|
||||||
|
size_t m_first_frame_index{};
|
||||||
|
|
||||||
|
std::vector<size_t> m_frames_in_file{};
|
||||||
|
|
||||||
|
std::filesystem::path m_base_path;
|
||||||
|
std::string m_base_name;
|
||||||
|
|
||||||
//Data sizes to guess the frame size
|
//Data sizes to guess the frame size
|
||||||
using value_type = uint16_t;
|
using value_type = uint16_t;
|
||||||
@ -21,8 +27,12 @@ class JungfrauDataFile {
|
|||||||
static constexpr size_t half_data_size = header_size + sizeof(value_type) * 256 * 1024;
|
static constexpr size_t half_data_size = header_size + sizeof(value_type) * 256 * 1024;
|
||||||
static constexpr size_t chip_data_size = header_size + sizeof(value_type) * 256 * 256;
|
static constexpr size_t chip_data_size = header_size + sizeof(value_type) * 256 * 256;
|
||||||
|
|
||||||
|
static constexpr size_t n_digits_in_file_index = 6;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
JungfrauDataFile(const std::filesystem::path &fname);
|
JungfrauDataFile(const std::filesystem::path &fname);
|
||||||
|
|
||||||
|
std::string base_name() const; //!< get the base name of the file (without path and extension)
|
||||||
size_t bytes_per_frame() const;
|
size_t bytes_per_frame() const;
|
||||||
size_t pixels_per_frame() const;
|
size_t pixels_per_frame() const;
|
||||||
size_t bytes_per_pixel() const;
|
size_t bytes_per_pixel() const;
|
||||||
@ -36,6 +46,7 @@ class JungfrauDataFile {
|
|||||||
void read_into(std::byte *image_buf, JungfrauDataHeader *header);
|
void read_into(std::byte *image_buf, JungfrauDataHeader *header);
|
||||||
|
|
||||||
static size_t guess_frame_size(const std::filesystem::path &fname);
|
static size_t guess_frame_size(const std::filesystem::path &fname);
|
||||||
|
static std::filesystem::path get_frame_path(const std::filesystem::path &path, const std::string& base_name, size_t frame_index);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aare
|
} // namespace aare
|
@ -23,7 +23,14 @@ void define_jungfrau_data_file_io_bindings(py::module &m) {
|
|||||||
return JungfrauDataFile::guess_frame_size(fname);
|
return JungfrauDataFile::guess_frame_size(fname);
|
||||||
})
|
})
|
||||||
.def_property_readonly("rows", &JungfrauDataFile::rows)
|
.def_property_readonly("rows", &JungfrauDataFile::rows)
|
||||||
.def_property_readonly("cols", &JungfrauDataFile::cols);
|
.def_property_readonly("cols", &JungfrauDataFile::cols)
|
||||||
|
.def_property_readonly("base_name", &JungfrauDataFile::base_name)
|
||||||
|
.def("get_frame_path",
|
||||||
|
[](const std::filesystem::path &path, const std::string &base_name,
|
||||||
|
size_t frame_index) {
|
||||||
|
return JungfrauDataFile::get_frame_path(path, base_name,
|
||||||
|
frame_index);
|
||||||
|
});
|
||||||
// .def("read_frame",
|
// .def("read_frame",
|
||||||
// [](RawFile &self) {
|
// [](RawFile &self) {
|
||||||
// py::array image;
|
// py::array image;
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
#include "aare/JungfrauDataFile.hpp"
|
#include "aare/JungfrauDataFile.hpp"
|
||||||
#include "aare/defs.hpp"
|
#include "aare/defs.hpp"
|
||||||
|
|
||||||
|
#include <fmt/format.h>
|
||||||
|
|
||||||
namespace aare{
|
namespace aare{
|
||||||
|
|
||||||
JungfrauDataFile::JungfrauDataFile(const std::filesystem::path& fname){
|
JungfrauDataFile::JungfrauDataFile(const std::filesystem::path& fname){
|
||||||
|
|
||||||
|
//setup geometry
|
||||||
auto frame_size = guess_frame_size(fname);
|
auto frame_size = guess_frame_size(fname);
|
||||||
if (frame_size == module_data_size) {
|
if (frame_size == module_data_size) {
|
||||||
m_rows = 512;
|
m_rows = 512;
|
||||||
@ -17,9 +21,32 @@ JungfrauDataFile::JungfrauDataFile(const std::filesystem::path& fname){
|
|||||||
} else {
|
} else {
|
||||||
throw std::runtime_error(LOCATION + "Cannot guess frame size: file size is not a multiple of any known frame size");
|
throw std::runtime_error(LOCATION + "Cannot guess frame size: file size is not a multiple of any known frame size");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_base_path = fname.parent_path();
|
||||||
|
m_base_name = fname.stem();
|
||||||
|
|
||||||
|
//need to know the first
|
||||||
|
|
||||||
|
//remove digits
|
||||||
|
while(std::isdigit(m_base_name.back())){
|
||||||
|
m_base_name.pop_back();
|
||||||
|
}
|
||||||
|
|
||||||
|
//find how many files we have
|
||||||
|
// size_t frame_index = 0;
|
||||||
|
// while (std::filesystem::exists(get_frame_path(m_base_path, m_base_name, frame_index))) {
|
||||||
|
// auto n_frames =
|
||||||
|
// m_frames_in_file.push_back(n_frames);
|
||||||
|
// ++frame_index;
|
||||||
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string JungfrauDataFile::base_name() const {
|
||||||
|
return m_base_name;
|
||||||
|
}
|
||||||
|
|
||||||
size_t JungfrauDataFile::bytes_per_frame() const{
|
size_t JungfrauDataFile::bytes_per_frame() const{
|
||||||
return m_rows * m_cols * bytes_per_pixel();
|
return m_rows * m_cols * bytes_per_pixel();
|
||||||
}
|
}
|
||||||
@ -67,9 +94,11 @@ size_t JungfrauDataFile::guess_frame_size(const std::filesystem::path& fname) {
|
|||||||
} else {
|
} else {
|
||||||
throw std::runtime_error(LOCATION + "Cannot guess frame size: file size is not a multiple of any known frame size");
|
throw std::runtime_error(LOCATION + "Cannot guess frame size: file size is not a multiple of any known frame size");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::filesystem::path JungfrauDataFile::get_frame_path(const std::filesystem::path& path, const std::string& base_name, size_t frame_index) {
|
||||||
|
auto fname = fmt::format("{}{:0{}}.dat", base_name, frame_index, n_digits_in_file_index);
|
||||||
|
return path / fname;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace aare
|
} // namespace aare
|
Reference in New Issue
Block a user