cedalion.io.anatomy

Functions for reading and processing anatomical data.

Functions

cell_coordinates(mask, affine[, units])

Get the coordinates of each voxel in the transformed mask.

read_parcel_colors(parcel_colors_file)

read_parcellations(parcel_file)

Read parcellation labels from a json file.

read_segmentation_masks(basedir[, mask_files])

Read segmentation masks from NIFTI files.

trimesh_from_freesurfer(lh, rh, crs, units)

Load freesurfer surfaces as a cdc.TrimeshSurface object.

cedalion.io.anatomy.read_segmentation_masks(
basedir: str,
mask_files: Dict[str, str] = {'csf': 'csf.nii', 'gm': 'gm.nii', 'scalp': 'scalp.nii', 'skull': 'skull.nii', 'wm': 'wm.nii'},
) Tuple[DataArray, ndarray][source]

Read segmentation masks from NIFTI files.

Parameters:
  • basedir (str) – Directory containing the mask files

  • mask_files (Dict[str, str]) – Dictionary mapping segmentation types to filenames

Returns:

  • masks (xr.DataArray): Concatenated segmentation masks with a new dimension segmentation_type.

  • affine (np.ndarray): Affine transformation matrix associated with the NIFTI files.

Return type:

Tuple[xr.DataArray, np.ndarray]

cedalion.io.anatomy.cell_coordinates(mask, affine, units='mm')[source]

Get the coordinates of each voxel in the transformed mask.

Parameters:
  • mask (xr.DataArray) – A binary mask of shape (i, j, k).

  • affine (np.ndarray) – Affine transformation matrix.

  • units (str) – Units of the output coordinates.

Returns:

Coordinates of the center of each voxel in the mask.

Return type:

xr.DataArray

cedalion.io.anatomy.read_parcellations(parcel_file: str | Path) DataFrame[source]

Read parcellation labels from a json file.

Parameters:

parcel_file – The parcels file name

Returns:

Contains vertices’ labels, their appropriate colors

Return type:

pd.DataFrame

cedalion.io.anatomy.read_parcel_colors(parcel_colors_file: str | Path) dict[str, list][source]
cedalion.io.anatomy.trimesh_from_freesurfer(
lh: str | Path,
rh: str | Path,
crs: str,
units: str,
offset_hemispheres: bool = True,
) TrimeshSurface[source]

Load freesurfer surfaces as a cdc.TrimeshSurface object.

Parameters:
  • lh – path of the left hemisphere surface file.

  • rh – path of the right hemisphere surface file.

  • crs – label of the coordinate reference system

  • units – units of vertex coordinates

  • offset_hemispheres – If True, offset the hemispheres along the x-axis such that the left hemisphere’s maximum x-coordinate aligns with the right hemisphere’s minimum x-coordinate, removing the overlap that occurs with inflated surfaces.

Returns:

A single TrimeshSurface containing both hemispheres, with left-hemisphere vertices preceding right-hemisphere vertices in the vertex array.