Skip to content

BUG: Fix swapped superior_of and inferior_of - #142

Open
demianw wants to merge 1 commit into
masterfrom
fix-superior-inferior
Open

demianw wants to merge 1 commit into
masterfrom
fix-superior-inferior

Conversation

@demianw

@demianw demianw commented Nov 4, 2026

Copy link
Copy Markdown
Owner

process_relative_term compares the tract bounding boxes with the region's using > for anterior and inferior and < otherwise. In RAS+ coordinates superior is the maximum z, so superior_of(X) selected tracts whose top is below the top of X, and inferior_of(X) tracts whose bottom is above the bottom of X (#141; also what #35 reported in 2017).

On the test data, superior_of(ins.left) (left insula, label 1035) returned 2,715 tracts, none of which reaches above the insula, and inferior_of(ins.left) 4,646 tracts, none of which reaches below it; anterior_of/posterior_of are correct (100% in front / behind).

Change

One line: > for superior (like anterior), < for inferior (like posterior). medial_of/lateral_of are unchanged.

New tract_querier/tests/test_relative_terms.py: a synthetic atlas (one region in the centre of a 20 mm cube) with one tract above, below, in front of and behind it; checks that each of superior_of, inferior_of, anterior_of, posterior_of returns exactly the expected tract. The superior/inferior cases fail on master.

Behaviour change

User queries that use superior_of / inferior_of now select the opposite (correct) side. No query file bundled in tract_querier/data uses these terms, so the bundled tract definitions are unchanged. Anyone who applied the #35 workaround (flipping z with --bounding_box_affine_transform) should drop it.

Testing

  • New tests: 4 passed (2 fail on master).
  • Full suite: 44 passed, 1 skipped (Python 3.12, without VTK).

Merge order

Touches the same function as #133 (relative-term argument checks) a few lines apart; whichever merges second may need a trivial rebase.

Closes #141.

🤖 Generated with Claude Code

`process_relative_term` compared the tract and region bounding boxes
with `>` for `anterior` and `inferior` and `<` otherwise. In RAS+
coordinates the `superior` side is the maximum z, so `superior_of(X)`
selected tracts whose top lies below the top of X, and `inferior_of(X)`
tracts whose bottom lies above the bottom of X. Use `>` for `superior`
(like `anterior`) and `<` for `inferior` (like `posterior`).

Add tests for the direction of the four antero-posterior and
supero-inferior terms on a synthetic atlas; the superior/inferior cases
fail before this change.

Closes #141.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

BUG: superior_of and inferior_of are swapped

1 participant