Browse Source

added three optionals to gui

master
Holger Frey 6 years ago
parent
commit
a71e05377c
  1. 5
      mtor/__init__.py
  2. 2
      mtor/commons.py
  3. 81
      mtor/gui.py
  4. 7
      mtor/parameters.py
  5. 4
      test_mtor.py

5
mtor/__init__.py

@ -15,13 +15,14 @@ __version__ = "0.1.0" @@ -15,13 +15,14 @@ __version__ = "0.1.0"
def run():
# pw = prescan_workflow("mtor-bilder", 50, 910, 300, 660)
pw = prescan_workflow("mtor-bilder", 50, 725 + 150, 300, 725)
#pw = prescan_workflow("mtor-bilder", 50, 725 + 150, 300, 725)
pw = prescan_workflow("mtor-bilder-2", 125, 795, 275, 700)
iw = image_workflow(pw.parameters)
dw = data_workflow(iw.data, iw.parameters)
fw = postprocessing_workflow(dw.data, dw.parameters) # noqa: F841
def run_data():
dw = cached_data_workflow("mtor-bilder-2") # noqa: F841
dw = cached_data_workflow("mtor-bilder") # noqa: F841
# postprocessing_workflow(dw.data, dw.parameters) # noqa: F841

2
mtor/commons.py

@ -15,8 +15,6 @@ LABEL_DISCARDED = "discarded" @@ -15,8 +15,6 @@ LABEL_DISCARDED = "discarded"
OUTPUT_FOLDER_NAMES = (
"colored",
"cuts",
f"cuts_{LABEL_DISCARDED}",
f"cuts_{LABEL_SELECTED}",
"data",
)

81
mtor/gui.py

@ -61,6 +61,22 @@ class MtorImageAnalysis(QWidget): @@ -61,6 +61,22 @@ class MtorImageAnalysis(QWidget):
self.roi_bottom_input.setValidator(QIntValidator())
self.roi_bottom_input.textChanged.connect(self.check_button_state)
# aditional parameters
self.pad_x_label = QLabel("Roi padding on x axis")
self.pad_x_input = QLineEdit()
self.pad_x_input.setValidator(QIntValidator())
self.pad_x_input.textChanged.connect(self.check_button_state)
self.pad_y_label = QLabel("Roi padding on y axis")
self.pad_y_input = QLineEdit()
self.pad_y_input.setValidator(QIntValidator())
self.pad_y_input.textChanged.connect(self.check_button_state)
self.cc_boost_label = QLabel("Intensity factor for colored images")
self.cc_boost_input = QLineEdit()
self.cc_boost_input.setValidator(QIntValidator())
self.cc_boost_input.textChanged.connect(self.check_button_state)
# action buttons
self.btn_run = QPushButton("Run", self)
self.btn_run.setEnabled(False)
@ -94,8 +110,22 @@ class MtorImageAnalysis(QWidget): @@ -94,8 +110,22 @@ class MtorImageAnalysis(QWidget):
grid.addWidget(QLabel(), 8, 0, 1, 2)
grid.addWidget(self.btn_exit, 9, 0)
grid.addWidget(self.btn_run, 9, 1)
grid.addWidget(self.pad_x_label, 9, 0)
grid.addWidget(self.pad_x_input, 9, 1)
grid.addWidget(self.pad_y_label, 10, 0)
grid.addWidget(self.pad_y_input, 10, 1)
grid.addWidget(self.cc_boost_label, 11, 0)
grid.addWidget(self.cc_boost_input, 11, 1)
grid.addWidget(self.btn_exit, 12, 0)
grid.addWidget(self.btn_run, 12, 1)
# set default values
self.pad_x_input.setText("50")
self.pad_y_input.setText("25")
self.cc_boost_input.setText("5")
self.setLayout(grid)
# self.resize(350, 300)
@ -128,35 +158,37 @@ class MtorImageAnalysis(QWidget): @@ -128,35 +158,37 @@ class MtorImageAnalysis(QWidget):
self.check_button_state()
def check_button_state(self):
values = self.get_values()
self.btn_run.setEnabled(all(values))
def get_values(self):
fields = [
(self.dir_selected, str),
(self.roi_top_input, int),
(self.roi_right_input, int),
(self.roi_bottom_input, int),
(self.roi_left_input, int),
]
result = []
for field, func in fields:
parameters = self.get_parameters()
self.btn_run.setEnabled(all(parameters.values()))
def get_parameters(self):
fields = {
'folder': (self.dir_selected, str),
'top': (self.roi_top_input, int),
'right': (self.roi_right_input, int),
'bottom': (self.roi_bottom_input, int),
'left': (self.roi_left_input, int),
'cut_pad_x': (self.pad_x_input, int),
'cut_pad_y': (self.pad_y_input, int),
'boost': (self.cc_boost_input, int),
}
parameters = {key: None for key in fields}
for key, name_and_func in fields.items():
field, func = name_and_func
raw_data = field.text().strip()
if raw_data:
if func is int:
# in qt5, a point as 1000 separator is allowed
raw_data = raw_data.replace(".", "")
result.append(func(raw_data))
else:
result.append(None)
return tuple(result)
parameters[key] = func(raw_data)
return parameters
def run_analysis(self):
parameters = self.get_values()
if all(parameters):
parameters = self.get_parameters()
if all(parameters.values()):
self.analysis_parameters = parameters
self.hide()
QApplication.instance().quit()
self.hide()
QApplication.instance().quit()
def run_gui():
@ -165,8 +197,7 @@ def run_gui(): @@ -165,8 +197,7 @@ def run_gui():
app.exec_()
if mia.analysis_parameters is not None:
analysis_parameters = tuple((p for p in mia.analysis_parameters))
pw = prescan_workflow(*analysis_parameters)
pw = prescan_workflow(**mia.analysis_parameters)
iw = image_workflow(pw.parameters)
dw = data_workflow(iw.data, iw.parameters)
fw = postprocessing_workflow(dw.data, dw.parameters)

7
mtor/parameters.py

@ -19,8 +19,7 @@ class Parameters(dict): @@ -19,8 +19,7 @@ class Parameters(dict):
cut_pad_y: pixels added to top or bottom edge to crop an image
cut_right: right edge for croping an image
cut_top: left edge for croping an image
cuts_discarded_dir: path to the directory of discarded croped images
cuts_selected_dir: path to the directory of selected croped images
cuts_dir: path to the directory of croped images
data_dir: path to the directory for graphs and numeric data
folder: name of the directory that holds the tif images
guard_filter_polynom: polynomal scalar for smoothing the guards histogram
@ -62,7 +61,7 @@ class Parameters(dict): @@ -62,7 +61,7 @@ class Parameters(dict):
self.folder = folder
# defaults
self.boost = 10
self.boost = 5
self.cut_pad_x = 50
self.cut_pad_y = 25
self.guard_histogram_bins = 100
@ -73,7 +72,7 @@ class Parameters(dict): @@ -73,7 +72,7 @@ class Parameters(dict):
self.savgol_filter_window = 51
self.savgol_filter_polynom = 1
self.peak_min_distance = 5
self.peak_threshold = 0.3
self.peak_threshold = 0.2
# labels for data items
self.roi_name = "roi"

4
test_mtor.py

@ -5,5 +5,5 @@ tif_dir = "original_tifs" @@ -5,5 +5,5 @@ tif_dir = "original_tifs"
#mtor.process_tifs(tif_dir, 50, 910, 300, 660, boost=5)
#mtor.run()
mtor.run_data()
mtor.run()
#mtor.run_data()

Loading…
Cancel
Save