Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Update hyperion to move just the aperture_scatterguard axes required #1544

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
3 changes: 2 additions & 1 deletion src/hyperion/device_setup_plans/manipulate_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import bluesky.plan_stubs as bps
from dodal.devices.aperturescatterguard import (
ApertureInOut,
AperturePositionGDANames,
ApertureScatterguard,
)
Expand Down Expand Up @@ -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,
)

Expand Down
5 changes: 4 additions & 1 deletion src/hyperion/experiment_plans/flyscan_xray_centre_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from attr import dataclass
from blueapi.core import BlueskyContext, MsgGenerator
from dodal.devices.aperturescatterguard import (
ApertureInOut,
AperturePosition,
ApertureScatterguard,
)
Expand Down Expand Up @@ -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)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe should be out as we're going to do OAV after this

)

yield from set_aperture()

Expand Down
7 changes: 5 additions & 2 deletions src/hyperion/experiment_plans/oav_snapshot_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)

Expand Down
4 changes: 2 additions & 2 deletions src/hyperion/experiment_plans/robot_load_then_centre_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do a set to (OUT, SMALL) small after this but will need to think about when to wait for it


Expand Down
43 changes: 6 additions & 37 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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

Expand Down
5 changes: 2 additions & 3 deletions tests/unit_tests/device_setup_plans/test_manipulate_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from bluesky.run_engine import RunEngine
from dodal.devices.aperturescatterguard import (
ApertureInOut,
AperturePosition,
AperturePositionGDANames,
ApertureScatterguard,
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions tests/unit_tests/experiment_plans/test_rotation_scan_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Loading