OpenImpala
Image-based parallel transport property solver
Loading...
Searching...
No Matches
OpenImpala::HDF5Reader Class Reference

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.

Detailed Description

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.

Warning
Assumes serial HDF5 I/O within the reading methods. In parallel runs, all ranks will open the file, but MFIter ensures each rank only reads data needed for its owned patches. For true parallel I/O performance, parallel HDF5 features would be needed.

Constructor & Destructor Documentation

◆ HDF5Reader() [1/4]

OpenImpala::HDF5Reader::HDF5Reader ( )

Default constructor. Creates an empty reader. Use readFile() later.

◆ HDF5Reader() [2/4]

OpenImpala::HDF5Reader::HDF5Reader ( const std::string & filename,
const std::string & hdf5dataset )
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.

Parameters
filenamePath to the HDF5 file.
hdf5datasetFull path to the 3D dataset within the HDF5 file (e.g., "/group/data").
Exceptions
std::runtime_erroron HDF5 errors (file not found, dataset not found, invalid rank, etc.).

◆ ~HDF5Reader()

virtual OpenImpala::HDF5Reader::~HDF5Reader ( )
virtualdefault

Virtual default destructor.

◆ HDF5Reader() [3/4]

OpenImpala::HDF5Reader::HDF5Reader ( const HDF5Reader & )
delete

◆ HDF5Reader() [4/4]

OpenImpala::HDF5Reader::HDF5Reader ( HDF5Reader && )
default

Member Function Documentation

◆ box()

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].

Returns
amrex::Box representing the full image dimensions. Returns empty box if metadata not read.

◆ depth()

int OpenImpala::HDF5Reader::depth ( ) const

Get depth (Z-dimension) of the dataset in pixels/voxels.

◆ getAllAttributes()

std::map< std::string, std::string > OpenImpala::HDF5Reader::getAllAttributes ( ) const

Reads all attributes from the HDF5 dataset. Attempts to read attribute values as strings.

Returns
A map of attribute names to string values. Returns empty map if no attributes or error.

◆ getAttribute()

std::string OpenImpala::HDF5Reader::getAttribute ( const std::string & attr_name) const

Reads a specific string attribute from the HDF5 dataset.

Parameters
attr_nameThe name of the attribute to read.
Returns
The attribute value as a string. Returns error string if fails.

◆ getNativeDataType()

H5::DataType OpenImpala::HDF5Reader::getNativeDataType ( ) const
inline

Get the native HDF5 data type detected in the dataset.

◆ height()

int OpenImpala::HDF5Reader::height ( ) const

Get height (Y-dimension) of the dataset in pixels/voxels.

◆ isRead()

bool OpenImpala::HDF5Reader::isRead ( ) const
inline

Check if metadata has been successfully read.

◆ operator=() [1/2]

HDF5Reader & OpenImpala::HDF5Reader::operator= ( const HDF5Reader & )
delete

◆ operator=() [2/2]

HDF5Reader & OpenImpala::HDF5Reader::operator= ( HDF5Reader && )
default

◆ readAndThresholdFab()

template<typename T_Native>
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

◆ readFile()

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.

Parameters
filenamePath to the HDF5 file.
hdf5datasetFull path to the 3D dataset within the HDF5 file.
Returns
true if successful, false otherwise. Prints errors via amrex::Print/Warning.

◆ threshold() [1/2]

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.

Parameters
raw_thresholdThe threshold value (compared against data converted to double).
mfOutput amrex::iMultiFab reference to fill (must be defined).
Exceptions
std::runtime_erroron HDF5 read errors or if metadata not read.

◆ threshold() [2/2]

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.

Parameters
raw_thresholdThe threshold value (compared against data converted to double).
value_if_trueThe integer value to set if condition is true.
value_if_falseThe integer value to set if condition is false.
mfOutput amrex::iMultiFab reference to fill (must be defined).
Exceptions
std::runtime_erroron HDF5 read errors or if metadata not read.

◆ width()

int OpenImpala::HDF5Reader::width ( ) const

Get width (X-dimension) of the dataset in pixels/voxels.


The documentation for this class was generated from the following files: