assets
lacuna.assets
¶
Unified asset management system for Lacuna.
This module provides centralized management of all neuroimaging assets: - Parcellations (bundled and user-registered) - Templates (from TemplateFlow) - Transforms (from TemplateFlow) - Connectomes (structural and functional, user-registered)
All asset types follow a consistent registry pattern with register/list/load functions.
AssetMetadata
dataclass
¶
Bases: ABC
Base class for all asset metadata.
All asset types must subclass this and implement the abstract methods.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Unique identifier for the asset |
description |
str
|
Human-readable description |
Source code in src/lacuna/assets/base.py
AssetRegistry
¶
Bases: Generic[T]
Generic registry for any asset type.
Provides consistent registration, listing, and retrieval patterns across all asset types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset_type_name
|
str
|
Human-readable name of asset type (for error messages) |
'asset'
|
Examples:
>>> registry = AssetRegistry[AtlasMetadata]("atlas")
>>> registry.register(atlas_metadata)
>>> atlases = registry.list(space="MNI152NLin2009cAsym")
>>> atlas = registry.get("schaefer2018parcels100networks7")
Source code in src/lacuna/assets/base.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
__contains__(name)
¶
Check if asset is registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Asset name |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if registered |
__init__(asset_type_name='asset')
¶
Initialize empty registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset_type_name
|
str
|
Name of asset type for error messages |
'asset'
|
Source code in src/lacuna/assets/base.py
__len__()
¶
get(name)
¶
Get asset metadata by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Asset name |
required |
Returns:
| Type | Description |
|---|---|
T
|
Asset metadata |
Raises:
| Type | Description |
|---|---|
KeyError
|
If asset not found |
Source code in src/lacuna/assets/base.py
keys()
¶
list(**filters)
¶
List assets matching filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**filters
|
Attribute filters (e.g., space="MNI152NLin2009cAsym") |
{}
|
Returns:
| Type | Description |
|---|---|
list[T]
|
Matching assets |
Examples:
>>> # Get all assets
>>> all_assets = registry.list()
>>>
>>> # Filter by space
>>> mni_assets = registry.list(space="MNI152NLin2009cAsym")
>>>
>>> # Filter by multiple criteria
>>> assets = registry.list(space="MNI152NLin2009cAsym", resolution=1.0)
Source code in src/lacuna/assets/base.py
register(metadata)
¶
Register an asset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
T
|
Asset metadata to register |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If asset already registered or metadata invalid |
Source code in src/lacuna/assets/base.py
unregister(name)
¶
Unregister an asset.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of asset to unregister |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If asset not found |
Source code in src/lacuna/assets/base.py
FunctionalConnectome
dataclass
¶
Loaded functional connectome for fLNM analysis.
Provides path to HDF5 file(s) with voxel-wise timeseries data needed for FunctionalNetworkMapping analysis.
Attributes:
| Name | Type | Description |
|---|---|---|
metadata |
FunctionalConnectomeMetadata
|
Connectome metadata |
data_path |
Path
|
Path to .h5 file or directory with batch files |
is_batched |
bool
|
True if data_path points to directory with multiple files |
Source code in src/lacuna/assets/connectomes/functional.py
FunctionalConnectomeMetadata
dataclass
¶
Bases: SpatialAssetMetadata
Metadata for a functional connectome (voxel-wise timeseries).
Used for functional lesion network mapping (fLNM). Requires HDF5 file(s) containing whole-brain voxel-wise BOLD timeseries data.
HDF5 structure: - 'timeseries': (n_subjects, n_timepoints, n_voxels) array - 'mask_indices': (3, n_voxels) or (n_voxels, 3) brain mask coordinates - 'mask_affine': (4, 4) affine transformation matrix - 'mask_shape': Tuple as attribute (e.g., (91, 109, 91))
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Unique identifier (e.g., "GSP1000") |
space |
str
|
Coordinate space (typically "MNI152NLin6Asym") |
resolution |
float
|
Resolution in mm (typically 2.0 for functional data) |
description |
str
|
Human-readable description |
n_subjects |
int
|
Sample size in connectome |
modality |
str
|
Imaging modality (always "bold") |
data_path |
Path
|
Path to .h5 file or directory containing batch files |
is_batched |
bool
|
True if data_path is directory with multiple HDF5 files |
Source code in src/lacuna/assets/connectomes/registry.py
__repr__()
¶
Concise representation showing only essential fields.
Source code in src/lacuna/assets/connectomes/registry.py
Parcellation
dataclass
¶
Loaded parcellation with image data, labels, and metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
image |
Nifti1Image
|
The parcellation image (3D or 4D for probabilistic parcellations) |
labels |
dict[int, str]
|
Mapping from region ID to region name |
metadata |
ParcellationMetadata
|
Parcellation metadata from registry |
Source code in src/lacuna/assets/parcellations/loader.py
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
SpatialAssetMetadata
dataclass
¶
Bases: AssetMetadata
Base class for assets with spatial properties.
Adds coordinate space and resolution tracking.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Unique identifier for the asset |
description |
str
|
Human-readable description |
space |
str
|
Coordinate space identifier (e.g., "MNI152NLin2009cAsym") |
resolution |
float
|
Voxel resolution in mm (e.g., 1.0, 2.0) |
Source code in src/lacuna/assets/base.py
validate()
¶
Validate space and resolution.
Raises:
| Type | Description |
|---|---|
ValueError
|
If space or resolution is invalid |
Source code in src/lacuna/assets/base.py
StructuralConnectome
dataclass
¶
Loaded structural connectome for sLNM analysis.
Provides tractogram path for StructuralNetworkMapping analysis. TDI is computed on-the-fly during analysis (with optional caching).
Attributes:
| Name | Type | Description |
|---|---|---|
metadata |
StructuralConnectomeMetadata
|
Connectome metadata |
tractogram_path |
Path
|
Path to .tck streamlines file |
template_path |
Path | None
|
Optional template image path |
Source code in src/lacuna/assets/connectomes/structural.py
StructuralConnectomeMetadata
dataclass
¶
Bases: SpatialAssetMetadata
Metadata for a structural connectome (tractography-based).
Used for structural lesion network mapping (sLNM). Requires: - Tractogram file (.tck format from MRtrix3) - TDI computed on-the-fly during analysis (with optional caching)
Note: Unlike functional connectomes, structural connectomes (tractograms) don't have an inherent voxel resolution - they exist in continuous 3D space. The output resolution is controlled by the StructuralNetworkMapping analysis.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Unique identifier (e.g., "dTOR985") |
space |
str
|
Coordinate space (typically "MNI152NLin2009bAsym") |
resolution |
float
|
Resolution in mm (placeholder value, not used for tractograms) |
description |
str
|
Human-readable description |
modality |
str
|
Imaging modality (always "dwi") |
tractogram_path |
Path
|
Path to .tck streamlines file |
template_path |
Path | None
|
Optional path to template image defining output grid |
Source code in src/lacuna/assets/connectomes/registry.py
__repr__()
¶
Concise representation showing only essential fields.
Source code in src/lacuna/assets/connectomes/registry.py
validate()
¶
Validate space only (tractograms don't have inherent resolution).
Raises:
| Type | Description |
|---|---|
ValueError
|
If space is invalid |
Source code in src/lacuna/assets/connectomes/registry.py
TemplateMetadata
dataclass
¶
Bases: SpatialAssetMetadata
Metadata for a reference brain template.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Template identifier (e.g., "MNI152NLin2009cAsym") |
space |
str
|
Coordinate space (same as name for templates) |
resolution |
float
|
Voxel resolution in mm |
description |
str
|
Human-readable description |
modality |
str
|
Image modality (e.g., "T1w", "T2w", "FLAIR") |
source |
str
|
Source of template (always "templateflow") |
Source code in src/lacuna/assets/templates/registry.py
TransformMetadata
dataclass
¶
Bases: AssetMetadata
Metadata for a spatial transformation.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Transform identifier (e.g., "MNI152NLin6Asym_to_MNI152NLin2009cAsym") |
description |
str
|
Human-readable description |
from_space |
str
|
Source coordinate space |
to_space |
str
|
Target coordinate space |
transform_type |
str
|
Type of transform ("nonlinear", "affine", "composite") |
source |
str
|
Source of transform (always "templateflow") |
Source code in src/lacuna/assets/transforms/registry.py
validate()
¶
Validate transform metadata.
Raises:
| Type | Description |
|---|---|
ValueError
|
If metadata is invalid |
Source code in src/lacuna/assets/transforms/registry.py
is_template_cached(name)
¶
Check if template is already cached locally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Template name from registry |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if template is cached, False otherwise |
Examples:
>>> from lacuna.assets.templates import is_template_cached
>>> is_template_cached("MNI152NLin2009cAsym_res-1")
True
Source code in src/lacuna/assets/templates/loader.py
is_transform_cached(name)
¶
Check if transform is already cached locally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Transform name from registry |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if transform is cached, False otherwise |
Examples:
>>> from lacuna.assets.transforms import is_transform_cached
>>> is_transform_cached("MNI152NLin6Asym_to_MNI152NLin2009cAsym")
True
Source code in src/lacuna/assets/transforms/loader.py
list_functional_connectomes(space=None)
¶
List registered functional connectomes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
str
|
Filter by coordinate space |
None
|
Returns:
| Type | Description |
|---|---|
list[FunctionalConnectomeMetadata]
|
Matching connectomes |
Examples:
>>> from lacuna.assets.connectomes import list_functional_connectomes
>>>
>>> # List all
>>> connectomes = list_functional_connectomes()
>>>
>>> # Filter by space
>>> mni_connectomes = list_functional_connectomes(space="MNI152NLin6Asym")
Source code in src/lacuna/assets/connectomes/functional.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
list_structural_connectomes(atlas=None, space=None)
¶
List registered structural connectomes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
atlas
|
str
|
Filter by atlas name |
None
|
space
|
str
|
Filter by coordinate space |
None
|
Returns:
| Type | Description |
|---|---|
list[StructuralConnectomeMetadata]
|
Matching connectomes |
Examples:
>>> from lacuna.assets.connectomes import list_structural_connectomes
>>>
>>> # List all
>>> connectomes = list_structural_connectomes()
>>>
>>> # Filter by atlas
>>> schaefer_connectomes = list_structural_connectomes(
... atlas="schaefer2018parcels100networks7"
... )
Source code in src/lacuna/assets/connectomes/structural.py
list_templates(space=None, resolution=None, modality=None)
¶
List available templates from TemplateFlow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
str
|
Filter by coordinate space |
None
|
resolution
|
float
|
Filter by resolution in mm |
None
|
modality
|
str
|
Filter by modality (e.g., "T1w", "T2w") |
None
|
Returns:
| Type | Description |
|---|---|
list[TemplateMetadata]
|
Matching templates |
Examples:
>>> from lacuna.assets.templates import list_templates
>>>
>>> # List all available templates
>>> templates = list_templates()
>>>
>>> # Filter by space and resolution
>>> mni_1mm = list_templates(space="MNI152NLin2009cAsym", resolution=1.0)
Source code in src/lacuna/assets/templates/registry.py
list_transforms(from_space=None, to_space=None)
¶
List available transforms from TemplateFlow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_space
|
str
|
Filter by source coordinate space |
None
|
to_space
|
str
|
Filter by target coordinate space |
None
|
Returns:
| Type | Description |
|---|---|
list[TransformMetadata]
|
Matching transforms |
Examples:
>>> from lacuna.assets.transforms import list_transforms
>>>
>>> # List all available transforms
>>> transforms = list_transforms()
>>>
>>> # Find transforms from NLin6 to NLin2009c
>>> transforms = list_transforms(
... from_space="MNI152NLin6Asym",
... to_space="MNI152NLin2009cAsym"
... )
Source code in src/lacuna/assets/transforms/registry.py
load_functional_connectome(name)
¶
Load a functional connectome for fLNM analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Connectome name |
required |
Returns:
| Type | Description |
|---|---|
FunctionalConnectome
|
Loaded connectome with path ready for FunctionalNetworkMapping |
Raises:
| Type | Description |
|---|---|
KeyError
|
If connectome not registered |
Examples:
>>> from lacuna.assets.connectomes import load_functional_connectome
>>> from lacuna.analysis import FunctionalNetworkMapping
>>>
>>> connectome = load_functional_connectome("GSP1000")
>>> analysis = FunctionalNetworkMapping(
... connectome_path=connectome.data_path,
... method="boes"
... )
Source code in src/lacuna/assets/connectomes/functional.py
load_parcellation(parcellation_name)
¶
Load an parcellation by name from the registry.
Loads bundled parcellations or user-registered custom parcellations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parcellation_name
|
str
|
Name of the parcellation from PARCELLATION_REGISTRY |
required |
Returns:
| Type | Description |
|---|---|
Parcellation
|
Loaded parcellation with image, labels, and metadata |
Raises:
| Type | Description |
|---|---|
KeyError
|
If parcellation_name is not in the registry |
FileNotFoundError
|
If parcellation files are not found |
Examples:
>>> parcellation = load_parcellation("schaefer2018parcels100networks7")
>>> print(f"Parcellation has {len(parcellation.labels)} regions")
>>> print(f"Space: {parcellation.metadata.space}")
Source code in src/lacuna/assets/parcellations/loader.py
load_structural_connectome(name)
¶
Load a structural connectome for sLNM analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Connectome name |
required |
Returns:
| Type | Description |
|---|---|
StructuralConnectome
|
Loaded connectome with tractogram path ready for StructuralNetworkMapping. TDI will be computed on-the-fly during analysis. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If connectome not registered |
Examples:
>>> from lacuna.assets.connectomes import load_structural_connectome
>>> from lacuna.analysis import StructuralNetworkMapping
>>>
>>> connectome = load_structural_connectome("dTOR985")
>>> analysis = StructuralNetworkMapping(
... connectome_name="dTOR985",
... cache_tdi=True # Cache computed TDI for reuse
... )
Source code in src/lacuna/assets/connectomes/structural.py
load_template(name)
¶
Load a reference brain template by name.
Downloads from TemplateFlow on first use and caches locally.
Supports space equivalence: anatomically identical spaces like MNI152NLin2009[abc]Asym are automatically normalized to their canonical form (cAsym).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Template name from registry (e.g., "MNI152NLin2009cAsym_res-1") |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to template NIfTI file |
Raises:
| Type | Description |
|---|---|
KeyError
|
If template not found in registry |
FileNotFoundError
|
If template download fails |
Examples:
>>> from lacuna.assets.templates import load_template
>>>
>>> # Load MNI template
>>> template_path = load_template("MNI152NLin2009cAsym_res-1")
>>> import nibabel as nib
>>> template = nib.load(template_path)
>>> print(template.shape)
(193, 229, 193)
Source code in src/lacuna/assets/templates/loader.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
load_transform(name)
¶
Load a spatial transform by name.
Downloads from TemplateFlow on first use and caches locally. Tries both forward and reverse directions since TemplateFlow may only have the transform stored in one direction.
Supports space equivalence: anatomically identical spaces like MNI152NLin2009[abc]Asym are automatically normalized to their canonical form (cAsym).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Transform name from registry (e.g., "MNI152NLin6Asym_to_MNI152NLin2009cAsym") |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to transform .h5 file |
Raises:
| Type | Description |
|---|---|
KeyError
|
If transform not found in registry |
FileNotFoundError
|
If transform download fails |
Examples:
>>> from lacuna.assets.transforms import load_transform
>>>
>>> # Load transform
>>> transform_path = load_transform("MNI152NLin6Asym_to_MNI152NLin2009cAsym")
>>> print(transform_path.exists())
True
Source code in src/lacuna/assets/transforms/loader.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
register_functional_connectome(name, space, resolution, data_path, n_subjects=None, description='')
¶
Register a functional connectome for fLNM analysis.
Supports both single HDF5 files and directories with batched files.
HDF5 Required Structure: - 'timeseries': (n_subjects, n_timepoints, n_voxels) array - 'mask_indices': (3, n_voxels) or (n_voxels, 3) coordinates - 'mask_affine': (4, 4) affine matrix - 'mask_shape': Tuple attribute (e.g., (91, 109, 91))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique identifier (e.g., "GSP1000") |
required |
space
|
str
|
Coordinate space (e.g., "MNI152NLin6Asym") |
required |
resolution
|
float
|
Resolution in mm (typically 2.0) |
required |
data_path
|
str or Path
|
Path to .h5 file or directory containing batch files |
required |
n_subjects
|
int
|
Total sample size (for documentation purposes only) |
None
|
description
|
str
|
Human-readable description |
''
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If data_path doesn't exist |
ValueError
|
If HDF5 structure is invalid |
Examples:
>>> from lacuna.assets.connectomes import register_functional_connectome
>>>
>>> # Single file
>>> register_functional_connectome(
... name="GSP1000",
... space="MNI152NLin6Asym",
... resolution=2.0,
... data_path="/data/gsp/gsp1000_connectome.h5",
... description="GSP1000 voxel-wise connectome"
... )
>>>
>>> # Batched directory
>>> register_functional_connectome(
... name="GSP1000_batched",
... space="MNI152NLin6Asym",
... resolution=2.0,
... data_path="/data/gsp/batches/",
... description="GSP1000 voxel-wise connectome (batched)"
... )
Source code in src/lacuna/assets/connectomes/functional.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
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 | |
register_structural_connectome(name, space, tractogram_path, template_path=None, description='')
¶
Register a structural connectome for sLNM analysis.
TDI is computed on-the-fly during analysis. Use cache_tdi=True (default) in StructuralNetworkMapping to cache computed TDIs for reuse, or cache_tdi=False to compute without caching.
Note: Unlike functional connectomes, structural connectomes (tractograms) don't
have an inherent voxel resolution - they exist in continuous 3D space. The output
resolution is controlled by the output_resolution parameter in
StructuralNetworkMapping analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique identifier (e.g., "dTOR985") |
required |
space
|
str
|
Coordinate space (e.g., "MNI152NLin2009bAsym") |
required |
tractogram_path
|
str or Path
|
Path to .tck whole-brain streamlines file |
required |
template_path
|
str or Path
|
Path to template image for output grid |
None
|
description
|
str
|
Human-readable description |
''
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If tractogram file doesn't exist |
ValueError
|
If file validation fails |
Examples:
>>> from lacuna.assets.connectomes import register_structural_connectome
>>>
>>> # Register tractogram (TDI computed on-the-fly during analysis)
>>> register_structural_connectome(
... name="dTOR985",
... space="MNI152NLin2009cAsym",
... tractogram_path="/data/dtor/dTOR985_tractogram.tck",
... description="dTOR tractogram - TDI computed on-demand"
... )
Source code in src/lacuna/assets/connectomes/structural.py
unregister_functional_connectome(name)
¶
Unregister a functional connectome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Connectome name |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If connectome not registered |
Source code in src/lacuna/assets/connectomes/functional.py
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")
Source code in src/lacuna/assets/parcellations/registry.py
unregister_structural_connectome(name)
¶
Unregister a structural connectome.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Connectome name |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If connectome not registered |
Examples:
>>> from lacuna.assets.connectomes import unregister_structural_connectome
>>> unregister_structural_connectome("dTOR985")