From b400a347f88d0d0376c694023b5be500188ad83f Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Wed, 20 Nov 2024 14:04:26 +0000 Subject: [PATCH 1/4] Add the prefix to the DCM crystal dspacing --- src/dodal/devices/dcm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dodal/devices/dcm.py b/src/dodal/devices/dcm.py index 60d08c2342..5324cbadd2 100644 --- a/src/dodal/devices/dcm.py +++ b/src/dodal/devices/dcm.py @@ -58,5 +58,5 @@ def __init__( Array1D[np.uint64], initial_value=reflection_array, ) - self.crystal_metadata_d_spacing = epics_signal_r(float, "DSPACING:RBV") + self.crystal_metadata_d_spacing = epics_signal_r(float, prefix + "DSPACING:RBV") super().__init__(name) From 9d31ab12ff4ca7bcf7d7185374225f78e2eca744 Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Wed, 20 Nov 2024 14:55:09 +0000 Subject: [PATCH 2/4] Fix getting the zoom level from the device --- src/dodal/devices/oav/oav_detector.py | 2 +- system_tests/test_oav_system.py | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/dodal/devices/oav/oav_detector.py b/src/dodal/devices/oav/oav_detector.py index 5b63412de9..319a870eac 100644 --- a/src/dodal/devices/oav/oav_detector.py +++ b/src/dodal/devices/oav/oav_detector.py @@ -48,7 +48,7 @@ def __init__(self, prefix: str, name: str = "") -> None: async def _get_allowed_zoom_levels(self) -> list: zoom_levels = await self.level.describe() - return zoom_levels["level"]["choices"] # type: ignore + return zoom_levels[self.level.name]["choices"] # type: ignore @AsyncStatus.wrap async def set(self, level_to_set: str): diff --git a/system_tests/test_oav_system.py b/system_tests/test_oav_system.py index c1a4d485ae..3cdc816046 100644 --- a/system_tests/test_oav_system.py +++ b/system_tests/test_oav_system.py @@ -46,10 +46,8 @@ def test_grid_overlay(RE: RunEngine): RE(take_snapshot_with_grid(oav, snapshot_filename, snapshot_directory)) -@pytest.mark.skip(reason="No OAV in S03") @pytest.mark.s03 async def test_get_zoom_levels(): - my_zoom_controller = ZoomController("BL03S-EA-OAV-01:FZOOM:", name="test_zoom") + my_zoom_controller = ZoomController("BL03I-EA-OAV-01:FZOOM:", name="test_zoom") await my_zoom_controller.connect() - description = await my_zoom_controller.level.describe() - assert description["zoom_controller-level"]["choices"][0] == "1.0x" # type: ignore + assert "1.0x" in await my_zoom_controller._get_allowed_zoom_levels() From 8edf19b9a26a7db73895ca23aa205f0aba3381fb Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Wed, 20 Nov 2024 15:07:09 +0000 Subject: [PATCH 3/4] Use correct NONE_VALUE for grid detect --- .../oav/pin_image_recognition/__init__.py | 4 ++-- .../image_recognition/test_pin_tip_detect.py | 20 ++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/dodal/devices/oav/pin_image_recognition/__init__.py b/src/dodal/devices/oav/pin_image_recognition/__init__.py index 540f08d65e..876c449f89 100644 --- a/src/dodal/devices/oav/pin_image_recognition/__init__.py +++ b/src/dodal/devices/oav/pin_image_recognition/__init__.py @@ -56,10 +56,10 @@ def __init__(self, prefix: str, name: str = ""): Tip, name="triggered_tip" ) self.triggered_top_edge, self._top_edge_setter = soft_signal_r_and_setter( - Array1D[np.uint32], name="triggered_top_edge" + Array1D[np.int32], name="triggered_top_edge" ) self.triggered_bottom_edge, self._bottom_edge_setter = soft_signal_r_and_setter( - Array1D[np.uint32], name="triggered_bottom_edge" + Array1D[np.int32], name="triggered_bottom_edge" ) self.array_data = epics_signal_r(Array1D[np.uint8], f"pva://{prefix}PVA:ARRAY") diff --git a/tests/devices/unit_tests/oav/image_recognition/test_pin_tip_detect.py b/tests/devices/unit_tests/oav/image_recognition/test_pin_tip_detect.py index 03959ecf59..11c14bd713 100644 --- a/tests/devices/unit_tests/oav/image_recognition/test_pin_tip_detect.py +++ b/tests/devices/unit_tests/oav/image_recognition/test_pin_tip_detect.py @@ -4,8 +4,11 @@ import numpy as np from ophyd_async.core import set_mock_value -from dodal.devices.oav.pin_image_recognition import MxSampleDetect, PinTipDetection -from dodal.devices.oav.pin_image_recognition.utils import SampleLocation +from dodal.devices.oav.pin_image_recognition import ( + MxSampleDetect, + PinTipDetection, +) +from dodal.devices.oav.pin_image_recognition.utils import NONE_VALUE, SampleLocation EVENT_LOOP = asyncio.new_event_loop() @@ -93,7 +96,10 @@ async def test_given_valid_data_reading_then_used_to_find_location(): device = await _get_pin_tip_detection_device() image_array = np.array([1, 2, 3]) test_sample_location = SampleLocation( - 100, 200, np.array([1, 2, 3]), np.array([4, 5, 6]) + 100, + 200, + top_edge := np.array([NONE_VALUE, 1, 2, 3]), + bottom_edge := np.array([NONE_VALUE, 4, 5, 6]), ) set_mock_value(device.array_data, image_array) @@ -109,12 +115,8 @@ async def test_given_valid_data_reading_then_used_to_find_location(): process_call = mock_process_array.call_args[0][0] assert np.array_equal(process_call, image_array) assert np.all(location[TRIGGERED_TIP_READING]["value"] == (100, 200)) - assert np.all( - location[TRIGGERED_TOP_EDGE_READING]["value"] == np.array([1, 2, 3]) - ) - assert np.all( - location[TRIGGERED_BOTTOM_EDGE_READING]["value"] == np.array([4, 5, 6]) - ) + assert np.all(location[TRIGGERED_TOP_EDGE_READING]["value"] == top_edge) + assert np.all(location[TRIGGERED_BOTTOM_EDGE_READING]["value"] == bottom_edge) assert location[TRIGGERED_TIP_READING]["timestamp"] > 0 From 1a8144877a79c656923a7e8f616ede1369757e4b Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Wed, 20 Nov 2024 15:25:04 +0000 Subject: [PATCH 4/4] Fix tests and linter --- src/dodal/devices/dcm.py | 4 +++- src/dodal/devices/oav/oav_detector.py | 2 +- tests/devices/unit_tests/oav/test_oav.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/dodal/devices/dcm.py b/src/dodal/devices/dcm.py index 5324cbadd2..b11d74bd73 100644 --- a/src/dodal/devices/dcm.py +++ b/src/dodal/devices/dcm.py @@ -58,5 +58,7 @@ def __init__( Array1D[np.uint64], initial_value=reflection_array, ) - self.crystal_metadata_d_spacing = epics_signal_r(float, prefix + "DSPACING:RBV") + self.crystal_metadata_d_spacing = epics_signal_r( + float, prefix + "DSPACING:RBV" + ) super().__init__(name) diff --git a/src/dodal/devices/oav/oav_detector.py b/src/dodal/devices/oav/oav_detector.py index 319a870eac..9da73e2120 100644 --- a/src/dodal/devices/oav/oav_detector.py +++ b/src/dodal/devices/oav/oav_detector.py @@ -40,11 +40,11 @@ class ZoomController(StandardReadable): """ def __init__(self, prefix: str, name: str = "") -> None: - super().__init__(name=name) self.percentage = epics_signal_rw(float, f"{prefix}ZOOMPOSCMD") # Level is the string description of the zoom level e.g. "1.0x" or "1.0" self.level = epics_signal_rw(str, f"{prefix}MP:SELECT") + super().__init__(name=name) async def _get_allowed_zoom_levels(self) -> list: zoom_levels = await self.level.describe() diff --git a/tests/devices/unit_tests/oav/test_oav.py b/tests/devices/unit_tests/oav/test_oav.py index e11af8d86a..86dbe11ac2 100644 --- a/tests/devices/unit_tests/oav/test_oav.py +++ b/tests/devices/unit_tests/oav/test_oav.py @@ -12,10 +12,10 @@ async def test_zoom_controller(): - zoom_controller = ZoomController("", "fake zoom controller") + zoom_controller = ZoomController("", "zoom_controller") await zoom_controller.connect(mock=True) zoom_controller.level.describe = AsyncMock( - return_value={"level": {"choices": ["1.0x", "3.0x"]}} + return_value={"zoom_controller-level": {"choices": ["1.0x", "3.0x"]}} ) status = zoom_controller.set("3.0x") await status