mirror of
https://github.com/bec-project/bec_widgets.git
synced 2025-07-13 19:21:50 +02:00
fix: fix missmatch of signal/slot in image and motormap
This commit is contained in:
@ -500,13 +500,14 @@ class BECImageShow(BECPlotBase):
|
||||
self.update_image(device, data)
|
||||
self.update_vrange(device, self.processor.config.stats)
|
||||
|
||||
@Slot(dict)
|
||||
def on_image_update(self, msg: dict):
|
||||
@Slot(dict, dict)
|
||||
def on_image_update(self, msg: dict, metadata: dict):
|
||||
"""
|
||||
Update the image of the device monitor from bec.
|
||||
|
||||
Args:
|
||||
msg(dict): The message from bec.
|
||||
metadata(dict): The metadata of the message.
|
||||
"""
|
||||
data = msg["data"]
|
||||
device = msg["device"]
|
||||
|
@ -493,13 +493,14 @@ class BECMotorMap(BECPlotBase):
|
||||
f"Motor position: ({round(float(current_x),precision)}, {round(float(current_y),precision)})"
|
||||
)
|
||||
|
||||
@Slot(dict)
|
||||
def on_device_readback(self, msg: dict) -> None:
|
||||
@Slot(dict, dict)
|
||||
def on_device_readback(self, msg: dict, metadata: dict) -> None:
|
||||
"""
|
||||
Update the motor map plot with the new motor position.
|
||||
|
||||
Args:
|
||||
msg(dict): Message from the device readback.
|
||||
metadata(dict): Metadata of the message.
|
||||
"""
|
||||
if self.motor_x is None or self.motor_y is None:
|
||||
return
|
||||
|
@ -17,10 +17,8 @@ def bec_image_show(bec_figure):
|
||||
|
||||
def test_on_image_update(bec_image_show):
|
||||
data = np.random.rand(100, 100)
|
||||
msg = messages.DeviceMonitor2DMessage(
|
||||
device="eiger", data=data, metadata={"scan_id": "12345"}
|
||||
).model_dump()
|
||||
bec_image_show.on_image_update(msg)
|
||||
msg = messages.DeviceMonitor2DMessage(device="eiger", data=data, metadata={"scan_id": "12345"})
|
||||
bec_image_show.on_image_update(msg.content, msg.metadata)
|
||||
img = bec_image_show.images[0]
|
||||
assert np.array_equal(img.get_data(), data)
|
||||
|
||||
@ -28,10 +26,8 @@ def test_on_image_update(bec_image_show):
|
||||
def test_autorange_on_image_update(bec_image_show):
|
||||
# Check if autorange mode "mean" works, should be default
|
||||
data = np.random.rand(100, 100)
|
||||
msg = messages.DeviceMonitor2DMessage(
|
||||
device="eiger", data=data, metadata={"scan_id": "12345"}
|
||||
).model_dump()
|
||||
bec_image_show.on_image_update(msg)
|
||||
msg = messages.DeviceMonitor2DMessage(device="eiger", data=data, metadata={"scan_id": "12345"})
|
||||
bec_image_show.on_image_update(msg.content, msg.metadata)
|
||||
img = bec_image_show.images[0]
|
||||
assert np.array_equal(img.get_data(), data)
|
||||
vmin = max(np.mean(data) - 2 * np.std(data), 0)
|
||||
@ -39,7 +35,7 @@ def test_autorange_on_image_update(bec_image_show):
|
||||
assert np.isclose(img.color_bar.getLevels(), (vmin, vmax), rtol=(1e-5, 1e-5)).all()
|
||||
# Test general update with autorange True, mode "max"
|
||||
bec_image_show.set_autorange_mode("max")
|
||||
bec_image_show.on_image_update(msg)
|
||||
bec_image_show.on_image_update(msg.content, msg.metadata)
|
||||
img = bec_image_show.images[0]
|
||||
vmin = np.min(data)
|
||||
vmax = np.max(data)
|
||||
@ -47,18 +43,16 @@ def test_autorange_on_image_update(bec_image_show):
|
||||
assert np.isclose(img.color_bar.getLevels(), (vmin, vmax), rtol=(1e-5, 1e-5)).all()
|
||||
# Change the input data, and switch to autorange False, colormap levels should stay untouched
|
||||
data *= 100
|
||||
msg = messages.DeviceMonitor2DMessage(
|
||||
device="eiger", data=data, metadata={"scan_id": "12345"}
|
||||
).model_dump()
|
||||
msg = messages.DeviceMonitor2DMessage(device="eiger", data=data, metadata={"scan_id": "12345"})
|
||||
bec_image_show.set_autorange(False)
|
||||
bec_image_show.on_image_update(msg)
|
||||
bec_image_show.on_image_update(msg.content, msg.metadata)
|
||||
img = bec_image_show.images[0]
|
||||
assert np.array_equal(img.get_data(), data)
|
||||
assert np.isclose(img.color_bar.getLevels(), (vmin, vmax), rtol=(1e-3, 1e-3)).all()
|
||||
# Reactivate autorange, should now scale the new data
|
||||
bec_image_show.set_autorange(True)
|
||||
bec_image_show.set_autorange_mode("mean")
|
||||
bec_image_show.on_image_update(msg)
|
||||
bec_image_show.on_image_update(msg.content, msg.metadata)
|
||||
img = bec_image_show.images[0]
|
||||
vmin = max(np.mean(data) - 2 * np.std(data), 0)
|
||||
vmax = np.mean(data) + 2 * np.std(data)
|
||||
|
@ -1,5 +1,6 @@
|
||||
import numpy as np
|
||||
import pytest
|
||||
from bec_lib.messages import DeviceMessage
|
||||
|
||||
from bec_widgets.widgets.figure.plots.motor_map.motor_map import BECMotorMap, MotorMapConfig
|
||||
from bec_widgets.widgets.figure.plots.waveform.waveform_curve import SignalData
|
||||
@ -72,7 +73,8 @@ def test_motor_movement_updates_position_and_database(bec_figure):
|
||||
|
||||
# Simulate motor movement for 'samx' only
|
||||
new_position_samx = 4.0
|
||||
mm.on_device_readback({"signals": {"samx": {"value": new_position_samx}}})
|
||||
msg = DeviceMessage(signals={"samx": {"value": new_position_samx}}, metadata={})
|
||||
mm.on_device_readback(msg.content, msg.metadata)
|
||||
|
||||
init_positions["samx"].append(new_position_samx)
|
||||
init_positions["samy"].append(init_positions["samy"][-1])
|
||||
@ -96,7 +98,8 @@ def test_scatter_plot_rendering(bec_figure):
|
||||
|
||||
# Simulate motor movement for 'samx' only
|
||||
new_position_samx = 4.0
|
||||
mm.on_device_readback({"signals": {"samx": {"value": new_position_samx}}})
|
||||
msg = DeviceMessage(signals={"samx": {"value": new_position_samx}}, metadata={})
|
||||
mm.on_device_readback(msg.content, msg.metadata)
|
||||
mm._update_plot()
|
||||
|
||||
# Get the scatter plot item
|
||||
@ -116,8 +119,10 @@ def test_plot_visualization_consistency(bec_figure):
|
||||
mm = bec_figure.motor_map("samx", "samy")
|
||||
mm.change_motors("samx", "samy")
|
||||
# Simulate updating the plot with new data
|
||||
mm.on_device_readback({"signals": {"samx": {"value": 5}}})
|
||||
mm.on_device_readback({"signals": {"samy": {"value": 9}}})
|
||||
msg = DeviceMessage(signals={"samx": {"value": 5}}, metadata={})
|
||||
mm.on_device_readback(msg.content, msg.metadata)
|
||||
msg = DeviceMessage(signals={"samy": {"value": 9}}, metadata={})
|
||||
mm.on_device_readback(msg.content, msg.metadata)
|
||||
mm._update_plot()
|
||||
|
||||
scatter_plot_item = mm.plot_components["scatter"]
|
||||
@ -234,10 +239,14 @@ def test_motor_map_get_data_max_points(bec_figure, qtbot):
|
||||
"samx": [motor_map_dev["samx"].read()["samx"]["value"]],
|
||||
"samy": [motor_map_dev["samy"].read()["samy"]["value"]],
|
||||
}
|
||||
mm.on_device_readback({"signals": {"samx": {"value": 5.0}}})
|
||||
mm.on_device_readback({"signals": {"samy": {"value": 9.0}}})
|
||||
mm.on_device_readback({"signals": {"samx": {"value": 6.0}}})
|
||||
mm.on_device_readback({"signals": {"samy": {"value": 7.0}}})
|
||||
msg = DeviceMessage(signals={"samx": {"value": 5.0}}, metadata={})
|
||||
mm.on_device_readback(msg.content, msg.metadata)
|
||||
msg = DeviceMessage(signals={"samy": {"value": 9.0}}, metadata={})
|
||||
mm.on_device_readback(msg.content, msg.metadata)
|
||||
msg = DeviceMessage(signals={"samx": {"value": 6.0}}, metadata={})
|
||||
mm.on_device_readback(msg.content, msg.metadata)
|
||||
msg = DeviceMessage(signals={"samy": {"value": 7.0}}, metadata={})
|
||||
mm.on_device_readback(msg.content, msg.metadata)
|
||||
|
||||
expected_x = [init_positions["samx"][-1], 5.0, 5.0, 6.0, 6.0]
|
||||
expected_y = [init_positions["samy"][-1], init_positions["samy"][-1], 9.0, 9.0, 7.0]
|
||||
|
Reference in New Issue
Block a user