diff --git a/src/allencell_ml_segmenter/_tests/prediction/test_file_input_widget.py b/src/allencell_ml_segmenter/_tests/prediction/test_file_input_widget.py index 10de0904..38c57940 100644 --- a/src/allencell_ml_segmenter/_tests/prediction/test_file_input_widget.py +++ b/src/allencell_ml_segmenter/_tests/prediction/test_file_input_widget.py @@ -90,12 +90,13 @@ def test_preprocessing_method( # ASSERT 2 assert file_input_widget._model.get_preprocessing_method() is None -def test_populate_input_channel_combobox( - qtbot: QtBot -) -> None: + +def test_populate_input_channel_combobox(qtbot: QtBot) -> None: # Arrange prediction_model: PredictionModel = PredictionModel() - prediction_file_input: PredictionFileInput = PredictionFileInput(prediction_model) + prediction_file_input: PredictionFileInput = PredictionFileInput( + prediction_model + ) prediction_model.set_max_channels(6) # Act diff --git a/src/allencell_ml_segmenter/_tests/prediction/test_model.py b/src/allencell_ml_segmenter/_tests/prediction/test_model.py index 7d8d87b7..37eb8435 100644 --- a/src/allencell_ml_segmenter/_tests/prediction/test_model.py +++ b/src/allencell_ml_segmenter/_tests/prediction/test_model.py @@ -31,6 +31,7 @@ def test_input_image_paths(prediction_model: PredictionModel) -> None: # ASSERT assert prediction_model.get_input_image_dir() == dummy_paths + def test_image_input_channel_index(prediction_model: PredictionModel) -> None: """ Tests that the channel index is set and retrieved properly. diff --git a/src/allencell_ml_segmenter/_tests/prediction/test_model_file_service.py b/src/allencell_ml_segmenter/_tests/prediction/test_model_file_service.py index 7c702057..02443118 100644 --- a/src/allencell_ml_segmenter/_tests/prediction/test_model_file_service.py +++ b/src/allencell_ml_segmenter/_tests/prediction/test_model_file_service.py @@ -15,7 +15,16 @@ def test_extract_num_channels_in_a_folder() -> None: model_file_service: ModelFileService = ModelFileService(prediction_model) # Act / Assert - assert model_file_service.extract_num_channels_in_folder(Path(allencell_ml_segmenter.__file__).parent / "_tests" / "test_files" / "images") == 3 + assert ( + model_file_service.extract_num_channels_in_folder( + Path(allencell_ml_segmenter.__file__).parent + / "_tests" + / "test_files" + / "images" + ) + == 3 + ) + def test_extract_num_channels_from_csv() -> None: # Arrange @@ -23,4 +32,13 @@ def test_extract_num_channels_from_csv() -> None: model_file_service: ModelFileService = ModelFileService(prediction_model) # Act / Assert - assert model_file_service.extract_num_channels_from_csv(Path(allencell_ml_segmenter.__file__).parent / "_tests" / "test_files" / "csv" / "test_csv.csv") == 3 + assert ( + model_file_service.extract_num_channels_from_csv( + Path(allencell_ml_segmenter.__file__).parent + / "_tests" + / "test_files" + / "csv" + / "test_csv.csv" + ) + == 3 + ) diff --git a/src/allencell_ml_segmenter/prediction/file_input_widget.py b/src/allencell_ml_segmenter/prediction/file_input_widget.py index b6f316e0..3c306aca 100644 --- a/src/allencell_ml_segmenter/prediction/file_input_widget.py +++ b/src/allencell_ml_segmenter/prediction/file_input_widget.py @@ -118,9 +118,7 @@ def __init__(self, model: PredictionModel): self._browse_dir_edit: InputButton = InputButton( self._model, - lambda dir: self._model.set_input_image_dir( - Path(dir) - ), + lambda dir: self._model.set_input_image_dir(Path(dir)), "Select directory...", FileInputMode.DIRECTORY_OR_CSV, ) @@ -140,13 +138,16 @@ def __init__(self, model: PredictionModel): self._channel_select_dropdown.setPlaceholderText( "select a channel index" ) - self._channel_select_dropdown.currentIndexChanged.connect(self._model.set_image_input_channel_index) + self._channel_select_dropdown.currentIndexChanged.connect( + self._model.set_image_input_channel_index + ) self._channel_select_dropdown.setEnabled(False) # Event to trigger combobox populate on input image directory selection - self._model.subscribe(Event.ACTION_PREDICTION_INPUT_PATH_SELECTED, - self, - self._populate_input_channel_combobox) - + self._model.subscribe( + Event.ACTION_PREDICTION_INPUT_PATH_SELECTED, + self, + self._populate_input_channel_combobox, + ) output_dir_label: LabelWithHint = LabelWithHint("Output directory") output_dir_label.set_hint("Location to save segmentations.") @@ -180,8 +181,8 @@ def _from_directory_slot(self) -> None: self._browse_dir_edit.setEnabled(True) def _populate_input_channel_combobox(self, event: Event = None) -> None: - values_range: List[str] = [str(i) for i in range(self._model.get_max_channels())] + values_range: List[str] = [ + str(i) for i in range(self._model.get_max_channels()) + ] self._channel_select_dropdown.addItems(values_range) self._channel_select_dropdown.setEnabled(True) - - diff --git a/src/allencell_ml_segmenter/prediction/service.py b/src/allencell_ml_segmenter/prediction/service.py index cf1c3f5d..0a518d45 100644 --- a/src/allencell_ml_segmenter/prediction/service.py +++ b/src/allencell_ml_segmenter/prediction/service.py @@ -27,7 +27,11 @@ def __init__(self, model: PredictionModel): self._model.subscribe( Event.ACTION_PREDICTION_EXTRACT_CHANNELS, self, - lambda e: self._model.set_max_channels(self._determine_input_selection_type(self._model.get_input_image_dir())) + lambda e: self._model.set_max_channels( + self._determine_input_selection_type( + self._model.get_input_image_dir() + ) + ), ) def handle_event(self, event: Event) -> None: @@ -47,10 +51,10 @@ def extract_num_channels_in_folder(self, path: Path) -> int: # we expect user to have the same number of channels for all images in their folders # and that only images are stored in those folders # Get first image path - path_generator: Generator[Path] = path.glob('*') + path_generator: Generator[Path] = path.glob("*") first_image: Path = next(path_generator) # ignore hidden files - while str(first_image.name).split('.')[0] == "": + while str(first_image.name).split(".")[0] == "": first_image = next(path_generator) img: AICSImage = AICSImage(str(first_image.resolve())) @@ -61,7 +65,7 @@ def extract_num_channels_from_csv(self, path: Path): reader: csv.reader = csv.reader(file) # skip heading next(reader) - line_data_path:str = next(reader)[1] + line_data_path: str = next(reader)[1] img: AICSImage = AICSImage(str(line_data_path)) return img.dims.C @@ -74,6 +78,3 @@ def _determine_input_selection_type(self, path: Path): # for testing current api return self.extract_num_channels_from_csv(path / "train.csv") - - - diff --git a/src/allencell_ml_segmenter/services/prediction_service.py b/src/allencell_ml_segmenter/services/prediction_service.py index bdabb361..17ddd4dd 100644 --- a/src/allencell_ml_segmenter/services/prediction_service.py +++ b/src/allencell_ml_segmenter/services/prediction_service.py @@ -9,7 +9,7 @@ from pathlib import Path from typing import Union, Dict -from cyto_dl.api.model import CytoDLModel +# from cyto_dl.api.model import CytoDLModel from napari.utils.notifications import show_warning diff --git a/src/allencell_ml_segmenter/services/training_service.py b/src/allencell_ml_segmenter/services/training_service.py index 78def9dd..3ff297d0 100644 --- a/src/allencell_ml_segmenter/services/training_service.py +++ b/src/allencell_ml_segmenter/services/training_service.py @@ -3,7 +3,7 @@ from allencell_ml_segmenter.core.subscriber import Subscriber from allencell_ml_segmenter.core.event import Event -from cyto_dl.api.model import CytoDLModel +# from cyto_dl.api.model import CytoDLModel # from lightning.pytorch.callbacks import Callback