Skip to content

Commit

Permalink
feat: load job kwargs from UI
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmueller committed Dec 20, 2023
1 parent 48f50ad commit 4847795
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 63 deletions.
48 changes: 47 additions & 1 deletion chipstream/gui/main_window.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from importlib import import_module, resources
import inspect
import logging
import multiprocessing as mp
import pathlib
import signal
import sys
import traceback
import webbrowser

from dcnum.feat import feat_background
from PyQt6 import uic, QtCore, QtWidgets

from .._version import version
Expand All @@ -29,6 +32,18 @@ def __init__(self, *arguments):
self.logger = logging.getLogger(__name__)
self.manager = self.tableView_input.model.manager

# Populate segmenter combobox
self.comboBox_segmenter.blockSignals(True)
self.comboBox_segmenter.clear()
self.comboBox_segmenter.addItem("Disabled (from input file)", "copy")
self.comboBox_segmenter.addItem("Threshold-based", "thresh")
self.comboBox_segmenter.blockSignals(False)
self.comboBox_segmenter.setCurrentIndex(1)

# Maximum CPU count
self.spinBox_procs.setMaximum(mp.cpu_count())
self.spinBox_procs.setValue(mp.cpu_count())

# Settings are stored in the .ini file format. Even though
# `self.settings` may return integer/bool in the same session,
# in the next session, it will reliably return strings. Lists
Expand Down Expand Up @@ -103,8 +118,38 @@ def dropEvent(self, e):
pathlist.append(pp)
self.append_paths(pathlist)

def get_job_kwargs(self):
segmenter = self.comboBox_segmenter.currentData()
segmenter_kwargs = {}
if segmenter == "thresh":
segmenter_kwargs["thresh"] = self.spinBox_thresh.value()
# default background computer is "sparsemed"
bg_default = feat_background.BackgroundSparseMed
job_kwargs = {
"data_code": "hdf",
"data_kwargs": None,
"background_code": bg_default.get_ppid_code(),
"background_kwargs": inspect.getfullargspec(
bg_default.check_user_kwargs).kwonlydefaults,
"segmenter_code": segmenter,
"segmenter_kwargs": segmenter_kwargs,
"feature_code": "legacy",
"feature_kwargs": {
"brightness": self.checkBox_feat_bright.isChecked(),
"haralick": self.checkBox_feat_haralick.isChecked(),
},
"gate_code": "norm",
"gate_kwargs": {},
"num_procs": self.spinBox_procs.value(),
}
# special case for copy-segmenter
if segmenter == "copy":
job_kwargs["no_basins_in_output"] = \
not self.checkBox_basin_based.isChecked()

return job_kwargs

def is_running(self):
print(self.manager.is_alive())
return self.manager.is_alive()

@QtCore.pyqtSlot()
Expand Down Expand Up @@ -161,6 +206,7 @@ def on_run(self):
# change the pipeline.
self.widget_options.setEnabled(False)
self.manager.run_all_in_thread(
job_kwargs=self.get_job_kwargs(),
callback_when_done=self.run_completed.emit)

@QtCore.pyqtSlot()
Expand Down
156 changes: 94 additions & 62 deletions chipstream/gui/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="4,1">
<item>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
Expand Down Expand Up @@ -128,43 +128,84 @@
<string>Event Segmentation</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="1">
<widget class="QSpinBox" name="spinBox_2">
<property name="toolTip">
<string>Mask-generating threshold for the background-corrected image.</string>
<item row="1" column="0" alignment="Qt::AlignTop">
<widget class="QStackedWidget" name="stackedWidget_segmenter">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimum">
<number>-10</number>
</property>
<property name="maximum">
<number>-1</number>
</property>
<property name="value">
<number>-6</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="radioButton_3">
<property name="text">
<string>Threshold-based</string>
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="page">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QCheckBox" name="checkBox_basin_based">
<property name="text">
<string>Use basins (output file links to input file)</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Threshold</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="spinBox_thresh">
<property name="toolTip">
<string>Mask-generating threshold for the background-corrected image.</string>
</property>
<property name="minimum">
<number>-10</number>
</property>
<property name="maximum">
<number>-1</number>
</property>
<property name="value">
<number>-6</number>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item row="0" column="0">
<widget class="QRadioButton" name="radioButton_4">
<property name="text">
<string>Disabled (from input file)</string>
<widget class="QComboBox" name="comboBox_segmenter">
<property name="enabled">
<bool>false</bool>
</property>
<property name="checked">
<bool>true</bool>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>Disabled (from input file)</string>
</property>
</item>
<item>
<property name="text">
<string>Threshold-based</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<item alignment="Qt::AlignTop">
<widget class="QGroupBox" name="groupBox_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
Expand All @@ -177,20 +218,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QCheckBox" name="checkBox_4">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Standard features</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_5">
<widget class="QCheckBox" name="checkBox_feat_bright">
<property name="text">
<string>Image brightness features</string>
</property>
Expand All @@ -200,7 +228,7 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_6">
<widget class="QCheckBox" name="checkBox_feat_haralick">
<property name="text">
<string>Haralick texture features</string>
</property>
Expand All @@ -221,26 +249,6 @@
<string>Processing</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QComboBox" name="comboBox_3">
<property name="enabled">
<bool>false</bool>
</property>
<property name="duplicatesEnabled">
<bool>false</bool>
</property>
<item>
<property name="text">
<string>Use basins whenever possible (most efficient)</string>
</property>
</item>
<item>
<property name="text">
<string>Duplicate input files (increases disk usage)</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBox_procs">
<property name="suffix">
Expand All @@ -254,6 +262,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_no_basins">
<property name="text">
<string>Don't use basins (larger, standalone files)</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<property name="enabled">
Expand Down Expand Up @@ -360,5 +375,22 @@
</customwidget>
</customwidgets>
<resources/>
<connections/>
<connections>
<connection>
<sender>comboBox_segmenter</sender>
<signal>currentIndexChanged(int)</signal>
<receiver>stackedWidget_segmenter</receiver>
<slot>setCurrentIndex(int)</slot>
<hints>
<hint type="sourcelabel">
<x>1052</x>
<y>248</y>
</hint>
<hint type="destinationlabel">
<x>1052</x>
<y>312</y>
</hint>
</hints>
</connection>
</connections>
</ui>

0 comments on commit 4847795

Please sign in to comment.