Skip to content

Commit

Permalink
Merge pull request #264 from zhujun98/add_reset_panel_in_main_gui
Browse files Browse the repository at this point in the history
Add reset panel in the main GUI
  • Loading branch information
zhujun98 authored Jul 20, 2020
2 parents 140bccf + 44731cf commit ae47029
Show file tree
Hide file tree
Showing 18 changed files with 169 additions and 88 deletions.
2 changes: 1 addition & 1 deletion extra_foam/database/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Metadata(metaclass=MetaMetadata):
PUMP_PROBE_PROC = "meta:proc:pump_probe"
ROI_PROC = "meta:proc:roi"
CORRELATION_PROC = "meta:proc:correlation"
BIN_PROC = "meta:proc:bin"
BINNING_PROC = "meta:proc:bin"
HISTOGRAM_PROC = "meta:proc:histogram"
FOM_FILTER_PROC = "meta:proc:fom_filter"
DARK_RUN_PROC = "meta:proc:dark_run"
Expand Down
24 changes: 21 additions & 3 deletions extra_foam/gui/ctrl_widgets/analysis_ctrl_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ def __init__(self, *args, **kwargs):
validator.setBottom(1)
self._ma_window_le.setValidator(validator)

self._reset_ma_btn = QPushButton("Reset")
self._reset_all_btn = QPushButton("Reset all")
self._reset_ma_btn = QPushButton("Reset moving average")
self._reset_pp_btn = QPushButton("Reset pump-probe")
self._reset_correlation_btn = QPushButton("Reset correlation")
self._reset_binning_btn = QPushButton("Reset binning")
self._reset_histogram_btn = QPushButton("Reset histogram")

self.initUI()
self.initConnections()
Expand All @@ -52,12 +57,18 @@ def initUI(self):
layout.addWidget(QLabel("POI indices: "), row, 0, 1, 1, AR)
layout.addWidget(self._poi_index_les[0], row, 1, 1, 1)
layout.addWidget(self._poi_index_les[1], row, 2, 1, 1)
layout.addWidget(QWidget(), 3, 1, 1, 1)

row += 1
layout.addWidget(QLabel("Moving average window: "), row, 0, AR)
layout.addWidget(self._ma_window_le, row, 1)
layout.addWidget(self._reset_ma_btn, row, 2, AR)

row += 1
layout.addWidget(self._reset_all_btn, row, 0,)
layout.addWidget(self._reset_ma_btn, row, 1)
layout.addWidget(self._reset_pp_btn, row + 1, 1)
layout.addWidget(self._reset_correlation_btn, row, 2)
layout.addWidget(self._reset_histogram_btn, row + 1, 2)
layout.addWidget(self._reset_binning_btn, row + 2, 2)

self.setLayout(layout)

Expand All @@ -75,7 +86,14 @@ def initConnections(self):
self._ma_window_le.value_changed_sgn.connect(
lambda x: mediator.onMaWindowChange(int(x)))

self._reset_all_btn.clicked.connect(mediator.onResetAll)

self._reset_ma_btn.clicked.connect(mediator.onResetMa)
self._reset_pp_btn.clicked.connect(mediator.onPpReset)

self._reset_correlation_btn.clicked.connect(mediator.onCorrelationReset)
self._reset_binning_btn.clicked.connect(mediator.onBinReset)
self._reset_histogram_btn.clicked.connect(mediator.onHistReset)

def updateMetaData(self):
"""Override"""
Expand Down
4 changes: 2 additions & 2 deletions extra_foam/gui/ctrl_widgets/bin_ctrl_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ def updateMetaData(self):

def loadMetaData(self):
"""Override."""
cfg = self._meta.hget_all(mt.BIN_PROC)
if not cfg:
cfg = self._meta.hget_all(mt.BINNING_PROC)
if "analysis_type" not in cfg:
# not initialized
return

Expand Down
6 changes: 3 additions & 3 deletions extra_foam/gui/ctrl_widgets/correlation_ctrl_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ def initUI(self):
llayout = QGridLayout()
llayout.addWidget(QLabel("Analysis type: "), 0, 0, AR)
llayout.addWidget(self._analysis_type_cb, 0, 1)
llayout.addWidget(self._reset_btn, 1, 1)
llayout.addWidget(self._auto_reset_ma_cb, 2, 0, 1, 2, AR)
llayout.addWidget(self._auto_reset_ma_cb, 1, 0, 1, 2, AR)
llayout.addWidget(self._reset_btn, 2, 0, 1, 2)
ctrl_widget.setLayout(llayout)
ctrl_widget.setFixedWidth(ctrl_widget.minimumSizeHint().width())

