LabelMapLoader#

class petpal.meta.label_maps.LabelMapLoader(label_map_option: str | dict)#

Class for loading label map data to convert between segmentation mappings and region labels.

There are three ways to load label maps, using argument label_map_option:

  1. (str) Load a preset option implemented in PETPAL. These include freesurfer, freesurfer_merge_lr, perlcyno, perlcyno_merge_lr. See from_petpal().

  2. (str) Load a json file that maps regions used in your study. Provide the path to the .json file. See from_json().

  3. (dict) Load a Python dictionary that implements a label map for region in your study. See from_dict().

Variables:
  • loader_method – A string or dictionary to load as a label map.

  • label_map – The label map to use in PETPAL methods.

from_petpal(label_map_name: str) dict#

Loads a label map based on an existing list of label maps implemented in PETPAL.

Options include:

  • freesurfer: The regions corresponding to the aparc+aseg segmentation image.

  • freesurfer_merge_lr: The regions corresponding to the aparc+aseg segmentation image. Unilateral map combining each left/right split into one region.

  • perlcyno: Bilateral regions in the PerlCyno primate atlas.

  • perlcyno_merge_lr: Unilateral map combining left/right regions in the PerlCyno primate atlas.

Parameters:

label_map_name (str) – A name matching a preset option for a label map.

Returns:

label_map (dict) – The label map selected.

from_dict(label_map: dict) dict#

Provide a label map implemented in Python.

Parameters:

label_map (dict) – The label map implemented for use in the PET study.

Returns:

label_map (dict) – The label map selected.

from_json(label_map_path: str) dict#

Load a label map from a .json file.

Parameters:

label_map_path (str) – Path to the label map for use in the PET study.

Returns:

label_map (dict) – The label map loaded from file.

from_dseg_tsv(label_map_path: str) dict#

Load a label map from a .tsv file.

Parameters:

label_map_path (str) – Path to the label map for use in the PET study.

Returns:

label_map (dict) – The label map loaded from file.

detect_option(label_map_option: dict | str) collections.abc.Callable#

Determine the label map loading method to use based on the provided option.

Raises:
  • FileNotFoundError – If the label_map_option looks like a path but doesn’t point to an existing file.

  • TypeError – If the label_map_option is not a str or dict instance.

labels_to_camel_case()#

Convert all label map labels to camel case and update label map.

validate_mappings()#

Validate mapping values for integer mappings in the label map. Mappings can be an integer or a list of integers.

Raises:

TypeError – If one of the mappings is not an integer or a list of integers.