Skip to content

Commit 3372699

Browse files
authored
Merge pull request #242 from zhujun98/fix_display_bug_in_gotthard_window
Fix display bug in Gotthard Window
2 parents c42d268 + 8c839e2 commit 3372699

15 files changed

+177
-56
lines changed

extra_foam/pipeline/f_transformer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,13 @@ def _not_found_message(self, tid, found):
177177
# is impossible to have a detailed error message
178178
# since we do not know which data are requested
179179
# in the old time.
180+
181+
# The first source name is required by the special suite
182+
# since matched source items are not encoded.
180183
if not_found:
181184
msg += f"Not found: {len(not_found)} out of " \
182-
f"{len(self._catalog)} source items."
185+
f"{len(self._catalog)} source items: " \
186+
f"{not_found[0]} ..."
183187
return msg
184188

185189
def reset(self):

extra_foam/pipeline/tests/test_transformer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ def testCorrelationSingle(self):
112112
self.assertDictEqual({'abc ppt': 2}, correlated['raw'])
113113
self.assertEqual(1004, correlated['processed'].tid)
114114
self.assertListEqual(['abc ppt'], matched)
115-
self.assertListEqual([(1002, 'Train 1002 dropped! Not found: 1 out of 1 source items.'),
116-
(1003, 'Train 1003 dropped! Not found: 1 out of 1 source items.')],
115+
self.assertListEqual([(1002, 'Train 1002 dropped! Not found: 1 out of 1 source items: abc ppt ...'),
116+
(1003, 'Train 1003 dropped! Not found: 1 out of 1 source items: abc ppt ...')],
117117
dropped)
118118

119119
def testCorrelationMultiple(self):
@@ -135,7 +135,7 @@ def testCorrelationMultiple(self):
135135
self.assertDictEqual({'abc ppt': 1, 'efg ppt': 1}, correlated['raw'])
136136
self.assertEqual(1002, correlated['processed'].tid)
137137
self.assertListEqual(['abc ppt', 'efg ppt'], matched)
138-
self.assertListEqual([(1001, 'Train 1001 dropped! Not found: 1 out of 2 source items.')],
138+
self.assertListEqual([(1001, 'Train 1001 dropped! Not found: 1 out of 2 source items: efg ppt ...')],
139139
dropped)
140140
self.assertListEqual([1003], list(trans._cached.keys()))
141141

extra_foam/special_suite/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,6 @@ def topics(self):
6767
_MAX_N_GOTTHARD_PULSES = 120
6868

6969
GOTTHARD_DEVICE = {
70-
"MID": "MID_EXP_DES/DET/GOTTHARD_RECEIVER:daqOutput",
70+
"MID": "MID_EXP_DES/DET/GOTTHARD_RECEIVER:output",
7171
"SCS": "SCS_PAM_XOX/DET/GOTTHARD_RECEIVER1:daqOutput",
7272
}

extra_foam/special_suite/gotthard_pump_probe_w.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
Copyright (C) European X-Ray Free-Electron Laser Facility GmbH.
88
All rights reserved.
99
"""
10+
import numpy as np
11+
1012
from PyQt5.QtCore import Qt
1113
from PyQt5.QtGui import QIntValidator
1214
from PyQt5.QtWidgets import QSplitter
@@ -94,8 +96,10 @@ def __init__(self, *, parent=None):
9496

9597
def updateF(self, data):
9698
"""Override."""
97-
self._mean.setData(data['vfom_mean'])
98-
self._mean_ma.setData(data['vfom_ma_mean'])
99+
vfom_mean, vfom_ma_mean = data['vfom_mean'], data['vfom_ma_mean']
100+
x = np.arange(len(vfom_mean))
101+
self._mean.setData(x, vfom_mean)
102+
self._mean_ma.setData(x, vfom_ma_mean)
99103

100104

101105
class GotthardPpFomPulsePlot(PlotWidgetF):
@@ -128,8 +132,10 @@ def updateF(self, data):
128132
self._idx = idx
129133
self._updateTitle()
130134

131-
self._poi.setData(data['vfom'][idx])
132-
self._poi_ma.setData(data['vfom_ma'][idx])
135+
vfom, vfom_ma = data['vfom'][idx], data['vfom_ma'][idx]
136+
x = np.arange(len(vfom))
137+
self._poi.setData(x, vfom)
138+
self._poi_ma.setData(x, vfom_ma)
133139

134140

135141
class GotthardPpRawPulsePlot(PlotWidgetF):
@@ -161,8 +167,11 @@ def updateF(self, data):
161167
self._idx = idx
162168
self._updateTitle()
163169

164-
self._on.setData(data['raw'][data['on_slicer']][idx])
165-
self._off.setData(data['raw'][data['off_slicer']][idx])
170+
on = data['raw'][data['on_slicer']][idx]
171+
off = data['raw'][data['off_slicer']][idx]
172+
x = np.arange(len(on))
173+
self._on.setData(x, on)
174+
self._off.setData(x, off)
166175

167176

168177
class GotthardPpDarkPulsePlot(PlotWidgetF):
@@ -192,7 +201,9 @@ def updateF(self, data):
192201
self._idx = idx
193202
self._updateTitle()
194203

195-
self._plot.setData(data['raw'][data['dark_slicer']][idx])
204+
y = data['raw'][data['dark_slicer']][idx]
205+
x = np.arange(len(y))
206+
self._plot.setData(x, y)
196207

197208

198209
class GotthardPpImageView(ImageViewF):

extra_foam/special_suite/gotthard_w.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"""
1010
from string import Template
1111

12+
import numpy as np
13+
1214
from PyQt5.QtCore import Qt
1315
from PyQt5.QtGui import QDoubleValidator, QIntValidator
1416
from PyQt5.QtWidgets import QCheckBox, QSplitter
@@ -112,16 +114,19 @@ def __init__(self, *, parent=None):
112114

113115
def updateF(self, data):
114116
"""Override."""
117+
spectrum = data['spectrum_mean']
118+
spectrum_ma = data['spectrum_ma_mean']
119+
115120
x = data["x"]
116121
if x is None:
117-
self._mean.setData(data['spectrum_mean'])
118-
self._mean_ma.setData(data['spectrum_ma_mean'])
119122
self.setLabel('bottom', "Pixel")
123+
x = np.arange(len(spectrum))
120124
else:
121-
self._mean.setData(x, data['spectrum_mean'])
122-
self._mean_ma.setData(x, data['spectrum_ma_mean'])
123125
self.setLabel('bottom', "eV")
124126

127+
self._mean.setData(x, spectrum)
128+
self._mean_ma.setData(x, spectrum_ma)
129+
125130

126131
class GotthardPulsePlot(PlotWidgetF):
127132
"""GotthardPulsePlot class.
@@ -152,16 +157,19 @@ def updateF(self, data):
152157
self._idx = idx
153158
self._updateTitle()
154159

160+
spectrum = data['spectrum'][idx]
161+
spectrum_ma = data['spectrum_ma'][idx]
162+
155163
x = data["x"]
156164
if x is None:
157-
self._poi.setData(data['spectrum'][idx])
158-
self._poi_ma.setData(data['spectrum_ma'][idx])
159165
self.setLabel('bottom', "Pixel")
166+
x = np.arange(len(spectrum))
160167
else:
161-
self._poi.setData(x, data['spectrum'][idx])
162-
self._poi_ma.setData(x, data['spectrum_ma'][idx])
163168
self.setLabel('bottom', "eV")
164169

170+
self._poi.setData(x, spectrum)
171+
self._poi_ma.setData(x, spectrum_ma)
172+
165173

166174
class GotthardImageView(ImageViewF):
167175
"""GotthardImageView class.

extra_foam/special_suite/tests/__init__.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
from extra_foam.gui.plot_widgets import TimedPlotWidgetF, TimedImageViewF
55

6+
from extra_foam.special_suite import logger, mkQApp
7+
68

79
class _SpecialSuiteWindowTestBase(unittest.TestCase):
810
@staticmethod
@@ -12,15 +14,22 @@ def data4visualization():
1214
def _check_update_plots(self):
1315
win = self._win
1416
worker = win._worker_st
15-
worker._output_st.put_pop(self.data4visualization())
16-
17-
win.updateWidgetsST()
18-
for widget in win._plot_widgets_st:
19-
if isinstance(widget, TimedPlotWidgetF):
20-
widget.refresh()
21-
for widget in win._image_views_st:
22-
if isinstance(widget, TimedImageViewF):
23-
widget.refresh()
17+
18+
with self.assertLogs(logger, level="ERROR") as cm:
19+
logger.error("dummy") # workaround
20+
21+
win.updateWidgetsST() # with empty data
22+
23+
worker._output_st.put_pop(self.data4visualization())
24+
win.updateWidgetsST()
25+
for widget in win._plot_widgets_st:
26+
if isinstance(widget, TimedPlotWidgetF):
27+
widget.refresh()
28+
for widget in win._image_views_st:
29+
if isinstance(widget, TimedImageViewF):
30+
widget.refresh()
31+
32+
self.assertEqual(1, len(cm.output))
2433

2534

2635
class _SpecialSuiteProcessorTestBase:

extra_foam/special_suite/tests/test_camview.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,15 @@
1717
CamViewWindow, CameraView, CameraViewRoiHist
1818
)
1919

20+
from . import _SpecialSuiteWindowTestBase, _SpecialSuiteProcessorTestBase
21+
22+
2023
app = mkQApp()
2124

22-
logger.setLevel('CRITICAL')
25+
logger.setLevel('INFO')
2326

2427

25-
class TestCamView(unittest.TestCase):
28+
class TestCamViewWindow(_SpecialSuiteWindowTestBase):
2629
@classmethod
2730
def setUpClass(cls):
2831
cls._win = CamViewWindow('SCS')
@@ -32,6 +35,14 @@ def tearDownClass(cls):
3235
# explicitly close the MainGUI to avoid error in GuiLogger
3336
cls._win.close()
3437

38+
@staticmethod
39+
def data4visualization():
40+
"""Override."""
41+
return {
42+
"displayed": np.arange(20).reshape(4, 5),
43+
"roi_hist": (np.arange(4), np.arange(4), 1, 2, 3)
44+
}
45+
3546
def testWindow(self):
3647
win = self._win
3748

@@ -43,7 +54,7 @@ def testWindow(self):
4354
self.assertEqual(1, counter[CameraView])
4455
self.assertEqual(1, counter[CameraViewRoiHist])
4556

46-
win.updateWidgetsST()
57+
self._check_update_plots()
4758

4859
def testCtrl(self):
4960
from extra_foam.special_suite.cam_view_w import (
@@ -99,7 +110,7 @@ def testCtrl(self):
99110
self.assertEqual(999, proc._n_bins)
100111

101112

102-
class TestCamViewProcessor(_RawDataMixin):
113+
class TestCamViewProcessor(_RawDataMixin, _SpecialSuiteProcessorTestBase):
103114
@pytest.fixture(autouse=True)
104115
def setUp(self):
105116
self._proc = CamViewProcessor(object(), object())
@@ -208,6 +219,7 @@ def testProcessing(self, subtract_dark):
208219

209220
# 1st train
210221
processed = proc.process(self._get_data(12345))
222+
self._check_processed_data_structure(processed)
211223
np.testing.assert_array_almost_equal(imgdata_gt, processed["displayed"])
212224

213225
# 2nd train
@@ -222,3 +234,8 @@ def testProcessing(self, subtract_dark):
222234
# reset
223235
proc.reset()
224236
assert proc._raw_ma is None
237+
238+
def _check_processed_data_structure(self, ret):
239+
"""Override."""
240+
data_gt = TestCamViewWindow.data4visualization().keys()
241+
assert set(ret.keys()) == set(data_gt)

extra_foam/special_suite/tests/test_gotthard.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
ProcessingError
2222
)
2323

24+
from . import _SpecialSuiteWindowTestBase, _SpecialSuiteProcessorTestBase
25+
2426
app = mkQApp()
2527

26-
logger.setLevel('CRITICAL')
28+
logger.setLevel('INFO')
2729

2830

29-
class TestGotthard(unittest.TestCase):
31+
class TestGotthardWindow(_SpecialSuiteWindowTestBase):
3032
@classmethod
3133
def setUpClass(cls):
3234
cls._win = GotthardWindow('MID')
@@ -36,6 +38,19 @@ def tearDownClass(cls):
3638
# explicitly close the MainGUI to avoid error in GuiLogger
3739
cls._win.close()
3840

41+
@staticmethod
42+
def data4visualization(n_pulses=4):
43+
"""Override."""
44+
return {
45+
"x": None,
46+
"spectrum": np.arange(10 * n_pulses).reshape(n_pulses, 10),
47+
"spectrum_ma": np.arange(10 * n_pulses).reshape(n_pulses, 10),
48+
"spectrum_mean": np.arange(10),
49+
"spectrum_ma_mean": np.arange(10),
50+
"poi_index": 0,
51+
"hist": (np.arange(5), np.arange(5), 1, 1, 1),
52+
}
53+
3954
def testWindow(self):
4055
win = self._win
4156

@@ -49,7 +64,7 @@ def testWindow(self):
4964
self.assertEqual(1, counter[GotthardPulsePlot])
5065
self.assertEqual(1, counter[GotthardHist])
5166

52-
win.updateWidgetsST()
67+
self._check_update_plots()
5368

5469
def testCtrl(self):
5570
from extra_foam.special_suite.gotthard_w import _DEFAULT_N_BINS, _DEFAULT_BIN_RANGE
@@ -135,7 +150,7 @@ def testCtrl(self):
135150
self.assertTrue(proc._hist_over_ma)
136151

137152

138-
class TestGotthardProcessor(_RawDataMixin):
153+
class TestGotthardProcessor(_RawDataMixin, _SpecialSuiteProcessorTestBase):
139154
@pytest.fixture(autouse=True)
140155
def setUp(self):
141156
self._proc = GotthardProcessor(object(), object())
@@ -269,6 +284,7 @@ def testProcessing(self, subtract_dark):
269284

270285
# 1st train
271286
processed = proc.process(self._get_data(12345))
287+
self._check_processed_data_structure(processed)
272288
assert 1 == processed["poi_index"]
273289
np.testing.assert_array_almost_equal(adc_gt, processed["spectrum"])
274290
np.testing.assert_array_almost_equal(adc_gt, processed["spectrum_ma"])
@@ -329,3 +345,8 @@ def testRemoveDark(self):
329345
proc.onRemoveDark()
330346
assert proc._dark_ma is None
331347
assert proc._dark_mean_ma is None
348+
349+
def _check_processed_data_structure(self, ret):
350+
"""Override."""
351+
data_gt = TestGotthardWindow.data4visualization().keys()
352+
assert set(ret.keys()) == set(data_gt)

0 commit comments

Comments
 (0)