Skip to content

Commit

Permalink
lint, mypy, and fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yrkim98 committed Dec 9, 2024
1 parent 04820f3 commit 34c2ad1
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 23 deletions.
23 changes: 14 additions & 9 deletions src/allencell_ml_segmenter/core/file_input_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,18 @@ def _from_directory_slot(self) -> None:
self._model.set_input_mode(InputMode.FROM_PATH)

def _update_layer_list(self, event: Optional[NapariEvent] = None) -> None:
existing_selection = [
self._image_list.item(i).text()
for i in self._image_list.get_checked_rows()
]
existing_selection: List[str] = []
for i in self._image_list.get_checked_rows():
item: Optional[QListWidgetItem] = self._image_list.item(i)
if item is not None:
existing_selection.append(item.text())

self._image_list.clear()
self._reset_channel_combobox()
for layer in self._viewer.get_layers():
path_of_layer_image: str = self._viewer.get_source_path(layer)
path_of_layer_image: Optional[Path] = self._viewer.get_source_path(
layer
)
if path_of_layer_image:
self._image_list.add_item(
layer.name, set_checked=layer.name in existing_selection
Expand All @@ -230,12 +234,13 @@ def _update_layer_list(self, event: Optional[NapariEvent] = None) -> None:
def _process_checked_signal(self, row: int, state: Qt.CheckState) -> None:
if self._model.get_input_mode() == InputMode.FROM_NAPARI_LAYERS:
selected_indices: List[int] = self._image_list.get_checked_rows()
selected_paths: List[Path] = [
self._viewer.get_source_path(
selected_paths: List[Path] = []
for i in selected_indices:
source_path: Optional[Path] = self._viewer.get_source_path(
self._viewer.get_layers_nonthreshold()[i]
)
for i in selected_indices
]
if source_path is not None:
selected_paths.append(source_path)

# this will preserve the invariant: the options in the dropdown will be equal
# to the number of channels in at least one of the selected images (or empty if no images selected)
Expand Down
7 changes: 4 additions & 3 deletions src/allencell_ml_segmenter/curation/main_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,22 +295,23 @@ def add_curr_images_to_widget(self) -> None:
)
if raw_img_data is not None and raw_img_data.np_data is not None:
self._viewer.add_image(
raw_img_data.np_data, f"[raw] {raw_img_data.path.name}"
raw_img_data.np_data, name=f"[raw] {raw_img_data.path.name}"
)
seg1_img_data: Optional[ImageData] = (
self._curation_model.get_curr_image_data(ImageType.SEG1)
)
if seg1_img_data is not None and seg1_img_data.np_data is not None:
self._viewer.add_labels(
seg1_img_data.np_data, f"[seg1] {seg1_img_data.path.name}"
seg1_img_data.np_data, name=f"[seg1] {seg1_img_data.path.name}"
)
if self._curation_model.has_seg2_data():
seg2_img_data: Optional[ImageData] = (
self._curation_model.get_curr_image_data(ImageType.SEG2)
)
if seg2_img_data is not None and seg2_img_data.np_data is not None:
self._viewer.add_labels(
seg2_img_data.np_data, f"[seg2] {seg2_img_data.path.name}"
seg2_img_data.np_data,
name=f"[seg2] {seg2_img_data.path.name}",
)

self.enable_valid_masks()
Expand Down
6 changes: 3 additions & 3 deletions src/allencell_ml_segmenter/main/i_viewer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import ABC, abstractmethod
from pathlib import Path
from typing import Optional, Callable
from typing import Optional, Callable, Any
from allencell_ml_segmenter.main.segmenter_layer import (
ShapesLayer,
ImageLayer,
Expand All @@ -16,7 +16,7 @@ def __init__(self) -> None:
super().__init__()

@abstractmethod
def add_image(self, image: np.ndarray, **kwargs) -> None:
def add_image(self, image: np.ndarray, **kwargs: Any) -> None:
pass

@abstractmethod
Expand All @@ -40,7 +40,7 @@ def get_all_shapes(self) -> list[ShapesLayer]:
pass

@abstractmethod
def add_labels(self, data: np.ndarray, **kwargs) -> None:
def add_labels(self, data: np.ndarray, **kwargs: Any) -> None:
pass

@abstractmethod
Expand Down
6 changes: 3 additions & 3 deletions src/allencell_ml_segmenter/main/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
LabelsLayer,
)
import napari # type: ignore
from typing import Callable, Optional
from typing import Callable, Optional, Any
import numpy as np


Expand All @@ -23,7 +23,7 @@ def __init__(
super().__init__()
self.viewer: napari.Viewer = viewer

def add_image(self, image: np.ndarray, **kwargs) -> None:
def add_image(self, image: np.ndarray, **kwargs: Any) -> None:
self.viewer.add_image(image, **kwargs)

def get_image(self, name: str) -> Optional[ImageLayer]:
Expand Down Expand Up @@ -61,7 +61,7 @@ def get_all_shapes(self) -> list[ShapesLayer]:
if isinstance(l, Shapes)
]

def add_labels(self, data: np.ndarray, **kwargs) -> None:
def add_labels(self, data: np.ndarray, **kwargs: Any) -> None:
self.viewer.add_labels(data, **kwargs)

def get_labels(self, name: str) -> Optional[LabelsLayer]:
Expand Down
4 changes: 2 additions & 2 deletions src/allencell_ml_segmenter/prediction/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ def showResults(self) -> None:
self._viewer.add_image(
raw_np_data,
name=f"[raw] {data['raw'].name}",
metadata={"source_path": data["raw"]},
metadata={"source_path": str(data["raw"])},
)
if seg_np_data is not None:
self._viewer.add_labels(
seg_np_data,
name=f"[seg] {data['seg'].name}",
metadata={"source_path": data["seg"]},
metadata={"source_path": str(data["seg"])},
)

self._main_model.set_predictions_in_viewer(True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,10 @@ def _update_original_layers(self, _: Event) -> None:
)
new_layers_added: list[Layer] = current_layers
if original_layers is not None:
new_layers_added: list[Layer] = [
new_layers_added = [
layer
for layer in current_layers
if layer.name
not in self._thresholding_model.get_original_layers()
if layer.name not in original_layers
]

# refresh layers only if the new layers are not threshold layers (we dont want to track this in original layers state)
Expand Down

0 comments on commit 34c2ad1

Please sign in to comment.