9.2.1. Data¶
Parcellations, coordinates and masks.
- class junifer.data.BasePipelineDataRegistry(*args, **kwargs)¶
Abstract base class for pipeline data registry.
For every interface that is required, one needs to provide a concrete implementation for this abstract class.
- Attributes:
Initialize the class.
- abstract deregister()¶
De-register data.
- abstract get()¶
Get tailored data for a target.
- abstract load()¶
Load data.
- abstract register()¶
Register data.
- 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.RuntimeErrorIf there is a problem fetching the coordinates file.
- 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 a built-in coordinates or if the coordinatesnameis already registered andoverwrite=Falseor 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.DataDispatcher¶
Class for helping dynamic data dispatch.
- clear()¶
Not implemented.
- popitem()¶
Not implemented.
- setdefault(key, value=None)¶
Not implemented.
- class junifer.data.MapsRegistry(*args, **kwargs)¶
Class for maps data registry.
This class is a singleton and is used for managing available maps data in a centralized manner.
Initialize the class.
- get(maps, target_data, extra_input=None)¶
Get map(s), tailored for the target image.
- Parameters:
- Returns:
Nifti1ImageThe map(s) image.
listofstrMap(s) labels.
- Raises:
ValueErrorIf
extra_inputis None whentarget_data’s space is native.
- load(name, target_space, resolution=None, path_only=False)¶
Load map(s) and labels.
- Parameters:
- name
str The name of the map(s).
- target_space
str The desired space of the map(s).
- resolution
float, optional The desired resolution of the map(s) 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 map(s) image will not be loaded (default False).
- name
- Returns:
Nifti1ImageorNoneLoaded map(s) image.
listofstrMap(s) labels.
pathlib.PathFile path to the map(s) image.
strThe space of the map(s).
- Raises:
ValueErrorIf
nameis invalid or if the map(s) family is invalid or if the map(s) values and labels don’t have equal dimension or if the value range is invalid.
- register(name, maps_path, maps_labels, space, overwrite=False)¶
Register a custom user map(s).
- Parameters:
- name
str The name of the map(s).
- maps_path
strorpathlib.Path The path to the map(s) file.
- maps_labels
listofstr The list of labels for the map(s).
- space
str The template space of the map(s), e.g., “MNI152NLin6Asym”.
- overwritebool, optional
If True, overwrite an existing maps with the same name. Does not apply to built-in maps (default False).
- name
- Raises:
ValueErrorIf the map(s)
nameis a built-in map(s) or if the map(s)nameis already registered andoverwrite=False.
- 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 a built-in mask or if the masknameis already registered andoverwrite=False.
- 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.
dictParcellation value to label mappings.
- Raises:
ValueErrorIf
extra_inputis None whentarget_data’s space is native.
- load(name, target_space, resolution=None, path_only=False)¶
Load parcellation and labels.
- Parameters:
- name
str The name of the parcellation.
- target_space
str The desired space of the parcellation.
- 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 family is 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 a built-in parcellation or if the parcellationnameis already registered andoverwrite=False.
- junifer.data.deregister_data(kind, name)¶
De-register
namefromkind.- Parameters:
- kind{“coordinates”, “parcellation”, “mask”, “maps”}
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”, “maps”}
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,dictorlistof str;nibabel.nifti1.Nifti1Image
- Raises:
ValueErrorIf
kindis invalid value.
- junifer.data.get_template(space, target_img, extra_input=None, template_type='T1w', resolution=None)¶
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”).
- resolution
intor “highest”, optional The resolution of the template to fetch. If None, the closest resolution to the target image is used (default None). If “highest”, the highest resolution is used.
- space
- Returns:
Nifti1ImageThe template image.
- Raises:
ValueErrorIf
spaceortemplate_typeis invalid or ifresolutionis not at int or “highest”.RuntimeErrorIf required template is not found.
- junifer.data.get_xfm(src, dst)¶
Fetch warp files to convert from
srctodst.- Parameters:
- Returns:
pathlib.PathThe path to the transformation file.
- junifer.data.list_data(kind)¶
List available data for
kind.- Parameters:
- kind{“coordinates”, “parcellation”, “mask”, “maps”}
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”, “maps”}
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.