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

fix: fix missmatch of signal/slot in image and motormap

This commit is contained in:
2024-07-29 16:05:21 +02:00
parent fee4901657
commit dcc5fd71ee
4 changed files with 31 additions and 26 deletions

View File

@ -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)