Skip to contents

A generic function for converting various types of R objects to HDF5 format, providing a standardized interface for serialization to HDF5.

Usage

as_h5(object, file, ...)

# S4 method for class 'NeuroVec'
as_h5(
  object,
  file = NULL,
  data_type = "FLOAT",
  chunk_dim = c(4, 4, 4, dim(object)[4]),
  compression = 6
)

# S4 method for class 'LatentNeuroVec'
as_h5(object, file = NULL, data_type = "FLOAT", compression = 6)

# S4 method for class 'LabeledVolumeSet'
as_h5(
  object,
  file,
  mask,
  labels,
  compression = 4,
  dtype = hdf5r::h5types$H5T_NATIVE_DOUBLE,
  chunk_size = 1024,
  header_values = list()
)

# S4 method for class 'ClusteredNeuroVec'
as_h5(
  object,
  file = NULL,
  scan_name = "scan_001",
  as_multiscan = FALSE,
  compression = 4,
  ...
)

# S4 method for class 'NeuroVecSeq'
as_h5(object, file = NULL, ...)

Arguments

object

The R object to convert to HDF5 (e.g., a NeuroVol or NeuroVec).

file

The path to the HDF5 file to create or modify.

...

Additional arguments specific to the particular method (see Details).

data_type

For NeuroVec/LatentNeuroVec methods: Storage type (e.g., "FLOAT"). Default "FLOAT"

chunk_dim

For NeuroVec method: Chunk dimensions. Default depends on input dimensions

compression

For all methods: Integer compression level [0..9]. Default varies by method

mask

For LabeledVolumeSet method: The mask to use (LogicalNeuroVol)

labels

For LabeledVolumeSet method: Character vector of labels

dtype

For LabeledVolumeSet method: HDF5 data type for values. Default H5T_NATIVE_DOUBLE

chunk_size

For LabeledVolumeSet method: Integer chunk size for HDF5. Default 1024

header_values

For LabeledVolumeSet method: List of additional header values

scan_name

For ClusteredNeuroVec method: Character name for this scan (default "scan_001")

as_multiscan

For ClusteredNeuroVec method: If TRUE, creates multi-scan container

Value

An object representing the HDF5 storage, typically of a class corresponding to the input type (e.g., H5NeuroVol for NeuroVol input, H5NeuroVec for NeuroVec input).

Methods

signature(object = "NeuroVec")

Creates an HDF5 file from a 4D NeuroVec object. Additional parameters:

data_type

Storage type (e.g., "FLOAT"). Default "FLOAT"

chunk_dim

Chunk dimensions. Default depends on input dimensions

compression

Integer [0..9], default 6

Returns an H5NeuroVec referencing the new HDF5 file.

signature(object = "LatentNeuroVec")

Saves a LatentNeuroVec to an HDF5 file in BasisEmbeddingSpec format. Additional parameters:

data_type

Storage type (e.g., "FLOAT"). Default "FLOAT"

compression

Integer [1..9], default 6

Returns an HDF5 file object.

signature(object = "LabeledVolume")

Saves a LabeledVolume to an HDF5 file. Additional parameters:

mask

The mask to use (LogicalNeuroVol)

labels

Character vector of labels

compression

Integer [0..9], default 4

dtype

HDF5 data type for values. Default H5T_NATIVE_DOUBLE

chunk_size

Integer chunk size for HDF5, default 1024

header_values

List of additional header values

Returns an HDF5 file object.

signature(object = "NeuroVecSeq")

Writes a sequence of NeuroVec objects (multiple 4D scans) to a single HDF5 file. All NeuroVec objects must have the same spatial dimensions. Additional parameters:

scan_names

Optional character vector of scan names. If NULL, uses "scan_1", "scan_2", etc.

data_type

Character string: "FLOAT" (default), "DOUBLE", or "INT"

chunk_dim

Numeric vector specifying chunk sizes. If NULL, uses time-optimized chunking

compression

Integer [0..9], default 6

scan_metadata

Optional named list of metadata lists, one per scan

Returns the file path of the created HDF5 file.

Examples