JungfrauDataFile¶
JungfrauDataFile is a class to read the .dat files that are produced by Aldo’s receiver. It is mostly used for calibration.
The structure of the file is:
JungfrauDataHeader
Binary data (256x256, 256x1024 or 512x1024)
JungfrauDataHeader
…
There is no metadata indicating number of frames or the size of the image, but this will be infered by this reader.
-
struct JungfrauDataHeader¶
-
class JungfrauDataFile : public aare::FileInterface¶
Public Functions
-
JungfrauDataFile(const std::filesystem::path &fname)¶
-
std::string base_name() const¶
get the base name of the file (without path and extension)
-
virtual size_t bytes_per_frame() override¶
get the size of one frame in bytes
- Returns:
size of one frame
-
virtual size_t pixels_per_frame() override¶
get the number of pixels in one frame
- Returns:
number of pixels in one frame
-
size_t bytes_per_pixel() const¶
-
virtual size_t bitdepth() const override¶
get the bitdepth of the file
- Returns:
bitdepth of the file
-
virtual void seek(size_t frame_index) override¶
seek to the given frame index (note not byte offset)
-
virtual size_t tell() override¶
get the frame index of the file pointer
-
virtual size_t total_frames() const override¶
get the total number of frames in the file
- Returns:
total number of frames in the file
-
virtual size_t rows() const override¶
get the number of rows in the file
- Returns:
number of rows in the file
-
virtual size_t cols() const override¶
get the number of columns in the file
- Returns:
number of columns in the file
-
std::array<ssize_t, 2> shape() const¶
-
size_t n_files() const¶
get the number of files in the series.
-
virtual Frame read_frame(size_t frame_number) override¶
read one frame from the file at the given frame number
- Parameters:
frame_number – frame number to read
- Returns:
frame
-
virtual std::vector<Frame> read_n(size_t n_frames = 0) override¶
read n_frames from the file at the current position
- Parameters:
n_frames – number of frames to read
- Returns:
vector of frames
-
virtual void read_into(std::byte *image_buf) override¶
read one frame from the file at the current position and store it in the provided buffer
- Parameters:
image_buf – buffer to store the frame
- Returns:
void
-
virtual void read_into(std::byte *image_buf, size_t n_frames) override¶
read n_frames from the file at the current position and store them in the provided buffer
- Parameters:
image_buf – buffer to store the frames
n_frames – number of frames to read
- Returns:
void
-
virtual size_t frame_number(size_t frame_index) override¶
get the frame number at the given frame index
- Parameters:
frame_index – index of the frame
- Returns:
frame number
-
virtual DetectorType detector_type() const override¶
-
void read_into(std::byte *image_buf, JungfrauDataHeader *header = nullptr)¶
Read a single frame from the file into the given buffer.
- Parameters:
image_buf – buffer to read the frame into. (Note the caller is responsible for allocating the buffer)
header – pointer to a JungfrauDataHeader or nullptr to skip header)
-
void read_into(std::byte *image_buf, size_t n_frames, JungfrauDataHeader *header = nullptr)¶
Read a multiple frames from the file into the given buffer.
- Parameters:
image_buf – buffer to read the frame into. (Note the caller is responsible for allocating the buffer)
n_frames – number of frames to read
header – pointer to a JungfrauDataHeader or nullptr to skip header)
-
void read_into(NDArray<uint16_t> *image, JungfrauDataHeader *header = nullptr)¶
Read a single frame from the file into the given NDArray.
- Parameters:
image – NDArray to read the frame into.
-
JungfrauDataHeader read_header()¶
-
inline std::filesystem::path current_file() const¶
Private Types
-
using pixel_type = uint16_t¶
Private Functions
-
void find_frame_size(const std::filesystem::path &fname)¶
Find the size of the frame in the file. (256x256, 256x1024, 512x1024)
- Parameters:
fname – path to the file
- Throws:
std::runtime_error – if the file is empty or the size cannot be determined
-
void parse_fname(const std::filesystem::path &fname)¶
-
void scan_files()¶
-
void open_file(size_t file_index)¶
-
std::filesystem::path fpath(size_t frame_index) const¶
Private Members
-
size_t m_rows = {}¶
number of rows in the image, from find_frame_size();
-
size_t m_cols = {}¶
number of columns in the image, from find_frame_size();
-
size_t m_bytes_per_frame = {}¶
number of bytes per frame excluding header
-
size_t m_total_frames = {}¶
total number of frames in the series of files
-
size_t m_offset = {}¶
file index of the first file, allow starting at non zero file
-
size_t m_current_file_index = {}¶
The index of the open file.
-
size_t m_current_frame_index = {}¶
The index of the current frame (with reference to all files)
-
std::vector<size_t> m_last_frame_in_file = {}¶
Used for seeking to the correct file.
-
std::filesystem::path m_path¶
path to the files
-
std::string m_base_name¶
base name used for formatting file names
-
FilePtr m_fp¶
RAII wrapper for a FILE*.
Private Static Attributes
-
static size_t header_size = sizeof(JungfrauDataHeader)¶
-
static size_t n_digits_in_file_index = 6¶
to format file names
-
JungfrauDataFile(const std::filesystem::path &fname)¶