napari / napari

napari: a fast, interactive, multi-dimensional image viewer for python
https://napari.org
BSD 3-Clause "New" or "Revised" License
2.07k stars 410 forks source link

"Shapes to Labels", "(float)Image to Labels": Don't pop layer being converted, append new one #6859

Closed psobolewskiPhD closed 1 day ago

psobolewskiPhD commented 3 weeks ago

References and relevant issues

When you use the layerlist contextual menu to convert a layer, e.g. to labels, it pops the layer. I find this to rarely be the behavior I want. Worse yet, there is no easy undo of that the layer is just gone! I feel like being conservative is better -- I can always remove the previous layer myself if I truly con't want it.

Description

This PR drops the pop of the Shapes layer from the LayerList and instead the new Labels layer is appended above the layer being converted. I updated the test accordingly.

The action calls a private function which isn't used anywhere else, so I don't think it needs any deprecation warnings. The existing docs are vague enough that there is no need to update anything. But I can do so, if folks think it's useful.

Additionally, because images with float data are also converted to int before convert to labels, I made that also not pop the original image layer, because it is not fully reversible.

codecov[bot] commented 3 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 92.43%. Comparing base (5527240) to head (b8ee1c1). Report is 3 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #6859 +/- ## ======================================== Coverage 92.43% 92.43% ======================================== Files 614 617 +3 Lines 54903 55158 +255 ======================================== + Hits 50748 50988 +240 - Misses 4155 4170 +15 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

psobolewskiPhD commented 3 weeks ago

I've modified things so that only in case of Shapes -> labels the src (shapes) layer is preserved and not pop'd. I actually had this come up in a workshop yesterday! We reached consensus that shapes->labels behaving differently was ok, because shapes is fundamentally different from a pixel layer like labels/image.

psobolewskiPhD commented 2 weeks ago

Here's the matching docs PR: https://github.com/napari/docs/pull/414

psobolewskiPhD commented 2 weeks ago

I updated this, the test, and the docs PR to cover float images not popped.