cedalion.io.anatomy
Functions for reading and processing anatomical data.
Functions
|
Get the coordinates of each voxel centre in the transformed mask. |
|
Read parcel RGB colors from a JSON file. |
|
Read parcellation labels from a json file. |
|
Read segmentation masks from NIFTI files. |
|
Load freesurfer surfaces as a cdc.TrimeshSurface object. |
Classes
|
Files of a head model, as listed in its |
- class cedalion.io.anatomy.HeadModelFiles(
- basedir: Path,
- mask_files: dict[str, str],
- name: str | None = None,
- landmarks_ras_file: str | None = None,
- brain_vertex_coordinates: str | None = None,
- scalp_surface_obj: str | None = None,
- brain_surface_obj: str | None = None,
- freesurfer_surface_obj: str | None = None,
- inflated_surface_obj: str | None = None,
- parcel_colors: str | None = None,
- voxel_to_vertex_mapping: str | None = None,
- surfaces_are_zero_based: bool = False,
- ras_crs: str | None = None,
Bases:
objectFiles of a head model, as listed in its
headmodel_manifest.json.File names are relative to
basedir, the folder containing the manifest. Apart from the segmentation masks all files are optional. Missing surfaces and voxel-to-vertex mappings are derived from the segmentation masks when the head model is constructed (seeTwoSurfaceHeadModel.from_manifest).- brain_vertex_coordinates[source]
CSV with additional brain vertex coordinates, e.g. parcel labels.
- Type:
str | None
- surfaces_are_zero_based[source]
Whether the voxel coordinates of the surfaces are zero-based (see
TwoSurfaceHeadModel.from_surfaces).- Type:
bool
- ras_crs[source]
If given, the name of the RAS coordinate system, replacing the name derived from the NIfTI header.
- Type:
str | None
- classmethod from_manifest(
- fname: str | Path,
Read a head model manifest.
- Parameters:
fname – Path to a
headmodel_manifest.json.- Returns:
The head model files with
basedirset to the manifest’s folder.
- 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'},
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 centre in the transformed mask.
Following NIfTI convention, voxel coordinates in ijk-space denote the centre of that voxel and the affine maps it to the centre’s world coordinates. (See also nifti1.h: “The (x,y,z) coordinates refer to the CENTER of a voxel.”)
- 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]
Read parcel RGB colors from a JSON file.
- Parameters:
parcel_colors_file – Path to the JSON file mapping parcel names to RGB color lists.
- Returns:
Dictionary mapping parcel label strings to RGB color lists.
- cedalion.io.anatomy.trimesh_from_freesurfer(
- lh: str | Path,
- rh: str | Path,
- crs: str,
- units: str,
- offset_hemispheres: bool = True,
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.