9.2.1. Data¶
Parcellations, coordinates and masks.
- class junifer.data.CoordinatesRegistry(*args, **kwargs)¶
Class for coordinates data registry.
This class is a singleton and is used for managing available coordinates data in a centralized manner.
Initialize the class.
- deregister(name)¶
De-register a custom user coordinates.
- Parameters:
- name
str The name of the coordinates.
- name
- get(coords, target_data, extra_input=None)¶
Get coordinates, tailored for the target data.
- 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 warping specification required for warping using ANTs, is not found.
ValueErrorIf
extra_inputis None whentarget_data’s space is native.
- load(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.
- register(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, 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
nameis already registered andoverwrite=Falseor if the coordinatesnameis a built-in coordinates or if thecoordinatesis 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.
- class junifer.data.MaskRegistry(*args, **kwargs)¶
Class for mask data registry.
This class is a singleton and is used for managing available mask data in a centralized manner.
Initialize the class.
- get(masks, target_data, extra_input=None)¶
Get mask, tailored for the target image.
- Parameters:
- masks
str,dictorlistofdictorstr The name(s) of the mask(s), or the name(s) of callable mask(s) and parameters of the mask(s) 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:
ValueErrorIf extra key is provided in addition to mask name in
masksor if no mask is provided or ifmasks = "inherit"andmaskkey for thetarget_datais not found or 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.
- load(name, resolution=None, path_only=False)¶
Load mask.
- Parameters:
- name
str The name of the mask.
- 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,callable()orNoneLoaded mask image.
pathlib.PathorNoneFile path to the mask image.
strThe space of the mask.
- Raises:
ValueErrorIf the
nameis invalid or if the mask family is invalid.
- register(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
nameis already registered andoverwrite=Falseor if the masknameis a built-in mask.
- class junifer.data.ParcellationRegistry(*args, **kwargs)¶
Class for parcellation data registry.
This class is a singleton and is used for managing available parcellation data in a centralized manner.
Initialize the class.
- deregister(name)¶
De-register a custom user parcellation.
- Parameters:
- name
str The name of the parcellation.
- name
- get(parcellations, target_data, extra_input=None)¶
Get parcellation, tailored for the target image.
- Parameters:
- parcellations
strorlistofstr 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).
- parcellations
- Returns:
Nifti1ImageThe parcellation image.
listofstrParcellation labels.
- Raises:
ValueErrorIf
extra_inputis None whentarget_data’s space is native.
- load(name, target_space, parcellations_dir=None, resolution=None, path_only=False)¶
Load parcellation and labels.
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.
- target_space
str The desired space of the parcellation.
- 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.
- register(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, 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
nameis already registered andoverwrite=Falseor if the parcellationnameis a built-in parcellation.
- junifer.data.deregister_data(kind, name)¶
De-register
namefromkind.- Parameters:
- kind{“coordinates”, “parcellation”, “mask”}
Kind of data to register.
- name
str The name to de-register.
- Raises:
ValueErrorIf
kindis invalid value.
- junifer.data.get_data(kind, names, target_data, extra_input=None)¶
Get tailored
kindfortarget_data.- Parameters:
- kind{“coordinates”, “parcellation”, “mask”}
Kind of data to fetch and apply.
- names
strordictorlistofstr/dict The registered name(s) of the data.
- target_data
dict The corresponding item of the data object to which the data will be applied.
- extra_input
dict, optional The other fields in the data object. Useful for accessing other data types that need to be used in the computation of data (default None).
- Returns:
tupleofnumpy.ndarray,listof str;tupleofnibabel.nifti1.Nifti1Image,listof str;nibabel.nifti1.Nifti1Image
- Raises:
ValueErrorIf
kindis invalid value.
- junifer.data.get_template(space, target_img, 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_img
Nifti1Image The corresponding image for which the template space will be loaded. This is used to obtain the best matching resolution.
- 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.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 cloning the xfm dataset or if there is a problem fetching the xfm file.
- junifer.data.list_data(kind)¶
List available data for
kind.- Parameters:
- kind{“coordinates”, “parcellation”, “mask”}
Kind of data registry to list.
- Returns:
- Raises:
ValueErrorIf
kindis invalid value.
- junifer.data.load_data(kind, name, **kwargs)¶
Load
kindnamedname.- Parameters:
- kind{“coordinates”, “parcellation”, “mask”}
Kind of data to load.
- name
str The registered name of the data.
- **kwargs
Keyword arguments are passed to respective registry class method.
- Returns:
tupleofnumpy.ndarray,listofstr, str;tupleofnibabel.nifti1.Nifti1ImageorNone,listofstr,pathlib.Path, str;tupleofnibabel.nifti1.Nifti1Imageorcallable()orNone,pathlib.PathorNone,str
- Raises:
ValueErrorIf
kindis invalid value.
- junifer.data.register_data(kind, name, space, overwrite=False, **kwargs)¶
Register
nameunderkind.- Parameters:
- Raises:
ValueErrorIf
kindis invalid value.