Fix widget compatibility with multi-scale napari image layers#267
Merged
Fix widget compatibility with multi-scale napari image layers#267
Conversation
Napari multi-scale Image layers store data as a MultiScaleData list rather than a single array. Passing this directly to processing functions caused a TypeError when the code tried to index or call .shape on it. Add get_layer_data() helper in utils.py that extracts the highest-resolution level (index 0) for multi-scale layers and returns .data unchanged for regular layers. Apply it in workflows.py at every point where user-supplied layer data is consumed: preprocessing (image/labels), segmentation (detection/contours), and optical flow. Add regression tests covering all three workflow modes (AUTO_DETECT, AUTO_FROM_LABELS, MANUAL) with two-level image pyramids.
The CLI already had the same multiscale-extraction pattern inline in flow.py, link.py, export.py, and as a private function in segment.py. Consolidate all five copies into a single get_layer_data() in ultrack/utils/napari.py and update every call site to import from there.
1b999cf to
d669a3a
Compare
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.
Problem
When a napari
Imagelayer is multi-scale (e.g. loaded from a zarr pyramid or created withviewer.add_image(..., multiscale=True)), its.dataattribute is aMultiScaleDataobject — a list of arrays at progressively lower resolutions — rather than a single array.The widget's workflow code passed
layer.datadirectly to processing functions and called.shapeon it, which raised:This affected all three workflow modes (AUTO_DETECT, AUTO_FROM_LABELS, MANUAL).
Fix
Added
get_layer_data(layer)helper inutils.pythat returnslayer.data[0](the highest-resolution level) when a layer is multi-scale, andlayer.dataotherwise.Applied it in
workflows.pyat every point where user-supplied layer data is consumed:Tests
Added
test_ultrack_widget_multiscaleparametrized over all three workflow choices, each using a two-level image pyramid built from the existing mock data fixtures. The tests confirmed the failure before the fix and pass after.