Skip to content

Centralizing and simplifying transformation system in SpatialData - #1291

Draft
ajkswamy wants to merge 31 commits into
mainfrom
transformation_manager
Draft

ajkswamy wants to merge 31 commits into
mainfrom
transformation_manager

Conversation

@ajkswamy

Copy link
Copy Markdown
Collaborator

Background and problems

Currently, transformation information in SpatialData objects are stored individually and independently in constituent spatial elements. This system makes the following complicated to different degrees:

  • I/O/roundtrip with NGFF 0.6 files
  • applying transformations defined for an element to an element linked to it
  • defining a network of transformation between elements that are beyond single hop transformations

Solution

  • Centralize all transformation information into a central multi-directional graph data structure at the root of SpatialData
  • Refactor all usage of ".attrs" of spatial elements to use information from the graph. Deprecate these usages/functions/methods
  • Add ergonomic methods to SpatialData to help specify transformation information from/to/between elements. Deprecate specifying transformation when create spatial elements from parse... methods of models
  • Remove deprecated code
  • ....

ajkswamy and others added 30 commits October 27, 2026 13:27
* chore: added pandas-stubs as dev dependency; helps with type checking

* chore: added local hatch.toml to gitignore

* chore: Add .kilo and plans to .gitignore

* feat: added literals and types for element types and group names

* feat: added .coverage and htmlcov to gitignore

* feat: transformation manager at the root of spatialdata object

* fix: io_zarr.py mixup between ELEMENT_TYPE_VECTOR/RASTER

* fix: avoid exposing TransformationManager in spatialdata __init__.py

* fix: element associated to cs -> element belonging to cs

* refac: transformation_manager now uses nx.MultiDiGraph

* refac: tests to match new transformation manager implementation

* fix: restored unintentionally removed functions + others fixes

* feat: custom error messages for transformation graph elements

* feat: custom exceptions for transform manager

* refac: transform manager attributes private; added missing method

* feat: more custom error and warnings + fixes

* feat: more test coverage + fixes

* feat: support for transformation management in graph with mutliple edges

* fix: fixes in tests + renaming for readability

* fix: typing Affine Transform

* feat: TransformationManager return Sequence instead of list

* feat: made TransformationManager.graph type specific over node type

* fix: removed internal attribute access warnings

* refac: rename check_if... methods to assert_... + one additional method

* fix: node type spec for TransformationManager._graph

* fix: made edge key definition from transforms more robust

* refac: method rename

* refac: TransformationManager get/remove methods don't raise error if edges are missing

* feat: new test for TransformationManager.add_transformation

* fix: better error messages and edge case handling for when transformation path is ambiguous

* feat: TransformationManager edge (key) definition made stronger

* fix: simplified access to attributes of TransformationManager

* fix: TransformationManager.unset_element is now private

* fix: throw error a path has one node

* fix: simplified checking if coordinate system has associated transforms

* fix: improved Transformation Manager code quality with better typing

* fix: improved Transformation Manager exception naming and messaging

* fix: improved Transformation Manager documentation

* feat: added tests for Transformation Manager

* fix: used explicit syntax for type definitoin

* refac: typo

* fix: removed TransformationManager import from spatialdata __init__.py

* fix: TransformationManager, simplified code using custom error
* chore: added pandas-stubs as dev dependency; helps with type checking

* chore: added local hatch.toml to gitignore

* chore: Add .kilo and plans to .gitignore

* feat: added literals and types for element types and group names

* feat: added .coverage and htmlcov to gitignore

* feat: transformation manager at the root of spatialdata object

* fix: io_zarr.py mixup between ELEMENT_TYPE_VECTOR/RASTER

* fix: avoid exposing TransformationManager in spatialdata __init__.py

* fix: element associated to cs -> element belonging to cs

* refac: transformation_manager now uses nx.MultiDiGraph

* refac: tests to match new transformation manager implementation

* fix: restored unintentionally removed functions + others fixes

* feat: custom error messages for transformation graph elements

* feat: custom exceptions for transform manager

* refac: transform manager attributes private; added missing method

* feat: more custom error and warnings + fixes

* feat: more test coverage + fixes

* feat: support for transformation management in graph with mutliple edges

* fix: fixes in tests + renaming for readability

* fix: typing Affine Transform

* feat: TransformationManager return Sequence instead of list

* feat: made TransformationManager.graph type specific over node type

* fix: removed internal attribute access warnings

* refac: rename check_if... methods to assert_... + one additional method

* fix: node type spec for TransformationManager._graph

* fix: made edge key definition from transforms more robust

* refac: method rename

* refac: TransformationManager get/remove methods don't raise error if edges are missing

* feat: new test for TransformationManager.add_transformation

* fix: better error messages and edge case handling for when transformation path is ambiguous

* feat: TransformationManager edge (key) definition made stronger

* fix: simplified access to attributes of TransformationManager

* fix: TransformationManager.unset_element is now private

* fix: throw error a path has one node

* fix: simplified checking if coordinate system has associated transforms

* fix: improved Transformation Manager code quality with better typing

* fix: improved Transformation Manager exception naming and messaging

* fix: improved Transformation Manager documentation

* feat: added tests for Transformation Manager

* fix: used explicit syntax for type definitoin

* refac: typo

* fix: removed TransformationManager import from spatialdata __init__.py

* fix: TransformationManager, simplified code using custom error
Cleans up and modernizes the NGff classes so that they have stronger
invariants and guarantee that they always have input and output.

Reading and writing to zarr is done via ome-zarr-models-py.

Uses graph module as part of io_raster.py::try_read_ngff06_multiscale
to interpret Ngff trnasformations and produce an output that could be
added to the new graph implementation.
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.97912% with 95 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.28%. Comparing base (1d5dcbe) to head (475d15b).

Files with missing lines Patch % Lines
src/spatialdata/transformations/graph/edge.py 86.24% 59 Missing ⚠️
src/spatialdata/transformations/graph/vert.py 78.75% 17 Missing ⚠️
src/spatialdata/_io/io_raster.py 74.19% 16 Missing ⚠️
...atialdata/_core/transformation_manager/__init__.py 98.63% 2 Missing ⚠️
src/spatialdata/_io/io_zarr.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1291      +/-   ##
==========================================
- Coverage   91.43%   91.28%   -0.15%     
==========================================
  Files          53       57       +4     
  Lines        8395     9238     +843     
==========================================
+ Hits         7676     8433     +757     
- Misses        719      805      +86     
Files with missing lines Coverage Δ
src/spatialdata/__init__.py 95.65% <ø> (ø)
src/spatialdata/_core/spatialdata.py 93.47% <100.00%> (+0.01%) ⬆️
...ialdata/_core/transformation_manager/exceptions.py 100.00% <100.00%> (ø)
src/spatialdata/_types.py 100.00% <100.00%> (ø)
src/spatialdata/_utils.py 85.27% <100.00%> (ø)
src/spatialdata/transformations/__init__.py 100.00% <100.00%> (ø)
src/spatialdata/_io/io_zarr.py 88.42% <80.00%> (ø)
...atialdata/_core/transformation_manager/__init__.py 98.63% <98.63%> (ø)
src/spatialdata/_io/io_raster.py 84.61% <74.19%> (-3.05%) ⬇️
src/spatialdata/transformations/graph/vert.py 78.75% <78.75%> (ø)
... and 1 more

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants