Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test coverage for async slicing of labels #5325

Merged
merged 5 commits into from Sep 5, 2023

Conversation

kcpevey
Copy link
Contributor

@kcpevey kcpevey commented Nov 10, 2022

References and relevant issues

Part of #4795.

Description

Adds test coverage to check that the layer slicer handles labels layers appropriately.

@github-actions github-actions bot added the tests Something related to our tests label Nov 10, 2022
@kcpevey
Copy link
Contributor Author

kcpevey commented Nov 10, 2022

This is my first time working with Labels. Now that I've dipped my toe in the water a bit and attempted an implementation similar to Images, I realize that much of this code (the vast majority) could be removed by allowing LabelSliceRequest/Response to inherit from ImageSliceRequest/Response. Any opinions on that @potating-potato or @andy-sweet ?

In fact, SO MUCH CODE would be removed that I'm starting to question if I've done this right.

@kcpevey
Copy link
Contributor Author

kcpevey commented Nov 14, 2022

Given discussion on this topic on zulip, I'll be making some major reductions to this PR. Stand by.

@@ -83,6 +83,7 @@ class LockableData:
def __init__(self, data: LayerDataProtocol):
self.data = data
self.lock = RLock()
self.ndim = data.ndim
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Required to avoid ValueError: Input data should be an array-like object, or a sequence of arrays of decreasing size. Got arrays of single shape: (10, 15) inside of layer.guess_multiscale()

Copy link
Member

Choose a reason for hiding this comment

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

Normally, passing multiscale=False in the layer initializer should be enough to avoid that error. But I'm not against adding this if needed.

Copy link
Member

Choose a reason for hiding this comment

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

If this is needed, then maybe just make this a derived property that comes from self.data.ndim?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because of the nonlinear if checking, even setting multiscale=False doesn't avoid this message. I can change it to a property derived from self.data.ndim though.

@kcpevey
Copy link
Contributor Author

kcpevey commented Nov 15, 2022

@andy-sweet / @perlman is this in line with what you were thinking?

@codecov
Copy link

codecov bot commented Nov 15, 2022

Codecov Report

Merging #5325 (b3a7a9d) into main (70b8ea4) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #5325   +/-   ##
=======================================
  Coverage   91.67%   91.67%           
=======================================
  Files         582      582           
  Lines       51073    51087   +14     
=======================================
+ Hits        46819    46836   +17     
+ Misses       4254     4251    -3     
Files Changed Coverage Δ
napari/_tests/utils.py 100.00% <100.00%> (ø)
napari/components/_tests/test_layer_slicer.py 98.04% <100.00%> (+0.08%) ⬆️

... and 1 file with indirect coverage changes

@andy-sweet
Copy link
Member

Looks good so far, but as discussed, I think it makes sense to put this one on hold until we have merged an initial integration PR. The PR is already draft, so no need to change anything. Could be interesting to combine this with a PR that enables async slicing/rendering for some of the labels layer specific functionality (e.g. painting).

@andy-sweet andy-sweet changed the title Add async slicing to label Add test coverage for async slicing of labels Aug 30, 2023
@andy-sweet andy-sweet marked this pull request as ready for review August 30, 2023 20:58
@andy-sweet
Copy link
Member

@brisvag : I picked this up while doing some PR grooming. It's very small now and just adds a little more test coverage for async slicing. Would appreciate a review!

@andy-sweet andy-sweet added this to the 0.5.0 milestone Aug 31, 2023
@andy-sweet andy-sweet added the maintenance PR with maintance changes, label Aug 31, 2023
Comment on lines +143 to +146
@property
def ndim(self) -> int:
# LayerDataProtocol does not have ndim, but this should be equivalent.
return len(self.data.shape)
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this protocol is only really used by images and labels? Otherwise this does not really hold true for layers that accept tuples like surface.

Copy link
Member

Choose a reason for hiding this comment

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

Yes. This change was needed because Labels also needs ndim in the test case here, so (at most) LayerDataProtocol only supports Image right now.

I like the intent of it and it's often useful for prototyping and testing, but would be great to give it a more thought and care. Outside of this PR though ;)

@andy-sweet andy-sweet added the ready to merge Last chance for comments! Will be merged in ~24h label Sep 1, 2023
@andy-sweet andy-sweet merged commit 16ea9d1 into napari:main Sep 5, 2023
40 checks passed
@andy-sweet andy-sweet deleted the label_slice_function branch September 5, 2023 16:01
kne42 added a commit to kne42/napari that referenced this pull request Sep 19, 2023
* main: (26 commits)
  Fix some typing in napari.components (napari#6203)
  Use class name for object that does not have qt name (napari#6222)
  test: [Automatic] Constraints upgrades: `hypothesis`, `magicgui`, `psygnal`, `tensorstore`, `tifffile`, `tqdm`, `virtualenv` (napari#6143)
  Replace more np.all( ... = ...) with np.array_equal (napari#6213)
  remove np.all(... == ...) in test_surface.py (napari#6218)
  Ensure pandas Series is initialized with a list as data (napari#6226)
  Stop using temporary directory for store array for paint test (napari#6191)
  Bugfix: ensure thumbnail represents canvas when multiscale (napari#6200)
  cleanup np.all(... == ...) from test_points.py (napari#6217)
  [pre-commit.ci] pre-commit autoupdate (napari#6221)
  use app-model for file menu (napari#4865)
  Add tests to cover slicing behavior when changing layers and data (napari#4819)
  [pre-commit.ci] pre-commit autoupdate (napari#6128)
  Add test coverage for async slicing of labels (napari#5325)
  Add collision check when set colors for labels layer (napari#6193)
  Update "toggle ndview" text (napari#6192)
  Prevent layer controls buttons changing layout while taking screenshots with flash effect on (napari#6194)
  Fix typing in napari.utils.perf (napari#6132)
  Add GUI test coverage for changes to Labels.show_selected_label (napari#5372)
  Fix types in 'napari.utils.colormaps.categorical_colormap' (napari#6154)
  ...
@Czaki Czaki removed the ready to merge Last chance for comments! Will be merged in ~24h label Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance PR with maintance changes, tests Something related to our tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants