Repository navigation
Conversation
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>
This was referenced Nov 4, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
With
--length_threshold> 0,compute_tract_label_indicesremoved the short tracts from its local copy of the tract list before building the label maps. The keys of the four maps (crossing_tracts_labels,crossing_labels_tractsand both ending maps) were therefore positions in the filtered list, whileTractographySpatialIndexingcomputes the tract bounding boxes and endpoint positions, and the CLI saves the tracts, from the full list. Query results mixed up unrelated tracts.Reproduction on the test dataset (
IIT3mean_left_hemisphere_small.trk, 6783 tracts, Desikan atlas), threshold at the 30th length percentile (52.5 mm), through the Python API on master:cortico_spinal.left(wmql_1_cst.qry): 385 tracts, of which 111 are shorter than the threshold and only 25 are in the correct result.wmql_2_uf.qry:KeyError: 4748fromanterior_of(relative terms select tracts from the full-length bounding boxes, then look them up in the filtered maps).all_commissural: 0 (correct by chance: the 3 tracts are all shorter than the threshold).The change
compute_label_crossingsandcompute_label_endings_start_endtake the original indices of the tracts they index.endpoints_in/both_endpoints_incan return them.tract_bounding_boxesandtract_endpoints_posare set to NaN (rows stay aligned with the tractography). Comparisons with NaN are false, so relative terms (anterior_of, ...) do not select them either.Testing
tract_querier/tests/test_tract_label_indices.py: a synthetic atlas (three slabs) with 7 tracts, and queries covering label terms,endpoints_in,both_endpoints_in,only,not, relative terms andendpoints_inof a relative term. It asserts that for every queryresult(threshold) == {i in result(0) : length(i) >= threshold}. It fails on master (KeyError) and passes with this change.cortico_spinal.left385 / 385 / 385 (none below the threshold),uncinate.left102 / 102 / 52,all_commissural3 / 0 / 0. Results at threshold 0 are unchanged.python -m pytest -q -p no:cacheprovider tract_querier: 43 passed, 1 skipped (the new test included).Merge order
Independent of the other open PRs. #129 (#50, single-point tracts) and #140 (#117, deduplicating the label/tract inversion) are stacked on this branch and must be merged after it. #135 (#100) is independent.
Closes #46
🤖 Generated with Claude Code