Expand Down Expand Up @@ -347,7 +347,7 @@ def updateMetaData(self):
def loadMetaData(self):
"""Override."""
cfg = self._meta.hget_all(mt.CORRELATION_PROC)
if not cfg:
if "analysis_type" not in cfg:
# not initialized
return

Expand Down
4 changes: 2 additions & 2 deletions extra_foam/gui/ctrl_widgets/histogram_ctrl_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def initUI(self):
llayout.addWidget(QLabel("Analysis type: "), 0, 0, AR)
llayout.addWidget(self._analysis_type_cb, 0, 1)
llayout.addWidget(self._pulse_resolved_cb, 1, 1)
llayout.addWidget(self._reset_btn, 2, 1)
llayout.addWidget(self._reset_btn, 2, 0, 1, 2)
lwidget.setLayout(llayout)

rwidget = QFrame()
Expand Down Expand Up @@ -113,7 +113,7 @@ def updateMetaData(self):
def loadMetaData(self):
"""Override."""
cfg = self._meta.hget_all(mt.HISTOGRAM_PROC)
if not cfg:
if "analysis_type" not in cfg:
# not initialized
return

Expand Down
4 changes: 2 additions & 2 deletions extra_foam/gui/ctrl_widgets/pump_probe_ctrl_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def initUI(self):
layout.addWidget(self._analysis_type_cb, 0, 1)
layout.addWidget(QLabel("Mode: "), 1, 0, AR)
layout.addWidget(self._mode_cb, 1, 1)
layout.addWidget(self._reset_btn, 2, 1, AR)
layout.addWidget(self._reset_btn, 2, 0, 1, 2)

layout.addWidget(QLabel("On-pulse indices: "), 0, 2, AR)
layout.addWidget(self._on_pulse_le, 0, 3)
Expand Down Expand Up @@ -132,7 +132,7 @@ def updateMetaData(self):
def loadMetaData(self):
"""Override."""
cfg = self._meta.hget_all(mt.PUMP_PROBE_PROC)
if not cfg:
if "analysis_type" not in cfg:
# not initialized
return

Expand Down
24 changes: 16 additions & 8 deletions extra_foam/gui/mediator.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ def onPhotonEnergyChange(self, value: float):
def onMaWindowChange(self, value: int):
self._meta.hset(mt.GLOBAL_PROC, "ma_window", value)

def onResetAll(self):
pipe = self._meta.pipeline()
pipe.hset(mt.GLOBAL_PROC, "reset_ma", 1)
pipe.hset(mt.PUMP_PROBE_PROC, "reset", 1)
pipe.hset(mt.CORRELATION_PROC, "reset1", 1)
pipe.hset(mt.CORRELATION_PROC, "reset2", 1)
pipe.hset(mt.HISTOGRAM_PROC, "reset", 1)
pipe.hset(mt.BINNING_PROC, "reset", 1)
pipe.execute()

def onResetMa(self):
self._meta.hset(mt.GLOBAL_PROC, "reset_ma", 1)

Expand Down Expand Up @@ -195,8 +205,6 @@ def onPpAbsDifferenceChange(self, value: bool):

def onPpReset(self):
self._meta.hset(mt.PUMP_PROBE_PROC, "reset", 1)
# reset moving average at the same time
self._meta.hset(mt.GLOBAL_PROC, "reset_ma", 1)

def onRoiGeometryChange(self, value: tuple):
idx, activated, locked, x, y, w, h = value
Expand Down Expand Up @@ -275,19 +283,19 @@ def onBinParamChange(self, value: tuple):
index, src, bin_range, n_bins = value

pipe = self._meta.pipeline()
pipe.hset(mt.BIN_PROC, f'source{index}', src)
pipe.hset(mt.BIN_PROC, f'bin_range{index}', str(bin_range))
pipe.hset(mt.BIN_PROC, f'n_bins{index}', n_bins)
pipe.hset(mt.BINNING_PROC, f'source{index}', src)
pipe.hset(mt.BINNING_PROC, f'bin_range{index}', str(bin_range))
pipe.hset(mt.BINNING_PROC, f'n_bins{index}', n_bins)
pipe.execute()

def onBinAnalysisTypeChange(self, value: IntEnum):
self._meta.hset(mt.BIN_PROC, "analysis_type", int(value))
self._meta.hset(mt.BINNING_PROC, "analysis_type", int(value))

def onBinModeChange(self, value: IntEnum):
self._meta.hset(mt.BIN_PROC, "mode", int(value))
self._meta.hset(mt.BINNING_PROC, "mode", int(value))

