Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions cellfinder/napari/curation.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,24 +495,29 @@ def check_image_data_for_extraction(self) -> bool:
return False

def check_training_data_exists(self) -> bool:
"""
Returns true if both training layers exist, and have len > 0.
Otherwise displays useful explanatory info and returns False.
"""
if not (
self.training_data_cell_layer or self.training_data_non_cell_layer
self.training_data_cell_layer and self.training_data_non_cell_layer
):
show_info(
"No training data layers have been added. "
"Please add a layer and annotate some points.",
"Please add layers for both cells and non-cells,"
"and annotate some points in both.",
)
return False
else:
if (
len(self.training_data_cell_layer.data) > 0
or len(self.training_data_non_cell_layer.data) > 0
and len(self.training_data_non_cell_layer.data) > 0
):
return True
else:
show_info(
"No training data points have been added. "
"Please annotate some points.",
"Please annotate points in both training data layers.",
)
return False

Expand Down
23 changes: 23 additions & 0 deletions tests/napari/test_curation.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,26 @@ def test_check_layer_removal_sync(valid_curation_widget):
assert valid_curation_widget.background_layer is None
assert valid_curation_widget.training_data_cell_layer is None
assert valid_curation_widget.training_data_non_cell_layer is None


@pytest.mark.xfail(reason="See discussion in #443", raises=AssertionError)
@pytest.mark.parametrize(
"layer_indices_to_remove",
[[-2], [-3], [-2, -3]],
ids=(
"users deletes non-cell training data layer",
"user deletes cell training data layer",
"user deletes both",
),
)
def test_training_data_does_not_exist_when_user_removes_layers(
valid_curation_widget, layer_indices_to_remove
):
for layer in layer_indices_to_remove:
valid_curation_widget.viewer.layers.pop(layer)
assert not valid_curation_widget.check_training_data_exists()


@pytest.mark.xfail(reason="See discussion in #443", raises=AssertionError)
def test_valid_widget_has_valid_training_data(valid_curation_widget):
assert valid_curation_widget.check_training_data_exists()