Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use separate aperture and scatterguard moves #685

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies = [
"ophyd == 1.9.0",
"ophyd-async >= 0.8a5",
"bluesky >= 1.13.0a4",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@main",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@fcd581d6e5cda2bb78c67893c856ec672581b8ff",
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ def run_grid_detection_plan(
parameters.box_size_um,
)

if parameters.selected_aperture:
# Start moving the aperture/scatterguard into position without moving it in
yield from bps.abs_set(
composite.aperture_scatterguard.aperture_outside_beam,
parameters.selected_aperture,
group=CONST.WAIT.GRID_READY_FOR_DC,
)

yield from run_grid_detection_plan(
oav_params,
snapshot_template,
Expand Down
10 changes: 2 additions & 8 deletions src/mx_bluesky/hyperion/experiment_plans/oav_snapshot_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from bluesky import plan_stubs as bps
from bluesky.utils import MsgGenerator
from dodal.devices.aperturescatterguard import ApertureScatterguard, ApertureValue
from dodal.devices.aperturescatterguard import 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 @@ -33,22 +33,16 @@ def setup_beamline_for_OAV(
max_vel = yield from bps.rd(smargon.omega.max_velocity)
yield from bps.abs_set(smargon.omega.velocity, max_vel, group=group)
yield from bps.abs_set(backlight, BacklightPosition.IN, group=group)
yield from bps.abs_set(
aperture_scatterguard,
ApertureValue.ROBOT_LOAD,
group=group,
)
yield from bps.trigger(aperture_scatterguard.move_out, group=group)


def oav_snapshot_plan(
composite: OavSnapshotComposite,
parameters: WithSnapshot,
oav_parameters: OAVParameters,
wait: bool = True,
) -> MsgGenerator:
if not parameters.take_snapshots:
return
yield from bps.wait(group=CONST.WAIT.READY_FOR_OAV)
yield from _setup_oav(composite, parameters, oav_parameters)
for omega in parameters.snapshot_omegas_deg or []:
yield from _take_oav_snapshot(composite, omega)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pydantic
from blueapi.core import BlueskyContext
from bluesky.utils import Msg
from dodal.devices.aperturescatterguard import ApertureScatterguard, ApertureValue
from dodal.devices.aperturescatterguard import ApertureScatterguard
from dodal.devices.attenuator import Attenuator
from dodal.devices.dcm import DCM
from dodal.devices.focusing_mirror import FocusingMirrorWithStripes, MirrorVoltages
Expand Down Expand Up @@ -94,11 +94,7 @@ def take_robot_snapshots(oav: OAV, webcam: Webcam, directory: Path):
def prepare_for_robot_load(
aperture_scatterguard: ApertureScatterguard, smargon: Smargon
):
yield from bps.abs_set(
aperture_scatterguard,
ApertureValue.ROBOT_LOAD,
group="prepare_robot_load",
)
yield from bps.trigger(aperture_scatterguard.move_out, group="prepare_robot_load")

yield from bps.mv(smargon.stub_offsets, StubPosition.RESET_TO_ROBOT_LOAD) # type: ignore # See: https://github.com/bluesky/bluesky/issues/1809

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ def _div_by_1000_if_not_none(num: float | None):
yield from setup_beamline_for_OAV(
composite.smargon, composite.backlight, composite.aperture_scatterguard
)
yield from bps.wait(group=CONST.WAIT.READY_FOR_OAV)
if params.selected_aperture:
yield from bps.abs_set(
composite.aperture_scatterguard.aperture_outside_beam,
params.selected_aperture,
group=CONST.WAIT.ROTATION_READY_FOR_DC,
)
yield from oav_snapshot_plan(composite, params, oav_params)
yield from rotation_scan_plan(
composite,
Expand Down
12 changes: 6 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,15 +559,15 @@ def aperture_scatterguard(RE):
):
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.scatterguard.x),
patch_async_motor(ap_sg.scatterguard.y),
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._scatterguard.x),
patch_async_motor(ap_sg._scatterguard.y),
):
RE(bps.abs_set(ap_sg, ApertureValue.SMALL))

