Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display bug in Gotthard Window #242

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion extra_foam/pipeline/f_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,13 @@ def _not_found_message(self, tid, found):
# is impossible to have a detailed error message
# since we do not know which data are requested
# in the old time.

# The first source name is required by the special suite
# since matched source items are not encoded.
if not_found:
msg += f"Not found: {len(not_found)} out of " \
f"{len(self._catalog)} source items."
f"{len(self._catalog)} source items: " \
f"{not_found[0]} ..."
return msg

def reset(self):
Expand Down
6 changes: 3 additions & 3 deletions extra_foam/pipeline/tests/test_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def testCorrelationSingle(self):
self.assertDictEqual({'abc ppt': 2}, correlated['raw'])
self.assertEqual(1004, correlated['processed'].tid)
self.assertListEqual(['abc ppt'], matched)
self.assertListEqual([(1002, 'Train 1002 dropped! Not found: 1 out of 1 source items.'),
(1003, 'Train 1003 dropped! Not found: 1 out of 1 source items.')],
self.assertListEqual([(1002, 'Train 1002 dropped! Not found: 1 out of 1 source items: abc ppt ...'),
(1003, 'Train 1003 dropped! Not found: 1 out of 1 source items: abc ppt ...')],
dropped)

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

Expand Down
2 changes: 1 addition & 1 deletion extra_foam/special_suite/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,6 @@ def topics(self):
_MAX_N_GOTTHARD_PULSES = 120

GOTTHARD_DEVICE = {
"MID": "MID_EXP_DES/DET/GOTTHARD_RECEIVER:daqOutput",
"MID": "MID_EXP_DES/DET/GOTTHARD_RECEIVER:output",
"SCS": "SCS_PAM_XOX/DET/GOTTHARD_RECEIVER1:daqOutput",
}
25 changes: 18 additions & 7 deletions extra_foam/special_suite/gotthard_pump_probe_w.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Copyright (C) European X-Ray Free-Electron Laser Facility GmbH.
All rights reserved.
"""
import numpy as np

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QIntValidator
from PyQt5.QtWidgets import QSplitter
Expand Down Expand Up @@ -94,8 +96,10 @@ def __init__(self, *, parent=None):

def updateF(self, data):
"""Override."""
self._mean.setData(data['vfom_mean'])
self._mean_ma.setData(data['vfom_ma_mean'])
vfom_mean, vfom_ma_mean = data['vfom_mean'], data['vfom_ma_mean']
x = np.arange(len(vfom_mean))
self._mean.setData(x, vfom_mean)
self._mean_ma.setData(x, vfom_ma_mean)


class GotthardPpFomPulsePlot(PlotWidgetF):
Expand Down Expand Up @@ -128,8 +132,10 @@ def updateF(self, data):
self._idx = idx
self._updateTitle()

self._poi.setData(data['vfom'][idx])
self._poi_ma.setData(data['vfom_ma'][idx])
vfom, vfom_ma = data['vfom'][idx], data['vfom_ma'][idx]
x = np.arange(len(vfom))
self._poi.setData(x, vfom)
self._poi_ma.setData(x, vfom_ma)


class GotthardPpRawPulsePlot(PlotWidgetF):
Expand Down Expand Up @@ -161,8 +167,11 @@ def updateF(self, data):
self._idx = idx
self._updateTitle()

self._on.setData(data['raw'][data['on_slicer']][idx])
self._off.setData(data['raw'][data['off_slicer']][idx])
on = data['raw'][data['on_slicer']][idx]
off = data['raw'][data['off_slicer']][idx]
x = np.arange(len(on))
self._on.setData(x, on)
self._off.setData(x, off)


class GotthardPpDarkPulsePlot(PlotWidgetF):
Expand Down Expand Up @@ -192,7 +201,9 @@ def updateF(self, data):
self._idx = idx
self._updateTitle()

self._plot.setData(data['raw'][data['dark_slicer']][idx])
y = data['raw'][data['dark_slicer']][idx]
x = np.arange(len(y))
self._plot.setData(x, y)


class GotthardPpImageView(ImageViewF):
Expand Down
24 changes: 16 additions & 8 deletions extra_foam/special_suite/gotthard_w.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"""
from string import Template

import numpy as np

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QDoubleValidator, QIntValidator
from PyQt5.QtWidgets import QCheckBox, QSplitter
Expand Down Expand Up @@ -112,16 +114,19 @@ def __init__(self, *, parent=None):

def updateF(self, data):
"""Override."""
spectrum = data['spectrum_mean']
spectrum_ma = data['spectrum_ma_mean']

x = data["x"]
if x is None:
self._mean.setData(data['spectrum_mean'])
self._mean_ma.setData(data['spectrum_ma_mean'])
self.setLabel('bottom', "Pixel")
x = np.arange(len(spectrum))
else:
self._mean.setData(x, data['spectrum_mean'])
self._mean_ma.setData(x, data['spectrum_ma_mean'])
self.setLabel('bottom', "eV")

self._mean.setData(x, spectrum)
self._mean_ma.setData(x, spectrum_ma)


class GotthardPulsePlot(PlotWidgetF):
"""GotthardPulsePlot class.
Expand Down Expand Up @@ -152,16 +157,19 @@ def updateF(self, data):
self._idx = idx
self._updateTitle()

spectrum = data['spectrum'][idx]
spectrum_ma = data['spectrum_ma'][idx]

x = data["x"]
if x is None:
self._poi.setData(data['spectrum'][idx])
self._poi_ma.setData(data['spectrum_ma'][idx])
self.setLabel('bottom', "Pixel")
x = np.arange(len(spectrum))
else:
self._poi.setData(x, data['spectrum'][idx])
self._poi_ma.setData(x, data['spectrum_ma'][idx])
self.setLabel('bottom', "eV")

self._poi.setData(x, spectrum)
self._poi_ma.setData(x, spectrum_ma)


class GotthardImageView(ImageViewF):
"""GotthardImageView class.
Expand Down
27 changes: 18 additions & 9 deletions extra_foam/special_suite/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

from extra_foam.gui.plot_widgets import TimedPlotWidgetF, TimedImageViewF

from extra_foam.special_suite import logger, mkQApp


class _SpecialSuiteWindowTestBase(unittest.TestCase):
@staticmethod
Expand All @@ -12,15 +14,22 @@ def data4visualization():
def _check_update_plots(self):
win = self._win
worker = win._worker_st
worker._output_st.put_pop(self.data4visualization())

win.updateWidgetsST()
for widget in win._plot_widgets_st:
if isinstance(widget, TimedPlotWidgetF):
widget.refresh()
for widget in win._image_views_st:
if isinstance(widget, TimedImageViewF):
widget.refresh()

with self.assertLogs(logger, level="ERROR") as cm:
logger.error("dummy") # workaround

win.updateWidgetsST() # with empty data

worker._output_st.put_pop(self.data4visualization())
win.updateWidgetsST()
for widget in win._plot_widgets_st:
if isinstance(widget, TimedPlotWidgetF):
widget.refresh()
for widget in win._image_views_st:
if isinstance(widget, TimedImageViewF):
widget.refresh()

self.assertEqual(1, len(cm.output))


class _SpecialSuiteProcessorTestBase:
Expand Down
25 changes: 21 additions & 4 deletions extra_foam/special_suite/tests/test_camview.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
CamViewWindow, CameraView, CameraViewRoiHist
)

