Skip to content

Add subject mapping adapter examples - #1496

Closed
fepegar wants to merge 11 commits into
fepegar/exact-transform-paramsfrom
fepegar/subject-mapping-adapters
Closed

Add subject mapping adapter examples#1496
fepegar wants to merge 11 commits into
fepegar/exact-transform-paramsfrom
fepegar/subject-mapping-adapters

Conversation

@fepegar

@fepegar fepegar commented Jul 13, 2026

Copy link
Copy Markdown
Member

[Generated by a coding agent]


Summary

  • refactor MONAI and Cornucopia adapters onto SubjectsBatch.map_subjects()
  • preserve copy semantics, prior histories, annotations, and deterministic metadata order
  • validate adapter result types and arity instead of silently dropping or misassigning outputs
  • add executable custom-transform examples for vectorized images, batched metadata, text mapping, and exact replay

Validation

  • full test suite and cross-platform GitHub Actions
  • Ruff lint and formatting
  • ty type checking
  • documentation tests and Zensical build
  • pre-commit.ci, including Xenon complexity checks

Stack (merge bottom-up)

  1. #1493 — documentation corrections — merged
  2. #1494 — lossless subject batching — next to merge
  3. #1495 — exact transform parameter replay
  4. Add subject mapping adapter examples #1496 — subject mapping adapters and examples (this PR)

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

📖 Docs Preview

Preview of the documentation for this PR:

🔗 https://smokeshow.helpmanual.io/1h4l0m671q3q0v2d215w/

Built from 8e30d6e

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates TorchIO’s MONAI and Cornucopia adapter transforms to apply per-subject logic via SubjectsBatch.map_subjects() (preserving batching semantics like history/annotations), tightens adapter output validation to avoid silently dropping unsupported outputs, and adds/links new documentation examples for writing batch-native and subject-mapped custom transforms.

Changes:

  • Refactor MonaiAdapter and CornucopiaAdapter to use SubjectsBatch.map_subjects() and fix probability gating edge case when p=0 and the random draw is exactly 0.
  • Make adapter output handling stricter (e.g., explicit rejection of new tensor keys / non-tensor outputs) and add tests covering metadata updates, history/annotation preservation, and the p=0 edge case.
  • Add a new “Write a custom transform” how-to and update conceptual/migration docs + nav to reference the new batching/mapping and replay APIs.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
zensical.toml Adds the new custom transform how-to page to site navigation.
tests/test_monai_adapter.py Adds coverage for metadata updates, explicit rejection of new tensor fields, preserved history/annotations, and p=0 edge case.
tests/test_cornucopia_adapter.py Adds coverage for preserved history/annotations, p=0 edge case, and non-tensor output rejection.
src/torchio/transforms/monai_adapter.py Switches to map_subjects(), fixes p=0 edge case, and makes dict-transform outputs explicit/validated (no silent drops).
src/torchio/transforms/cornucopia_adapter.py Switches to map_subjects(), fixes p=0 edge case, and enforces tensor outputs.
docs/how-to/custom-transform.md New executable examples for vectorized image ops, batched metadata ops, subject-wise mapping, and exact replay.
docs/get-started/migration.md Updates migration guidance to use map_subjects() and clarifies schema/annotation constraints.
docs/concepts/transforms.md Updates schema rules, clarifies spatial+annotation behavior, and documents apply_with_params() replay with links to the new how-to.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fepegar
fepegar force-pushed the fepegar/subject-mapping-adapters branch from 3b0b687 to 661c177 Compare July 13, 2026 21:33
@fepegar
fepegar force-pushed the fepegar/exact-transform-params branch from 530c9ed to cf91c4e Compare July 13, 2026 21:33
@fepegar
fepegar force-pushed the fepegar/subject-mapping-adapters branch from 661c177 to 980611a Compare July 13, 2026 21:47
@fepegar
fepegar force-pushed the fepegar/exact-transform-params branch from cf91c4e to 2951b11 Compare July 13, 2026 21:47
@fepegar
fepegar requested a review from Copilot July 13, 2026 21:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread src/torchio/transforms/monai_adapter.py Outdated
Comment thread src/torchio/transforms/cornucopia_adapter.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread src/torchio/transforms/monai_adapter.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread src/torchio/transforms/monai_adapter.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

@fepegar
fepegar force-pushed the fepegar/subject-mapping-adapters branch from 4d0023c to 48cc8ed Compare July 13, 2026 22:15
@fepegar
fepegar force-pushed the fepegar/exact-transform-params branch from 2951b11 to b2cb211 Compare July 13, 2026 22:15
@fepegar
fepegar force-pushed the fepegar/subject-mapping-adapters branch from 48cc8ed to e0dd3a1 Compare July 13, 2026 22:48
@fepegar
fepegar force-pushed the fepegar/exact-transform-params branch from b2cb211 to 2253d34 Compare July 13, 2026 22:48
@fepegar
fepegar force-pushed the fepegar/subject-mapping-adapters branch from e0dd3a1 to 09967c1 Compare July 13, 2026 23:02
@fepegar
fepegar requested a review from Copilot July 13, 2026 23:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Comment thread src/torchio/transforms/cornucopia_adapter.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Comment thread src/torchio/transforms/cornucopia_adapter.py
Comment thread src/torchio/data/batch.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

@fepegar
fepegar force-pushed the fepegar/exact-transform-params branch from 5c0ed59 to 6124888 Compare July 14, 2026 09:01
@fepegar
fepegar force-pushed the fepegar/subject-mapping-adapters branch from 7437809 to ab7a8f1 Compare July 14, 2026 09:01
@fepegar
fepegar requested a review from Copilot July 14, 2026 09:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

fepegar added 11 commits July 20, 2026 21:17
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: baf5f11a-f67c-44dc-804e-6be849fa9160
@fepegar
fepegar force-pushed the fepegar/subject-mapping-adapters branch from ab7a8f1 to 8e30d6e Compare July 20, 2026 20:20
@fepegar
fepegar force-pushed the fepegar/exact-transform-params branch from 6124888 to 88d4d99 Compare July 20, 2026 20:20
@fepegar
fepegar marked this pull request as draft July 20, 2026 20:21
@fepegar

fepegar commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

[Generated by a coding agent]


Superseded by the simpler replacement stack:

The adapter and custom-transform features remain, now built on the simplified exact-history model.

@fepegar fepegar closed this Jul 20, 2026
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