Skip to content

STYLE: Use one helper to invert the tract to label maps - #140

Open
demianw wants to merge 2 commits into
masterfrom
dedupe-label-tract-inversion
Open

demianw wants to merge 2 commits into
masterfrom
dedupe-label-tract-inversion

Conversation

@demianw

@demianw demianw commented Nov 4, 2026

Copy link
Copy Markdown
Owner

What was wrong

The inversion of a tract → labels map into a label → tracts map was written four times (#117): query_processor.labels_for_tracts, tract_label_indices.compute_label_crossings, compute_label_endings and compute_label_endings_start_end.

The change

  • labels_for_tracts moves to tract_label_indices.py, where the maps are built, and is the only implementation. compute_label_crossings and compute_label_endings_start_end use it (the ending maps hold one label per tract, so they are passed as one-element tuples). query_processor imports it from there, so query_processor.labels_for_tracts keeps working (it is used by test_query_eval.py); the diff in query_processor.py is that import plus the removal of the old definition.
  • compute_label_endings is removed: git grep -w compute_label_endings over the whole repository (package, scripts/, tests, doc/) finds only its definition. It is also listed as dead code in ENH: remove dead and broken code #107.

No behaviour change.

Testing

  • On the test dataset, the four maps of TractographySpatialIndexing (crossing_tracts_labels, crossing_labels_tracts, ending_tracts_labels, ending_labels_tracts) are equal before and after this commit, with length threshold 0 and with the 30th length percentile.
  • The three test-dataset query files (wmql_1_cst, wmql_2_uf, wmql_3_commissural), length threshold at percentiles 0/30/60: identical tract sets before and after.
  • python -m pytest -q -p no:cacheprovider tract_querier: 43 passed, 1 skipped.
  • Docs build (make -C doc html) succeeds; no warning involves tract_label_indices.
  • Trial merge of this branch with ENH: Ignore tracts with fewer than 2 points with a warning #129 and BUG: Compute label bounding boxes the same way with or without SciPy #135: no conflict, 47 passed, 1 skipped.

Merge order

Branched from #122 (#46), not from master, because #122 rewrites the same two functions and branching from master would give a hard conflict; until #122 is merged the diff here also shows its commit. Merge after #122; it merges cleanly with #129 and #135 in either order, but is meant to go after them. It also touches query_processor.py (import + removal at the end of the file), which other open work on that file may need to rebase over.

Closes #117
Part of #107

🤖 Generated with Claude Code

Tiber and others added 2 commits November 4, 2026 19:24
compute_tract_label_indices dropped the tracts shorter than
length_threshold from its local list before indexing, so the keys of the
four label maps were positions in the filtered list, while the tract
bounding boxes, the endpoint positions and the saved tracts use positions
in the full tractography. Queries combined unrelated tracts, returned
tracts below the threshold, and relative terms raised KeyError.

Key the label maps by the position in the full tractography and leave
the short tracts out of all of them. Set the bounding boxes and endpoint
positions of the left-out tracts to NaN so that relative terms do not
select them either.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The inversion of a tract -> labels map into a label -> tracts map was
written four times: query_processor.labels_for_tracts,
compute_label_crossings, compute_label_endings and
compute_label_endings_start_end.

Move labels_for_tracts to tract_label_indices, where the maps are built,
use it in the two functions that build the indices (query_processor
imports it from there), and remove compute_label_endings, which nothing
calls. No change in behaviour.

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.

ENH: deduplicate the label-to-tracts index inversion

1 participant