0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 11:41:49 +02:00

fix(multi_waveform): update on_async_readback to use structured metadata for async updates with "add" instead of "extend"

This commit is contained in:
2025-03-04 22:31:14 +01:00
parent 4db0f9f10c
commit fa91366dcb
3 changed files with 15 additions and 20 deletions

View File

@ -338,16 +338,3 @@ class BECMultiWaveform(BECPlotBase):
Export current waveform to matplotlib GUI. Available only if matplotlib is installed in the environment. Export current waveform to matplotlib GUI. Available only if matplotlib is installed in the environment.
""" """
MatplotlibExporter(self.plot_item).export() MatplotlibExporter(self.plot_item).export()
if __name__ == "__main__":
import sys
from qtpy.QtWidgets import QApplication
from bec_widgets.widgets.containers.figure import BECFigure
app = QApplication(sys.argv)
widget = BECFigure()
widget.show()
sys.exit(app.exec_())

View File

@ -1242,16 +1242,22 @@ class BECWaveform(BECPlotBase):
msg(dict): Message with the async data. msg(dict): Message with the async data.
metadata(dict): Metadata of the message. metadata(dict): Metadata of the message.
""" """
instruction = metadata.get("async_update") y_data = None
x_data = None
instruction = metadata.get("async_update", {}).get("type")
max_shape = metadata.get("async_update", {}).get("max_shape", [])
for curve in self._curves_data["async"].values(): for curve in self._curves_data["async"].values():
y_name = curve.config.signals.y.name
y_entry = curve.config.signals.y.entry y_entry = curve.config.signals.y.entry
x_name = self._x_axis_mode["name"] x_name = self._x_axis_mode["name"]
for device, async_data in msg["signals"].items(): for device, async_data in msg["signals"].items():
if device == y_entry: if device == y_entry:
data_plot = async_data["value"] data_plot = async_data["value"]
if instruction == "extend": if instruction == "add":
x_data, y_data = curve.get_data() if len(max_shape) > 1:
if len(data_plot.shape) > 1:
data_plot = data_plot[-1, :]
else:
x_data, y_data = curve.get_data()
if y_data is not None: if y_data is not None:
new_data = np.hstack((y_data, data_plot)) new_data = np.hstack((y_data, data_plot))
else: else:

View File

@ -694,7 +694,8 @@ def test_waveform_async_data_update(qtbot, mocked_client):
# w1.queue.scan_storage.find_scan_by_ID.return_value = scan_item_mock # w1.queue.scan_storage.find_scan_by_ID.return_value = scan_item_mock
msg_1 = {"signals": {"async_device": {"value": [7, 8, 9]}}} msg_1 = {"signals": {"async_device": {"value": [7, 8, 9]}}}
w1.on_async_readback(msg_1, {"async_update": "extend"}) metadata_1 = {"async_update": {"max_shape": [None], "type": "add"}}
w1.on_async_readback(msg_1, metadata_1)
qtbot.wait(200) qtbot.wait(200)
x_data, y_data = w1.curves[0].get_data() x_data, y_data = w1.curves[0].get_data()
@ -703,7 +704,7 @@ def test_waveform_async_data_update(qtbot, mocked_client):
assert w1.plot_item.getAxis("bottom").labelText == custom_label + " [best_effort]" assert w1.plot_item.getAxis("bottom").labelText == custom_label + " [best_effort]"
msg_2 = {"signals": {"async_device": {"value": [10, 11, 12]}}} msg_2 = {"signals": {"async_device": {"value": [10, 11, 12]}}}
w1.on_async_readback(msg_2, {"async_update": "extend"}) w1.on_async_readback(msg_2, metadata_1)
qtbot.wait(200) qtbot.wait(200)
x_data, y_data = w1.curves[0].get_data() x_data, y_data = w1.curves[0].get_data()
@ -712,7 +713,8 @@ def test_waveform_async_data_update(qtbot, mocked_client):
assert w1.plot_item.getAxis("bottom").labelText == custom_label + " [best_effort]" assert w1.plot_item.getAxis("bottom").labelText == custom_label + " [best_effort]"
msg_3 = {"signals": {"async_device": {"value": [20, 21, 22]}}} msg_3 = {"signals": {"async_device": {"value": [20, 21, 22]}}}
w1.on_async_readback(msg_3, {"async_update": "replace"}) metadata_3 = {"async_update": {"max_shape": [None], "type": "replace"}}
w1.on_async_readback(msg_3, metadata_3)
qtbot.wait(200) qtbot.wait(200)
x_data, y_data = w1.curves[0].get_data() x_data, y_data = w1.curves[0].get_data()