Skip to content

Commit

Permalink
Switch which OAV stream we use during thawing
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed Sep 19, 2024
1 parent 1dc26a5 commit 080f87f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies = [
"ophyd == 1.9.0",
"ophyd-async >= 0.3a5",
"bluesky >= 1.13.0a4",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@040a72885deaca1055a930f09eccef4acca812f5",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@94adbaa5f3860baa1831c0e236232e5275364a84",
]


Expand Down
21 changes: 17 additions & 4 deletions src/mx_bluesky/beamlines/i04/thawing_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from dodal.beamlines.i04 import MURKO_REDIS_DB, REDIS_HOST, REDIS_PASSWORD
from dodal.common import inject
from dodal.devices.oav.oav_detector import OAV
from dodal.devices.oav.oav_to_redis_forwarder import OAVToRedisForwarder
from dodal.devices.oav.oav_to_redis_forwarder import OAVToRedisForwarder, Source
from dodal.devices.robot import BartRobot
from dodal.devices.smargon import Smargon
from dodal.devices.thawer import Thawer, ThawerStates
Expand All @@ -25,8 +25,14 @@ def thaw_and_stream_to_redis(
zoom_percentage = yield from bps.rd(oav.zoom_controller.percentage)
sample_id = yield from bps.rd(robot.sample_id)

yield from bps.abs_set(oav.zoom_controller.level, "1.0x", wait=True)
yield from bps.abs_set(oav_to_redis_forwarder.sample_id, sample_id)
yield from bps.mv(oav.zoom_controller.level, "1.0x")
yield from bps.mv(oav_to_redis_forwarder.sample_id, sample_id)
yield from bps.mv(oav_to_redis_forwarder.selected_source, Source.FULL_SCREEN)

def switch_forwarder_to_ROI():
yield from bps.complete(oav_to_redis_forwarder)
yield from bps.mv(oav_to_redis_forwarder.selected_source, Source.ROI)
yield from bps.kickoff(oav_to_redis_forwarder, wait=True)

@subs_decorator(MurkoCallback(REDIS_HOST, REDIS_PASSWORD, MURKO_REDIS_DB))
@run_decorator(
Expand All @@ -43,7 +49,9 @@ def _thaw_and_stream_to_redis():
yield from bps.kickoff(oav_to_redis_forwarder, wait=True)
yield from bps.monitor(smargon.omega.user_readback, name="smargon")
yield from bps.monitor(oav_to_redis_forwarder.uuid, name="oav")
yield from thaw(time_to_thaw, rotation, thawer, smargon)
yield from thaw(
time_to_thaw, rotation, thawer, smargon, switch_forwarder_to_ROI
)
yield from bps.complete(oav_to_redis_forwarder)

yield from _thaw_and_stream_to_redis()
Expand All @@ -54,6 +62,7 @@ def thaw(
rotation: float = 360,
thawer: Thawer = inject("thawer"),
smargon: Smargon = inject("smargon"),
plan_between_rotations=None,
) -> MsgGenerator:
"""Rotates the sample and thaws it at the same time.
Expand All @@ -64,6 +73,8 @@ def thaw(
thawer (Thawer, optional): The thawing device. Defaults to inject("thawer").
smargon (Smargon, optional): The smargon used to rotate.
Defaults to inject("smargon")
plan_between_rotations (MsgGenerator, optional): A plan to run between rotations
of the smargon. Defaults to no plan.
"""
inital_velocity = yield from bps.rd(smargon.omega.velocity)
new_velocity = abs(rotation / time_to_thaw) * 2.0
Expand All @@ -72,6 +83,8 @@ def do_thaw():
yield from bps.abs_set(smargon.omega.velocity, new_velocity, wait=True)
yield from bps.abs_set(thawer.control, ThawerStates.ON, wait=True)
yield from bps.rel_set(smargon.omega, rotation, wait=True)
if plan_between_rotations:
yield from plan_between_rotations()
yield from bps.rel_set(smargon.omega, -rotation, wait=True)

def cleanup():
Expand Down
41 changes: 38 additions & 3 deletions tests/unit_tests/beamlines/i04/test_thawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
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_to_redis_forwarder import OAVToRedisForwarder
from dodal.devices.oav.oav_to_redis_forwarder import OAVToRedisForwarder, Source
from dodal.devices.robot import BartRobot
from dodal.devices.smargon import Smargon
from dodal.devices.thawer import Thawer, ThawerStates
Expand Down Expand Up @@ -195,8 +196,8 @@ async def test_thaw_and_stream_sets_sample_id_and_kicks_off_forwarder(
)
)
assert await oav_forwarder.sample_id.get_value() == 100
oav_forwarder.kickoff.assert_called_once() # type: ignore
oav_forwarder.complete.assert_called_once() # type: ignore
oav_forwarder.kickoff.assert_called() # type: ignore
oav_forwarder.complete.assert_called() # type: ignore


@patch("mx_bluesky.beamlines.i04.thawing_plan.MurkoCallback")
Expand Down Expand Up @@ -255,3 +256,37 @@ def test_thaw_and_stream_will_produce_events_that_call_murko(
)
)
patch_murko_call.assert_called()


def test_thaw_and_stream_will_switch_murko_source_half_way_through_thaw(
sim_run_engine,
smargon: Smargon,
thawer: Thawer,
oav_forwarder: OAVToRedisForwarder,
oav: OAV,
robot: BartRobot,
):
msgs = sim_run_engine.simulate_plan(
thaw_and_stream_to_redis(10, 360, robot, thawer, smargon, oav, oav_forwarder)
)
for source in [Source.FULL_SCREEN, Source.ROI]:
msgs = assert_message_and_return_remaining(
msgs,
lambda msg: msg.command == "set"
and msg.obj.name == "oav_to_redis_forwarder-selected_source"
and msg.args[0] == source,
)
msgs = assert_message_and_return_remaining(
msgs,
lambda msg: msg.command == "kickoff"
and msg.obj.name == "oav_to_redis_forwarder",
)
msgs = assert_message_and_return_remaining(
msgs,
lambda msg: msg.command == "set" and msg.obj.name == "smargon-omega",
)
msgs = assert_message_and_return_remaining(
msgs,
lambda msg: msg.command == "complete"
and msg.obj.name == "oav_to_redis_forwarder",
)

0 comments on commit 080f87f

Please sign in to comment.