Skip to main content

Metadata for ANTs transform objects

Project description

AIND ANTs Transform Sidecar

CI PyPI - Version semantic-release: angular License ruff uv Copier

Metadata for ANTs transform objects

Overview

This package provides metadata "sidecars" for ANTs (Advanced Normalization Tools) transform objects. ANTs produces spatial transformations (affine matrices and displacement fields) for medical image registration, but the transform files alone don't document important context like:

  • The spatial domains (bounding boxes, spacing, voxel dimensions) of the fixed and moving images
  • The coordinate system and units being used
  • How to correctly chain and apply multiple transformation steps

This package provides Pydantic models that bundle ANTs transform file paths with their spatial metadata, enabling:

  • Easy domain comparison: Hash functions make it simple to verify domains match
  • Documentation: Clear specification of coordinate frames (LPS), units (mm), and domain definitions
  • Interoperability: Standardized JSON format for sharing transformation metadata
  • Convenience: Easy conversion to ANTsPy function arguments for applying transforms

Installation

If you choose to clone the repository, you can install the package by running the following command from the root directory of the repository:

pip install .

Otherwise, you can use pip:

pip install aind-ants-transform-sidecar

Usage

from aind_ants_transform_sidecar import (
    TransformSidecarV1,
    Domain,
    BBox,
    SynTriplet,
    load_package,
    dump_package,
)

# Define spatial domains for fixed and moving images
fixed_domain = Domain(
    spacing_LPS=(0.5, 0.5, 0.5),
    bbox=BBox(L=(-50.0, 50.0), P=(-50.0, 50.0), S=(-50.0, 50.0)),
    shape_canonical=(200, 200, 200),
)

moving_domain = Domain(
    spacing_LPS=(0.5, 0.5, 0.5),
    bbox=BBox(L=(-50.0, 50.0), P=(-50.0, 50.0), S=(-50.0, 50.0)),
    shape_canonical=(200, 200, 200),
)

# Create sidecar for ANTs SyN registration output
sidecar = TransformSidecarV1(
    fixed_domain=fixed_domain,
    moving_domain=moving_domain,
    transform=SynTriplet(
        affine="0GenericAffine.mat",
        warp="1Warp.nii.gz",
        inverse_warp="1InverseWarp.nii.gz",
    ),
)

# Serialize to JSON
json_str = dump_package(sidecar)

# Load from JSON
loaded = load_package(json_str)

# Get transformation chains
forward_chain = loaded.forward_chain()  # moving → fixed
inverse_chain = loaded.inverse_chain()  # fixed → moving

# Convert to ANTsPy arguments
transforms, whichtoinvert = forward_chain.antspy_apply_transforms_args()

Development

To develop the code, run:

uv sync

Development

Please test your changes using the full linting and testing suite:

./scripts/run_linters_and_checks.sh -c

Or run individual commands:

uv run --frozen ruff format          # Code formatting
uv run --frozen ruff check           # Linting
uv run --frozen mypy                 # Type checking
uv run --frozen interrogate -v       # Documentation coverage
uv run --frozen codespell --check-filenames  # Spell checking
uv run --frozen pytest --cov  # Tests with coverage

Documentation

sphinx-build -b html docs/source/ docs/build/html

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aind_ants_transform_sidecar-0.1.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aind_ants_transform_sidecar-0.1.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file aind_ants_transform_sidecar-0.1.0.tar.gz.

File metadata

File hashes

Hashes for aind_ants_transform_sidecar-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e84b88c855044b816e5912d9d160887e796454a9b0b8931fd4b96bb56215228d
MD5 8508068248580bfa45e6eff2d7d19e4b
BLAKE2b-256 214caa2b8164afb43a79aa176f2f3c055ce4ec5821833a09c63261f66c6e1d7a

See more details on using hashes here.

File details

Details for the file aind_ants_transform_sidecar-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aind_ants_transform_sidecar-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07a4123fbc740f08dbff569ea7bb936eec79153721b72ff0b5ab778213ee84a9
MD5 1a5e4627199ff11a5f3ec34e17a5ea32
BLAKE2b-256 7716536e004cfd2f939edc15078a2c0a1dbf1e17f3d3d63198f809131090229a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page