From b2a2331d7b39ad560b3d55d3482ab24afa1855dd Mon Sep 17 00:00:00 2001 From: Peter Sobolewski <76622105+psobolewskiPhD@users.noreply.github.com> Date: Sun, 27 Oct 2024 13:57:29 +0100 Subject: [PATCH] Set `process_3D` checkbox based on image_layer.ndim (#34) * set process_3D based on image_layer.ndim * have 3D test check process_3D value --------- Co-authored-by: Talley Lambert --- cellpose_napari/_dock_widget.py | 10 +++++++++- tests/test_plugin.py | 7 +++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cellpose_napari/_dock_widget.py b/cellpose_napari/_dock_widget.py index 87723f8..043a62f 100644 --- a/cellpose_napari/_dock_widget.py +++ b/cellpose_napari/_dock_widget.py @@ -279,7 +279,15 @@ def update_masks(masks): widget.masks_orig = masks logger.debug('masks updated') - + @widget.image_layer.changed.connect + def check_dims(image_layer): + if image_layer.ndim == 4 and not image_layer.rgb: + widget.process_3D.value = True + elif image_layer.ndim==3 and not image_layer.rgb: + widget.process_3D.value = True + else: + widget.process_3D.value = False + @widget.compute_masks_button.changed.connect def _compute_masks(e: Any): diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 748f028..ff5d4e9 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -69,10 +69,13 @@ def test_compute_diameter(qtbot, viewer_widget): def test_3D_segmentation(qtbot, viewer_widget): viewer, widget = viewer_widget + # by default the widget loads with `process_3D` set to False + assert widget.process_3D.value == False viewer.open_sample(PLUGIN_NAME, 'rgb_3D') - # set 3D processing - widget.process_3D.value = True + # check that 3D processing is set correctly after opening a 3D image + assert widget.process_3D.value == True + widget.model_type.value = "cyto3" widget() # run segmentation with all default parameters