Skip to content

Adaptive viral tracing informed tractography (AdaViT) - #1345

Open
CHrlS98 wants to merge 13 commits into
scilus:masterfrom
CHrlS98:cdmri-tracking-mask-from-ambca
Open

Adaptive viral tracing informed tractography (AdaViT)#1345
CHrlS98 wants to merge 13 commits into
scilus:masterfrom
CHrlS98:cdmri-tracking-mask-from-ambca

Conversation

@CHrlS98

@CHrlS98 CHrlS98 commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Quick description

Addition of a new CLI script for adaptive viral tracing informed tractography (AdaViT), allowing for dynamically updating the tracking mask based on streamline position. This is the code from my CDMRI 26 conference paper.

New functionality:

  • Added new CLI script scil_tracking_adavit.py implementing the AdaViT algorithm for viral tracing informed tractography, including support for 4D tracking masks, exclusion masks, and backtracking options.

Other:

  • Improved tractogram information output in scil_tractogram_print_info.py by including the median streamline length in the statistics.

Type of change

Check the relevant options.

  • Bug fix (non-breaking change which fixes an issue)
  • [ x ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist

  • My code follows the style guidelines of this project (run autopep8)
  • I added relevant citations to scripts, modules and functions docstrings and descriptions
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I moved all functions from the script file (except the argparser and main) to scilpy modules
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Copilot AI lite review requested due to automatic review settings August 12, 2026 13:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces an “Adaptive viral tracing informed tractography (AdaViT)” workflow to scilpy by adding a dedicated CLI and a corresponding tracker implementation that supports 4D tracking masks and optional exclusion-mask-based backtracking. It also extends tractogram info reporting with an additional streamline-length statistic.

Changes:

  • Added scil_tracking_adavit CLI entrypoint and implementation for AdaViT tracking with 4D masks, optional dilation, and (probabilistic-only) backtracking via an exclusion mask.
  • Added TrackerAdaViT (and related stopping-criteria signature update) to support trajectory-dependent tracking masks.
  • Extended scil_tractogram_print_info.py statistics with median streamline length.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
src/scilpy/tracking/tracker.py Updates base stopping-criteria signature and adds TrackerAdaViT (plus a new MouseTracker class).
src/scilpy/cli/scil_tractogram_print_info.py Adds median streamline length to printed tractogram statistics.
src/scilpy/cli/scil_tracking_adavit.py New AdaViT CLI script wiring inputs/args to TrackerAdaViT and saving output tractograms.
pyproject.toml Registers the new scil_tracking_adavit console script entrypoint.
Suppressed comments (1)

src/scilpy/tracking/tracker.py:1043

  • The space/origin guard uses and, so it will only raise when both space is not VOX and origin is not CENTER. This allows unsupported configurations through.
        self.origin = self.propagator.origin
        self.space = self.propagator.space
        if self.space != Space.VOX and self.origin != Origin.CENTER:
            raise NotImplementedError("This version of the Tracker only works in VOX space with CENTER origin.")


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +738 to +751
def _verify_stopping_criteria(self, line):
# project line coordinates onto a grid to find which masks we are in
# TODO: Support trilinear interpolation for line-masks intersection
line_mask = np.zeros(self.tracking_masks.shape[:-1], dtype=bool)

# line is in origin center, so we add 0.5 to get to
# corner and then floor to get voxel coordinates
coords = np.floor(np.array(line) + 0.5).astype(int)

line_mask[coords[:, 0], coords[:, 1], coords[:, 2]] = True
line_masks_intersection = self.tracking_masks[line_mask]

matching_tracking_masks = np.all(line_masks_intersection, axis=0)
return np.any(matching_tracking_masks)
Comment on lines +668 to +671
# assert space
if self.space != Space.VOX and self.origin != Origin.CENTER:
raise NotImplementedError("This version of the Tracker only works in VOX space with CENTER origin.")

Comment on lines +578 to +581
AdaViT uses a 4D volume containing many tracking masks and tracks only
in the union of all masks intersecting the streamline trajectory. In the
original publication, AdaViT is used with tracking masks estimated from
viral tracing experiments, but in practice, any list of masks can be used.
Comment on lines +168 to +175
tracts_format = detect_format(args.out_tractogram)
if tracts_format is not TrkFile:
logging.warning("You have selected option --save_seeds but you are "
"not saving your tractogram as a .trk file. \n"
"Data_per_point information CANNOT be saved.\n"
"Ignoring.")
args.save_seeds = False

Comment on lines +269 to +272
# condition for backtracking
backtrack = args.mask_exclude is not None and args.algo == 'prob'
backtrack_n_pts = int(args.backtrack_distance / step_size)

Comment on lines +305 to +309
# Compared with scil_tracking_local, using sft rather than
# LazyTractogram to deal with space.
# Contrary to scilpy or dipy, where space after tracking is vox, here
# space after tracking is voxmm.
# Smallest possible streamline coordinate is (0,0,0), equivalent of
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 19.08602% with 301 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.84%. Comparing base (31cf4e5) to head (779b427).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1345      +/-   ##
==========================================
- Coverage   72.59%   71.84%   -0.76%     
==========================================
  Files         301      302       +1     
  Lines       26283    26649     +366     
  Branches     3700     3763      +63     
==========================================
+ Hits        19080    19145      +65     
- Misses       5651     5950     +299     
- Partials     1552     1554       +2     
Flag Coverage Δ
smoketests 69.03% <19.08%> (-0.72%) ⬇️
unittests 14.01% <0.00%> (-0.20%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Scripts 74.98% <39.23%> (-0.34%) ⬇️
Library 68.11% <8.26%> (-1.22%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants