Skip to content

Commit

Permalink
Fixes for thawing plan based on beamline testing (#196)
Browse files Browse the repository at this point in the history
* Set sample id on forwarder when thawing and streaming
  • Loading branch information
DominicOram authored Sep 4, 2024
1 parent f481842 commit 5370444
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 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",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@1c8d3d2f3e10f1b667781b30f7bcc25c76450a06",
]


Expand Down
4 changes: 2 additions & 2 deletions src/mx_bluesky/beamlines/i04/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from mx_bluesky.beamlines.i04.thawing_plan import thaw, thaw_and_center
from mx_bluesky.beamlines.i04.thawing_plan import thaw, thaw_and_stream_to_redis

__all__ = ["thaw", "thaw_and_center"]
__all__ = ["thaw", "thaw_and_stream_to_redis"]
7 changes: 4 additions & 3 deletions src/mx_bluesky/beamlines/i04/thawing_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from mx_bluesky.beamlines.i04.callbacks.murko_callback import MurkoCallback


def thaw_and_center(
def thaw_and_stream_to_redis(
time_to_thaw: float,
rotation: float = 360,
robot: BartRobot = inject("robot"),
Expand All @@ -26,6 +26,7 @@ def thaw_and_center(
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)

@subs_decorator(MurkoCallback(REDIS_HOST, REDIS_PASSWORD, MURKO_REDIS_DB))
@run_decorator(
Expand All @@ -38,14 +39,14 @@ def thaw_and_center(
"sample_id": sample_id,
}
)
def _thaw_and_center():
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 bps.complete(oav_to_redis_forwarder)

yield from _thaw_and_center()
yield from _thaw_and_stream_to_redis()


def thaw(
Expand Down
52 changes: 47 additions & 5 deletions tests/unit_tests/beamlines/i04/test_thawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
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.robot import BartRobot
from dodal.devices.smargon import Smargon
from dodal.devices.thawer import Thawer, ThawerStates
from ophyd.sim import NullStatus, instantiate_fake_device
from ophyd_async.core import (
AsyncStatus,
DeviceCollector,
callback_on_mock_put,
get_mock_put,
set_mock_value,
)
from ophyd_async.epics.motion import Motor

from mx_bluesky.beamlines.i04.thawing_plan import thaw, thaw_and_center
from mx_bluesky.beamlines.i04.thawing_plan import thaw, thaw_and_stream_to_redis

DISPLAY_CONFIGURATION = "tests/devices/unit_tests/test_display.configuration"
ZOOM_LEVELS_XML = "tests/devices/unit_tests/test_jCameraManZoomLevels.xml"
Expand Down Expand Up @@ -73,9 +75,22 @@ async def oav_forwarder(RE: RunEngine) -> OAVToRedisForwarder:
oav_forwarder = OAVToRedisForwarder(
"prefix", "host", "password", name="oav_to_redis_forwarder"
)

# Replace when https://github.com/bluesky/ophyd-async/issues/521 is released
@AsyncStatus.wrap
async def completed_status():
pass

oav_forwarder.kickoff = MagicMock(side_effect=completed_status)
oav_forwarder.complete = MagicMock(side_effect=completed_status)
return oav_forwarder


@pytest.fixture
async def robot(RE: RunEngine) -> BartRobot:
return i04.robot(fake_with_ophyd_sim=True)


def _do_thaw_and_confirm_cleanup(
move_mock: MagicMock, smargon: Smargon, thawer: Thawer, do_thaw_func
):
Expand Down Expand Up @@ -158,7 +173,34 @@ def test_given_different_rotations_then_motor_moved_relative(


@patch("mx_bluesky.beamlines.i04.thawing_plan.MurkoCallback")
def test_thaw_and_centre_adds_murko_callback_and_produces_expected_messages(
async def test_thaw_and_stream_sets_sample_id_and_kicks_off_forwarder(
patch_murko_callback: MagicMock,
smargon: Smargon,
thawer: Thawer,
oav_forwarder: OAVToRedisForwarder,
oav: OAV,
robot: BartRobot,
RE: RunEngine,
):
set_mock_value(robot.sample_id, 100)
RE(
thaw_and_stream_to_redis(
10,
360,
thawer=thawer,
smargon=smargon,
oav=oav,
robot=robot,
oav_to_redis_forwarder=oav_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


@patch("mx_bluesky.beamlines.i04.thawing_plan.MurkoCallback")
def test_thaw_and_stream_adds_murko_callback_and_produces_expected_messages(
patch_murko_callback: MagicMock,
smargon: Smargon,
thawer: Thawer,
Expand All @@ -168,7 +210,7 @@ def test_thaw_and_centre_adds_murko_callback_and_produces_expected_messages(
):
patch_murko_instance = patch_murko_callback.return_value
RE(
thaw_and_center(
thaw_and_stream_to_redis(
10,
360,
thawer=thawer,
Expand All @@ -193,7 +235,7 @@ def test_thaw_and_centre_adds_murko_callback_and_produces_expected_messages(


@patch("mx_bluesky.beamlines.i04.thawing_plan.MurkoCallback.call_murko")
def test_thaw_and_centre_will_produce_events_that_call_murko(
def test_thaw_and_stream_will_produce_events_that_call_murko(
patch_murko_call: MagicMock,
smargon: Smargon,
thawer: Thawer,
Expand All @@ -202,7 +244,7 @@ def test_thaw_and_centre_will_produce_events_that_call_murko(
RE: RunEngine,
):
RE(
thaw_and_center(
thaw_and_stream_to_redis(
10,
360,
thawer=thawer,
Expand Down

0 comments on commit 5370444

Please sign in to comment.