Skip to content

Commit

Permalink
feat: implement segmenter validation step in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Jun 12, 2024
1 parent 73ca843 commit 0ed4cf1
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
0.6.0
- feat: implement segmenter validation step in CLI
- feat: implement segmenter validation step in CLI and GUI
- feat: support PyTorch segmentation models
- fix: show correct default mask postprocessing arguments in CLI help
- setup: bump dcnum from 0.22.1 to 0.23.2
Expand Down
3 changes: 3 additions & 0 deletions chipstream/gui/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ def run_job(self, path_in, path_out):
path_out=path_out,
**self.job_kwargs)
self.jobs.append(job)
# Make sure the job will run (This must be done after adding it
# to the jobs list and before adding it to the runners list)
job.validate()
with dclogic.DCNumJobRunner(job) as runner:
self.runners.append(runner)
# We might encounter a scenario in which the output file
Expand Down
42 changes: 42 additions & 0 deletions tests/test_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,48 @@ def test_gui_segm_torch_model(mw, qtbot, monkeypatch):
== f"torchmpo:m={path_model.name}:cle=1^f=1^clo=0"


def test_gui_segm_torch_model_with_wrong_model(mw, qtbot, monkeypatch):
# Create a test dataset with metadata that will make the model invalid
path = retrieve_data(
"fmt-hdf5_cytoshot_full-features_legacy_allev_2023.zip")

with h5py.File(path, "a") as h5:
h5.attrs["setup:chip region"] = "reservoir"

path_model = retrieve_model(
"segm-torch-model_unet-dcnum-test_g1_910c2.zip")

# Import the model
monkeypatch.setattr(QtWidgets.QFileDialog, "getOpenFileNames",
lambda *args: ([path_model], ""))
qtbot.mouseClick(mw.toolButton_torch_add, QtCore.Qt.MouseButton.LeftButton)
# select the model
for idm in range(mw.comboBox_torch_model.count()):
data = mw.comboBox_torch_model.itemData(idm)
if data.name == path_model.name:
break
else:
assert False

mw.comboBox_torch_model.setCurrentIndex(idm)

# Add the input file
mw.append_paths([path])

# Run the analysis
mw.on_run()
while mw.job_manager.is_busy():
time.sleep(.1)
out_path = path.with_name(path.stem + "_dcn.rtdc")
assert not out_path.exists()

# Make sure there is an error message in the interface
qtbot.mouseClick(mw.tableWidget_input.cellWidget(0, 2),
QtCore.Qt.MouseButton.LeftButton)
assert mw.textBrowser.toPlainText().count(
"only experiments in channel region supported")


def test_gui_set_pixel_size(mw):
path = retrieve_data(
"fmt-hdf5_cytoshot_full-features_legacy_allev_2023.zip")
Expand Down
32 changes: 31 additions & 1 deletion tests/test_gui_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

from chipstream.gui import manager

import h5py

from helper_methods import retrieve_data
from helper_methods import retrieve_data, retrieve_model


def test_manager_get_paths_out(tmp_path):
Expand Down Expand Up @@ -90,6 +91,35 @@ def test_manager_run_defaults():
"norm:o=0^s=10")


def test_manager_run_error_wrong_model():
model_file = retrieve_model(
"segm-torch-model_unet-dcnum-test_g1_910c2.zip")

# Create a test dataset with metadata that will make the model invalid
path = retrieve_data(
"fmt-hdf5_cytoshot_full-features_legacy_allev_2023.zip")

with h5py.File(path, "a") as h5:
h5.attrs["setup:chip region"] = "reservoir"

mg = manager.ChipStreamJobManager()
mg.add_path(path)
mg.run_all_in_thread(job_kwargs={
"segmenter_code": "torchmpo",
"segmenter_kwargs": {"model_file": model_file}
}
)
# wait for the thread to join
mg.join()

assert mg.current_index == 0
assert mg[0]["progress"] == 0
assert mg[0]["state"] == "error"
assert mg.get_info(0).count("only experiments in channel region supported")

assert not mg.is_busy()


def test_manager_run_with_path_out(tmp_path):
path = retrieve_data(
"fmt-hdf5_cytoshot_full-features_legacy_allev_2023.zip")
Expand Down

0 comments on commit 0ed4cf1

Please sign in to comment.