laion_fmri.io¶
Low-level file loaders for laion_fmri.
Functions
|
Load a FreeSurfer |
|
Load a |
|
Load a 4-D NIfTI's values within a voxel mask. |
|
Load a 3-D NIfTI's values within a brain mask. |
|
Load a NIfTI mask as a flat 1-D boolean array. |
|
Load a NIfTI's data and 4×4 affine. |
|
Load a TSV file as a pandas DataFrame. |
- laion_fmri.io.load_freesurfer_label(path)[source]¶
Load a FreeSurfer
.labelfile’s vertex indices.- Parameters:
path (str or Path)
- Returns:
Shape
(n_label_vertices,), dtype int.- Return type:
np.ndarray
- laion_fmri.io.load_gifti_mask(path)[source]¶
Load a
.func.giisurface mask as a 1-D boolean array.- Parameters:
path (str or Path)
- Returns:
Shape
(n_vertices,), dtype bool.- Return type:
np.ndarray
- laion_fmri.io.load_nifti_4d(path, voxel_mask, streaming=False)[source]¶
Load a 4-D NIfTI’s values within a voxel mask.
Returns each volume as a row of voxel values.
- Parameters:
path (str or Path)
voxel_mask (np.ndarray) – 1-D bool array of length
X*Y*Z. Build withload_nifti_maskfor a brain-only mask, or combine brain + ROI + NC once on the caller side so the streaming path can apply the combination inline.streaming (bool) – If False (default), materialize the full 4-D array up front, then mask per volume. Decompresses any
.nii.gzonce; peak memory is the full 4-D file (~12 GB for a real session) plus the masked output. If True, stream the file volume-by-volume: for.nii.gza custom gzip pipe is used so each volume is read sequentially without re-decompression, keeping peak memory at one volume plus the masked output. For raw.niinibabel’s per-volume slicing is used (cheap, no streaming needed).
- Returns:
Shape
(n_volumes, n_mask_voxels), dtype float32, C-contiguous so row indexing is cheap.- Return type:
np.ndarray
- laion_fmri.io.load_nifti_data(path, mask_path)[source]¶
Load a 3-D NIfTI’s values within a brain mask.
- laion_fmri.io.load_nifti_mask(path)[source]¶
Load a NIfTI mask as a flat 1-D boolean array.
Voxels with
NaNare treated as out-of-mask. This matters when the source NIfTI is a stat map (e.g. the R^2 file the rsquare-derived brain mask is built from): GLMsingle writesNaNat voxels where the model couldn’t fit, andnp.nan.astype(bool)isTrue– without this guard, those failed-fit voxels would leak into every downstream voxel-axis accessor.- Parameters:
path (str or Path)
- Returns:
Shape
(n_total_voxels,), dtype bool.- Return type:
np.ndarray