diff --git a/setup.cfg b/setup.cfg index 4c140471c..b8aa40260 100644 --- a/setup.cfg +++ b/setup.cfg @@ -41,7 +41,7 @@ install_requires = ophyd-async >= 0.3a5 bluesky >= 1.13.0a4 blueapi >= 0.4.3-rc1 - dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git + dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@be39aac2020879b1ac28bffaae5dea52b9fd3b00 [options.entry_points] console_scripts = diff --git a/src/hyperion/device_setup_plans/manipulate_sample.py b/src/hyperion/device_setup_plans/manipulate_sample.py index ee942b17a..90a1d83d0 100644 --- a/src/hyperion/device_setup_plans/manipulate_sample.py +++ b/src/hyperion/device_setup_plans/manipulate_sample.py @@ -2,6 +2,7 @@ import bluesky.plan_stubs as bps from dodal.devices.aperturescatterguard import ( + ApertureInOut, AperturePositionGDANames, ApertureScatterguard, ) @@ -61,7 +62,7 @@ def move_aperture_if_required( LOGGER.info(f"Setting aperture position to {aperture_position}") yield from bps.abs_set( aperture_scatterguard, - aperture_position, + (ApertureInOut.IN, aperture_position), group=group, ) diff --git a/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py b/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py index 92c071471..2794cbd2a 100755 --- a/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py +++ b/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py @@ -12,6 +12,7 @@ from attr import dataclass from blueapi.core import BlueskyContext, MsgGenerator from dodal.devices.aperturescatterguard import ( + ApertureInOut, AperturePosition, ApertureScatterguard, ) @@ -383,7 +384,9 @@ def set_aperture_for_bbox_size( } ) def set_aperture(): - yield from bps.abs_set(aperture_device, new_selected_aperture) + yield from bps.abs_set( + aperture_device, (ApertureInOut.IN, new_selected_aperture) + ) yield from set_aperture() diff --git a/src/hyperion/experiment_plans/oav_snapshot_plan.py b/src/hyperion/experiment_plans/oav_snapshot_plan.py index ac13b5ce7..120bca1ce 100644 --- a/src/hyperion/experiment_plans/oav_snapshot_plan.py +++ b/src/hyperion/experiment_plans/oav_snapshot_plan.py @@ -3,7 +3,10 @@ from blueapi.core import MsgGenerator from bluesky import plan_stubs as bps -from dodal.devices.aperturescatterguard import AperturePosition, ApertureScatterguard +from dodal.devices.aperturescatterguard import ( + ApertureInOut, + ApertureScatterguard, +) from dodal.devices.backlight import Backlight, BacklightPosition from dodal.devices.oav.oav_detector import OAV from dodal.devices.oav.oav_parameters import OAVParameters @@ -41,7 +44,7 @@ def setup_oav_snapshot_plan( ) yield from bps.abs_set( composite.aperture_scatterguard, - AperturePosition.ROBOT_LOAD, + (ApertureInOut.OUT, None), group=OAV_SNAPSHOT_SETUP_GROUP, ) diff --git a/src/hyperion/experiment_plans/robot_load_then_centre_plan.py b/src/hyperion/experiment_plans/robot_load_then_centre_plan.py index 0bb840145..22e1b7209 100644 --- a/src/hyperion/experiment_plans/robot_load_then_centre_plan.py +++ b/src/hyperion/experiment_plans/robot_load_then_centre_plan.py @@ -8,7 +8,7 @@ import bluesky.plan_stubs as bps import bluesky.preprocessors as bpp from blueapi.core import BlueskyContext, MsgGenerator -from dodal.devices.aperturescatterguard import AperturePosition, ApertureScatterguard +from dodal.devices.aperturescatterguard import ApertureInOut, ApertureScatterguard from dodal.devices.attenuator import Attenuator from dodal.devices.backlight import Backlight from dodal.devices.dcm import DCM @@ -130,7 +130,7 @@ def take_robot_snapshots(oav: OAV, webcam: Webcam, directory: Path): def prepare_for_robot_load(composite: RobotLoadThenCentreComposite): yield from bps.abs_set( composite.aperture_scatterguard, - AperturePosition.ROBOT_LOAD, + (ApertureInOut.OUT, None), group="prepare_robot_load", ) diff --git a/tests/conftest.py b/tests/conftest.py index 443197f41..5773d86c0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -21,11 +21,9 @@ ) from dodal.common.beamlines.beamline_utils import clear_devices from dodal.devices.aperturescatterguard import ( - ApertureFiveDimensionalLocation, + ApertureConfigData, AperturePosition, ApertureScatterguard, - ApertureScatterguardTolerances, - SingleAperturePosition, ) from dodal.devices.attenuator import Attenuator from dodal.devices.backlight import Backlight @@ -186,7 +184,7 @@ def _pass_on_mock(value, **kwargs): def patch_async_motor( - motor: Motor, initial_position=0, call_log: MagicMock | None = None + motor: Motor, initial_position: float = 0, call_log: MagicMock | None = None ): set_mock_value(motor.user_setpoint, initial_position) set_mock_value(motor.user_readback, initial_position) @@ -451,45 +449,16 @@ def thawer(RE) -> Generator[Thawer, Any, Any]: @pytest.fixture -def aperture_scatterguard(RE): - positions = { - AperturePosition.LARGE: SingleAperturePosition( - location=ApertureFiveDimensionalLocation(0, 1, 2, 3, 4), - name="Large", - GDA_name="LARGE_APERTURE", - radius_microns=100, - ), - AperturePosition.MEDIUM: SingleAperturePosition( - location=ApertureFiveDimensionalLocation(5, 6, 2, 8, 9), - name="Medium", - GDA_name="MEDIUM_APERTURE", - radius_microns=50, - ), - AperturePosition.SMALL: SingleAperturePosition( - location=ApertureFiveDimensionalLocation(10, 11, 2, 13, 14), - name="Small", - GDA_name="SMALL_APERTURE", - radius_microns=20, - ), - AperturePosition.ROBOT_LOAD: SingleAperturePosition( - location=ApertureFiveDimensionalLocation(15, 16, 2, 18, 19), - name="Robot_load", - GDA_name="ROBOT_LOAD", - radius_microns=None, - ), - } +def aperture_scatterguard(RE, beamline_parameters): with patch( - "dodal.beamlines.i03.load_positions_from_beamline_parameters", - return_value=positions, - ), patch( - "dodal.beamlines.i03.load_tolerances_from_beamline_params", - return_value=ApertureScatterguardTolerances(0.1, 0.1, 0.1, 0.1, 0.1), + "dodal.beamlines.i03.ApertureConfigData", + return_value=ApertureConfigData(beamline_parameters), ): ap_sg = i03.aperture_scatterguard(fake_with_ophyd_sim=True) with ( patch_async_motor(ap_sg._aperture.x), patch_async_motor(ap_sg._aperture.y), - patch_async_motor(ap_sg._aperture.z, 2), + patch_async_motor(ap_sg._aperture.z, 15.8), patch_async_motor(ap_sg._scatterguard.x), patch_async_motor(ap_sg._scatterguard.y), ): diff --git a/tests/system_tests/hyperion/test_aperturescatterguard_system.py b/tests/system_tests/hyperion/test_aperturescatterguard_system.py index acd425fa5..9d61f9af1 100644 --- a/tests/system_tests/hyperion/test_aperturescatterguard_system.py +++ b/tests/system_tests/hyperion/test_aperturescatterguard_system.py @@ -3,11 +3,7 @@ BEAMLINE_PARAMETER_PATHS, GDABeamlineParameters, ) -from dodal.devices.aperturescatterguard import ( - ApertureScatterguard, - load_positions_from_beamline_parameters, - load_tolerances_from_beamline_params, -) +from dodal.devices.aperturescatterguard import ApertureConfigData, ApertureScatterguard from ophyd_async.core import DeviceCollector @@ -18,8 +14,7 @@ def ap_sg(): ap_sg = ApertureScatterguard( prefix="BL03S", name="ap_sg", - loaded_positions=load_positions_from_beamline_parameters(params), - tolerances=load_tolerances_from_beamline_params(params), + configuration_data=ApertureConfigData(params), ) return ap_sg diff --git a/tests/unit_tests/device_setup_plans/test_manipulate_sample.py b/tests/unit_tests/device_setup_plans/test_manipulate_sample.py index 91ebb958e..d3fb21f32 100644 --- a/tests/unit_tests/device_setup_plans/test_manipulate_sample.py +++ b/tests/unit_tests/device_setup_plans/test_manipulate_sample.py @@ -2,6 +2,7 @@ from bluesky.run_engine import RunEngine from dodal.devices.aperturescatterguard import ( + ApertureInOut, AperturePosition, AperturePositionGDANames, ApertureScatterguard, @@ -19,9 +20,7 @@ async def test_move_aperture_goes_to_correct_position( aperture_scatterguard, AperturePositionGDANames.LARGE_APERTURE ) ) - mock_set.assert_called_once_with( - AperturePosition.LARGE, - ) + mock_set.assert_called_once_with((ApertureInOut.IN, AperturePosition.LARGE)) async def test_move_aperture_does_nothing_when_none_selected( diff --git a/tests/unit_tests/experiment_plans/test_flyscan_xray_centre_plan.py b/tests/unit_tests/experiment_plans/test_flyscan_xray_centre_plan.py index d87a5c058..5bc1005d7 100644 --- a/tests/unit_tests/experiment_plans/test_flyscan_xray_centre_plan.py +++ b/tests/unit_tests/experiment_plans/test_flyscan_xray_centre_plan.py @@ -2,7 +2,7 @@ import types from pathlib import Path from typing import Tuple -from unittest.mock import DEFAULT, MagicMock, call, patch +from unittest.mock import ANY, DEFAULT, MagicMock, call, patch import bluesky.plan_stubs as bps import bluesky.preprocessors as bpp @@ -238,7 +238,7 @@ def test_read_hardware_for_ispyb_updates_from_ophyd_devices( "name": "Small", "GDA_name": "SMALL_APERTURE", "radius_microns": 20, - "location": (10, 11, 2, 13, 14), + "location": ANY, } fake_fgs_composite.s4_slit_gaps.xgap.user_readback.sim_put(xgap_test_value) # type: ignore fake_fgs_composite.s4_slit_gaps.ygap.user_readback.sim_put(ygap_test_value) # type: ignore diff --git a/tests/unit_tests/experiment_plans/test_grid_detect_then_xray_centre_plan.py b/tests/unit_tests/experiment_plans/test_grid_detect_then_xray_centre_plan.py index 8f7810c64..c906095a9 100644 --- a/tests/unit_tests/experiment_plans/test_grid_detect_then_xray_centre_plan.py +++ b/tests/unit_tests/experiment_plans/test_grid_detect_then_xray_centre_plan.py @@ -7,7 +7,7 @@ from bluesky.run_engine import RunEngine from bluesky.simulators import RunEngineSimulator, assert_message_and_return_remaining from dodal.beamlines import i03 -from dodal.devices.aperturescatterguard import AperturePosition +from dodal.devices.aperturescatterguard import ApertureInOut, AperturePosition from dodal.devices.backlight import BacklightPosition from dodal.devices.eiger import EigerDetector from dodal.devices.oav.oav_detector import OAVConfigParams @@ -150,7 +150,9 @@ async def test_detect_grid_and_do_gridscan( ) # Check aperture was changed to SMALL - mock_aperture_scatterguard.assert_called_once_with(AperturePosition.SMALL) + mock_aperture_scatterguard.assert_called_once_with( + (ApertureInOut.IN, AperturePosition.SMALL) + ) # Check we called out to underlying fast grid scan plan mock_flyscan_xray_centre_plan.assert_called_once_with(ANY, ANY) diff --git a/tests/unit_tests/experiment_plans/test_rotation_scan_plan.py b/tests/unit_tests/experiment_plans/test_rotation_scan_plan.py index f832733d0..cc30b1770 100644 --- a/tests/unit_tests/experiment_plans/test_rotation_scan_plan.py +++ b/tests/unit_tests/experiment_plans/test_rotation_scan_plan.py @@ -7,7 +7,11 @@ import pytest from bluesky.run_engine import RunEngine from bluesky.simulators import RunEngineSimulator, assert_message_and_return_remaining -from dodal.devices.aperturescatterguard import AperturePosition, ApertureScatterguard +from dodal.devices.aperturescatterguard import ( + ApertureInOut, + AperturePosition, + ApertureScatterguard, +) from dodal.devices.backlight import BacklightPosition from dodal.devices.oav.oav_parameters import OAVParameters from dodal.devices.smargon import Smargon @@ -422,7 +426,7 @@ def test_rotation_scan_moves_aperture_in_backlight_out_after_snapshots_before_ro msgs, lambda msg: msg.command == "set" and msg.obj.name == "aperture_scatterguard" - and msg.args[0] == AperturePosition.SMALL + and msg.args[0] == (ApertureInOut.IN, AperturePosition.SMALL) and msg.kwargs["group"] == "setup_senv", ) msgs = assert_message_and_return_remaining( @@ -509,7 +513,7 @@ def test_rotation_snapshot_setup_called_to_move_backlight_in_aperture_out_before msgs, lambda msg: msg.command == "set" and msg.obj.name == "aperture_scatterguard" - and msg.args[0] == AperturePosition.ROBOT_LOAD + and msg.args[0] == (ApertureInOut.OUT, None) and msg.kwargs["group"] == OAV_SNAPSHOT_SETUP_GROUP, ) msgs = assert_message_and_return_remaining( diff --git a/tests/unit_tests/experiment_plans/test_wait_for_robot_load_then_centre.py b/tests/unit_tests/experiment_plans/test_wait_for_robot_load_then_centre.py index 0ab146979..ffbcacc87 100644 --- a/tests/unit_tests/experiment_plans/test_wait_for_robot_load_then_centre.py +++ b/tests/unit_tests/experiment_plans/test_wait_for_robot_load_then_centre.py @@ -6,7 +6,7 @@ from bluesky.run_engine import RunEngine from bluesky.simulators import RunEngineSimulator, assert_message_and_return_remaining from bluesky.utils import Msg -from dodal.devices.aperturescatterguard import AperturePosition +from dodal.devices.aperturescatterguard import ApertureInOut from dodal.devices.oav.oav_detector import OAV from dodal.devices.smargon import StubPosition from dodal.devices.webcam import Webcam @@ -286,7 +286,7 @@ async def test_when_prepare_for_robot_load_called_then_moves_as_expected( assert await smargon.omega.user_readback.get_value() == 0 smargon.stub_offsets.set.assert_called_once_with(StubPosition.RESET_TO_ROBOT_LOAD) # type: ignore - aperture_scatterguard.set.assert_called_once_with(AperturePosition.ROBOT_LOAD) # type: ignore + aperture_scatterguard.set.assert_called_once_with((ApertureInOut.OUT, None)) # type: ignore @patch(