def onBinReset(self):
self._meta.hset(mt.BIN_PROC, "reset", 1)
self._meta.hset(mt.BINNING_PROC, "reset", 1)

def onHistAnalysisTypeChange(self, value: IntEnum):
self._meta.hset(mt.HISTOGRAM_PROC, "analysis_type", int(value))
Expand Down
40 changes: 29 additions & 11 deletions extra_foam/gui/tests/test_main_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,36 @@ def testAnalysisCtrlWidget(self):
roi_proc = train_worker._image_roi
ai_proc = train_worker._ai_proc

# test various reset_ma buttons

# tests of other reset buttons go to the respective unittest

meta = xgm_proc._meta # any meta is OK
# test "Reset moving average" button
widget._reset_ma_btn.clicked.emit()
self.assertEqual('1', meta.hget(mt.GLOBAL_PROC, 'reset_ma'))
roi_proc.update()
self.assertEqual('1', meta.hget(mt.GLOBAL_PROC, 'reset_ma'))
ai_proc.update()
self.assertEqual('1', meta.hget(mt.GLOBAL_PROC, 'reset_ma'))
xgm_proc.update()
self.assertEqual('1', meta.hget(mt.GLOBAL_PROC, 'reset_ma'))
digitizer_proc.update()
self.assertEqual('1', meta.hget(mt.GLOBAL_PROC, 'reset_ma'))

with patch.object(roi_proc, "_reset_ma") as patched_reset_roi:
with patch.object(ai_proc, "_reset_ma") as patched_reset_ai:
with patch.object(xgm_proc, "_reset_ma") as patched_reset_xgm:
with patch.object(digitizer_proc, "_reset_ma") as patched_reset_digitizer:

def _check_reset_ma():
roi_proc.update()
patched_reset_roi.assert_called_once()
patched_reset_roi.reset_mock()
ai_proc.update()
patched_reset_ai.assert_called_once()
patched_reset_ai.reset_mock()
xgm_proc.update()
patched_reset_xgm.assert_called_once()
patched_reset_xgm.reset_mock()
digitizer_proc.update()
patched_reset_digitizer.assert_called_once()
patched_reset_digitizer.reset_mock()

widget._reset_ma_btn.clicked.emit()
_check_reset_ma()

widget._reset_all_btn.clicked.emit()
_check_reset_ma()

# ----------------
# Test POI indices
Expand Down
34 changes: 33 additions & 1 deletion extra_foam/gui/windows/tests/test_plot_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def _check_close_satellite_window(self, window):

def _checkAnalysisTypeRegistration(self, registered):
meta = self.train_worker._binning_proc._meta
for key in [mt.BIN_PROC, mt.CORRELATION_PROC, mt.HISTOGRAM_PROC]:
for key in [mt.BINNING_PROC, mt.CORRELATION_PROC, mt.HISTOGRAM_PROC]:
cfg = meta.hget_all(key)
self.assertEqual(registered, bool(int(cfg["analysis_type"])))

Expand Down Expand Up @@ -335,6 +335,14 @@ def _checkPumpProbeCtrlWidget(self, win):
widget._reset_btn.clicked.emit()
pp_proc.update()
self.assertTrue(pp_proc._reset)
pp_proc._reset = False
self.gui.analysis_ctrl_widget._reset_pp_btn.clicked.emit()
pp_proc.update()
self.assertTrue(pp_proc._reset)
pp_proc._reset = False
self.gui.analysis_ctrl_widget._reset_all_btn.clicked.emit()
pp_proc.update()
self.assertTrue(pp_proc._reset)

# test loading meta data
mediator = widget._mediator
Expand Down Expand Up @@ -489,6 +497,14 @@ def _checkCorrelationCtrlWidget(self, win):
widget._reset_btn.clicked.emit()
proc.update()
self.assertTrue(proc._reset)
proc._reset = False
self.gui.analysis_ctrl_widget._reset_correlation_btn.clicked.emit()
proc.update()
self.assertTrue(proc._reset)
proc._reset = False
self.gui.analysis_ctrl_widget._reset_all_btn.clicked.emit()
proc.update()
self.assertTrue(proc._reset)

# test loading meta data
mediator = widget._mediator
Expand Down Expand Up @@ -643,6 +659,14 @@ def _checkBinCtrlWidget(self, win):
widget._reset_btn.clicked.emit()
proc.update()
self.assertTrue(proc._reset)
proc._reset = False
self.gui.analysis_ctrl_widget._reset_binning_btn.clicked.emit()
proc.update()
self.assertTrue(proc._reset)
proc._reset = False
self.gui.analysis_ctrl_widget._reset_all_btn.clicked.emit()
proc.update()
self.assertTrue(proc._reset)

