registry
lacuna.assets.parcellations.registry
¶
Parcellation registry with metadata for all supported parcellations.
This module provides a centralized registry of bundled parcellations with their metadata (space, resolution, description, etc.). The registry enables:
- Discovery of available parcellations
- Filtering parcellations by space/resolution
- Access to parcellation metadata without loading image data
- Consistent naming and citation tracking
Examples:
>>> from lacuna.assets.parcellations import list_parcellations, PARCELLATION_REGISTRY
>>>
>>> # List all available parcellations
>>> parcellations = list_parcellations()
>>> print([a.name for a in parcellations])
>>>
>>> # Filter by coordinate space
>>> mni6_parcellations = list_parcellations(space="MNI152NLin6Asym")
>>>
>>> # Get specific parcellation metadata
>>> schaefer = PARCELLATION_REGISTRY["schaefer2018parcels100networks7"]
>>> print(schaefer.space, schaefer.resolution)
ParcellationMetadata
dataclass
¶
Bases: SpatialAssetMetadata
Metadata for a neuroimaging parcellation.
Inherits from SpatialAssetMetadata to include space and resolution validation.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Unique identifier for the parcellation |
space |
str
|
Coordinate space (e.g., "MNI152NLin6Asym") |
resolution |
float
|
Resolution in mm (e.g., 1.0, 2.0) |
description |
str
|
Human-readable description |
parcellation_filename |
str
|
Filename of the NIfTI parcellation file |
labels_filename |
str
|
Filename of the labels text file |
citation |
(str, optional)
|
Citation information for the parcellation |
networks |
(list[str], optional)
|
List of network names if parcellation has network organization |
n_regions |
(int, optional)
|
Number of regions/parcels in the parcellation |
is_4d |
(bool, optional)
|
Whether the parcellation is 4D (multiple volumes) or 3D (single volume). Default is False. 4D parcellations are transformed volume-by-volume and aggregated independently. |
region_labels |
(list[str] | None, optional)
|
Human-readable labels for each region (1-indexed, matching ROI values). If None, labels will be auto-generated as "region_001", "region_002", etc. Loaded automatically from labels_filename during parcellation registration. |
Source code in src/lacuna/assets/parcellations/registry.py
list_parcellations(space=None, resolution=None)
¶
List available parcellations with optional filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
str
|
Filter by coordinate space (e.g., "MNI152NLin6Asym") |
None
|
resolution
|
int
|
Filter by resolution in mm (e.g., 1, 2) |
None
|
Returns:
| Type | Description |
|---|---|
list[ParcellationMetadata]
|
List of parcellation metadata matching the filters |
Examples:
>>> # List all parcellations
>>> parcellations = list_parcellations()
>>>
>>> # Filter by space
>>> mni6_parcellations = list_parcellations(space="MNI152NLin6Asym")
>>>
>>> # Filter by resolution
>>> res1_parcellations = list_parcellations(resolution=1)
>>>
>>> # Combined filters
>>> filtered = list_parcellations(space="MNI152NLin6Asym", resolution=1)
Source code in src/lacuna/assets/parcellations/registry.py
register_parcellation(metadata)
¶
Register a custom parcellation with the registry.
Allows users to add their own parcellations to the registry for use with Lacuna's analysis modules.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
ParcellationMetadata
|
Complete metadata for the custom parcellation. The parcellation_filename and labels_filename should be absolute paths to the parcellation files. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If an parcellation with the same name already exists in the registry |
Examples:
>>> from pathlib import Path
>>> from lacuna.parcellation.registry import register_parcellation, ParcellationMetadata
>>>
>>> # Register a custom parcellation
>>> custom_metadata = ParcellationMetadata(
... name="MyCustomParcellation",
... space="MNI152NLin6Asym",
... resolution=1,
... description="My custom parcellation",
... parcellation_filename="/path/to/my_parcellation.nii.gz",
... labels_filename="/path/to/my_parcellation_labels.txt",
... )
>>> register_parcellation(custom_metadata)
Source code in src/lacuna/assets/parcellations/registry.py
register_parcellation_from_files(name, parcellation_path, labels_path, space, resolution, description, citation=None, networks=None, n_regions=None)
¶
Register a custom parcellation from file paths.
Convenience function that creates ParcellationMetadata from file paths and registers the parcellation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique identifier for the parcellation |
required |
parcellation_path
|
str or Path
|
Path to the NIfTI parcellation file |
required |
labels_path
|
str or Path
|
Path to the labels text file |
required |
space
|
str
|
Coordinate space (e.g., "MNI152NLin6Asym") |
required |
resolution
|
int
|
Resolution in mm |
required |
description
|
str
|
Human-readable description |
required |
citation
|
str
|
Citation information |
None
|
networks
|
list[str]
|
List of network names if parcellation has network organization |
None
|
n_regions
|
int
|
Number of regions in the parcellation |
None
|
Examples:
>>> from lacuna.parcellation.registry import register_parcellation_from_files
>>>
>>> register_parcellation_from_files(
... name="MyParcellation",
... parcellation_path="/data/parcellations/my_parcellation.nii.gz",
... labels_path="/data/parcellations/my_parcellation_labels.txt",
... space="MNI152NLin6Asym",
... resolution=2,
... description="Custom 2mm parcellation",
... )
Source code in src/lacuna/assets/parcellations/registry.py
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 | |
register_parcellations_from_directory(directory, space=None, resolution=None, overwrite=False)
¶
Register all parcellations found in a directory.
Discovers parcellation files in the directory and registers them. Each parcellation should have: - NIfTI file (.nii or .nii.gz) - Labels file with same base name + "_labels.txt" or ".txt"
If space/resolution are not provided, attempts to parse from BIDS-style filenames (tpl-{SPACE}res-{RES}...) or detect from image headers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directory
|
str or Path
|
Directory containing parcellation files |
required |
space
|
str
|
Default coordinate space for parcellations without BIDS naming |
None
|
resolution
|
int
|
Default resolution for parcellations without BIDS naming |
None
|
overwrite
|
bool
|
If True, overwrite existing parcellations with same names |
False
|
Returns:
| Type | Description |
|---|---|
list[str]
|
Names of successfully registered parcellations |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If directory doesn't exist |
Examples:
>>> from lacuna.parcellation.registry import register_parcellations_from_directory
>>>
>>> # Register all parcellations from a directory
>>> registered = register_parcellations_from_directory("/data/my_parcellations")
>>> print(f"Registered {len(registered)} parcellations: {registered}")
>>>
>>> # Register with explicit space/resolution for non-BIDS parcellations
>>> registered = register_parcellations_from_directory(
... "/data/custom_parcellations",
... space="MNI152NLin6Asym",
... resolution=2
... )
Source code in src/lacuna/assets/parcellations/registry.py
913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 | |
unregister_parcellation(name)
¶
Remove an parcellation from the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the parcellation to unregister |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If parcellation is not in the registry |
Examples:
>>> from lacuna.parcellation.registry import unregister_parcellation
>>> unregister_parcellation("MyCustomParcellation")