from . import _SpecialSuiteWindowTestBase, _SpecialSuiteProcessorTestBase


app = mkQApp()

logger.setLevel('CRITICAL')
logger.setLevel('INFO')


class TestCamView(unittest.TestCase):
class TestCamViewWindow(_SpecialSuiteWindowTestBase):
@classmethod
def setUpClass(cls):
cls._win = CamViewWindow('SCS')
Expand All @@ -32,6 +35,14 @@ def tearDownClass(cls):
# explicitly close the MainGUI to avoid error in GuiLogger
cls._win.close()

@staticmethod
def data4visualization():
"""Override."""
return {
"displayed": np.arange(20).reshape(4, 5),
"roi_hist": (np.arange(4), np.arange(4), 1, 2, 3)
}

def testWindow(self):
win = self._win

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

win.updateWidgetsST()
self._check_update_plots()

def testCtrl(self):
from extra_foam.special_suite.cam_view_w import (
Expand Down Expand Up @@ -99,7 +110,7 @@ def testCtrl(self):
self.assertEqual(999, proc._n_bins)


class TestCamViewProcessor(_RawDataMixin):
class TestCamViewProcessor(_RawDataMixin, _SpecialSuiteProcessorTestBase):
@pytest.fixture(autouse=True)
def setUp(self):
self._proc = CamViewProcessor(object(), object())
Expand Down Expand Up @@ -208,6 +219,7 @@ def testProcessing(self, subtract_dark):

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

# 2nd train
Expand All @@ -222,3 +234,8 @@ def testProcessing(self, subtract_dark):
# reset
proc.reset()
assert proc._raw_ma is None

def _check_processed_data_structure(self, ret):
"""Override."""
data_gt = TestCamViewWindow.data4visualization().keys()
assert set(ret.keys()) == set(data_gt)
29 changes: 25 additions & 4 deletions extra_foam/special_suite/tests/test_gotthard.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
ProcessingError
)

