9.2.1. Parcellations#
Provide functions for parcellation.
- junifer.data.parcellations.get_parcellation(parcellation, target_data, extra_input=None)#
Get parcellation, tailored for the target image.
- Parameters:
- parcellation
listofstr The name(s) of the parcellation(s).
- target_data
dict The corresponding item of the data object to which the parcellation will be applied.
- extra_input
dict, optional The other fields in the data object. Useful for accessing other data kinds that needs to be used in the computation of parcellations (default None).
- parcellation
- Returns:
Nifti1ImageThe parcellation image.
listofstrParcellation labels.
- Raises:
RuntimeErrorIf warp / transformation file extension is not “.mat” or “.h5”.
ValueErrorIf
extra_inputis None whentarget_data’s space is native.
- junifer.data.parcellations.list_parcellations()#
List all the available parcellations.
- junifer.data.parcellations.load_parcellation(name, parcellations_dir=None, resolution=None, path_only=False)#
Load a brain parcellation (including a label file).
If it is a built-in parcellation and the file is not present in the
parcellations_dirdirectory, it will be downloaded.- Parameters:
- name
str The name of the parcellation. Check valid options by calling
list_parcellations().- parcellations_dir
strorpathlib.Path, optional Path where the parcellations files are stored. The default location is “$HOME/junifer/data/parcellations” (default None).
- resolution
float, optional The desired resolution of the parcellation to load. If it is not available, the closest resolution will be loaded. Preferably, use a resolution higher than the desired one. By default, will load the highest one (default None).
- path_onlybool, optional
If True, the parcellation image will not be loaded (default False).
- name
- Returns:
Nifti1ImageorNoneLoaded parcellation image.
listofstrParcellation labels.
pathlib.PathFile path to the parcellation image.
strThe space of the parcellation.
- Raises:
ValueErrorIf
nameis invalid or if the parcellation values and labels don’t have equal dimension or if the value range is invalid.
- junifer.data.parcellations.merge_parcellations(parcellations_list, parcellations_names, labels_lists)#
Merge all parcellations from a list into one parcellation.
- Parameters:
- parcellations_list
listof niimg-like object List of parcellations to merge.
- parcellations_names: list of str
List of names for parcellations at the corresponding indices.
- labels_lists
listoflistofstr A list of lists. Each list in the list contains the labels for the parcellation at the corresponding index.
- parcellations_list
- Returns:
- junifer.data.parcellations.register_parcellation(name, parcellation_path, parcels_labels, space, overwrite=False)#
Register a custom user parcellation.
- Parameters:
- name
str The name of the parcellation.
- parcellation_path
strorpathlib.Path The path to the parcellation file.
- parcels_labels
listofstr The list of labels for the parcellation.
- space
str The template space of the parcellation, for e.g., “MNI152NLin6Asym”.
- overwritebool, optional
If True, overwrite an existing parcellation with the same name. Does not apply to built-in parcellations (default False).
- name
- Raises:
ValueErrorIf the parcellation name is already registered and overwrite is set to False or if the parcellation name is a built-in parcellation.
9.2.2. Coordinates#
Provide functions for list of coordinates.
- junifer.data.coordinates.get_coordinates(coords, target_data, extra_input=None)#
Get coordinates, tailored for the target image.
- Parameters:
- coords
str The name of the coordinates.
- target_data
dict The corresponding item of the data object to which the coordinates will be applied.
- extra_input
dict, optional The other fields in the data object. Useful for accessing other data kinds that needs to be used in the computation of coordinates (default None).
- coords
- Returns:
numpy.ndarrayThe coordinates.
listofstrThe names of the VOIs.
- Raises:
RuntimeErrorIf warp / transformation file extension is not “.mat” or “.h5”.
ValueErrorIf
extra_inputis None whentarget_data’s space is native.
- junifer.data.coordinates.list_coordinates()#
List all the available coordinates (VOIs).
- junifer.data.coordinates.load_coordinates(name)#
Load coordinates.
- Parameters:
- name
str The name of the coordinates.
- name
- Returns:
numpy.ndarrayThe coordinates.
listofstrThe names of the VOIs.
strThe space of the coordinates.
- Raises:
ValueErrorIf
nameis invalid.
- Warns:
DeprecationWarningIf
Poweris provided as thename.
- junifer.data.coordinates.register_coordinates(name, coordinates, voi_names, space, overwrite=False)#
Register a custom user coordinates.
- Parameters:
- name
str The name of the coordinates.
- coordinates
numpy.ndarray The coordinates. This should be a 2-dimensional array with three columns. Each row corresponds to a volume-of-interest (VOI) and each column corresponds to a spatial dimension (i.e. x, y, and z-coordinates).
- voi_names
listofstr The names of the VOIs.
- space
str The space of the coordinates, for e.g., “MNI”.
- overwritebool, optional
If True, overwrite an existing list of coordinates with the same name. Does not apply to built-in coordinates (default False).
- name
- Raises:
ValueErrorIf the coordinates name is already registered and overwrite is set to False or if the coordinates name is a built-in coordinates or if the
coordinatesis not a 2D array or if coordinate value does not have 3 components or if thevoi_namesshape does not match thecoordinatesshape.TypeErrorIf
coordinatesis not anumpy.ndarray.
9.2.3. Masks#
Provide functions for masks.
- junifer.data.masks.compute_brain_mask(target_data, extra_input=None, mask_type='brain', threshold=0.5)#
Compute the whole-brain, grey-matter or white-matter mask.
This mask is calculated using the template space and resolution as found in the
target_data.- Parameters:
- target_data
dict The corresponding item of the data object for which mask will be loaded.
- extra_input
dict, optional The other fields in the data object. Useful for accessing other data types (default None).
- mask_type{“brain”, “gm”, “wm”}, optional
Type of mask to be computed:
“brain” : whole-brain mask
“gm” : grey-matter mask
“wm” : white-matter mask
(default “brain”).
- threshold
float, optional The value under which the template is cut off (default 0.5).
- target_data
- Returns:
Nifti1ImageThe mask (3D image).
- Raises:
ValueErrorIf
mask_typeis invalid or ifextra_inputis None whentarget_data’s space is native.
- junifer.data.masks.get_mask(masks, target_data, extra_input=None)#
Get mask, tailored for the target image.
- Parameters:
- masks
str,dictorlistofdictorstr The name of the mask, or the name of a callable mask and the parameters of the mask as a dictionary. Several masks can be passed as a list.
- target_data
dict The corresponding item of the data object to which the mask will be applied.
- extra_input
dict, optional The other fields in the data object. Useful for accessing other data kinds that needs to be used in the computation of masks (default None).
- masks
- Returns:
Nifti1ImageThe mask image.
- Raises:
RuntimeErrorIf warp / transformation file extension is not “.mat” or “.h5” or if fetch_icbm152_brain_gm_mask is used and requires warping to other template space.
ValueErrorIf extra key is provided in addition to mask name in
masksor if no mask is provided or ifmasks = "inherit"butextra_inputis None ormask_itemis None ormask_items’s value is not inextra_inputor if callable parameters are passed to non-callable mask or if parameters are passed tonilearn.masking.intersect_masks()when there is only one mask or ifextra_inputis None whentarget_data’s space is native.
- junifer.data.masks.list_masks()#
List all the available masks.
- junifer.data.masks.load_mask(name, resolution=None, path_only=False)#
Load a mask.
- Parameters:
- name
str The name of the mask. Check valid options by calling
list_masks().- resolution
float, optional The desired resolution of the mask to load. If it is not available, the closest resolution will be loaded. Preferably, use a resolution higher than the desired one. By default, will load the highest one (default None).
- path_onlybool, optional
If True, the mask image will not be loaded (default False).
- name
- Returns:
Nifti1Image,CallableorNoneLoaded mask image.
pathlib.PathorNoneFile path to the mask image.
strThe space of the mask.
- Raises:
ValueErrorIf the
nameis invalid of if the mask family is invalid.
- junifer.data.masks.register_mask(name, mask_path, space, overwrite=False)#
Register a custom user mask.
- Parameters:
- name
str The name of the mask.
- mask_path
strorpathlib.Path The path to the mask file.
- space
str The space of the mask, for e.g., “MNI152NLin6Asym”.
- overwritebool, optional
If True, overwrite an existing mask with the same name. Does not apply to built-in mask (default False).
- name
- Raises:
ValueErrorIf the mask name is already registered and overwrite is set to False or if the mask name is a built-in mask.
9.2.4. Template Spaces#
Provide functions for template spaces.
- junifer.data.template_spaces.get_template(space, target_data, extra_input=None, template_type='T1w')#
Get template for the space, tailored for the target image.
- Parameters:
- space
str The name of the template space.
- target_data
dict The corresponding item of the data object for which the template space will be loaded.
- extra_input
dict, optional The other fields in the data object. Useful for accessing other data types (default None).
- template_type{“T1w”, “brain”, “gm”, “wm”, “csf”}, optional
The template type to retrieve (default “T1w”).
- space
- Returns:
Nifti1ImageThe template image.
- Raises:
ValueErrorIf
spaceortemplate_typeis invalid.RuntimeErrorIf required template is not found.
- junifer.data.template_spaces.get_xfm(src, dst, xfms_dir=None)#
Fetch warp files to convert from
srctodst.- Parameters:
- src
str The template space to transform from.
- dst
str The template space to transform to.
- xfms_dir
strorpathlib.Path, optional Path where the retrieved transformation files are stored. The default location is “$HOME/junifer/data/xfms” (default None).
- src
- Returns:
pathlib.PathThe path to the transformation file.
- Raises:
RuntimeErrorIf there is a problem fetching files.