|
OpenImpala
Image-based parallel transport property solver
|
Reads 3D image/scalar field data from a specified dataset within an HDF5 file directly into AMReX MultiFabs, suitable for large datasets. More...
#include <HDF5Reader.H>
Public Member Functions | |
| amrex::Box | box () const |
| Returns the index space Box covering the entire image domain [0, w-1] x [0, h-1] x [0, d-1]. | |
| int | depth () const |
| Get depth (Z-dimension) of the dataset in pixels/voxels. | |
| std::map< std::string, std::string > | getAllAttributes () const |
| Reads all attributes from the HDF5 dataset. Attempts to read attribute values as strings. | |
| std::string | getAttribute (const std::string &attr_name) const |
| Reads a specific string attribute from the HDF5 dataset. | |
| H5::DataType | getNativeDataType () const |
| Get the native HDF5 data type detected in the dataset. | |
| HDF5Reader () | |
| Default constructor. Creates an empty reader. Use readFile() later. | |
| HDF5Reader (const HDF5Reader &)=delete | |
| HDF5Reader (const std::string &filename, const std::string &hdf5dataset) | |
| Constructs an HDF5Reader, opens the file, and reads dataset metadata. | |
| HDF5Reader (HDF5Reader &&)=default | |
| int | height () const |
| Get height (Y-dimension) of the dataset in pixels/voxels. | |
| bool | isRead () const |
| Check if metadata has been successfully read. | |
| HDF5Reader & | operator= (const HDF5Reader &)=delete |
| HDF5Reader & | operator= (HDF5Reader &&)=default |
| template<typename T_Native> | |
| void | readAndThresholdFab (H5::DataSet &dataset, double raw_threshold, int value_if_true, int value_if_false, const amrex::Box &box, amrex::IArrayBox &fab) const |
| bool | readFile (const std::string &filename, const std::string &hdf5dataset) |
| Reads metadata (dimensions, datatype) from the specified HDF5 file and dataset. | |
| void | threshold (double raw_threshold, amrex::iMultiFab &mf) const |
| Reads data chunk-by-chunk into an iMultiFab based on thresholding. | |
| void | threshold (double raw_threshold, int value_if_true, int value_if_false, amrex::iMultiFab &mf) const |
| Reads data chunk-by-chunk into an iMultiFab based on thresholding with custom output values. | |
| int | width () const |
| Get width (X-dimension) of the dataset in pixels/voxels. | |
| virtual | ~HDF5Reader ()=default |
| Virtual default destructor. | |
Reads 3D image/scalar field data from a specified dataset within an HDF5 file directly into AMReX MultiFabs, suitable for large datasets.
This class uses the HDF5 C++ API to open an HDF5 file, access a specific 3D dataset, read its dimensions, and provide methods for reading data chunk-by-chunk (via AMReX MFIter) into an iMultiFab while applying a threshold.
It assumes the target dataset is 3-dimensional. It detects the dataset's native datatype and performs thresholding based on that type.
| OpenImpala::HDF5Reader::HDF5Reader | ( | ) |
Default constructor. Creates an empty reader. Use readFile() later.
|
explicit |
Constructs an HDF5Reader, opens the file, and reads dataset metadata.
Reads dataset dimensions and detects native datatype. Does NOT read the full dataset into memory. Uses HDF5 C++ exceptions internally, rethrowing as std::runtime_error on failure.
| filename | Path to the HDF5 file. |
| hdf5dataset | Full path to the 3D dataset within the HDF5 file (e.g., "/group/data"). |
| std::runtime_error | on HDF5 errors (file not found, dataset not found, invalid rank, etc.). |
|
virtualdefault |
Virtual default destructor.
|
delete |
|
default |
| amrex::Box OpenImpala::HDF5Reader::box | ( | ) | const |
Returns the index space Box covering the entire image domain [0, w-1] x [0, h-1] x [0, d-1].
| int OpenImpala::HDF5Reader::depth | ( | ) | const |
Get depth (Z-dimension) of the dataset in pixels/voxels.
| std::map< std::string, std::string > OpenImpala::HDF5Reader::getAllAttributes | ( | ) | const |
Reads all attributes from the HDF5 dataset. Attempts to read attribute values as strings.
| std::string OpenImpala::HDF5Reader::getAttribute | ( | const std::string & | attr_name | ) | const |
Reads a specific string attribute from the HDF5 dataset.
| attr_name | The name of the attribute to read. |
|
inline |
Get the native HDF5 data type detected in the dataset.
| int OpenImpala::HDF5Reader::height | ( | ) | const |
Get height (Y-dimension) of the dataset in pixels/voxels.
|
inline |
Check if metadata has been successfully read.
|
delete |
|
default |
| void OpenImpala::HDF5Reader::readAndThresholdFab | ( | H5::DataSet & | dataset, |
| double | raw_threshold, | ||
| int | value_if_true, | ||
| int | value_if_false, | ||
| const amrex::Box & | box, | ||
| amrex::IArrayBox & | fab ) const |
| bool OpenImpala::HDF5Reader::readFile | ( | const std::string & | filename, |
| const std::string & | hdf5dataset ) |
Reads metadata (dimensions, datatype) from the specified HDF5 file and dataset.
Clears any existing metadata. Opens file, finds dataset, reads dimensions/metadata. Does NOT read voxel data. Uses HDF5 C++ exceptions internally for error handling.
| filename | Path to the HDF5 file. |
| hdf5dataset | Full path to the 3D dataset within the HDF5 file. |
| void OpenImpala::HDF5Reader::threshold | ( | double | raw_threshold, |
| amrex::iMultiFab & | mf ) const |
Reads data chunk-by-chunk into an iMultiFab based on thresholding.
Iterates through the patches of the output iMultiFab mf. For each patch, reads the corresponding hyperslab from the HDF5 dataset and fills the patch's FArrayBox based on the threshold comparison. Sets output cells to 1 if native_value > raw_threshold, else 0. Assumes mf is defined on a box compatible with the dataset dimensions read previously. Handles conversion from native HDF5 type to double for comparison.
| raw_threshold | The threshold value (compared against data converted to double). |
| mf | Output amrex::iMultiFab reference to fill (must be defined). |
| std::runtime_error | on HDF5 read errors or if metadata not read. |
| void OpenImpala::HDF5Reader::threshold | ( | double | raw_threshold, |
| int | value_if_true, | ||
| int | value_if_false, | ||
| amrex::iMultiFab & | mf ) const |
Reads data chunk-by-chunk into an iMultiFab based on thresholding with custom output values.
Iterates through the patches of the output iMultiFab mf. For each patch, reads the corresponding hyperslab from the HDF5 dataset and fills the patch's FArrayBox based on the threshold comparison. Sets output cells to value_if_true if native_value > raw_threshold, else value_if_false. Assumes mf is defined on a box compatible with the dataset dimensions read previously. Handles conversion from native HDF5 type to double for comparison.
| raw_threshold | The threshold value (compared against data converted to double). |
| value_if_true | The integer value to set if condition is true. |
| value_if_false | The integer value to set if condition is false. |
| mf | Output amrex::iMultiFab reference to fill (must be defined). |
| std::runtime_error | on HDF5 read errors or if metadata not read. |
| int OpenImpala::HDF5Reader::width | ( | ) | const |
Get width (X-dimension) of the dataset in pixels/voxels.