Skip to content

ENH: Remove dead code from tract_math - #147

Open
demianw wants to merge 1 commit into
masterfrom
tract-math-dead-code
Open

demianw wants to merge 1 commit into
masterfrom
tract-math-dead-code

Conversation

@demianw

@demianw demianw commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

What was wrong

Part of the dead code listed in #107, restricted to tract_math:

  • tract_querier/tract_math/tract_obb.py (1,281 lines): the only function used outside the module is prototype_tract (by the tract_prototype_median and tract_prototype_mean operations; git grep over the whole repository finds no other import of tract_obb or of any of its names). A transitive call graph from prototype_tract (AST walk over the module's names) reaches only Box2D, Box3D, orthogonal_vector, box_cut and all_obb_3d_along_tract. The other 22 top-level definitions (738 lines) are unreachable: Box3DRich, all_obb_2d, all_obb_3d, all_obb_3d_nr, all_obb_3d_old, point_coverage_by_level, draw_boxes_2d, draw_box_2d, draw_box_3d (pylab/mayavi plotting), oriented_trace, trace, get_most_probable_trace, get_level, overlapping_boxes, containing_boxes, min_max, overlap_vtk, obb_tree_dfs, obb_tree_dfs_recursive, obb_tree_level, obb_tree_level_dfs, obb_from_tractography. All the debug print calls of the module were in them.
  • tensor_operations.tract_expand_tensor_metrics: no callers, and could not run (uses the undefined name new_scalar_data_flat).
  • scripts/cli_tract_math.py:11: an unused copy of the tract_math_operation decorator. Operations are registered by tract_querier.tract_math.decorator.tract_math_operation and collected with inspect.getmembers; the copy in the script is never applied.

None of the removed functions is a decorator-registered operation.

The change

Delete the definitions above and the NumPy imports that only they used (arccos, sign, cov, inf, pi, numpy.linalg.solve); pyflakes reports no unused names in tract_obb.py afterwards. The remaining code is unchanged. tract_obb.py goes from 1,281 to 500 lines.

Testing

  • The registered operations (sorted(tract_querier.tract_math.operations), 32 operations) and the full tract_math --help output are byte-identical before (master) and after.
  • python -m pytest -q -p no:cacheprovider tract_querier: 42 passed, 1 skipped (pre-existing unconditional skip).
  • On master tract_obb cannot be imported with NumPy 2 (numpy.in1d, fixed in BUG: Fix crashing tract_math operations #143), so the prototype operations cannot run on this branch alone. I merged this branch with BUG: Fix crashing tract_math operations #143 locally (resolving the import-line conflict as below): the BUG: Fix crashing tract_math operations #143 prototype tests pass, tract_prototype_median and tract_prototype_mean (smooth order 0 and 1) run on 100 tracts of the test data, and the whole suite passed (52 passed, 1 skipped) in 9 of 10 runs; the one failing run was not captured and did not recur, most likely the known flaky test_not_in (TST: Fix random failures of test_not_in #97).
  • Docs build (make -C doc html): succeeded with the same 20 warnings as master.

Merge order

Merge after #143 and #144. It conflicts with #143 on the from numpy import (...) block of tract_obb.py (resolution: keep this PR's shorter list with isin and ptp from #143) and on the removed all_obb_3d (take this PR's deletion). #144 also edits scripts/cli_tract_math.py (removes the traceback import next to the deleted decorator); a local merge of the two is clean. Local merges with #145 and #146 are clean too. The rest of #107 (outside tract_math) is handled in a separate PR (#136).

Part of #107

🤖 Generated with Claude Code

- tract_obb.py: keep only what `prototype_tract`, the only entry point
  used (by the tract_prototype_* operations), reaches: Box2D, Box3D,
  orthogonal_vector, box_cut and all_obb_3d_along_tract. The removed
  functions and Box3DRich had no callers in the repository and
  included debug prints and pylab/mayavi plotting code. Drop the
  numpy imports that became unused.
- tensor_operations.tract_expand_tensor_metrics: no callers and could
  not run (uses the undefined name `new_scalar_data_flat`).
- scripts/cli_tract_math.py: unused copy of the `tract_math_operation`
  decorator; operations are registered by the one in
  tract_querier.tract_math.decorator.

The registered tract_math operations and `tract_math --help` are
unchanged.

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.

1 participant