Skip to content

ENH: Ignore tracts with fewer than 2 points with a warning - #129

Open
demianw wants to merge 2 commits into
masterfrom
ignore-single-point-tracts
Open

demianw wants to merge 2 commits into
masterfrom
ignore-single-point-tracts

Conversation

@demianw

@demianw demianw commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

What was wrong

A tractography containing a tract with fewer than 2 points could not be queried: compute_tract_bounding_boxes raised ValueError: Tracts in the tractography must have at least 2 points ... (the error in #50). As discussed in #46, such tracts should be ignored with a warning instead.

The change

Tracts with fewer than 2 points (including empty ones) are left out of the label indices through the same mechanism as tracts below --length_threshold (introduced in #122): they are absent from the four label maps and their bounding boxes and endpoint positions are NaN, so no query (label terms, endpoints_in, relative terms) selects them. A single UserWarning gives their number and suggests tract_math to prune them. Indices of the other tracts are unchanged, so the saved results still refer to the input tractography.

Behaviour change: inputs that used to stop with the ValueError now run, with the warning.

Testing

  • New test_tracts_with_fewer_than_two_points in tract_querier/tests/test_tract_label_indices.py: appends two 1-point tracts (inside labels) and an empty tract to the synthetic tractography; checks the warning and that every query gives the same result as without them. It fails without this change.
  • CLI: the test dataset with two 1-point tracts inserted (6785 tracts), tract_querier -q wmql_1_cst.qry: warns 2 tracts have fewer than 2 points and are ignored, and returns cortico_spinal.left: 000385, cortico_spinal.right: 000000, as for the original file.
  • python -m pytest -q -p no:cacheprovider tract_querier: 44 passed, 1 skipped.

Merge order

Depends on #122 (#46) and must be merged after it: this branch is stacked on it, so until #122 is merged the diff here also shows its commit. #140 (#117) and #135 (#100) touch the same file; all of them merge together without conflict.

Closes #50

🤖 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>
compute_tract_bounding_boxes raised a ValueError when a tract had fewer
than 2 points, so tract_querier could not process tractographies
containing such tracts.

Leave tracts with fewer than 2 points out of the label indices, the same
way as tracts shorter than the length threshold, give them NaN bounding
boxes and endpoint positions so that no query selects them, and warn
once with their number.

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.

Atlas dissection

1 participant