This commit is contained in:
froejdh_e
2025-04-03 14:53:47 +02:00
parent 277f9e787a
commit 19855e6403
3 changed files with 50 additions and 3 deletions

View File

@ -13,6 +13,12 @@ class JungfrauDataFile {
size_t m_rows{};
size_t m_cols{};
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
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 chip_data_size = header_size + sizeof(value_type) * 256 * 256;
static constexpr size_t n_digits_in_file_index = 6;
public:
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 pixels_per_frame() const;
size_t bytes_per_pixel() const;
@ -36,6 +46,7 @@ class JungfrauDataFile {
void read_into(std::byte *image_buf, JungfrauDataHeader *header);
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

View File

@ -23,7 +23,14 @@ void define_jungfrau_data_file_io_bindings(py::module &m) {
return JungfrauDataFile::guess_frame_size(fname);
})
.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",
// [](RawFile &self) {
// py::array image;

View File

@ -1,9 +1,13 @@
#include "aare/JungfrauDataFile.hpp"
#include "aare/defs.hpp"
#include <fmt/format.h>
namespace aare{
JungfrauDataFile::JungfrauDataFile(const std::filesystem::path& fname){
//setup geometry
auto frame_size = guess_frame_size(fname);
if (frame_size == module_data_size) {
m_rows = 512;
@ -17,9 +21,32 @@ JungfrauDataFile::JungfrauDataFile(const std::filesystem::path& fname){
} else {
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{
return m_rows * m_cols * bytes_per_pixel();
}
@ -67,9 +94,11 @@ size_t JungfrauDataFile::guess_frame_size(const std::filesystem::path& fname) {
} else {
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