Skip to contents

A class representing a three-dimensional brain image backed by an HDF5 dataset. H5NeuroVol objects provide efficient storage and access for large-scale brain imaging data in the HDF5 format.

Details

The H5NeuroVol class inherits a space slot from NeuroVol-class, which specifies the spatial domain (dimensions, orientation, etc.). Data I/O is performed by reading/writing subsets of the HDF5 dataset, allowing efficient handling of large 3D volumes.

Slots

h5obj

An instance of class H5File from the hdf5r package, representing the underlying HDF5 file containing the brain image data.

Inheritance

H5NeuroVol inherits from:

See also

NeuroVol-class for the base 3D brain volume class. H5File for details on HDF5 file objects.

Examples

if (FALSE) { # \dontrun{
if (requireNamespace("neuroim2", quietly = TRUE) &&
    requireNamespace("hdf5r", quietly = TRUE) &&
    exists("H5NeuroVol", where = "package:fmristore") && # Check if constructor is available
    !is.null(fmristore:::create_minimal_h5_for_H5NeuroVol)) { # Check helper

  # Setup: Create a temporary HDF5 file using a helper
  # The helper creates a dataset named "data/elements" by default.
  temp_h5_path <- NULL
  h5_vol <- NULL
  tryCatch({
    temp_h5_path <- fmristore:::create_minimal_h5_for_H5NeuroVol(dims = c(5L, 5L, 3L))

    # Create an H5NeuroVol object using the constructor
    # The constructor defaults to dataset_name = "data/elements" if not specified
    # and if a NeuroSpace is not given, it reads it from /space in the HDF5 file.
    h5_vol <- fmristore::H5NeuroVol(file_name = temp_h5_path)

    print(h5_vol)

    # Access a subset of the data
    subset_data <- h5_vol[1:2, 1:2, 1]
    print(subset_data)

  }, error = function(e) {
    message("H5NeuroVol example failed: ", e$message)
  }, finally = {
    # Close HDF5 handle owned by H5NeuroVol object
    if (!is.null(h5_vol) && inherits(h5_vol, "H5NeuroVol")) {
      try(close(h5_vol), silent = TRUE)
    }
    # Cleanup temporary file
    if (!is.null(temp_h5_path) && file.exists(temp_h5_path)) {
      unlink(temp_h5_path)
    }
  })
} else {
  message("Skipping H5NeuroVol example: fmristore, neuroim2, hdf5r, or helper not available.")
}
} # }