Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

io

io

nltools I/O utilities.

HDF5 serialization for neuroimaging data types.

Methods:

NameDescription
is_h5_pathCheck if a file path indicates an HDF5 file.
load_brain_data_h5Load BrainData from HDF5 file.
to_h5Save BrainData or Adjacency objects to HDF5 files.

Modules:

NameDescription
h5HDF5 I/O utilities for nltools data types.

Methods

is_h5_path

is_h5_path(file_name) -> bool

Check if a file path indicates an HDF5 file.

Parameters:

NameTypeDescriptionDefault
file_namePath to check (str or Path object).required

Returns:

NameTypeDescription
boolboolTrue if the file has an HDF5 extension (.h5 or .hdf5).

Examples:

>>> is_h5_path("data.h5")
True
>>> is_h5_path("data.csv")
False
>>> is_h5_path(Path("results.hdf5"))
True

load_brain_data_h5

load_brain_data_h5(file_path, mask = None)

Load BrainData from HDF5 file.

Supports the v0.6 layout (X/Y as h5py groups with columns + values) and the legacy deepdish/PyTables layout written by nltools <= 0.5.1 (X/Y as flat datasets with sibling X_columns/X_index nodes).

Parameters:

NameTypeDescriptionDefault
file_pathPath to HDF5 file.required
maskOptional mask to use. If None, loads mask from file if available.None

Returns:

NameTypeDescription
dictDictionary containing loaded data, X, Y, and optionally mask info.

to_h5

to_h5(obj, file_name, obj_type = 'brain_data', h5_compression = 'gzip')

Save BrainData or Adjacency objects to HDF5 files.

Uses h5py for both types; X/Y (BrainData) and Y (Adjacency) are stored as polars-compatible groups with columns and values datasets. A BrainData mask is always stored by value (data + affine datasets); its filename is stored alongside only when the mask is file-backed, so in-memory masks serialize without one and round-trip by value.

Parameters:

NameTypeDescriptionDefault
objObject to save (BrainData or Adjacency).required
file_namePath to save file to.required
obj_typeType of object (‘brain_data’ or ‘adjacency’).‘brain_data’
h5_compressionCompression type for h5py datasets.‘gzip’

Modules

h5

HDF5 I/O utilities for nltools data types.

Shared serialization logic for BrainData and Adjacency objects.

Methods:

NameDescription
is_h5_pathCheck if a file path indicates an HDF5 file.
load_brain_data_h5Load BrainData from HDF5 file.
to_h5Save BrainData or Adjacency objects to HDF5 files.

Methods

is_h5_path
is_h5_path(file_name) -> bool

Check if a file path indicates an HDF5 file.

Parameters:

NameTypeDescriptionDefault
file_namePath to check (str or Path object).required

Returns:

NameTypeDescription
boolboolTrue if the file has an HDF5 extension (.h5 or .hdf5).

Examples:

>>> is_h5_path("data.h5")
True
>>> is_h5_path("data.csv")
False
>>> is_h5_path(Path("results.hdf5"))
True
load_brain_data_h5
load_brain_data_h5(file_path, mask = None)

Load BrainData from HDF5 file.

Supports the v0.6 layout (X/Y as h5py groups with columns + values) and the legacy deepdish/PyTables layout written by nltools <= 0.5.1 (X/Y as flat datasets with sibling X_columns/X_index nodes).

Parameters:

NameTypeDescriptionDefault
file_pathPath to HDF5 file.required
maskOptional mask to use. If None, loads mask from file if available.None

Returns:

NameTypeDescription
dictDictionary containing loaded data, X, Y, and optionally mask info.
to_h5
to_h5(obj, file_name, obj_type = 'brain_data', h5_compression = 'gzip')

Save BrainData or Adjacency objects to HDF5 files.

Uses h5py for both types; X/Y (BrainData) and Y (Adjacency) are stored as polars-compatible groups with columns and values datasets. A BrainData mask is always stored by value (data + affine datasets); its filename is stored alongside only when the mask is file-backed, so in-memory masks serialize without one and round-trip by value.

Parameters:

NameTypeDescriptionDefault
objObject to save (BrainData or Adjacency).required
file_namePath to save file to.required
obj_typeType of object (‘brain_data’ or ‘adjacency’).‘brain_data’
h5_compressionCompression type for h5py datasets.‘gzip’