# test "Auto level" button
win._bin1d_vfom._auto_level = False
Expand Down Expand Up @@ -724,6 +748,14 @@ def _checkHistogramCtrlWidget(self, win):
widget._reset_btn.clicked.emit()
proc.update()
self.assertTrue(proc._reset)
proc._reset = False
self.gui.analysis_ctrl_widget._reset_histogram_btn.clicked.emit()
proc.update()
self.assertTrue(proc._reset)
proc._reset = False
self.gui.analysis_ctrl_widget._reset_all_btn.clicked.emit()
proc.update()
self.assertTrue(proc._reset)

# test loading meta data
mediator = widget._mediator
Expand Down
18 changes: 10 additions & 8 deletions extra_foam/pipeline/processors/azimuthal_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,15 @@ def __init__(self):
self._peak_prominence = None
self._peak_slicer = slice(None, None)

self._reset_ma = False

def update(self):
"""Override."""
g_cfg = self._meta.hget_all(mt.GLOBAL_PROC)
g_cfg, cfg = self._meta.hget_all_multi(
[mt.GLOBAL_PROC, mt.AZIMUTHAL_INTEG_PROC])

self._sample_dist = float(g_cfg['sample_distance'])
self._wavelength = energy2wavelength(1e3 * float(g_cfg['photon_energy']))
self._update_moving_average(g_cfg)

cfg = self._meta.hget_all(mt.AZIMUTHAL_INTEG_PROC)
self._pixel1 = float(cfg['pixel_size_y'])
self._pixel2 = float(cfg['pixel_size_x'])
self._poni1 = float(cfg['integ_center_y']) * self._pixel1
Expand Down Expand Up @@ -234,12 +233,15 @@ def _set_ma_window(self, v):
self.__class__._intensity_on_ma.window = v
self.__class__._intensity_off_ma.window = v

def _reset_ma(self):
del self._intensity_ma
del self._intensity_on_ma
del self._intensity_off_ma

def _update_moving_average(self, cfg):
"""Override."""
if 'reset_ma' in cfg:
# reset moving average
del self._intensity_ma
del self._intensity_on_ma
del self._intensity_off_ma
self._reset_ma()

v = int(cfg['ma_window'])
if self._ma_window != v:
Expand Down
6 changes: 3 additions & 3 deletions extra_foam/pipeline/processors/binning.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ def __init__(self):

def update(self):
"""Override."""
cfg = self._meta.hget_all(mt.BIN_PROC)
if not cfg:
cfg = self._meta.hget_all(mt.BINNING_PROC)
if 'analysis_type' not in cfg:
# BinningWindow not initialized
return

Expand Down Expand Up @@ -247,7 +247,7 @@ def update(self):
self._auto_range2[:] = [math.isinf(v) for v in bin_range2]

if 'reset' in cfg:
self._meta.hdel(mt.BIN_PROC, 'reset')
self._meta.hdel(mt.BINNING_PROC, 'reset')
# reset when commanded by the GUI
self._reset = True

Expand Down
2 changes: 1 addition & 1 deletion extra_foam/pipeline/processors/correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def update(self):
"""Override."""
g_cfg, cfg = self._meta.hget_all_multi(
[mt.GLOBAL_PROC, mt.CORRELATION_PROC])
if not cfg:
if 'analysis_type' not in cfg:
# CorrelationWindow not initialized
return

Expand Down
14 changes: 8 additions & 6 deletions extra_foam/pipeline/processors/digitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,16 @@ def _set_ma_window(self, v):
self.__class__._pulse_integral_d_ma.window = v
self.__class__._fast_adc_peaks_ma.window = v

def _reset_ma(self):
del self._pulse_integral_a_ma
del self._pulse_integral_b_ma
del self._pulse_integral_c_ma
del self._pulse_integral_d_ma
del self._fast_adc_peaks_ma

def _update_moving_average(self, cfg):
if 'reset_ma' in cfg:
# reset moving average
del self._pulse_integral_a_ma
del self._pulse_integral_b_ma
del self._pulse_integral_c_ma
del self._pulse_integral_d_ma
del self._fast_adc_peaks_ma
self._reset_ma()

v = int(cfg['ma_window'])
if self._ma_window != v:
Expand Down
2 changes: 1 addition & 1 deletion extra_foam/pipeline/processors/histogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(self):
def update(self):
"""Override."""
cfg = self._meta.hget_all(mt.HISTOGRAM_PROC)
if not cfg:
if 'analysis_type' not in cfg:
# HistogramWindow not initialized
return

Expand Down
Loading

0 comments on commit ae47029

Please sign in to comment.