From c2d3d06bbe5885700708fc7d83a15a5ae2128482 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Wed, 23 Oct 2024 14:48:41 +0100 Subject: [PATCH 01/18] Fix imports in i24 --- .../beamlines/i24/serial/fixed_target/i24ssx_moveonclick.py | 2 +- .../beamlines/i24/serial/fixed_target/test_moveonclick.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_moveonclick.py b/src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_moveonclick.py index aaf8db3f3..16bcf28fa 100755 --- a/src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_moveonclick.py +++ b/src/mx_bluesky/beamlines/i24/serial/fixed_target/i24ssx_moveonclick.py @@ -11,7 +11,7 @@ from bluesky.run_engine import RunEngine from dodal.beamlines import i24 from dodal.devices.i24.pmac import PMAC -from dodal.devices.oav.oav_async import OAV +from dodal.devices.oav.oav_detector import OAV from mx_bluesky.beamlines.i24.serial.fixed_target import ( i24ssx_Chip_Manager_py3v1 as manager, diff --git a/tests/unit_tests/beamlines/i24/serial/fixed_target/test_moveonclick.py b/tests/unit_tests/beamlines/i24/serial/fixed_target/test_moveonclick.py index 647894f2a..fd44a9014 100644 --- a/tests/unit_tests/beamlines/i24/serial/fixed_target/test_moveonclick.py +++ b/tests/unit_tests/beamlines/i24/serial/fixed_target/test_moveonclick.py @@ -4,7 +4,7 @@ import cv2 as cv import pytest from dodal.devices.i24.pmac import PMAC -from dodal.devices.oav.oav_async import OAV +from dodal.devices.oav.oav_detector import OAV from ophyd_async.core import get_mock_put from mx_bluesky.beamlines.i24.serial.fixed_target.i24ssx_moveonclick import ( From a7551e6b73735648b824fb9cbef1284ab4660fd8 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Wed, 23 Oct 2024 15:44:10 +0100 Subject: [PATCH 02/18] Pin to dodal --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 4a835cb38..3d10e01be 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ dependencies = [ "ophyd == 1.9.0", "ophyd-async >= 0.3a5", "bluesky >= 1.13.0a4", - "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@main", + "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@b4ec7a23d457288f701b7270e117f59a89b661c8", ] From aa7fbb7af2af4aa3abb499980c8408b27085fbcc Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Thu, 24 Oct 2024 14:31:17 +0100 Subject: [PATCH 03/18] A first pass replacing oav with ophyd_async device --- pyproject.toml | 2 +- src/mx_bluesky/beamlines/i04/thawing_plan.py | 8 +-- .../hyperion/device_setup_plans/setup_oav.py | 8 +-- .../oav_grid_detection_plan.py | 12 ++-- .../experiment_plans/pin_tip_centring_plan.py | 7 ++- .../callbacks/grid_detection_callback.py | 20 +++--- src/mx_bluesky/hyperion/utils/validation.py | 7 +-- tests/conftest.py | 36 ++--------- tests/system_tests/conftest.py | 43 +++++-------- .../unit_tests/beamlines/i04/test_thawing.py | 6 +- .../hyperion/experiment_plans/conftest.py | 9 ++- .../test_grid_detect_then_xray_centre_plan.py | 22 +++---- .../test_grid_detection_plan.py | 61 ++++++++----------- .../experiment_plans/test_pin_tip_centring.py | 12 ++-- 14 files changed, 102 insertions(+), 151 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3d10e01be..2d852561a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ dependencies = [ "ophyd == 1.9.0", "ophyd-async >= 0.3a5", "bluesky >= 1.13.0a4", - "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@b4ec7a23d457288f701b7270e117f59a89b661c8", + "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@b2d0dbe4c63fb0ca1313be5155c6a57832a446ad", ] diff --git a/src/mx_bluesky/beamlines/i04/thawing_plan.py b/src/mx_bluesky/beamlines/i04/thawing_plan.py index 63487f9b8..0fbed1661 100644 --- a/src/mx_bluesky/beamlines/i04/thawing_plan.py +++ b/src/mx_bluesky/beamlines/i04/thawing_plan.py @@ -41,10 +41,10 @@ def switch_forwarder_to_ROI() -> MsgGenerator: @subs_decorator(MurkoCallback(REDIS_HOST, REDIS_PASSWORD, MURKO_REDIS_DB)) @run_decorator( md={ - "microns_per_x_pixel": oav.parameters.micronsPerXPixel, - "microns_per_y_pixel": oav.parameters.micronsPerYPixel, - "beam_centre_i": oav.parameters.beam_centre_i, - "beam_centre_j": oav.parameters.beam_centre_j, + "microns_per_x_pixel": oav.microns_per_pixel_x, + "microns_per_y_pixel": oav.microns_per_pixel_y, + "beam_centre_i": oav.beam_centre_i, + "beam_centre_j": oav.beam_centre_j, "zoom_percentage": zoom_percentage, "sample_id": sample_id, } diff --git a/src/mx_bluesky/hyperion/device_setup_plans/setup_oav.py b/src/mx_bluesky/hyperion/device_setup_plans/setup_oav.py index 11a640fc8..ec59b4894 100644 --- a/src/mx_bluesky/hyperion/device_setup_plans/setup_oav.py +++ b/src/mx_bluesky/hyperion/device_setup_plans/setup_oav.py @@ -1,11 +1,10 @@ from functools import partial import bluesky.plan_stubs as bps +from dodal.devices.areadetector.plugins.CAM import ColorMode from dodal.devices.oav.oav_detector import OAV -from dodal.devices.oav.oav_errors import OAVError_ZoomLevelNotFound from dodal.devices.oav.oav_parameters import OAVParameters from dodal.devices.oav.pin_image_recognition import PinTipDetection -from dodal.devices.oav.utils import ColorMode from mx_bluesky.hyperion.parameters.constants import CONST @@ -62,11 +61,6 @@ def setup_general_oav_params(oav: OAV, parameters: OAVParameters): yield from set_using_group(oav.cam.gain, parameters.gain) # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809 zoom_level_str = f"{float(parameters.zoom)}x" - if zoom_level_str not in oav.zoom_controller.allowed_zoom_levels: - raise OAVError_ZoomLevelNotFound( - f"Found {zoom_level_str} as a zoom level but expected one of {oav.zoom_controller.allowed_zoom_levels}" - ) - yield from bps.abs_set( oav.zoom_controller, # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809 zoom_level_str, diff --git a/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py b/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py index d48f026eb..85fa9bc88 100644 --- a/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py +++ b/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py @@ -90,12 +90,12 @@ def grid_detection_plan( LOGGER.info("OAV Centring: Camera set up") - assert isinstance(oav.parameters.micronsPerXPixel, float) - box_size_x_pixels = box_size_um / oav.parameters.micronsPerXPixel - assert isinstance(oav.parameters.micronsPerYPixel, float) - box_size_y_pixels = box_size_um / oav.parameters.micronsPerYPixel + assert isinstance(oav.microns_per_pixel_x, float) + box_size_x_pixels = box_size_um / oav.microns_per_pixel_x + assert isinstance(oav.microns_per_pixel_y, float) + box_size_y_pixels = box_size_um / oav.microns_per_pixel_y - grid_width_pixels = int(grid_width_microns / oav.parameters.micronsPerXPixel) + grid_width_pixels = int(grid_width_microns / oav.microns_per_pixel_x) # The FGS uses -90 so we need to match it for angle in [0, -90]: @@ -115,7 +115,7 @@ def grid_detection_plan( (yield from bps.rd(pin_tip_detection.triggered_bottom_edge)) ) - full_image_height_px = yield from bps.rd(oav.cam.array_size.array_size_y) + full_image_height_px = yield from bps.rd(oav.cam.array_size_y) # only use the area from the start of the pin onwards top_edge = top_edge[tip_x_px : tip_x_px + grid_width_pixels] diff --git a/src/mx_bluesky/hyperion/experiment_plans/pin_tip_centring_plan.py b/src/mx_bluesky/hyperion/experiment_plans/pin_tip_centring_plan.py index 4dc9faa9b..c6904ebbd 100644 --- a/src/mx_bluesky/hyperion/experiment_plans/pin_tip_centring_plan.py +++ b/src/mx_bluesky/hyperion/experiment_plans/pin_tip_centring_plan.py @@ -132,13 +132,14 @@ def pin_tip_centre_plan( pin_tip_setup = composite.pin_tip_detection pin_tip_detect = composite.pin_tip_detection - assert oav.parameters.micronsPerXPixel is not None - tip_offset_px = int(tip_offset_microns / oav.parameters.micronsPerXPixel) + microns_per_pixel_x = yield from bps.rd(oav.microns_per_pixel_x) + assert microns_per_pixel_x is not None + tip_offset_px = int(tip_offset_microns / microns_per_pixel_x) def offset_and_move(tip: Pixel): pixel_to_move_to = (tip[0] + tip_offset_px, tip[1]) position_mm = yield from get_move_required_so_that_beam_is_at_pixel( - smargon, pixel_to_move_to, oav.parameters + smargon, pixel_to_move_to, oav ) LOGGER.info(f"Tip centring moving to : {position_mm}") yield from move_smargon_warn_on_out_of_range(smargon, position_mm) diff --git a/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py b/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py index ff011fc9a..2e678d0a7 100644 --- a/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py +++ b/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py @@ -2,7 +2,6 @@ import numpy as np from bluesky.callbacks import CallbackBase -from dodal.devices.oav.oav_detector import OAVConfigParams from dodal.devices.oav.utils import calculate_x_y_z_of_pixel from event_model.documents import Event @@ -26,11 +25,9 @@ class GridParamUpdate(TypedDict): class GridDetectionCallback(CallbackBase): def __init__( self, - oav_params: OAVConfigParams, *args, ) -> None: super().__init__(*args) - self.oav_params = oav_params self.start_positions: list = [] self.box_numbers: list = [] @@ -53,8 +50,17 @@ def event(self, doc: Event): y_of_centre_of_first_box_px, ) + microns_per_pixel_x = data["oav_microns_per_pixel_x"] + microns_per_pixel_y = data["oav_microns_per_pixel_y"] + beam_x = data["oav_beam_centre_i"] + beam_y = data["oav_beam_centre_j"] + position_grid_start = calculate_x_y_z_of_pixel( - current_xyz, smargon_omega, centre_of_first_box, self.oav_params + current_xyz, + smargon_omega, + centre_of_first_box, + (beam_x, beam_y), + (microns_per_pixel_x, microns_per_pixel_y), ) LOGGER.info(f"Calculated start position {position_grid_start}") @@ -67,9 +73,9 @@ def event(self, doc: Event): ) ) - self.x_step_size_mm = box_width_px * self.oav_params.micronsPerXPixel / 1000 - self.y_step_size_mm = box_width_px * self.oav_params.micronsPerYPixel / 1000 - self.z_step_size_mm = box_width_px * self.oav_params.micronsPerYPixel / 1000 + self.x_step_size_mm = box_width_px * microns_per_pixel_x / 1000 + self.y_step_size_mm = box_width_px * microns_per_pixel_y / 1000 + self.z_step_size_mm = box_width_px * microns_per_pixel_y / 1000 return doc def get_grid_parameters(self) -> GridParamUpdate: diff --git a/src/mx_bluesky/hyperion/utils/validation.py b/src/mx_bluesky/hyperion/utils/validation.py index 11a62ecaa..67de213a9 100644 --- a/src/mx_bluesky/hyperion/utils/validation.py +++ b/src/mx_bluesky/hyperion/utils/validation.py @@ -8,7 +8,7 @@ import bluesky.preprocessors as bpp from bluesky.run_engine import RunEngine from dodal.beamlines import i03 -from dodal.devices.oav.oav_parameters import OAVConfigParams +from dodal.devices.oav.oav_parameters import OAVConfig from ophyd_async.core import set_mock_value from mx_bluesky.hyperion.device_setup_plans.read_hardware_for_setup import ( @@ -94,15 +94,14 @@ def fake_create_rotation_devices(): robot = i03.robot(fake_with_ophyd_sim=True) oav = i03.oav( fake_with_ophyd_sim=True, - params=OAVConfigParams( - zoom_params_file=ZOOM_LEVELS_XML, display_config=DISPLAY_CONFIGURATION + config=OAVConfig( + zoom_params_file=ZOOM_LEVELS_XML, display_config_file=DISPLAY_CONFIGURATION ), ) xbpm_feedback = i03.xbpm_feedback(fake_with_ophyd_sim=True) set_mock_value(smargon.omega.max_velocity, 131) set_mock_value(dcm.energy_in_kev.user_readback, 12700) - oav.zoom_controller.fvst.sim_put("1.0x") # type: ignore return RotationScanComposite( attenuator=attenuator, diff --git a/tests/conftest.py b/tests/conftest.py index de94051b2..819f334b9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -22,7 +22,7 @@ from dodal.common.beamlines.beamline_parameters import ( GDABeamlineParameters, ) -from dodal.common.beamlines.beamline_utils import clear_device, clear_devices +from dodal.common.beamlines.beamline_utils import clear_devices from dodal.devices.aperturescatterguard import ( AperturePosition, ApertureScatterguard, @@ -35,7 +35,7 @@ from dodal.devices.eiger import EigerDetector from dodal.devices.fast_grid_scan import FastGridScanCommon from dodal.devices.flux import Flux -from dodal.devices.oav.oav_detector import OAV, OAVConfigParams +from dodal.devices.oav.oav_detector import OAV, OAVConfig from dodal.devices.oav.oav_parameters import OAVParameters from dodal.devices.robot import BartRobot from dodal.devices.s4_slit_gaps import S4SlitGaps @@ -351,38 +351,16 @@ def synchrotron(RE): @pytest.fixture -def oav(test_config_files): - parameters = OAVConfigParams( +def oav(test_config_files, RE): + parameters = OAVConfig( test_config_files["zoom_params_file"], test_config_files["display_config"] ) - parameters.micronsPerXPixel = 2.87 - parameters.micronsPerYPixel = 2.87 - - # This should only be needed until issues with https://github.com/DiamondLightSource/dodal/pull/854 - # or ophyd-async OAV are resolved - try: - clear_device("oav") - except KeyError: - ... oav = i03.oav(fake_with_ophyd_sim=True, params=parameters) - oav.zoom_controller.zrst.set("1.0x") - oav.zoom_controller.onst.set("2.0x") - - oav.parameters.micronsPerXPixel = 1.58 - oav.parameters.micronsPerYPixel = 1.58 - oav.parameters.beam_centre_i = 517 - oav.parameters.beam_centre_j = 350 + # Equivalent to previously set values for microns and beam centre + set_mock_value(oav.zoom_controller.level, "5.0x") oav.snapshot.trigger = MagicMock(return_value=NullStatus()) - oav.zoom_controller.zrst.set("1.0x") - oav.zoom_controller.onst.set("2.0x") - oav.zoom_controller.twst.set("3.0x") - oav.zoom_controller.thst.set("5.0x") - oav.zoom_controller.frst.set("7.0x") - oav.zoom_controller.fvst.set("9.0x") - oav.proc.port_name.sim_put("proc") # type: ignore - oav.cam.port_name.sim_put("CAM") # type: ignore oav.grid_snapshot.trigger = MagicMock(return_value=NullStatus()) return oav @@ -640,8 +618,6 @@ def fake_create_rotation_devices( xbpm_feedback: XBPMFeedback, ): set_mock_value(smargon.omega.max_velocity, 131) - oav.zoom_controller.zrst.sim_put("1.0x") # type: ignore - oav.zoom_controller.fvst.sim_put("5.0x") # type: ignore return RotationScanComposite( attenuator=attenuator, diff --git a/tests/system_tests/conftest.py b/tests/system_tests/conftest.py index face5c4b9..7a3cefe1c 100644 --- a/tests/system_tests/conftest.py +++ b/tests/system_tests/conftest.py @@ -4,7 +4,7 @@ import pytest from dodal.beamlines import i03 -from dodal.devices.oav.oav_parameters import OAVConfigParams +from dodal.devices.oav.oav_parameters import OAVConfig from ophyd_async.core import AsyncStatus, set_mock_value from requests import Response @@ -127,32 +127,26 @@ def undulator_for_system_test(undulator): @pytest.fixture def oav_for_system_test(test_config_files): - parameters = OAVConfigParams( + parameters = OAVConfig( test_config_files["zoom_params_file"], test_config_files["display_config"] ) - oav = i03.oav(fake_with_ophyd_sim=True, params=parameters) - oav.zoom_controller.zrst.set("1.0x") - oav.zoom_controller.onst.set("7.5x") - oav.cam.array_size.array_size_x.sim_put(1024) - oav.cam.array_size.array_size_y.sim_put(768) - - unpatched_method = oav.parameters.load_microns_per_pixel - - def patch_lmpp(zoom, xsize, ysize): - unpatched_method(zoom, 1024, 768) + oav = i03.oav(fake_with_ophyd_sim=True, config=parameters) + set_mock_value(oav.cam.array_size_x, 1024) + set_mock_value(oav.cam.array_size_y, 768) # Grid snapshots - oav.grid_snapshot.x_size.sim_put(1024) # type: ignore - oav.grid_snapshot.y_size.sim_put(768) # type: ignore - oav.grid_snapshot.top_left_x.set(50) - oav.grid_snapshot.top_left_y.set(100) - oav.grid_snapshot.box_width.set(0.1 * 1000 / 1.25) # size in pixels + set_mock_value(oav.grid_snapshot.x_size, 1024) + set_mock_value(oav.grid_snapshot.y_size, 768) + set_mock_value(oav.grid_snapshot.top_left_x, 50) + set_mock_value(oav.grid_snapshot.top_left_y, 100) + size_in_pixels = 0.1 * 1000 / 1.25 + set_mock_value(oav.grid_snapshot.box_width, size_in_pixels) unpatched_snapshot_trigger = oav.grid_snapshot.trigger - def mock_grid_snapshot_trigger(): - oav.grid_snapshot.last_path_full_overlay.set("test_1_y") - oav.grid_snapshot.last_path_outer.set("test_2_y") - oav.grid_snapshot.last_saved_path.set("test_3_y") + async def mock_grid_snapshot_trigger(): + await oav.grid_snapshot.last_path_full_overlay.set("test_1_y") + await oav.grid_snapshot.last_path_outer.set("test_2_y") + await oav.grid_snapshot.last_saved_path.set("test_3_y") return unpatched_snapshot_trigger() # Plain snapshots @@ -174,11 +168,6 @@ def next_snapshot(): patch.object( oav.grid_snapshot, "trigger", side_effect=mock_grid_snapshot_trigger ), - patch.object( - oav.parameters, - "load_microns_per_pixel", - new=MagicMock(side_effect=patch_lmpp), - ), patch.object(oav.snapshot.last_saved_path, "get") as mock_last_saved_path, ): it_next_snapshot = next_snapshot() @@ -192,7 +181,7 @@ async def mock_rotation_snapshot_trigger(): "trigger", side_effect=mock_rotation_snapshot_trigger, ): - oav.parameters.load_microns_per_pixel(1.0, 1024, 768) + set_mock_value(oav.zoom_controller.level, "1.0") yield oav diff --git a/tests/unit_tests/beamlines/i04/test_thawing.py b/tests/unit_tests/beamlines/i04/test_thawing.py index c5150770e..d2f428661 100644 --- a/tests/unit_tests/beamlines/i04/test_thawing.py +++ b/tests/unit_tests/beamlines/i04/test_thawing.py @@ -298,11 +298,7 @@ def _run_thaw_and_stream_and_assert_zoom_changes( ): mock_set = MagicMock() - def cb(*args, value, **kwargs): - mock_set(value) - - oav.zoom_controller.level.sim_put("2.0x") # type:ignore - oav.zoom_controller.level.subscribe(cb) + set_mock_value(oav.zoom_controller.level, "2.0x") run_plan = partial( RE, diff --git a/tests/unit_tests/hyperion/experiment_plans/conftest.py b/tests/unit_tests/hyperion/experiment_plans/conftest.py index f0eb33442..18e61be6b 100644 --- a/tests/unit_tests/hyperion/experiment_plans/conftest.py +++ b/tests/unit_tests/hyperion/experiment_plans/conftest.py @@ -8,7 +8,7 @@ from dodal.devices.backlight import Backlight from dodal.devices.detector.detector_motion import DetectorMotion from dodal.devices.fast_grid_scan import ZebraFastGridScan -from dodal.devices.oav.oav_detector import OAVConfigParams +from dodal.devices.oav.oav_detector import OAVConfig from dodal.devices.smargon import Smargon from dodal.devices.synchrotron import SynchrotronMode from dodal.devices.zocalo import ZocaloResults, ZocaloTrigger @@ -240,11 +240,10 @@ def simple_beamline( magic_mock.dcm = dcm magic_mock.synchrotron = synchrotron magic_mock.eiger = eiger - oav.zoom_controller.frst.set("7.5x") - oav.parameters = OAVConfigParams( + oav.zoom_controller.set("7.5x") + oav.parameters = OAVConfig( test_config_files["zoom_params_file"], test_config_files["display_config"] - ) - oav.parameters.update_on_zoom(7.5, 1024, 768) + ).get_parameters() return magic_mock diff --git a/tests/unit_tests/hyperion/experiment_plans/test_grid_detect_then_xray_centre_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_grid_detect_then_xray_centre_plan.py index 2d49fe2cc..44acfec54 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_grid_detect_then_xray_centre_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_grid_detect_then_xray_centre_plan.py @@ -11,9 +11,10 @@ from dodal.devices.aperturescatterguard import ApertureValue from dodal.devices.backlight import BacklightPosition from dodal.devices.eiger import EigerDetector -from dodal.devices.oav.oav_detector import OAVConfigParams +from dodal.devices.oav.oav_detector import OAVConfig from dodal.devices.oav.oav_parameters import OAVParameters from dodal.devices.smargon import Smargon +from ophyd_async.core import set_mock_value from mx_bluesky.hyperion.experiment_plans.grid_detect_then_xray_centre_plan import ( GridDetectThenXRayCentreComposite, @@ -42,18 +43,18 @@ def _fake_grid_detection( box_size_um: float = 0.0, ): oav = i03.oav(fake_with_ophyd_sim=True) - oav.grid_snapshot.box_width.put(635.00986) + set_mock_value(oav.grid_snapshot.box_width, 635.00986) # first grid detection: x * y - oav.grid_snapshot.num_boxes_x.put(10) - oav.grid_snapshot.num_boxes_y.put(4) + set_mock_value(oav.grid_snapshot.num_boxes_x, 10) + set_mock_value(oav.grid_snapshot.num_boxes_y, 4) yield from bps.create(CONST.DESCRIPTORS.OAV_GRID_SNAPSHOT_TRIGGERED) yield from bps.read(oav.grid_snapshot) # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809 yield from bps.read(devices.smargon) yield from bps.save() # second grid detection: x * z, so num_boxes_y refers to smargon z - oav.grid_snapshot.num_boxes_x.put(10) - oav.grid_snapshot.num_boxes_y.put(1) + set_mock_value(oav.grid_snapshot.num_boxes_x, 10) + set_mock_value(oav.grid_snapshot.num_boxes_y, 1) yield from bps.create(CONST.DESCRIPTORS.OAV_GRID_SNAPSHOT_TRIGGERED) yield from bps.read(oav.grid_snapshot) # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809 yield from bps.read(devices.smargon) @@ -77,13 +78,10 @@ def grid_detect_devices_with_oav_config_params( grid_detect_devices: GridDetectThenXRayCentreComposite, test_config_files: dict[str, str], ) -> GridDetectThenXRayCentreComposite: - grid_detect_devices.oav.parameters = OAVConfigParams( + grid_detect_devices.oav.parameters = OAVConfig( test_config_files["zoom_params_file"], test_config_files["display_config"] - ) - grid_detect_devices.oav.parameters.micronsPerXPixel = 0.806 - grid_detect_devices.oav.parameters.micronsPerYPixel = 0.806 - grid_detect_devices.oav.parameters.beam_centre_i = 549 - grid_detect_devices.oav.parameters.beam_centre_j = 347 + ).get_parameters() + set_mock_value(grid_detect_devices.oav.zoom_controller.level, "7.5x") return grid_detect_devices diff --git a/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py index f84033744..d154ae2b0 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py @@ -9,7 +9,7 @@ from bluesky.utils import Msg from dodal.beamlines import i03 from dodal.devices.backlight import Backlight -from dodal.devices.oav.oav_detector import OAVConfigParams +from dodal.devices.oav.oav_detector import OAVConfig from dodal.devices.oav.oav_parameters import OAVParameters from dodal.devices.oav.pin_image_recognition import PinTipDetection from dodal.devices.oav.pin_image_recognition.utils import NONE_VALUE, SampleLocation @@ -42,18 +42,11 @@ def fake_devices( backlight: Backlight, test_config_files: dict[str, str], ): - params = OAVConfigParams( + params = OAVConfig( test_config_files["zoom_params_file"], test_config_files["display_config"] ) - oav = i03.oav(wait_for_connection=False, fake_with_ophyd_sim=True, params=params) - oav.parameters.update_on_zoom = MagicMock() - oav.parameters.load_microns_per_pixel = MagicMock() - oav.parameters.micronsPerXPixel = 1.58 - oav.parameters.micronsPerYPixel = 1.58 - oav.parameters.beam_centre_i = 517 - oav.parameters.beam_centre_j = 350 - - oav.wait_for_connection() + oav = i03.oav(fake_with_ophyd_sim=True, config=params) + set_mock_value(oav.zoom_controller.level, "5.0") pin_tip_detection = i03.pin_tip_detection(fake_with_ophyd_sim=True) pin_tip_detection._get_tip_and_edge_data = AsyncMock( @@ -65,18 +58,15 @@ def fake_devices( ) ) - oav.zoom_controller.zrst.set("1.0x") - oav.zoom_controller.onst.set("2.0x") - oav.zoom_controller.twst.set("3.0x") - oav.zoom_controller.thst.set("5.0x") - oav.zoom_controller.frst.set("7.0x") - oav.zoom_controller.fvst.set("9.0x") - with ( - patch("dodal.devices.areadetector.plugins.MJPG.requests") as patch_requests, + patch( + "dodal.devices.areadetector.plugins.MJPG.ClientSession" + ) as patch_requests, patch("dodal.devices.areadetector.plugins.MJPG.Image") as mock_image_class, ): - patch_requests.get.return_value.content = b"" + patch_get = patch_requests.get + patch_get.return_value.__aenter__.return_value = (mock_response := AsyncMock()) + mock_response.read.return_value = b"" mock_image = MagicMock() mock_image_class.open.return_value.__enter__.return_value = mock_image @@ -158,7 +148,7 @@ async def test_grid_detection_plan_gives_warning_error_if_tip_not_found( lambda a, b: True, ) @patch("bluesky.plan_stubs.sleep", new=MagicMock()) -def test_given_when_grid_detect_then_start_position_as_expected( +async def test_given_when_grid_detect_then_start_position_as_expected( fake_devices: tuple[OavGridDetectionComposite, MagicMock], RE: RunEngine, test_config_files: dict[str, str], @@ -166,13 +156,15 @@ def test_given_when_grid_detect_then_start_position_as_expected( params = OAVParameters("loopCentring", test_config_files["oav_config_json"]) box_size_um = 0.2 composite, _ = fake_devices - composite.oav.parameters.micronsPerXPixel = 0.1 - composite.oav.parameters.micronsPerYPixel = 0.1 - composite.oav.parameters.beam_centre_i = 4 - composite.oav.parameters.beam_centre_j = 4 - box_size_y_pixels = box_size_um / composite.oav.parameters.micronsPerYPixel - - grid_param_cb = GridDetectionCallback(composite.oav.parameters) + # FIXME This won't work + await composite.oav.microns_per_pixel_x._backend.put(0.1) + await composite.oav.microns_per_pixel_y._backend.put(0.1) + await composite.oav.beam_centre_i._backend.put(4) + await composite.oav.beam_centre_j._backend.put(4) + microns_per_pixel_y = await composite.oav.microns_per_pixel_y.get_value() + box_size_y_pixels = box_size_um / microns_per_pixel_y + + grid_param_cb = GridDetectionCallback() RE.subscribe(grid_param_cb) @bpp.run_decorator() @@ -193,9 +185,7 @@ def decorated(): assert gridscan_params["x_start_um"] == pytest.approx(0.0005) assert gridscan_params["y_start_um"] == pytest.approx( -0.0001 - - ( - (box_size_y_pixels / 2) * composite.oav.parameters.micronsPerYPixel * 1e-3 - ) # microns to mm + - ((box_size_y_pixels / 2) * microns_per_pixel_y * 1e-3) # microns to mm ) assert gridscan_params["z_start_um"] == pytest.approx(-0.0001) @@ -238,7 +228,7 @@ def decorated(): lambda a, b: True, ) @patch("bluesky.plan_stubs.sleep", new=MagicMock()) -def test_when_grid_detection_plan_run_then_ispyb_callback_gets_correct_values( +async def test_when_grid_detection_plan_run_then_ispyb_callback_gets_correct_values( fake_devices: tuple[OavGridDetectionComposite, MagicMock], RE: RunEngine, test_config_files: dict[str, str], @@ -246,8 +236,9 @@ def test_when_grid_detection_plan_run_then_ispyb_callback_gets_correct_values( ): params = OAVParameters("loopCentring", test_config_files["oav_config_json"]) composite, _ = fake_devices - composite.oav.parameters.micronsPerYPixel = 1.25 - composite.oav.parameters.micronsPerXPixel = 1.25 + # FIXME This won't work + await composite.oav.microns_per_pixel_x._backend.put(1.25) + await composite.oav.microns_per_pixel_y._backend.put(1.25) cb = GridscanISPyBCallback() RE.subscribe(cb) @@ -313,7 +304,7 @@ def test_when_grid_detection_plan_run_then_grid_detection_callback_gets_correct_ params = OAVParameters("loopCentring", test_config_files["oav_config_json"]) composite, _ = fake_devices box_size_um = 20 - cb = GridDetectionCallback(composite.oav.parameters) + cb = GridDetectionCallback() RE.subscribe(cb) def decorated(): diff --git a/tests/unit_tests/hyperion/experiment_plans/test_pin_tip_centring.py b/tests/unit_tests/hyperion/experiment_plans/test_pin_tip_centring.py index 3210ba66f..8634df82d 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_pin_tip_centring.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_pin_tip_centring.py @@ -5,7 +5,7 @@ import pytest from bluesky.plan_stubs import null from bluesky.run_engine import RunEngine, RunEngineResult -from dodal.devices.oav.oav_detector import OAV, OAVConfigParams +from dodal.devices.oav.oav_detector import OAV, OAVConfig from dodal.devices.oav.pin_image_recognition import PinTipDetection from dodal.devices.oav.pin_image_recognition.utils import SampleLocation from dodal.devices.smargon import Smargon @@ -262,11 +262,13 @@ async def test_when_pin_tip_centre_plan_called_then_expected_plans_called( ): set_mock_value(smargon.omega.user_readback, 0) mock_oav: OAV = MagicMock(spec=OAV) - mock_oav.parameters = OAVConfigParams( + mock_oav.parameters = OAVConfig( test_config_files["zoom_params_file"], test_config_files["display_config"] - ) - mock_oav.parameters.micronsPerXPixel = 2.87 - mock_oav.parameters.micronsPerYPixel = 2.87 + ).get_parameters() + mock_oav.zoom_controller = MagicMock() + mock_oav.zoom_controller.level = MagicMock(return_value="1.0") + mock_oav.microns_per_pixel_x = MagicMock(return_value=2.87) + mock_oav.microns_per_pixel_y = MagicMock(return_value=2.87) composite = PinTipCentringComposite( backlight=MagicMock(), oav=mock_oav, From 881504e4b59dad79680955e8b0f0e9fbeec34f95 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Thu, 24 Oct 2024 14:43:27 +0100 Subject: [PATCH 04/18] Update dodal pin --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2d852561a..ff0c9c7f5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ dependencies = [ "ophyd == 1.9.0", "ophyd-async >= 0.3a5", "bluesky >= 1.13.0a4", - "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@b2d0dbe4c63fb0ca1313be5155c6a57832a446ad", + "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@bffbd299afe09fbdda89c5e7322cf1f46663bd9d", ] From 3551e08d6e67f4b38e8cf818e00e808916ee944c Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Fri, 25 Oct 2024 09:23:18 +0100 Subject: [PATCH 05/18] Fix linting --- tests/system_tests/conftest.py | 2 +- .../test_grid_detect_then_xray_centre_plan.py | 2 +- .../experiment_plans/test_grid_detection_plan.py | 7 ++++--- .../test_load_centre_collect_full_plan.py | 3 +-- .../hyperion/experiment_plans/test_oav_snapshot_plan.py | 2 +- .../test_robot_load_and_change_energy.py | 9 +++++---- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/system_tests/conftest.py b/tests/system_tests/conftest.py index 7a3cefe1c..7beb31891 100644 --- a/tests/system_tests/conftest.py +++ b/tests/system_tests/conftest.py @@ -139,7 +139,7 @@ def oav_for_system_test(test_config_files): set_mock_value(oav.grid_snapshot.y_size, 768) set_mock_value(oav.grid_snapshot.top_left_x, 50) set_mock_value(oav.grid_snapshot.top_left_y, 100) - size_in_pixels = 0.1 * 1000 / 1.25 + size_in_pixels = int(0.1 * 1000 / 1.25) set_mock_value(oav.grid_snapshot.box_width, size_in_pixels) unpatched_snapshot_trigger = oav.grid_snapshot.trigger diff --git a/tests/unit_tests/hyperion/experiment_plans/test_grid_detect_then_xray_centre_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_grid_detect_then_xray_centre_plan.py index 44acfec54..aa91941cb 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_grid_detect_then_xray_centre_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_grid_detect_then_xray_centre_plan.py @@ -43,7 +43,7 @@ def _fake_grid_detection( box_size_um: float = 0.0, ): oav = i03.oav(fake_with_ophyd_sim=True) - set_mock_value(oav.grid_snapshot.box_width, 635.00986) + set_mock_value(oav.grid_snapshot.box_width, 635) # first grid detection: x * y set_mock_value(oav.grid_snapshot.num_boxes_x, 10) set_mock_value(oav.grid_snapshot.num_boxes_y, 4) diff --git a/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py index d154ae2b0..ebe60470d 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py @@ -348,7 +348,7 @@ def decorated(): ) @patch("bluesky.plan_stubs.sleep", new=MagicMock()) @patch("mx_bluesky.hyperion.experiment_plans.oav_grid_detection_plan.LOGGER") -def test_when_detected_grid_has_odd_y_steps_then_add_a_y_step_and_shift_grid( +async def test_when_detected_grid_has_odd_y_steps_then_add_a_y_step_and_shift_grid( fake_logger: MagicMock, fake_devices: tuple[OavGridDetectionComposite, MagicMock], sim_run_engine: RunEngineSimulator, @@ -359,8 +359,9 @@ def test_when_detected_grid_has_odd_y_steps_then_add_a_y_step_and_shift_grid( params = OAVParameters("loopCentring", test_config_files["oav_config_json"]) grid_width_microns = 161.2 box_size_um = 20 - assert composite.oav.parameters.micronsPerYPixel is not None - box_size_y_pixels = box_size_um / composite.oav.parameters.micronsPerYPixel + microns_per_pixel_y = await composite.oav.microns_per_pixel_y.get_value() + assert microns_per_pixel_y is not None + box_size_y_pixels = box_size_um / microns_per_pixel_y initial_min_y = 1 abs_sets: dict[str, list] = { diff --git a/tests/unit_tests/hyperion/experiment_plans/test_load_centre_collect_full_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_load_centre_collect_full_plan.py index c29567ffb..82fc4af4b 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_load_centre_collect_full_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_load_centre_collect_full_plan.py @@ -85,8 +85,7 @@ def composite( sim_run_engine.add_read_handler_for( composite.pin_tip_detection.triggered_bottom_edge, bottom_edge_array ) - composite.oav.parameters.update_on_zoom(7.5, 1024, 768) - composite.oav.zoom_controller.frst.set("7.5x") + set_mock_value(composite.oav.zoom_controller.level, "7.5x") sim_run_engine.add_read_handler_for( composite.pin_tip_detection.triggered_tip, (tip_x_px, tip_y_px) diff --git a/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py index 00c2e79dd..11134a38b 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py @@ -5,10 +5,10 @@ import pytest from bluesky.simulators import assert_message_and_return_remaining from dodal.devices.aperturescatterguard import ApertureScatterguard +from dodal.devices.areadetector.plugins.CAM import ColorMode from dodal.devices.backlight import Backlight from dodal.devices.oav.oav_detector import OAV from dodal.devices.oav.oav_parameters import OAVParameters -from dodal.devices.oav.utils import ColorMode from dodal.devices.smargon import Smargon from mx_bluesky.hyperion.experiment_plans.oav_snapshot_plan import ( diff --git a/tests/unit_tests/hyperion/experiment_plans/test_robot_load_and_change_energy.py b/tests/unit_tests/hyperion/experiment_plans/test_robot_load_and_change_energy.py index dad4695f7..71507b5b3 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_robot_load_and_change_energy.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_robot_load_and_change_energy.py @@ -208,8 +208,9 @@ def test_given_ispyb_callback_attached_when_robot_load_then_centre_plan_called_t robot_load_and_energy_change_composite: RobotLoadAndEnergyChangeComposite, robot_load_and_energy_change_params: RobotLoadAndEnergyChange, ): - robot_load_and_energy_change_composite.oav.snapshot.last_saved_path.put( - "test_oav_snapshot" + set_mock_value( + robot_load_and_energy_change_composite.oav.snapshot.last_saved_path, + "test_oav_snapshot", ) # type: ignore set_mock_value( robot_load_and_energy_change_composite.webcam.last_saved_path, @@ -253,8 +254,8 @@ async def test_when_take_snapshots_called_then_filename_and_directory_set_and_de RE(take_robot_snapshots(oav, webcam, Path(TEST_DIRECTORY))) oav.snapshot.trigger.assert_called_once() - assert oav.snapshot.filename.get() == "TIME_oav_snapshot_after_load" - assert oav.snapshot.directory.get() == TEST_DIRECTORY + assert await oav.snapshot.filename.get_value() == "TIME_oav_snapshot_after_load" + assert await oav.snapshot.directory.get_value() == TEST_DIRECTORY webcam.trigger.assert_called_once() assert (await webcam.filename.get_value()) == "TIME_webcam_after_load" From 6fcbd23c5fced4850e7f3e154bd33ff0ee0aeea2 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Fri, 25 Oct 2024 10:18:17 +0100 Subject: [PATCH 06/18] Try to fix thawing pla --- pyproject.toml | 2 +- tests/conftest.py | 6 ++++- .../unit_tests/beamlines/i04/test_thawing.py | 22 +++++++++++++++---- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index ff0c9c7f5..7e8ba66b6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ dependencies = [ "ophyd == 1.9.0", "ophyd-async >= 0.3a5", "bluesky >= 1.13.0a4", - "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@bffbd299afe09fbdda89c5e7322cf1f46663bd9d", + "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@f30a5198cb97616a5dd742289fc3c5f738979f14", ] diff --git a/tests/conftest.py b/tests/conftest.py index 819f334b9..85dd54395 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,7 +8,7 @@ from contextlib import ExitStack from functools import partial from typing import Any -from unittest.mock import MagicMock, patch +from unittest.mock import AsyncMock, MagicMock, patch import bluesky.plan_stubs as bps import numpy @@ -357,6 +357,10 @@ def oav(test_config_files, RE): ) oav = i03.oav(fake_with_ophyd_sim=True, params=parameters) + zoom_levels_list = ["1.0x", "3.0x", "5.0x", "7.5x", "10.0x", "15.0x"] + oav.zoom_controller._get_allowed_zoom_levels = AsyncMock( + return_value=zoom_levels_list + ) # Equivalent to previously set values for microns and beam centre set_mock_value(oav.zoom_controller.level, "5.0x") diff --git a/tests/unit_tests/beamlines/i04/test_thawing.py b/tests/unit_tests/beamlines/i04/test_thawing.py index d2f428661..fe14d8aa4 100644 --- a/tests/unit_tests/beamlines/i04/test_thawing.py +++ b/tests/unit_tests/beamlines/i04/test_thawing.py @@ -1,13 +1,13 @@ from collections.abc import AsyncGenerator from functools import partial -from unittest.mock import ANY, MagicMock, call, patch +from unittest.mock import ANY, AsyncMock, MagicMock, call, patch import pytest from _pytest.python_api import ApproxBase from bluesky.run_engine import RunEngine from bluesky.simulators import assert_message_and_return_remaining from dodal.beamlines import i04 -from dodal.devices.oav.oav_detector import OAV +from dodal.devices.oav.oav_detector import OAV, OAVConfig from dodal.devices.oav.oav_to_redis_forwarder import OAVToRedisForwarder, Source from dodal.devices.robot import BartRobot from dodal.devices.smargon import Smargon @@ -25,8 +25,8 @@ from mx_bluesky.beamlines.i04.thawing_plan import thaw, thaw_and_stream_to_redis from mx_bluesky.common.test_utils import rebuild_oa_device_as_mocked_if_necessary -DISPLAY_CONFIGURATION = "tests/devices/unit_tests/test_display.configuration" -ZOOM_LEVELS_XML = "tests/devices/unit_tests/test_jCameraManZoomLevels.xml" +DISPLAY_CONFIGURATION = "tests/test_data/test_display.configuration" +ZOOM_LEVELS_XML = "tests/test_data/test_jCameraManZoomLevels.xml" class MyException(Exception): @@ -45,6 +45,20 @@ def patch_motor(motor: Motor, initial_position: float = 0): ) +@pytest.fixture +async def oav(RE: RunEngine) -> OAV: + oav_config = OAVConfig(ZOOM_LEVELS_XML, DISPLAY_CONFIGURATION) + oav = rebuild_oa_device_as_mocked_if_necessary( + i04.oav, fake_with_ophyd_sim=True, params=oav_config + ) + zoom_levels_list = ["1.0x", "3.0x", "5.0x", "7.5x", "10.0x", "15.0x"] + oav.zoom_controller._get_allowed_zoom_levels = AsyncMock( + return_value=zoom_levels_list + ) + set_mock_value(oav.zoom_controller.level, "5.0x") + return oav + + @pytest.fixture async def smargon(RE: RunEngine) -> AsyncGenerator[Smargon, None]: smargon = Smargon(name="smargon") From a11659d2106ec7ccf5178ac723855fe8bc81374d Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Fri, 25 Oct 2024 10:44:12 +0100 Subject: [PATCH 07/18] Still ignoring mock device --- tests/unit_tests/beamlines/i04/test_thawing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit_tests/beamlines/i04/test_thawing.py b/tests/unit_tests/beamlines/i04/test_thawing.py index fe14d8aa4..fee3ad6a4 100644 --- a/tests/unit_tests/beamlines/i04/test_thawing.py +++ b/tests/unit_tests/beamlines/i04/test_thawing.py @@ -51,11 +51,11 @@ async def oav(RE: RunEngine) -> OAV: oav = rebuild_oa_device_as_mocked_if_necessary( i04.oav, fake_with_ophyd_sim=True, params=oav_config ) - zoom_levels_list = ["1.0x", "3.0x", "5.0x", "7.5x", "10.0x", "15.0x"] + zoom_levels_list = ["1.0x", "3.0x", "5.0x", "7.5x"] oav.zoom_controller._get_allowed_zoom_levels = AsyncMock( return_value=zoom_levels_list ) - set_mock_value(oav.zoom_controller.level, "5.0x") + set_mock_value(oav.zoom_controller.level, "1.0x") return oav From 0a410def4072f282875e32c20e4fd29bc696fc1f Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Mon, 28 Oct 2024 15:12:32 +0000 Subject: [PATCH 08/18] Get thawing tests to pass --- pyproject.toml | 2 +- src/mx_bluesky/beamlines/i04/thawing_plan.py | 13 +++++++---- .../unit_tests/beamlines/i04/test_thawing.py | 23 +++++++------------ 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7e8ba66b6..a3e509881 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ dependencies = [ "ophyd == 1.9.0", "ophyd-async >= 0.3a5", "bluesky >= 1.13.0a4", - "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@f30a5198cb97616a5dd742289fc3c5f738979f14", + "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@8d0567c72428f527b7936fff209ddaebdb29fd9b", ] diff --git a/src/mx_bluesky/beamlines/i04/thawing_plan.py b/src/mx_bluesky/beamlines/i04/thawing_plan.py index b0284425b..853e7c405 100644 --- a/src/mx_bluesky/beamlines/i04/thawing_plan.py +++ b/src/mx_bluesky/beamlines/i04/thawing_plan.py @@ -39,13 +39,18 @@ def switch_forwarder_to_ROI() -> MsgGenerator: yield from bps.mv(oav_to_redis_forwarder.selected_source, Source.ROI) # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809 yield from bps.kickoff(oav_to_redis_forwarder, wait=True) + microns_per_pixel_x = yield from bps.rd(oav.microns_per_pixel_x) + microns_per_pixel_y = yield from bps.rd(oav.microns_per_pixel_y) + beam_centre_i = yield from bps.rd(oav.beam_centre_i) + beam_centre_j = yield from bps.rd(oav.beam_centre_j) + @subs_decorator(MurkoCallback(REDIS_HOST, REDIS_PASSWORD, MURKO_REDIS_DB)) @run_decorator( md={ - "microns_per_x_pixel": oav.microns_per_pixel_x, - "microns_per_y_pixel": oav.microns_per_pixel_y, - "beam_centre_i": oav.beam_centre_i, - "beam_centre_j": oav.beam_centre_j, + "microns_per_x_pixel": microns_per_pixel_x, + "microns_per_y_pixel": microns_per_pixel_y, + "beam_centre_i": beam_centre_i, + "beam_centre_j": beam_centre_j, "zoom_percentage": zoom_percentage, "sample_id": sample_id, } diff --git a/tests/unit_tests/beamlines/i04/test_thawing.py b/tests/unit_tests/beamlines/i04/test_thawing.py index fee3ad6a4..22d6b84f1 100644 --- a/tests/unit_tests/beamlines/i04/test_thawing.py +++ b/tests/unit_tests/beamlines/i04/test_thawing.py @@ -48,14 +48,15 @@ def patch_motor(motor: Motor, initial_position: float = 0): @pytest.fixture async def oav(RE: RunEngine) -> OAV: oav_config = OAVConfig(ZOOM_LEVELS_XML, DISPLAY_CONFIGURATION) - oav = rebuild_oa_device_as_mocked_if_necessary( - i04.oav, fake_with_ophyd_sim=True, params=oav_config - ) - zoom_levels_list = ["1.0x", "3.0x", "5.0x", "7.5x"] + async with DeviceCollector(mock=True, connect=True): + oav = OAV("", config=oav_config, name="fake_oav") + zoom_levels_list = ["1.0x", "2.0x", "5.0x"] oav.zoom_controller._get_allowed_zoom_levels = AsyncMock( return_value=zoom_levels_list ) set_mock_value(oav.zoom_controller.level, "1.0x") + set_mock_value(oav.grid_snapshot.x_size, 1024) + set_mock_value(oav.grid_snapshot.y_size, 768) return oav @@ -310,8 +311,6 @@ def _run_thaw_and_stream_and_assert_zoom_changes( RE: RunEngine, expect_raises=None, ): - mock_set = MagicMock() - set_mock_value(oav.zoom_controller.level, "2.0x") run_plan = partial( @@ -333,15 +332,9 @@ def _run_thaw_and_stream_and_assert_zoom_changes( else: run_plan() - mock_set.assert_has_calls( - [ - call( - "1.0x", - ), - call( - "2.0x", - ), - ] + mock_level_set = get_mock_put(oav.zoom_controller.level) + mock_level_set.assert_has_calls( + [call("1.0x", wait=True, timeout=ANY), call("2.0x", wait=True, timeout=ANY)] ) From 28950994a7f4531b0e53399818c914417dadb8b2 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Wed, 30 Oct 2024 14:01:47 +0000 Subject: [PATCH 09/18] Pin dodal --- pyproject.toml | 2 +- .../experiment_plans/test_load_centre_collect_full_plan.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index f7f506781..dcc10df57 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ dependencies = [ "ophyd == 1.9.0", "ophyd-async >= 0.3a5", "bluesky >= 1.13.0a4", - "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@8d0567c72428f527b7936fff209ddaebdb29fd9b", + "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@a12ca189d02f5572d74d875c3e8fc95aa917e7b8", ] diff --git a/tests/unit_tests/hyperion/experiment_plans/test_load_centre_collect_full_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_load_centre_collect_full_plan.py index 82fc4af4b..429343b42 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_load_centre_collect_full_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_load_centre_collect_full_plan.py @@ -1,5 +1,5 @@ import dataclasses -from unittest.mock import MagicMock, patch +from unittest.mock import AsyncMock, MagicMock, patch import pytest from bluesky.protocols import Location @@ -85,6 +85,10 @@ def composite( sim_run_engine.add_read_handler_for( composite.pin_tip_detection.triggered_bottom_edge, bottom_edge_array ) + zoom_levels_list = ["1.0x", "3.0x", "5.0x", "7.5x", "10.0x"] + composite.oav.zoom_controller.level.describe = AsyncMock( + return_value={"level": {"choices": zoom_levels_list}} + ) set_mock_value(composite.oav.zoom_controller.level, "7.5x") sim_run_engine.add_read_handler_for( From 44290c9906221832ad1867e29c27cc31e202b3b1 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Wed, 30 Oct 2024 16:16:41 +0000 Subject: [PATCH 10/18] Start fixing some tests --- pyproject.toml | 2 +- .../grid_detect_then_xray_centre_plan.py | 2 +- .../oav_grid_detection_plan.py | 2 +- .../callbacks/grid_detection_callback.py | 18 ++++---- .../callbacks/xray_centre/ispyb_callback.py | 26 ++++++------ tests/conftest.py | 3 ++ tests/system_tests/conftest.py | 2 +- tests/unit_tests/hyperion/conftest.py | 40 +++++++++--------- .../hyperion/experiment_plans/conftest.py | 5 ++- .../test_grid_detect_then_xray_centre_plan.py | 11 ++--- .../test_grid_detection_plan.py | 42 +++++++++---------- .../test_robot_load_ispyb_callback.py | 2 +- 12 files changed, 77 insertions(+), 78 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index dcc10df57..2228f511f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ dependencies = [ "ophyd == 1.9.0", "ophyd-async >= 0.3a5", "bluesky >= 1.13.0a4", - "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@a12ca189d02f5572d74d875c3e8fc95aa917e7b8", + "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@eeb8daf36189c9bd4f797ef52153a122ef1ba783", ] diff --git a/src/mx_bluesky/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py b/src/mx_bluesky/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py index 361013eba..28e008290 100644 --- a/src/mx_bluesky/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py +++ b/src/mx_bluesky/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py @@ -109,7 +109,7 @@ def detect_grid_and_do_gridscan( ): snapshot_template = f"{parameters.detector_params.prefix}_{parameters.detector_params.run_number}_{{angle}}" - grid_params_callback = GridDetectionCallback(composite.oav.parameters) + grid_params_callback = GridDetectionCallback() @bpp.subs_decorator([grid_params_callback]) def run_grid_detection_plan( diff --git a/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py b/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py index 85fa9bc88..5cc385e38 100644 --- a/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py +++ b/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py @@ -164,7 +164,7 @@ def grid_detection_plan( yield from bps.trigger(oav.grid_snapshot, wait=True) # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809 yield from bps.create(CONST.DESCRIPTORS.OAV_GRID_SNAPSHOT_TRIGGERED) - yield from bps.read(oav.grid_snapshot) # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809 + yield from bps.read(oav) # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809 yield from bps.read(smargon) yield from bps.save() diff --git a/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py b/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py index 2e678d0a7..258e0aa4c 100644 --- a/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py +++ b/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py @@ -33,11 +33,11 @@ def __init__( def event(self, doc: Event): data = doc.get("data") - top_left_x_px = data["oav_grid_snapshot_top_left_x"] - box_width_px = data["oav_grid_snapshot_box_width"] + top_left_x_px = data["oav-grid_snapshot-top_left_x"] + box_width_px = data["oav-grid_snapshot-box_width"] x_of_centre_of_first_box_px = top_left_x_px + box_width_px / 2 - top_left_y_px = data["oav_grid_snapshot_top_left_y"] + top_left_y_px = data["oav-grid_snapshot-top_left_y"] y_of_centre_of_first_box_px = top_left_y_px + box_width_px / 2 smargon_omega = data["smargon-omega"] @@ -50,10 +50,10 @@ def event(self, doc: Event): y_of_centre_of_first_box_px, ) - microns_per_pixel_x = data["oav_microns_per_pixel_x"] - microns_per_pixel_y = data["oav_microns_per_pixel_y"] - beam_x = data["oav_beam_centre_i"] - beam_y = data["oav_beam_centre_j"] + microns_per_pixel_x = data["oav-microns_per_pixel_x"] + microns_per_pixel_y = data["oav-microns_per_pixel_y"] + beam_x = data["oav-snapshot-beam_centre_i"] + beam_y = data["oav-snapshot-beam_centre_j"] position_grid_start = calculate_x_y_z_of_pixel( current_xyz, @@ -68,8 +68,8 @@ def event(self, doc: Event): self.start_positions.append(position_grid_start) self.box_numbers.append( ( - data["oav_grid_snapshot_num_boxes_x"], - data["oav_grid_snapshot_num_boxes_y"], + data["oav-grid_snapshot-num_boxes_x"], + data["oav-grid_snapshot-num_boxes_y"], ) ) diff --git a/src/mx_bluesky/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py b/src/mx_bluesky/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py index 8e624ce2c..1ccec4dfa 100644 --- a/src/mx_bluesky/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py +++ b/src/mx_bluesky/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py @@ -180,25 +180,25 @@ def _handle_oav_grid_snapshot_triggered(self, doc) -> Sequence[ScanDataInfo]: data = doc["data"] data_collection_id = None data_collection_info = DataCollectionInfo( - xtal_snapshot1=data.get("oav_grid_snapshot_last_path_full_overlay"), - xtal_snapshot2=data.get("oav_grid_snapshot_last_path_outer"), - xtal_snapshot3=data.get("oav_grid_snapshot_last_saved_path"), + xtal_snapshot1=data.get("oav-grid_snapshot-last_path_full_overlay"), + xtal_snapshot2=data.get("oav-grid_snapshot-last_path_outer"), + xtal_snapshot3=data.get("oav-grid_snapshot-last_saved_path"), n_images=( - data["oav_grid_snapshot_num_boxes_x"] - * data["oav_grid_snapshot_num_boxes_y"] + data["oav-grid_snapshot-num_boxes_x"] + * data["oav-grid_snapshot-num_boxes_y"] ), ) - microns_per_pixel_x = data["oav_grid_snapshot_microns_per_pixel_x"] - microns_per_pixel_y = data["oav_grid_snapshot_microns_per_pixel_y"] + microns_per_pixel_x = data["oav-grid_snapshot-microns_per_pixel_x"] + microns_per_pixel_y = data["oav-grid_snapshot-microns_per_pixel_y"] data_collection_grid_info = DataCollectionGridInfo( - dx_in_mm=data["oav_grid_snapshot_box_width"] * microns_per_pixel_x / 1000, - dy_in_mm=data["oav_grid_snapshot_box_width"] * microns_per_pixel_y / 1000, - steps_x=data["oav_grid_snapshot_num_boxes_x"], - steps_y=data["oav_grid_snapshot_num_boxes_y"], + dx_in_mm=data["oav-grid_snapshot-box_width"] * microns_per_pixel_x / 1000, + dy_in_mm=data["oav-grid_snapshot-box_width"] * microns_per_pixel_y / 1000, + steps_x=data["oav-grid_snapshot-num_boxes_x"], + steps_y=data["oav-grid_snapshot-num_boxes_y"], microns_per_pixel_x=microns_per_pixel_x, microns_per_pixel_y=microns_per_pixel_y, - snapshot_offset_x_pixel=int(data["oav_grid_snapshot_top_left_x"]), - snapshot_offset_y_pixel=int(data["oav_grid_snapshot_top_left_y"]), + snapshot_offset_x_pixel=int(data["oav-grid_snapshot-top_left_x"]), + snapshot_offset_y_pixel=int(data["oav-grid_snapshot-top_left_y"]), orientation=Orientation.HORIZONTAL, snaked=True, ) diff --git a/tests/conftest.py b/tests/conftest.py index e01ce8b54..c7f95df23 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -364,6 +364,9 @@ def oav(test_config_files, RE): # Equivalent to previously set values for microns and beam centre set_mock_value(oav.zoom_controller.level, "5.0x") + set_mock_value(oav.grid_snapshot.x_size, 1024) + set_mock_value(oav.grid_snapshot.y_size, 768) + oav.snapshot.trigger = MagicMock(return_value=NullStatus()) oav.grid_snapshot.trigger = MagicMock(return_value=NullStatus()) return oav diff --git a/tests/system_tests/conftest.py b/tests/system_tests/conftest.py index 7beb31891..568667185 100644 --- a/tests/system_tests/conftest.py +++ b/tests/system_tests/conftest.py @@ -130,7 +130,7 @@ def oav_for_system_test(test_config_files): parameters = OAVConfig( test_config_files["zoom_params_file"], test_config_files["display_config"] ) - oav = i03.oav(fake_with_ophyd_sim=True, config=parameters) + oav = i03.oav(fake_with_ophyd_sim=True, params=parameters) set_mock_value(oav.cam.array_size_x, 1024) set_mock_value(oav.cam.array_size_y, 768) diff --git a/tests/unit_tests/hyperion/conftest.py b/tests/unit_tests/hyperion/conftest.py index 1c34d0f88..14bd5ea2a 100644 --- a/tests/unit_tests/hyperion/conftest.py +++ b/tests/unit_tests/hyperion/conftest.py @@ -39,16 +39,16 @@ class OavGridSnapshotTestEvents: "seq_num": 1, "uid": "29033ecf-e052-43dd-98af-c7cdd62e8174", "data": { - "oav_grid_snapshot_top_left_x": 50, - "oav_grid_snapshot_top_left_y": 100, - "oav_grid_snapshot_num_boxes_x": 40, - "oav_grid_snapshot_num_boxes_y": 20, - "oav_grid_snapshot_microns_per_pixel_x": 1.25, - "oav_grid_snapshot_microns_per_pixel_y": 1.5, - "oav_grid_snapshot_box_width": 0.1 * 1000 / 1.25, # size in pixels - "oav_grid_snapshot_last_path_full_overlay": "test_1_y", - "oav_grid_snapshot_last_path_outer": "test_2_y", - "oav_grid_snapshot_last_saved_path": "test_3_y", + "oav-grid_snapshot-top_left_x": 50, + "oav-grid_snapshot-top_left_y": 100, + "oav-grid_snapshot-num_boxes_x": 40, + "oav-grid_snapshot-num_boxes_y": 20, + "oav-grid_snapshot-microns_per_pixel_x": 1.25, + "oav-grid_snapshot-microns_per_pixel_y": 1.5, + "oav-grid_snapshot-box_width": 0.1 * 1000 / 1.25, # size in pixels + "oav-grid_snapshot-last_path_full_overlay": "test_1_y", + "oav-grid_snapshot-last_path_outer": "test_2_y", + "oav-grid_snapshot-last_saved_path": "test_3_y", "smargon-omega": 0, "smargon-x": 0, "smargon-y": 0, @@ -62,16 +62,16 @@ class OavGridSnapshotTestEvents: "seq_num": 1, "uid": "29033ecf-e052-43dd-98af-c7cdd62e8174", "data": { - "oav_grid_snapshot_top_left_x": 50, - "oav_grid_snapshot_top_left_y": 0, - "oav_grid_snapshot_num_boxes_x": 40, - "oav_grid_snapshot_num_boxes_y": 10, - "oav_grid_snapshot_box_width": 0.1 * 1000 / 1.25, # size in pixels - "oav_grid_snapshot_last_path_full_overlay": "test_1_z", - "oav_grid_snapshot_last_path_outer": "test_2_z", - "oav_grid_snapshot_last_saved_path": "test_3_z", - "oav_grid_snapshot_microns_per_pixel_x": 1.25, - "oav_grid_snapshot_microns_per_pixel_y": 1.5, + "oav-grid_snapshot-top_left_x": 50, + "oav-grid_snapshot-top_left_y": 0, + "oav-grid_snapshot-num_boxes_x": 40, + "oav-grid_snapshot-num_boxes_y": 10, + "oav-grid_snapshot-box_width": 0.1 * 1000 / 1.25, # size in pixels + "oav-grid_snapshot-last_path_full_overlay": "test_1_z", + "oav-grid_snapshot-last_path_outer": "test_2_z", + "oav-grid_snapshot-last_saved_path": "test_3_z", + "oav-grid_snapshot-microns_per_pixel_x": 1.25, + "oav-grid_snapshot-microns_per_pixel_y": 1.5, "smargon-omega": -90, "smargon-x": 0, "smargon-y": 0, diff --git a/tests/unit_tests/hyperion/experiment_plans/conftest.py b/tests/unit_tests/hyperion/experiment_plans/conftest.py index 18e61be6b..316ea2856 100644 --- a/tests/unit_tests/hyperion/experiment_plans/conftest.py +++ b/tests/unit_tests/hyperion/experiment_plans/conftest.py @@ -8,7 +8,7 @@ from dodal.devices.backlight import Backlight from dodal.devices.detector.detector_motion import DetectorMotion from dodal.devices.fast_grid_scan import ZebraFastGridScan -from dodal.devices.oav.oav_detector import OAVConfig +from dodal.devices.oav.oav_detector import OAV, OAVConfig from dodal.devices.smargon import Smargon from dodal.devices.synchrotron import SynchrotronMode from dodal.devices.zocalo import ZocaloResults, ZocaloTrigger @@ -80,6 +80,7 @@ def grid_detect_devices( backlight: Backlight, detector_motion: DetectorMotion, smargon: Smargon, + oav: OAV, ) -> GridDetectThenXRayCentreComposite: return GridDetectThenXRayCentreComposite( aperture_scatterguard=aperture_scatterguard, @@ -89,7 +90,7 @@ def grid_detect_devices( eiger=MagicMock(), zebra_fast_grid_scan=MagicMock(), flux=MagicMock(), - oav=MagicMock(), + oav=oav, pin_tip_detection=MagicMock(), smargon=smargon, synchrotron=MagicMock(), diff --git a/tests/unit_tests/hyperion/experiment_plans/test_grid_detect_then_xray_centre_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_grid_detect_then_xray_centre_plan.py index aa91941cb..a933cda01 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_grid_detect_then_xray_centre_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_grid_detect_then_xray_centre_plan.py @@ -7,11 +7,9 @@ from bluesky.run_engine import RunEngine from bluesky.simulators import RunEngineSimulator, assert_message_and_return_remaining from bluesky.utils import Msg -from dodal.beamlines import i03 from dodal.devices.aperturescatterguard import ApertureValue from dodal.devices.backlight import BacklightPosition from dodal.devices.eiger import EigerDetector -from dodal.devices.oav.oav_detector import OAVConfig from dodal.devices.oav.oav_parameters import OAVParameters from dodal.devices.smargon import Smargon from ophyd_async.core import set_mock_value @@ -42,13 +40,13 @@ def _fake_grid_detection( grid_width_microns: float = 0, box_size_um: float = 0.0, ): - oav = i03.oav(fake_with_ophyd_sim=True) + oav = devices.oav set_mock_value(oav.grid_snapshot.box_width, 635) # first grid detection: x * y set_mock_value(oav.grid_snapshot.num_boxes_x, 10) set_mock_value(oav.grid_snapshot.num_boxes_y, 4) yield from bps.create(CONST.DESCRIPTORS.OAV_GRID_SNAPSHOT_TRIGGERED) - yield from bps.read(oav.grid_snapshot) # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809 + yield from bps.read(oav) # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809 yield from bps.read(devices.smargon) yield from bps.save() @@ -56,7 +54,7 @@ def _fake_grid_detection( set_mock_value(oav.grid_snapshot.num_boxes_x, 10) set_mock_value(oav.grid_snapshot.num_boxes_y, 1) yield from bps.create(CONST.DESCRIPTORS.OAV_GRID_SNAPSHOT_TRIGGERED) - yield from bps.read(oav.grid_snapshot) # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809 + yield from bps.read(oav) # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809 yield from bps.read(devices.smargon) yield from bps.save() @@ -78,9 +76,6 @@ def grid_detect_devices_with_oav_config_params( grid_detect_devices: GridDetectThenXRayCentreComposite, test_config_files: dict[str, str], ) -> GridDetectThenXRayCentreComposite: - grid_detect_devices.oav.parameters = OAVConfig( - test_config_files["zoom_params_file"], test_config_files["display_config"] - ).get_parameters() set_mock_value(grid_detect_devices.oav.zoom_controller.level, "7.5x") return grid_detect_devices diff --git a/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py index ebe60470d..100261c1c 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py @@ -45,7 +45,7 @@ def fake_devices( params = OAVConfig( test_config_files["zoom_params_file"], test_config_files["display_config"] ) - oav = i03.oav(fake_with_ophyd_sim=True, config=params) + oav = i03.oav(fake_with_ophyd_sim=True, params=params) set_mock_value(oav.zoom_controller.level, "5.0") pin_tip_detection = i03.pin_tip_detection(fake_with_ophyd_sim=True) @@ -261,31 +261,31 @@ def decorated(): assert_event( cb.activity_gated_event.mock_calls[0], # pyright: ignore { - "oav_grid_snapshot_top_left_x": 8, - "oav_grid_snapshot_top_left_y": -6, - "oav_grid_snapshot_num_boxes_x": 8, - "oav_grid_snapshot_num_boxes_y": 2, - "oav_grid_snapshot_box_width": 16, - "oav_grid_snapshot_microns_per_pixel_x": 1.25, - "oav_grid_snapshot_microns_per_pixel_y": 1.25, - "oav_grid_snapshot_last_path_full_overlay": "tmp/test_0_grid_overlay.png", - "oav_grid_snapshot_last_path_outer": "tmp/test_0_outer_overlay.png", - "oav_grid_snapshot_last_saved_path": "tmp/test_0.png", + "oav-grid_snapshot-top_left_x": 8, + "oav-grid_snapshot-top_left_y": -6, + "oav-grid_snapshot-num_boxes_x": 8, + "oav-grid_snapshot-num_boxes_y": 2, + "oav-grid_snapshot-box_width": 16, + "oav-grid_snapshot-microns_per_pixel_x": 1.25, + "oav-grid_snapshot-microns_per_pixel_y": 1.25, + "oav-grid_snapshot-last_path_full_overlay": "tmp/test_0_grid_overlay.png", + "oav-grid_snapshot-last_path_outer": "tmp/test_0_outer_overlay.png", + "oav-grid_snapshot-last_saved_path": "tmp/test_0.png", }, ) assert_event( cb.activity_gated_event.mock_calls[1], # pyright:ignore { - "oav_grid_snapshot_top_left_x": 8, - "oav_grid_snapshot_top_left_y": 2, - "oav_grid_snapshot_num_boxes_x": 8, - "oav_grid_snapshot_num_boxes_y": 1, - "oav_grid_snapshot_box_width": 16, - "oav_grid_snapshot_microns_per_pixel_x": 1.25, - "oav_grid_snapshot_microns_per_pixel_y": 1.25, - "oav_grid_snapshot_last_path_full_overlay": "tmp/test_90_grid_overlay.png", - "oav_grid_snapshot_last_path_outer": "tmp/test_90_outer_overlay.png", - "oav_grid_snapshot_last_saved_path": "tmp/test_90.png", + "oav-grid_snapshot-top_left_x": 8, + "oav-grid_snapshot-top_left_y": 2, + "oav-grid_snapshot-num_boxes_x": 8, + "oav-grid_snapshot-num_boxes_y": 1, + "oav-grid_snapshot-box_width": 16, + "oav-grid_snapshot-microns_per_pixel_x": 1.25, + "oav-grid_snapshot-microns_per_pixel_y": 1.25, + "oav-grid_snapshot-last_path_full_overlay": "tmp/test_90_grid_overlay.png", + "oav-grid_snapshot-last_path_outer": "tmp/test_90_outer_overlay.png", + "oav-grid_snapshot-last_saved_path": "tmp/test_90.png", }, ) diff --git a/tests/unit_tests/hyperion/external_interaction/callbacks/robot_load/test_robot_load_ispyb_callback.py b/tests/unit_tests/hyperion/external_interaction/callbacks/robot_load/test_robot_load_ispyb_callback.py index 72167953c..7b6ee86a3 100644 --- a/tests/unit_tests/hyperion/external_interaction/callbacks/robot_load/test_robot_load_ispyb_callback.py +++ b/tests/unit_tests/hyperion/external_interaction/callbacks/robot_load/test_robot_load_ispyb_callback.py @@ -119,7 +119,7 @@ def test_given_plan_reads_barcode_then_data_put_in_ispyb( RE.subscribe(RobotLoadISPyBCallback()) start_load.return_value = ACTION_ID - oav.snapshot.last_saved_path.put("test_oav_snapshot") # type: ignore + set_mock_value(oav.snapshot.last_saved_path, "test_oav_snapshot") set_mock_value(webcam.last_saved_path, "test_webcam_snapshot") @bpp.run_decorator(md=metadata) From 82a0f81bbb6328555dc7a86bae5da11049c0fcdc Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Wed, 30 Oct 2024 17:50:00 +0000 Subject: [PATCH 11/18] Try to fix some more tests --- .../experiment_plans/oav_grid_detection_plan.py | 13 ++++++++----- tests/unit_tests/hyperion/conftest.py | 8 ++++---- .../experiment_plans/test_grid_detection_plan.py | 6 ++++++ .../experiment_plans/test_oav_snapshot_plan.py | 1 - .../test_robot_load_and_change_energy.py | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py b/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py index 5cc385e38..58458b0c3 100644 --- a/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py +++ b/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py @@ -90,12 +90,15 @@ def grid_detection_plan( LOGGER.info("OAV Centring: Camera set up") - assert isinstance(oav.microns_per_pixel_x, float) - box_size_x_pixels = box_size_um / oav.microns_per_pixel_x - assert isinstance(oav.microns_per_pixel_y, float) - box_size_y_pixels = box_size_um / oav.microns_per_pixel_y + microns_per_pixel_x = yield from bps.rd(oav.microns_per_pixel_x) + microns_per_pixel_y = yield from bps.rd(oav.microns_per_pixel_y) - grid_width_pixels = int(grid_width_microns / oav.microns_per_pixel_x) + assert isinstance(microns_per_pixel_x, float) + box_size_x_pixels = box_size_um / microns_per_pixel_x + assert isinstance(microns_per_pixel_y, float) + box_size_y_pixels = box_size_um / microns_per_pixel_y + + grid_width_pixels = int(grid_width_microns / microns_per_pixel_x) # The FGS uses -90 so we need to match it for angle in [0, -90]: diff --git a/tests/unit_tests/hyperion/conftest.py b/tests/unit_tests/hyperion/conftest.py index 14bd5ea2a..2a6fe242e 100644 --- a/tests/unit_tests/hyperion/conftest.py +++ b/tests/unit_tests/hyperion/conftest.py @@ -43,8 +43,8 @@ class OavGridSnapshotTestEvents: "oav-grid_snapshot-top_left_y": 100, "oav-grid_snapshot-num_boxes_x": 40, "oav-grid_snapshot-num_boxes_y": 20, - "oav-grid_snapshot-microns_per_pixel_x": 1.25, - "oav-grid_snapshot-microns_per_pixel_y": 1.5, + "oav-microns_per_pixel_x": 1.25, + "oav-microns_per_pixel_y": 1.5, "oav-grid_snapshot-box_width": 0.1 * 1000 / 1.25, # size in pixels "oav-grid_snapshot-last_path_full_overlay": "test_1_y", "oav-grid_snapshot-last_path_outer": "test_2_y", @@ -70,8 +70,8 @@ class OavGridSnapshotTestEvents: "oav-grid_snapshot-last_path_full_overlay": "test_1_z", "oav-grid_snapshot-last_path_outer": "test_2_z", "oav-grid_snapshot-last_saved_path": "test_3_z", - "oav-grid_snapshot-microns_per_pixel_x": 1.25, - "oav-grid_snapshot-microns_per_pixel_y": 1.5, + "oav-microns_per_pixel_x": 1.25, + "oav-microns_per_pixel_y": 1.5, "smargon-omega": -90, "smargon-x": 0, "smargon-y": 0, diff --git a/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py index 100261c1c..c5e189656 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py @@ -46,7 +46,13 @@ def fake_devices( test_config_files["zoom_params_file"], test_config_files["display_config"] ) oav = i03.oav(fake_with_ophyd_sim=True, params=params) + zoom_levels_list = ["1.0x", "3.0x", "5.0x", "7.5x", "10.0x", "15.0x"] + oav.zoom_controller._get_allowed_zoom_levels = AsyncMock( + return_value=zoom_levels_list + ) set_mock_value(oav.zoom_controller.level, "5.0") + set_mock_value(oav.grid_snapshot.x_size, 1024) + set_mock_value(oav.grid_snapshot.y_size, 768) pin_tip_detection = i03.pin_tip_detection(fake_with_ophyd_sim=True) pin_tip_detection._get_tip_and_edge_data = AsyncMock( diff --git a/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py index ab8de42dc..68d2ffbd5 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py @@ -41,7 +41,6 @@ class CompositeImpl(OavSnapshotComposite): @pytest.fixture def oav_snapshot_composite(smargon, oav, aperture_scatterguard, backlight): - oav.zoom_controller.fvst.sim_put("5.0x") return CompositeImpl( smargon=smargon, oav=oav, diff --git a/tests/unit_tests/hyperion/experiment_plans/test_robot_load_and_change_energy.py b/tests/unit_tests/hyperion/experiment_plans/test_robot_load_and_change_energy.py index 71507b5b3..2c150d44c 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_robot_load_and_change_energy.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_robot_load_and_change_energy.py @@ -254,7 +254,7 @@ async def test_when_take_snapshots_called_then_filename_and_directory_set_and_de RE(take_robot_snapshots(oav, webcam, Path(TEST_DIRECTORY))) oav.snapshot.trigger.assert_called_once() - assert await oav.snapshot.filename.get_value() == "TIME_oav_snapshot_after_load" + assert await oav.snapshot.filename.get_value() == "TIME_oav-snapshot_after_load" assert await oav.snapshot.directory.get_value() == TEST_DIRECTORY webcam.trigger.assert_called_once() From 310e5a6992a3af949ca11871c03e3db19124b46f Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Fri, 1 Nov 2024 15:04:41 +0000 Subject: [PATCH 12/18] Let's see what fails now --- .../callbacks/grid_detection_callback.py | 4 ++-- .../callbacks/robot_load/ispyb_callback.py | 2 +- .../callbacks/rotation/ispyb_callback.py | 2 +- tests/unit_tests/hyperion/conftest.py | 12 ++++++++---- .../experiment_plans/test_oav_snapshot_plan.py | 6 +++--- .../experiment_plans/test_pin_tip_centring.py | 14 ++++---------- .../external_interaction/callbacks/conftest.py | 2 +- 7 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py b/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py index 258e0aa4c..18c7d42d5 100644 --- a/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py +++ b/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py @@ -52,8 +52,8 @@ def event(self, doc: Event): microns_per_pixel_x = data["oav-microns_per_pixel_x"] microns_per_pixel_y = data["oav-microns_per_pixel_y"] - beam_x = data["oav-snapshot-beam_centre_i"] - beam_y = data["oav-snapshot-beam_centre_j"] + beam_x = data["oav-beam_centre_i"] + beam_y = data["oav-beam_centre_j"] position_grid_start = calculate_x_y_z_of_pixel( current_xyz, diff --git a/src/mx_bluesky/hyperion/external_interaction/callbacks/robot_load/ispyb_callback.py b/src/mx_bluesky/hyperion/external_interaction/callbacks/robot_load/ispyb_callback.py index e2cc8866a..dea3d5af4 100644 --- a/src/mx_bluesky/hyperion/external_interaction/callbacks/robot_load/ispyb_callback.py +++ b/src/mx_bluesky/hyperion/external_interaction/callbacks/robot_load/ispyb_callback.py @@ -62,7 +62,7 @@ def activity_gated_event(self, doc: Event) -> Event | None: self.action_id is not None ), "ISPyB Robot load callback event called unexpectedly" barcode = doc["data"]["robot-barcode"] - oav_snapshot = doc["data"]["oav_snapshot_last_saved_path"] + oav_snapshot = doc["data"]["oav-snapshot-last_saved_path"] webcam_snapshot = doc["data"]["webcam-last_saved_path"] # I03 uses webcam/oav snapshots in place of before/after snapshots self.expeye.update_barcode_and_snapshots( diff --git a/src/mx_bluesky/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py b/src/mx_bluesky/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py index 027b67115..feeac6463 100644 --- a/src/mx_bluesky/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py +++ b/src/mx_bluesky/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py @@ -158,7 +158,7 @@ def _handle_oav_rotation_snapshot_triggered(self, doc) -> Sequence[ScanDataInfo] data_collection_info = DataCollectionInfo( **{ f"xtal_snapshot{self._oav_snapshot_event_idx}": data.get( - "oav_snapshot_last_saved_path" + "oav-snapshot-last_saved_path" ) } ) diff --git a/tests/unit_tests/hyperion/conftest.py b/tests/unit_tests/hyperion/conftest.py index 2a6fe242e..21e44c9f0 100644 --- a/tests/unit_tests/hyperion/conftest.py +++ b/tests/unit_tests/hyperion/conftest.py @@ -43,8 +43,10 @@ class OavGridSnapshotTestEvents: "oav-grid_snapshot-top_left_y": 100, "oav-grid_snapshot-num_boxes_x": 40, "oav-grid_snapshot-num_boxes_y": 20, - "oav-microns_per_pixel_x": 1.25, - "oav-microns_per_pixel_y": 1.5, + "oav-microns_per_pixel_x": 1.58, + "oav-microns_per_pixel_y": 1.58, + "oa-beam_centre_i": 517, + "oav-beam_centre_j": 350, "oav-grid_snapshot-box_width": 0.1 * 1000 / 1.25, # size in pixels "oav-grid_snapshot-last_path_full_overlay": "test_1_y", "oav-grid_snapshot-last_path_outer": "test_2_y", @@ -70,8 +72,10 @@ class OavGridSnapshotTestEvents: "oav-grid_snapshot-last_path_full_overlay": "test_1_z", "oav-grid_snapshot-last_path_outer": "test_2_z", "oav-grid_snapshot-last_saved_path": "test_3_z", - "oav-microns_per_pixel_x": 1.25, - "oav-microns_per_pixel_y": 1.5, + "oav-microns_per_pixel_x": 1.58, + "oav-microns_per_pixel_y": 1.58, + "oav-beam_centre_i": 517, + "oav-beam_centre_j": 350, "smargon-omega": -90, "smargon-x": 0, "smargon-y": 0, diff --git a/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py index 68d2ffbd5..1dd9f286d 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py @@ -95,7 +95,7 @@ def test_oav_snapshot_plan_issues_rotations_and_generates_events( msgs = assert_message_and_return_remaining( msgs, lambda msg: msg.command == "set" - and msg.obj.name == "oav_snapshot_directory" + and msg.obj.name == "oav-snapshot-directory" and msg.args[0] == "/tmp/my_snapshots", ) for expected in [ @@ -114,13 +114,13 @@ def test_oav_snapshot_plan_issues_rotations_and_generates_events( msgs = assert_message_and_return_remaining( msgs, lambda msg: msg.command == "set" - and msg.obj.name == "oav_snapshot_filename" + and msg.obj.name == "oav-snapshot-filename" and msg.args[0] == expected["filename"], ) msgs = assert_message_and_return_remaining( msgs, lambda msg: msg.command == "trigger" - and msg.obj.name == "oav_snapshot" + and msg.obj.name == "oav-snapshot" and msg.kwargs["group"] is None, ) msgs = assert_message_and_return_remaining( diff --git a/tests/unit_tests/hyperion/experiment_plans/test_pin_tip_centring.py b/tests/unit_tests/hyperion/experiment_plans/test_pin_tip_centring.py index 8634df82d..4040dd015 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_pin_tip_centring.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_pin_tip_centring.py @@ -5,7 +5,7 @@ import pytest from bluesky.plan_stubs import null from bluesky.run_engine import RunEngine, RunEngineResult -from dodal.devices.oav.oav_detector import OAV, OAVConfig +from dodal.devices.oav.oav_detector import OAV from dodal.devices.oav.pin_image_recognition import PinTipDetection from dodal.devices.oav.pin_image_recognition.utils import SampleLocation from dodal.devices.smargon import Smargon @@ -257,21 +257,15 @@ async def test_when_pin_tip_centre_plan_called_then_expected_plans_called( mock_setup_oav, get_move: MagicMock, smargon: Smargon, + oav: OAV, test_config_files: dict[str, str], RE: RunEngine, ): set_mock_value(smargon.omega.user_readback, 0) - mock_oav: OAV = MagicMock(spec=OAV) - mock_oav.parameters = OAVConfig( - test_config_files["zoom_params_file"], test_config_files["display_config"] - ).get_parameters() - mock_oav.zoom_controller = MagicMock() - mock_oav.zoom_controller.level = MagicMock(return_value="1.0") - mock_oav.microns_per_pixel_x = MagicMock(return_value=2.87) - mock_oav.microns_per_pixel_y = MagicMock(return_value=2.87) + set_mock_value(oav.zoom_controller.level, "1.0") composite = PinTipCentringComposite( backlight=MagicMock(), - oav=mock_oav, + oav=oav, smargon=smargon, pin_tip_detection=MagicMock(), ) diff --git a/tests/unit_tests/hyperion/external_interaction/callbacks/conftest.py b/tests/unit_tests/hyperion/external_interaction/callbacks/conftest.py index c61ae9305..69caacb1e 100644 --- a/tests/unit_tests/hyperion/external_interaction/callbacks/conftest.py +++ b/tests/unit_tests/hyperion/external_interaction/callbacks/conftest.py @@ -160,7 +160,7 @@ class TestData(OavGridSnapshotTestEvents): "timestamps": {}, "seq_num": 1, "uid": "32d7c25c-c310-4292-ac78-36ce6509be3d", - "data": {"oav_snapshot_last_saved_path": "snapshot_0"}, + "data": {"oav-snapshot-last_saved_path": "snapshot_0"}, } test_event_document_pre_data_collection: Event = { "descriptor": "bd45c2e5-2b85-4280-95d7-a9a15800a78b", From a3a1ab66a492b817ec1e0b0333fd3d592d2e2d42 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Fri, 1 Nov 2024 16:51:32 +0000 Subject: [PATCH 13/18] Fix a couple more --- pyproject.toml | 2 +- .../oav_grid_detection_plan.py | 2 - .../callbacks/grid_detection_callback.py | 4 +- .../test_grid_detection_plan.py | 77 +++++++++++-------- 4 files changed, 46 insertions(+), 39 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2228f511f..d5de8504b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ dependencies = [ "ophyd == 1.9.0", "ophyd-async >= 0.3a5", "bluesky >= 1.13.0a4", - "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@eeb8daf36189c9bd4f797ef52153a122ef1ba783", + "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@7f4482e78f0c73a06f4f745bac8c28a4183c9170", ] diff --git a/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py b/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py index 58458b0c3..1666fc6ea 100644 --- a/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py +++ b/src/mx_bluesky/hyperion/experiment_plans/oav_grid_detection_plan.py @@ -93,9 +93,7 @@ def grid_detection_plan( microns_per_pixel_x = yield from bps.rd(oav.microns_per_pixel_x) microns_per_pixel_y = yield from bps.rd(oav.microns_per_pixel_y) - assert isinstance(microns_per_pixel_x, float) box_size_x_pixels = box_size_um / microns_per_pixel_x - assert isinstance(microns_per_pixel_y, float) box_size_y_pixels = box_size_um / microns_per_pixel_y grid_width_pixels = int(grid_width_microns / microns_per_pixel_x) diff --git a/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py b/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py index 18c7d42d5..258e0aa4c 100644 --- a/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py +++ b/src/mx_bluesky/hyperion/external_interaction/callbacks/grid_detection_callback.py @@ -52,8 +52,8 @@ def event(self, doc: Event): microns_per_pixel_x = data["oav-microns_per_pixel_x"] microns_per_pixel_y = data["oav-microns_per_pixel_y"] - beam_x = data["oav-beam_centre_i"] - beam_y = data["oav-beam_centre_j"] + beam_x = data["oav-snapshot-beam_centre_i"] + beam_y = data["oav-snapshot-beam_centre_j"] position_grid_start = calculate_x_y_z_of_pixel( current_xyz, diff --git a/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py index c5e189656..faf6599a9 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py @@ -5,7 +5,7 @@ import numpy as np import pytest from bluesky.run_engine import RunEngine -from bluesky.simulators import RunEngineSimulator +from bluesky.simulators import RunEngineSimulator, assert_message_and_return_remaining from bluesky.utils import Msg from dodal.beamlines import i03 from dodal.devices.backlight import Backlight @@ -50,7 +50,7 @@ def fake_devices( oav.zoom_controller._get_allowed_zoom_levels = AsyncMock( return_value=zoom_levels_list ) - set_mock_value(oav.zoom_controller.level, "5.0") + set_mock_value(oav.zoom_controller.level, "5.0x") set_mock_value(oav.grid_snapshot.x_size, 1024) set_mock_value(oav.grid_snapshot.y_size, 768) @@ -66,15 +66,19 @@ def fake_devices( with ( patch( - "dodal.devices.areadetector.plugins.MJPG.ClientSession" - ) as patch_requests, + "dodal.devices.areadetector.plugins.MJPG.ClientSession.get", autospec=True + ) as patch_get, patch("dodal.devices.areadetector.plugins.MJPG.Image") as mock_image_class, + patch( + "dodal.devices.oav.snapshots.snapshot_with_grid.asyncio_save_image" + ) as mock_save_image, ): - patch_get = patch_requests.get patch_get.return_value.__aenter__.return_value = (mock_response := AsyncMock()) + mock_response.ok = True mock_response.read.return_value = b"" - mock_image = MagicMock() - mock_image_class.open.return_value.__enter__.return_value = mock_image + mock_image_class.open.return_value.__aenter__.return_value = b"" + + oav.grid_snapshot._save_image = AsyncMock() composite = OavGridDetectionComposite( backlight=backlight, @@ -83,7 +87,7 @@ def fake_devices( pin_tip_detection=pin_tip_detection, ) - yield composite, mock_image + yield composite, mock_save_image @patch( @@ -97,7 +101,7 @@ def test_grid_detection_plan_runs_and_triggers_snapshots( fake_devices: tuple[OavGridDetectionComposite, MagicMock], ): params = OAVParameters("loopCentring", test_config_files["oav_config_json"]) - composite, image = fake_devices + composite, image_save = fake_devices @bpp.run_decorator() def decorated(): @@ -110,7 +114,8 @@ def decorated(): ) RE(decorated()) - assert image.save.call_count == 6 + assert image_save.await_count == 4 + assert composite.oav.grid_snapshot._save_image.call_count == 2 @patch( @@ -162,11 +167,6 @@ async def test_given_when_grid_detect_then_start_position_as_expected( params = OAVParameters("loopCentring", test_config_files["oav_config_json"]) box_size_um = 0.2 composite, _ = fake_devices - # FIXME This won't work - await composite.oav.microns_per_pixel_x._backend.put(0.1) - await composite.oav.microns_per_pixel_y._backend.put(0.1) - await composite.oav.beam_centre_i._backend.put(4) - await composite.oav.beam_centre_j._backend.put(4) microns_per_pixel_y = await composite.oav.microns_per_pixel_y.get_value() box_size_y_pixels = box_size_um / microns_per_pixel_y @@ -188,12 +188,12 @@ def decorated(): gridscan_params = grid_param_cb.get_grid_parameters() - assert gridscan_params["x_start_um"] == pytest.approx(0.0005) + assert gridscan_params["x_start_um"] == pytest.approx(-0.804, abs=1e-3) assert gridscan_params["y_start_um"] == pytest.approx( - -0.0001 - - ((box_size_y_pixels / 2) * microns_per_pixel_y * 1e-3) # microns to mm + -0.55 - ((box_size_y_pixels / 2) * microns_per_pixel_y * 1e-3), + abs=1e-3, # microns to mm ) - assert gridscan_params["z_start_um"] == pytest.approx(-0.0001) + assert gridscan_params["z_start_um"] == pytest.approx(-0.55, abs=1e-3) @patch( @@ -242,9 +242,6 @@ async def test_when_grid_detection_plan_run_then_ispyb_callback_gets_correct_val ): params = OAVParameters("loopCentring", test_config_files["oav_config_json"]) composite, _ = fake_devices - # FIXME This won't work - await composite.oav.microns_per_pixel_x._backend.put(1.25) - await composite.oav.microns_per_pixel_y._backend.put(1.25) cb = GridscanISPyBCallback() RE.subscribe(cb) @@ -268,12 +265,12 @@ def decorated(): cb.activity_gated_event.mock_calls[0], # pyright: ignore { "oav-grid_snapshot-top_left_x": 8, - "oav-grid_snapshot-top_left_y": -6, - "oav-grid_snapshot-num_boxes_x": 8, + "oav-grid_snapshot-top_left_y": pytest.approx(-4, abs=1), + "oav-grid_snapshot-num_boxes_x": 9, "oav-grid_snapshot-num_boxes_y": 2, - "oav-grid_snapshot-box_width": 16, - "oav-grid_snapshot-microns_per_pixel_x": 1.25, - "oav-grid_snapshot-microns_per_pixel_y": 1.25, + "oav-grid_snapshot-box_width": pytest.approx(12, abs=1), + "oav-microns_per_pixel_x": 1.58, + "oav-microns_per_pixel_y": 1.58, "oav-grid_snapshot-last_path_full_overlay": "tmp/test_0_grid_overlay.png", "oav-grid_snapshot-last_path_outer": "tmp/test_0_outer_overlay.png", "oav-grid_snapshot-last_saved_path": "tmp/test_0.png", @@ -284,11 +281,11 @@ def decorated(): { "oav-grid_snapshot-top_left_x": 8, "oav-grid_snapshot-top_left_y": 2, - "oav-grid_snapshot-num_boxes_x": 8, + "oav-grid_snapshot-num_boxes_x": 9, "oav-grid_snapshot-num_boxes_y": 1, - "oav-grid_snapshot-box_width": 16, - "oav-grid_snapshot-microns_per_pixel_x": 1.25, - "oav-grid_snapshot-microns_per_pixel_y": 1.25, + "oav-grid_snapshot-box_width": pytest.approx(12, abs=1), + "oav-microns_per_pixel_x": 1.58, + "oav-microns_per_pixel_y": 1.58, "oav-grid_snapshot-last_path_full_overlay": "tmp/test_90_grid_overlay.png", "oav-grid_snapshot-last_path_outer": "tmp/test_90_outer_overlay.png", "oav-grid_snapshot-last_saved_path": "tmp/test_90.png", @@ -398,7 +395,9 @@ def record_set(msg: Msg): sim_run_engine.add_handler("set", record_set) sim_run_engine.add_handler("read", handle_read) - sim_run_engine.simulate_plan( + sim_run_engine.add_read_handler_for(composite.oav.microns_per_pixel_x, 1.58) + sim_run_engine.add_read_handler_for(composite.oav.microns_per_pixel_y, 1.58) + msgs = sim_run_engine.simulate_plan( grid_detection_plan( composite, parameters=params, @@ -418,8 +417,18 @@ def record_set(msg: Msg): else: fake_logger.debug.assert_not_called() - assert abs_sets["grid_snapshot.top_left_y"][0] == expected_min_y - assert abs_sets["grid_snapshot.num_boxes_y"][0] == expected_y_steps + msgs = assert_message_and_return_remaining( + msgs, + lambda msg: msg.command == "set" + and msg.obj.name == "oav-grid_snapshot-top_left_y" + and msg.args == (expected_min_y,), + ) + msgs = assert_message_and_return_remaining( + msgs, + lambda msg: msg.command == "set" + and msg.obj.name == "oav-grid_snapshot-num_boxes_y" + and msg.args == (expected_y_steps,), + ) @pytest.mark.parametrize( From e52d709f24623ddba8f40da226df629fdf7d155b Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Fri, 1 Nov 2024 17:25:39 +0000 Subject: [PATCH 14/18] Just a handful left --- .../callbacks/xray_centre/ispyb_callback.py | 4 ++-- src/mx_bluesky/hyperion/utils/validation.py | 6 +++--- tests/unit_tests/hyperion/conftest.py | 8 ++++---- .../unit_tests/hyperion/experiment_plans/conftest.py | 2 +- .../experiment_plans/test_grid_detection_plan.py | 6 +++--- .../test_load_centre_collect_full_plan.py | 5 +++++ .../experiment_plans/test_oav_snapshot_plan.py | 12 ++++++------ .../experiment_plans/test_rotation_scan_plan.py | 4 ++-- 8 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/mx_bluesky/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py b/src/mx_bluesky/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py index 1ccec4dfa..69d218bfc 100644 --- a/src/mx_bluesky/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py +++ b/src/mx_bluesky/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py @@ -188,8 +188,8 @@ def _handle_oav_grid_snapshot_triggered(self, doc) -> Sequence[ScanDataInfo]: * data["oav-grid_snapshot-num_boxes_y"] ), ) - microns_per_pixel_x = data["oav-grid_snapshot-microns_per_pixel_x"] - microns_per_pixel_y = data["oav-grid_snapshot-microns_per_pixel_y"] + microns_per_pixel_x = data["oav-microns_per_pixel_x"] + microns_per_pixel_y = data["oav-microns_per_pixel_y"] data_collection_grid_info = DataCollectionGridInfo( dx_in_mm=data["oav-grid_snapshot-box_width"] * microns_per_pixel_x / 1000, dy_in_mm=data["oav-grid_snapshot-box_width"] * microns_per_pixel_y / 1000, diff --git a/src/mx_bluesky/hyperion/utils/validation.py b/src/mx_bluesky/hyperion/utils/validation.py index 67de213a9..8e02a714d 100644 --- a/src/mx_bluesky/hyperion/utils/validation.py +++ b/src/mx_bluesky/hyperion/utils/validation.py @@ -23,8 +23,8 @@ from mx_bluesky.hyperion.parameters.constants import CONST from mx_bluesky.hyperion.parameters.rotation import RotationScan -DISPLAY_CONFIGURATION = "tests/devices/unit_tests/test_display.configuration" -ZOOM_LEVELS_XML = "tests/devices/unit_tests/test_jCameraManZoomLevels.xml" +DISPLAY_CONFIGURATION = "tests/test_data/test_display.configuration" +ZOOM_LEVELS_XML = "tests/test_data/test_jCameraManZoomLevels.xml" TEST_DATA_DIRECTORY = Path("tests/test_data/nexus_files/rotation") TEST_METAFILE = "ins_8_5_meta.h5.gz" FAKE_DATAFILE = "../fake_data.h5" @@ -94,7 +94,7 @@ def fake_create_rotation_devices(): robot = i03.robot(fake_with_ophyd_sim=True) oav = i03.oav( fake_with_ophyd_sim=True, - config=OAVConfig( + params=OAVConfig( zoom_params_file=ZOOM_LEVELS_XML, display_config_file=DISPLAY_CONFIGURATION ), ) diff --git a/tests/unit_tests/hyperion/conftest.py b/tests/unit_tests/hyperion/conftest.py index 21e44c9f0..722dfa6b5 100644 --- a/tests/unit_tests/hyperion/conftest.py +++ b/tests/unit_tests/hyperion/conftest.py @@ -45,8 +45,8 @@ class OavGridSnapshotTestEvents: "oav-grid_snapshot-num_boxes_y": 20, "oav-microns_per_pixel_x": 1.58, "oav-microns_per_pixel_y": 1.58, - "oa-beam_centre_i": 517, - "oav-beam_centre_j": 350, + "oav-snapshot-beam_centre_i": 517, + "oav-snapshot-beam_centre_j": 350, "oav-grid_snapshot-box_width": 0.1 * 1000 / 1.25, # size in pixels "oav-grid_snapshot-last_path_full_overlay": "test_1_y", "oav-grid_snapshot-last_path_outer": "test_2_y", @@ -74,8 +74,8 @@ class OavGridSnapshotTestEvents: "oav-grid_snapshot-last_saved_path": "test_3_z", "oav-microns_per_pixel_x": 1.58, "oav-microns_per_pixel_y": 1.58, - "oav-beam_centre_i": 517, - "oav-beam_centre_j": 350, + "oav-snapshot-beam_centre_i": 517, + "oav-snapshot-beam_centre_j": 350, "smargon-omega": -90, "smargon-x": 0, "smargon-y": 0, diff --git a/tests/unit_tests/hyperion/experiment_plans/conftest.py b/tests/unit_tests/hyperion/experiment_plans/conftest.py index 316ea2856..aaaa36a54 100644 --- a/tests/unit_tests/hyperion/experiment_plans/conftest.py +++ b/tests/unit_tests/hyperion/experiment_plans/conftest.py @@ -241,7 +241,7 @@ def simple_beamline( magic_mock.dcm = dcm magic_mock.synchrotron = synchrotron magic_mock.eiger = eiger - oav.zoom_controller.set("7.5x") + oav.zoom_controller.level.set("7.5x") oav.parameters = OAVConfig( test_config_files["zoom_params_file"], test_config_files["display_config"] ).get_parameters() diff --git a/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py index faf6599a9..127c8375d 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_grid_detection_plan.py @@ -78,8 +78,6 @@ def fake_devices( mock_response.read.return_value = b"" mock_image_class.open.return_value.__aenter__.return_value = b"" - oav.grid_snapshot._save_image = AsyncMock() - composite = OavGridDetectionComposite( backlight=backlight, oav=oav, @@ -103,6 +101,8 @@ def test_grid_detection_plan_runs_and_triggers_snapshots( params = OAVParameters("loopCentring", test_config_files["oav_config_json"]) composite, image_save = fake_devices + composite.oav.grid_snapshot._save_image = (mock_save := AsyncMock()) + @bpp.run_decorator() def decorated(): yield from grid_detection_plan( @@ -115,7 +115,7 @@ def decorated(): RE(decorated()) assert image_save.await_count == 4 - assert composite.oav.grid_snapshot._save_image.call_count == 2 + assert mock_save.call_count == 2 @patch( diff --git a/tests/unit_tests/hyperion/experiment_plans/test_load_centre_collect_full_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_load_centre_collect_full_plan.py index 429343b42..6c7c163f3 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_load_centre_collect_full_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_load_centre_collect_full_plan.py @@ -190,6 +190,8 @@ def test_load_centre_collect_full_plan_skips_collect_if_pin_tip_not_found( sim_run_engine.add_read_handler_for( composite.pin_tip_detection.triggered_tip, PinTipDetection.INVALID_POSITION ) + sim_run_engine.add_read_handler_for(composite.oav.microns_per_pixel_x, 1.58) + sim_run_engine.add_read_handler_for(composite.oav.microns_per_pixel_y, 1.58) with pytest.raises(WarningException, match="Pin tip centring failed"): sim_run_engine.simulate_plan( @@ -217,6 +219,9 @@ def test_load_centre_collect_full_plan_skips_collect_if_no_diffraction( sim_run_engine, grid_detection_callback_with_detected_grid, ): + sim_run_engine.add_read_handler_for(composite.oav.microns_per_pixel_x, 1.58) + sim_run_engine.add_read_handler_for(composite.oav.microns_per_pixel_y, 1.58) + with pytest.raises(CrystalNotFoundException): sim_run_engine.simulate_plan( load_centre_collect_full_plan( diff --git a/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py index 1dd9f286d..ac38bfce2 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_oav_snapshot_plan.py @@ -65,31 +65,31 @@ def test_oav_snapshot_plan_issues_rotations_and_generates_events( msgs = assert_message_and_return_remaining( msgs, lambda msg: msg.command == "set" - and msg.obj.name == "oav_cam_color_mode" + and msg.obj.name == "oav-cam-color_mode" and msg.args[0] == ColorMode.RGB1, ) msgs = assert_message_and_return_remaining( msgs, lambda msg: msg.command == "set" - and msg.obj.name == "oav_cam_acquire_period" + and msg.obj.name == "oav-cam-acquire_period" and msg.args[0] == 0.05, ) msgs = assert_message_and_return_remaining( msgs, lambda msg: msg.command == "set" - and msg.obj.name == "oav_cam_acquire_time" + and msg.obj.name == "oav-cam-acquire_time" and msg.args[0] == 0.075, ) msgs = assert_message_and_return_remaining( msgs, lambda msg: msg.command == "set" - and msg.obj.name == "oav_cam_gain" + and msg.obj.name == "oav-cam-gain" and msg.args[0] == 1, ) msgs = assert_message_and_return_remaining( msgs, lambda msg: msg.command == "set" - and msg.obj.name == "oav_zoom_controller" + and msg.obj.name == "oav-zoom_controller" and msg.args[0] == "5.0x", ) msgs = assert_message_and_return_remaining( @@ -134,7 +134,7 @@ def test_oav_snapshot_plan_issues_rotations_and_generates_events( == DocDescriptorNames.OAV_ROTATION_SNAPSHOT_TRIGGERED, ) msgs = assert_message_and_return_remaining( - msgs, lambda msg: msg.command == "read" and msg.obj.name == "oav_snapshot" + msgs, lambda msg: msg.command == "read" and msg.obj.name == "oav-snapshot" ) msgs = assert_message_and_return_remaining( msgs, lambda msg: msg.command == "save" diff --git a/tests/unit_tests/hyperion/experiment_plans/test_rotation_scan_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_rotation_scan_plan.py index a266f439c..9bb6a35ef 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_rotation_scan_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_rotation_scan_plan.py @@ -518,7 +518,7 @@ def test_rotation_snapshot_setup_called_to_move_backlight_in_aperture_out_before and msg.kwargs["group"] == CONST.WAIT.READY_FOR_OAV, ) msgs = assert_message_and_return_remaining( - msgs, lambda msg: msg.command == "trigger" and msg.obj.name == "oav_snapshot" + msgs, lambda msg: msg.command == "trigger" and msg.obj.name == "oav-snapshot" ) @@ -629,7 +629,7 @@ def test_rotation_scan_arms_detector_and_takes_snapshots_whilst_arming( and msg.kwargs["group"] == CONST.WAIT.ROTATION_READY_FOR_DC, ) msgs = assert_message_and_return_remaining( - msgs, lambda msg: msg.command == "trigger" and msg.obj.name == "oav_snapshot" + msgs, lambda msg: msg.command == "trigger" and msg.obj.name == "oav-snapshot" ) msgs = assert_message_and_return_remaining( msgs, From 725901e7991425fb46042e2dd5ed8fb75349020b Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Mon, 4 Nov 2024 09:41:18 +0000 Subject: [PATCH 15/18] Fix mock oav in simple_beamline --- tests/unit_tests/hyperion/experiment_plans/conftest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/hyperion/experiment_plans/conftest.py b/tests/unit_tests/hyperion/experiment_plans/conftest.py index aaaa36a54..bbc4605ad 100644 --- a/tests/unit_tests/hyperion/experiment_plans/conftest.py +++ b/tests/unit_tests/hyperion/experiment_plans/conftest.py @@ -241,7 +241,7 @@ def simple_beamline( magic_mock.dcm = dcm magic_mock.synchrotron = synchrotron magic_mock.eiger = eiger - oav.zoom_controller.level.set("7.5x") + oav.zoom_controller.level = MagicMock(return_value="7.5x") oav.parameters = OAVConfig( test_config_files["zoom_params_file"], test_config_files["display_config"] ).get_parameters() From c960e766f2756eff0ef8ef943a2494f131c48c42 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Mon, 4 Nov 2024 10:18:09 +0000 Subject: [PATCH 16/18] Finish fixing tests --- .../callbacks/rotation/test_ispyb_callback.py | 2 +- .../xray_centre/test_ispyb_callback.py | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/unit_tests/hyperion/external_interaction/callbacks/rotation/test_ispyb_callback.py b/tests/unit_tests/hyperion/external_interaction/callbacks/rotation/test_ispyb_callback.py index 7bbc285d0..4becd6809 100644 --- a/tests/unit_tests/hyperion/external_interaction/callbacks/rotation/test_ispyb_callback.py +++ b/tests/unit_tests/hyperion/external_interaction/callbacks/rotation/test_ispyb_callback.py @@ -228,7 +228,7 @@ def test_oav_rotation_snapshot_triggered_event( ]: mx.upsert_data_collection.reset_mock() event_doc = dict(TestData.test_event_document_oav_rotation_snapshot) - event_doc["data"]["oav_snapshot_last_saved_path"] = snapshot["filename"] # type: ignore + event_doc["data"]["oav-snapshot-last_saved_path"] = snapshot["filename"] # type: ignore callback.activity_gated_event( TestData.test_event_document_oav_rotation_snapshot ) diff --git a/tests/unit_tests/hyperion/external_interaction/callbacks/xray_centre/test_ispyb_callback.py b/tests/unit_tests/hyperion/external_interaction/callbacks/xray_centre/test_ispyb_callback.py index d5fda80ad..c1b193b0a 100644 --- a/tests/unit_tests/hyperion/external_interaction/callbacks/xray_centre/test_ispyb_callback.py +++ b/tests/unit_tests/hyperion/external_interaction/callbacks/xray_centre/test_ispyb_callback.py @@ -184,7 +184,7 @@ def test_activity_gated_event_oav_snapshot_triggered(self, mock_ispyb_conn): "xtal_snapshot2": "test_2_y", "xtal_snapshot3": "test_3_y", "comments": "Hyperion: Xray centring - Diffraction grid scan of 40 by 20 " - "images in 100.0 um by 120.0 um steps. Top left (px): [50,100], " + "images in 126.4 um by 126.4 um steps. Top left (px): [50,100], " "bottom right (px): [3250,1700].", "axisstart": 0, "omegastart": 0, @@ -203,7 +203,7 @@ def test_activity_gated_event_oav_snapshot_triggered(self, mock_ispyb_conn): "xtal_snapshot2": "test_2_z", "xtal_snapshot3": "test_3_z", "comments": "Hyperion: Xray centring - Diffraction grid scan of 40 by 10 " - "images in 100.0 um by 120.0 um steps. Top left (px): [50,0], " + "images in 126.4 um by 126.4 um steps. Top left (px): [50,0], " "bottom right (px): [3250,800].", "axisstart": 90, "omegastart": 90, @@ -216,12 +216,12 @@ def test_activity_gated_event_oav_snapshot_triggered(self, mock_ispyb_conn): mx_acq.get_dc_grid_params(), { "parentid": TEST_DATA_COLLECTION_IDS[0], - "dxinmm": 0.1, - "dyinmm": 0.12, + "dxinmm": 0.1264, + "dyinmm": 0.1264, "stepsx": 40, "stepsy": 20, - "micronsperpixelx": 1.25, - "micronsperpixely": 1.5, + "micronsperpixelx": 1.58, + "micronsperpixely": 1.58, "snapshotoffsetxpixel": 50, "snapshotoffsetypixel": 100, "orientation": "horizontal", @@ -233,12 +233,12 @@ def test_activity_gated_event_oav_snapshot_triggered(self, mock_ispyb_conn): mx_acq.get_dc_grid_params(), { "parentid": TEST_DATA_COLLECTION_IDS[1], - "dxinmm": 0.1, - "dyinmm": 0.12, + "dxinmm": 0.1264, + "dyinmm": 0.1264, "stepsx": 40, "stepsy": 10, - "micronsperpixelx": 1.25, - "micronsperpixely": 1.5, + "micronsperpixelx": 1.58, + "micronsperpixely": 1.58, "snapshotoffsetxpixel": 50, "snapshotoffsetypixel": 0, "orientation": "horizontal", From 061fcaf0663664756f889b7ebf5d76f26ab2a7c9 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Mon, 4 Nov 2024 13:10:52 +0000 Subject: [PATCH 17/18] Remove assert --- .../hyperion/experiment_plans/pin_tip_centring_plan.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mx_bluesky/hyperion/experiment_plans/pin_tip_centring_plan.py b/src/mx_bluesky/hyperion/experiment_plans/pin_tip_centring_plan.py index c6904ebbd..cc9f6a79d 100644 --- a/src/mx_bluesky/hyperion/experiment_plans/pin_tip_centring_plan.py +++ b/src/mx_bluesky/hyperion/experiment_plans/pin_tip_centring_plan.py @@ -133,7 +133,6 @@ def pin_tip_centre_plan( pin_tip_detect = composite.pin_tip_detection microns_per_pixel_x = yield from bps.rd(oav.microns_per_pixel_x) - assert microns_per_pixel_x is not None tip_offset_px = int(tip_offset_microns / microns_per_pixel_x) def offset_and_move(tip: Pixel): From da7604be944ce8435f3590e25a29a0ce6cf7cd01 Mon Sep 17 00:00:00 2001 From: Noemi Frisina Date: Mon, 4 Nov 2024 13:12:58 +0000 Subject: [PATCH 18/18] Update dodal pin --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index d5de8504b..75e12b401 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ dependencies = [ "ophyd == 1.9.0", "ophyd-async >= 0.3a5", "bluesky >= 1.13.0a4", - "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@7f4482e78f0c73a06f4f745bac8c28a4183c9170", + "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@598d2560e5bdb1f92c9f4895563274449233a6a8", ]