set_mock_value(ap_sg.aperture.small, 1)
set_mock_value(ap_sg._aperture.small, 1)
yield ap_sg


Expand Down
4 changes: 3 additions & 1 deletion tests/system_tests/hyperion/external_interaction/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ def fgs_composite_for_fake_zocalo(
zocalo_for_fake_zocalo: ZocaloResults,
done_status: NullStatus,
) -> FlyScanXRayCentreComposite:
set_mock_value(fake_fgs_composite.aperture_scatterguard.aperture.z.user_setpoint, 2)
set_mock_value(
fake_fgs_composite.aperture_scatterguard._aperture.z.user_setpoint, 2
)
fake_fgs_composite.eiger.unstage = MagicMock(return_value=done_status) # type: ignore
fake_fgs_composite.smargon.stub_offsets.set = MagicMock(return_value=done_status) # type: ignore
callback_on_mock_put(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def test_read_hardware_for_ispyb_updates_from_ophyd_devices(
# fmt: on

@patch(
"dodal.devices.aperturescatterguard.ApertureScatterguard._safe_move_within_datacollection_range",
"dodal.devices.aperturescatterguard._safe_move_whilst_in_beam",
Copy link
Contributor

Choose a reason for hiding this comment

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

The assert_event in the previous line needs updating for the new underscored device names

return_value=NullStatus(),
)
@patch(
Expand Down Expand Up @@ -452,7 +452,7 @@ def test_results_passed_to_move_motors(
)

@patch(
"dodal.devices.aperturescatterguard.ApertureScatterguard._safe_move_within_datacollection_range",
"dodal.devices.aperturescatterguard._safe_move_whilst_in_beam",
return_value=NullStatus(),
)
@patch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
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 ApertureValue
from dodal.devices.backlight import BacklightPosition
from dodal.devices.detector.detector_motion import ShutterState
from dodal.devices.smargon import Smargon
Expand Down Expand Up @@ -292,9 +291,8 @@ def test_pin_centre_then_xray_centre_plan_sets_up_backlight_and_aperture(
)
msgs = assert_message_and_return_remaining(
msgs,
lambda msg: msg.command == "set"
and msg.obj.name == "aperture_scatterguard"
and msg.args == (ApertureValue.ROBOT_LOAD,)
lambda msg: msg.command == "trigger"
and msg.obj.name == "aperture_scatterguard-move_out"
and msg.kwargs["group"] == CONST.WAIT.READY_FOR_OAV,
)

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 ApertureScatterguard, ApertureValue
from dodal.devices.aperturescatterguard import ApertureScatterguard
from dodal.devices.oav.oav_detector import OAV
from dodal.devices.smargon import Smargon, StubPosition
from dodal.devices.webcam import Webcam
Expand Down Expand Up @@ -171,7 +171,7 @@ async def test_when_prepare_for_robot_load_called_then_moves_as_expected(
aperture_scatterguard: ApertureScatterguard, smargon: Smargon, done_status
):
smargon.stub_offsets.set = MagicMock(return_value=done_status)
aperture_scatterguard.set = MagicMock(return_value=done_status)
aperture_scatterguard.move_out.trigger = MagicMock(return_value=done_status)

set_mock_value(smargon.x.user_readback, 10)
set_mock_value(smargon.z.user_readback, 5)
Expand All @@ -185,7 +185,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(ApertureValue.ROBOT_LOAD) # type: ignore
aperture_scatterguard.move_out.trigger.assert_called_once_with() # type: ignore


@patch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,8 @@ def test_rotation_snapshot_setup_called_to_move_backlight_in_aperture_out_before
)
msgs = assert_message_and_return_remaining(
msgs,
lambda msg: msg.command == "set"
and msg.obj.name == "aperture_scatterguard"
and msg.args[0] == ApertureValue.ROBOT_LOAD
lambda msg: msg.command == "trigger"
and msg.obj.name == "aperture_scatterguard-move_out"
and msg.kwargs["group"] == CONST.WAIT.READY_FOR_OAV,
)
msgs = assert_message_and_return_remaining(
Expand Down
Loading