from . import _SpecialSuiteWindowTestBase, _SpecialSuiteProcessorTestBase

app = mkQApp()

logger.setLevel('CRITICAL')
logger.setLevel('INFO')


class TestGotthard(unittest.TestCase):
class TestGotthardWindow(_SpecialSuiteWindowTestBase):
@classmethod
def setUpClass(cls):
cls._win = GotthardWindow('MID')
Expand All @@ -36,6 +38,19 @@ def tearDownClass(cls):
# explicitly close the MainGUI to avoid error in GuiLogger
cls._win.close()

@staticmethod
def data4visualization(n_pulses=4):
"""Override."""
return {
"x": None,
"spectrum": np.arange(10 * n_pulses).reshape(n_pulses, 10),
"spectrum_ma": np.arange(10 * n_pulses).reshape(n_pulses, 10),
"spectrum_mean": np.arange(10),
"spectrum_ma_mean": np.arange(10),
"poi_index": 0,
"hist": (np.arange(5), np.arange(5), 1, 1, 1),
}

def testWindow(self):
win = self._win

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

win.updateWidgetsST()
self._check_update_plots()

def testCtrl(self):
from extra_foam.special_suite.gotthard_w import _DEFAULT_N_BINS, _DEFAULT_BIN_RANGE
Expand Down Expand Up @@ -135,7 +150,7 @@ def testCtrl(self):
self.assertTrue(proc._hist_over_ma)


class TestGotthardProcessor(_RawDataMixin):
class TestGotthardProcessor(_RawDataMixin, _SpecialSuiteProcessorTestBase):
@pytest.fixture(autouse=True)
def setUp(self):
self._proc = GotthardProcessor(object(), object())
Expand Down Expand Up @@ -269,6 +284,7 @@ def testProcessing(self, subtract_dark):

# 1st train
processed = proc.process(self._get_data(12345))
self._check_processed_data_structure(processed)
assert 1 == processed["poi_index"]
np.testing.assert_array_almost_equal(adc_gt, processed["spectrum"])
np.testing.assert_array_almost_equal(adc_gt, processed["spectrum_ma"])
Expand Down Expand Up @@ -329,3 +345,8 @@ def testRemoveDark(self):
proc.onRemoveDark()
assert proc._dark_ma is None
assert proc._dark_mean_ma is None

def _check_processed_data_structure(self, ret):
"""Override."""
data_gt = TestGotthardWindow.data4visualization().keys()
assert set(ret.keys()) == set(data_gt)