spectralbrain.io.export#
Export spectral decompositions, meshes, scalar maps, and connectomes.
All export functions accept the canonical type aliases from
spectralbrain.runtime and write to standard neuroimaging or
geometry formats. The primary cache format is HDF5 (via h5py).
Functions
|
Load a SpectralBrain HDF5 cache file. |
|
Save a connectome matrix to .tsv (BIDS-compatible). |
|
Save a scalar map or descriptor matrix as .func.gii. |
|
Save spectral decomposition and descriptors to HDF5. |
|
Save a mesh to .ply, .obj, .stl, .vtk, or .vtp. |
|
Save named arrays to a compressed .npz archive. |
- spectralbrain.io.export.load_hdf5(path)[source]#
Load a SpectralBrain HDF5 cache file.
- Parameters:
path (PathLike)
- Returns:
dict – Keys mirror what was passed to
save_hdf5().- Return type:
- spectralbrain.io.export.save_connectome(path, matrix, *, labels=None)[source]#
Save a connectome matrix to .tsv (BIDS-compatible).
- spectralbrain.io.export.save_gifti_func(path, scalars)[source]#
Save a scalar map or descriptor matrix as .func.gii.
- spectralbrain.io.export.save_hdf5(path, *, eigenvalues=None, eigenvectors=None, vertices=None, faces=None, descriptors=None, metadata=None, compression='gzip', compression_opts=4)[source]#
Save spectral decomposition and descriptors to HDF5.
This is the primary caching mechanism. A full eigendecomposition for a 160 k-vertex cortical surface (~300 eigenpairs) takes minutes; saving to HDF5 allows instant reload.
- Parameters:
path (PathLike) – Output
.h5file.eigenvalues (ndarray, shape (k,), optional)
eigenvectors (ndarray, shape (N, k), optional)
vertices (ndarray, shape (N, 3), optional)
faces (ndarray, shape (F, 3), optional)
descriptors (dict of {str: ndarray}, optional) – Named descriptor arrays (e.g.
{"hks": hks_matrix}).metadata (dict, optional) – Scalar metadata stored as HDF5 attributes (version, atlas, subject ID, structure name, backend used, …).
compression (str) – HDF5 compression filter.
compression_opts (int) – Compression level (1–9).
- Returns:
Path – The written file path.
- Return type:
Examples
>>> sb.io.export.save_hdf5( ... "sub-01_lh_white_spectral.h5", ... eigenvalues=evals, ... eigenvectors=evecs, ... vertices=verts, ... faces=faces, ... descriptors={"hks": hks, "wks": wks}, ... metadata={"subject": "sub-01", "hemi": "lh", ... "n_eigenvalues": 100}, ... )