Skip to content

Commit

Permalink
fix error thrown when removing outlier
Browse files Browse the repository at this point in the history
  • Loading branch information
christinab12 committed Jul 24, 2024
1 parent 0d144a6 commit 8c82b56
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/client/dcp_client/gui/_filesystem_wig.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
import numpy as np
from skimage.io import imread
from skimage.color import label2rgb


from PyQt5.QtWidgets import QFileSystemModel
from PyQt5.QtCore import Qt, QVariant, QDir
from PyQt5.QtGui import QImage
Expand Down Expand Up @@ -71,7 +73,7 @@ def data(self, index, role=Qt.DisplayRole):
if filepath_img.endswith(settings.accepted_types):

# if a mask make sure it is displayed properly
if "_seg" in filepath_img:
if "_seg" in filepath_img and os.path.exists(filepath_img):
img = imread(filepath_img)
if img.ndim > 2: img = img[0]
img = label2rgb(img)
Expand Down
34 changes: 23 additions & 11 deletions src/client/dcp_client/gui/napari_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ def __init__(self, app: Application) -> None:
self.app = app
self.setWindowTitle("napari viewer")
self.setStyleSheet("background-color: #262930;")
#screen_size = QGuiApplication.primaryScreen().geometry()
#self.resize(int(screen_size.width()*0.9), int(screen_size.height()*0.8))
screen_size = QGuiApplication.primaryScreen().geometry()
self.resize(int(screen_size.width()*0.8), int(screen_size.height()*0.8))

# Load image and get corresponding segmentation filenames
img = self.app.load_image()
Expand Down Expand Up @@ -203,16 +203,25 @@ def on_remove_from_dataset_button_clicked(self) -> None:
"""
Defines what happens when the "Remove from dataset" button is clicked.
"""
seg_name_to_remove = self.viewer.layers.selection.active.name
if seg_name_to_remove:
# Delete the image and corresponding masks from the dataset
image_name = self.app.cur_selected_img
seg_files_to_remove = [seg_name_to_remove + '.tiff']
self.app.delete_images([image_name] + seg_files_to_remove)
'''

Check warning on line 206 in src/client/dcp_client/gui/napari_window.py

View check run for this annotation

Codecov / codecov/patch

src/client/dcp_client/gui/napari_window.py#L206

Added line #L206 was not covered by tests
try:
# get image name
files_to_remove = [self.viewer.layers.selection.active.name]
except AttributeError:
message_text = "Please first select the image in the layer list."
_ = self.create_warning_box(message_text, message_title="Warning")
return
'''
rmv_files = [self.app.cur_selected_img]
self.app.search_segs()
rmv_files.extend(self.app.seg_filepaths)

Check warning on line 217 in src/client/dcp_client/gui/napari_window.py

View check run for this annotation

Codecov / codecov/patch

src/client/dcp_client/gui/napari_window.py#L215-L217

Added lines #L215 - L217 were not covered by tests
# Delete the image and corresponding masks from the dataset
self.app.delete_images(rmv_files)
self.app.cur_selected_img = ""
self.app.seg_filepaths = []
self.viewer.close()
self.close()

Check warning on line 223 in src/client/dcp_client/gui/napari_window.py

View check run for this annotation

Codecov / codecov/patch

src/client/dcp_client/gui/napari_window.py#L219-L223

Added lines #L219 - L223 were not covered by tests

self.viewer.close()
self.close()

def set_editable_mask(self) -> None:
"""
This function is not implemented. In theory the use can choose between which mask to edit.
Expand Down Expand Up @@ -241,6 +250,9 @@ def axis_changed(self, event) -> None:
Is triggered each time the user switches the viewer between the mask channels. At this point the class mask
needs to be updated according to the changes made tot the instance segmentation mask.
"""

if self.app.cur_selected_img=="": return # because this also gets triggered when removing outlier

self.active_mask_index = self.viewer.dims.current_step[0]
masks = deepcopy(self.layer.data)

Expand Down

0 comments on commit 8c82b56

Please sign in to comment.