laion_fmri.io

Low-level file loaders for laion_fmri.

Functions

load_freesurfer_label(path)

Load a FreeSurfer .label file's vertex indices.

load_gifti_mask(path)

Load a .func.gii surface mask as a 1-D boolean array.

load_nifti_4d(path, mask_path[, streaming])

Load a 4-D NIfTI's values within a brain mask.

load_nifti_data(path, mask_path)

Load a 3-D NIfTI's values within a brain mask.

load_nifti_mask(path)

Load a NIfTI mask as a flat 1-D boolean array.

load_nifti_with_affine(path)

Load a NIfTI's data and 4×4 affine.

load_tsv(path)

Load a TSV file as a pandas DataFrame.

laion_fmri.io.load_freesurfer_label(path)[source]

Load a FreeSurfer .label file’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.gii surface 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, mask_path, streaming=False)[source]

Load a 4-D NIfTI’s values within a brain mask.

Returns each volume as a row of voxel values.

Parameters:
  • path (str or Path)

  • mask_path (str or Path)

  • streaming (bool) – If False (default), materialize the full 4-D array up front, then mask per volume. Decompresses any .nii.gz once and is the right choice for the bucket’s compressed files; peak memory is the full 4-D file plus the masked output, so a real session is ~12 GB. If True, read one volume at a time – peak memory stays at one volume plus the masked output. Streaming is only fast on raw uncompressed ``.nii`` (or with the file already in OS cache); on .nii.gz nibabel re-decompresses up to the offset on every slice, so streaming becomes effectively quadratic in the number of volumes.

Returns:

Shape (n_volumes, n_brain_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.

Parameters:
  • path (str or Path)

  • mask_path (str or Path)

Returns:

Shape (n_brain_voxels,), dtype float32.

Return type:

np.ndarray

laion_fmri.io.load_nifti_mask(path)[source]

Load a NIfTI mask as a flat 1-D boolean array.

Parameters:

path (str or Path)

Returns:

Shape (n_total_voxels,), dtype bool.

Return type:

np.ndarray

laion_fmri.io.load_nifti_with_affine(path)[source]

Load a NIfTI’s data and 4×4 affine.

Parameters:

path (str or Path)

Return type:

tuple[np.ndarray, np.ndarray]

laion_fmri.io.load_tsv(path)[source]

Load a TSV file as a pandas DataFrame.

Parameters:

path (str or Path)

Return type:

pd.DataFrame