Skip to content

implement grapharrayview downscale in Tracks - #301

Draft
TeunHuijben wants to merge 1 commit into
mainfrom
segmentation-downscale
Draft

TeunHuijben wants to merge 1 commit into
mainfrom
segmentation-downscale

Conversation

@TeunHuijben

@TeunHuijben TeunHuijben commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

What this branch does

Before, a Tracks had exactly one segmentation: a full-size label image, one number per pixel, where the number is the node id. Drawing one 3D timepoint of a big dataset means building that whole thing in memory — several gigabytes — and napari rebuilds it every time you click something.

This branch adds a second, smaller version of that same picture. You ask for it with tracks.display_segmentation((1, 4, 4)), meaning "keep every z slice, but shrink y and x by 4". It is built from the same graph, and the cells still carry their own node ids as labels, so clicking one still identifies the right cell. It is just 16x less data to build and draw. Cells too small to survive the shrinking are drawn as a single dot instead of disappearing, which is what keeps them clickable.

Three supporting pieces:

  • tracks.display_scale((1, 4, 4)) tells you how big the voxels are in the small picture. Without it, napari would draw the shrunken image at a quarter of its real size.
  • Asking for the same size twice gives you the same object back, so it keeps what it already drew instead of starting over.
  • Asking for size 1 gives you the original full-size picture, unchanged. So the calling code never needs an if-statement — it just always asks.

And one safety rail. The full-size tracks.segmentation is not only for display: saving segmentation to disk, checking intensity images, and computing overlap between cells all read it. If a shrunken picture ever got put there, saving would silently write a broken file — no error, just wrong output. So tracks.segmentation now refuses to accept a shrunken one.

The other rule lives on the caller's side: positions read off the small picture are in small-picture coordinates. Never use them to edit. Use the full-size picture for anything you draw or measure.

Breaking changes

None in practice. tracks.segmentation reads exactly as before — same object, same shape, same dtype, same contents — so existing apps need no change, and display_segmentation is purely opt-in.

Technically, segmentation is a property now rather than a plain attribute. Reading and assigning work as before, and assigning still accepts any full-resolution GraphArrayView or None; the only new rejection is a downscaled view, which nothing predating this PR can construct. The one way it could bite is code reaching into tracks.__dict__["segmentation"], which is now _segmentation_array — nothing in funtracks does that, and nothing pickles a Tracks.

Worth noting that this has no breaking changes, as Tracks.segmentation works the same as before. Only change is that any downstream application that wants to use the downscaling should use Tracks.display_sgmentation. for nTE, it should always use Tracks.display_segmentation, as the downscale factors default to 1, and in that case Tracks.display_segmentation returns Tracks.segmentation directly

Dependency

Pinned to TeunHuijben/tracksdata@49388d6, which carries royerlab/tracksdata#341 (GraphArrayView(downscale=...)). That commit also carries #340 (GraphView(root_fallback=True)), but nothing here uses it — root_fallback defaults to False and does not appear in src/. Repin once #341 lands in a tracksdata release.

@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.03%. Comparing base (346409e) to head (762d148).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #301      +/-   ##
==========================================
+ Coverage   93.97%   94.03%   +0.06%     
==========================================
  Files          60       60              
  Lines        3599     3640      +41     
==========================================
+ Hits         3382     3423      +41     
  Misses        217      217              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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