loader
lacuna.assets.templates.loader
¶
Template loading with TemplateFlow integration.
This module provides functions to load reference brain templates, automatically downloading from TemplateFlow as needed.
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
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 | |