Skip to content

registry

lacuna.assets.transforms.registry

Transform registry with TemplateFlow integration.

This module provides registry and metadata for spatial transformations between coordinate spaces.

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
@dataclass(frozen=True)
class TransformMetadata(AssetMetadata):
    """Metadata for a spatial transformation.

    Attributes
    ----------
    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")
    """

    from_space: str = ""
    to_space: str = ""
    transform_type: str = "nonlinear"
    source: str = "templateflow"

    def validate(self) -> None:
        """Validate transform metadata.

        Raises
        ------
        ValueError
            If metadata is invalid
        """
        from lacuna.core.spaces import SUPPORTED_SPACES

        # Check spaces
        for space in [self.from_space, self.to_space]:
            if space and space not in SUPPORTED_SPACES:
                raise ValueError(f"Unsupported space: {space}. " f"Supported: {SUPPORTED_SPACES}")

validate()

Validate transform metadata.

Raises:

Type Description
ValueError

If metadata is invalid

Source code in src/lacuna/assets/transforms/registry.py
def validate(self) -> None:
    """Validate transform metadata.

    Raises
    ------
    ValueError
        If metadata is invalid
    """
    from lacuna.core.spaces import SUPPORTED_SPACES

    # Check spaces
    for space in [self.from_space, self.to_space]:
        if space and space not in SUPPORTED_SPACES:
            raise ValueError(f"Unsupported space: {space}. " f"Supported: {SUPPORTED_SPACES}")

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
def list_transforms(
    from_space: str | None = None,
    to_space: str | None = None,
) -> list[TransformMetadata]:
    """List available transforms from TemplateFlow.

    Parameters
    ----------
    from_space : str, optional
        Filter by source coordinate space
    to_space : str, optional
        Filter by target coordinate space

    Returns
    -------
    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"
    ... )
    """
    # Use registry filtering
    # Note: AssetRegistry.list() doesn't support from_space/to_space directly,
    # so we need to filter manually
    all_transforms = TRANSFORM_REGISTRY.list()

    if from_space is not None:
        all_transforms = [t for t in all_transforms if t.from_space == from_space]

    if to_space is not None:
        all_transforms = [t for t in all_transforms if t.to_space == to_space]

    return all_transforms