Skip to content

Commit

Permalink
Stage eiger asynchronously on a rotation plan (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed Sep 3, 2024
1 parent 9244985 commit 3b89bc7
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,11 @@


def begin_sample_environment_setup(
detector_motion: DetectorMotion,
attenuator: Attenuator,
transmission_fraction: float,
detector_distance: float,
group="setup_senv",
):
"""Start all sample environment changes that can be initiated before OAV snapshots are taken"""
yield from bps.abs_set(detector_motion.shutter, 1, group=group)
yield from bps.abs_set(detector_motion.z, detector_distance, group=group)
yield from bps.abs_set(attenuator, transmission_fraction, group=group)


Expand Down
35 changes: 23 additions & 12 deletions src/mx_bluesky/hyperion/experiment_plans/rotation_scan_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
make_trigger_safe,
setup_zebra_for_rotation,
)
from mx_bluesky.hyperion.device_setup_plans.utils import (
start_preparing_data_collection_then_do_plan,
)
from mx_bluesky.hyperion.experiment_plans.oav_snapshot_plan import (
OavSnapshotComposite,
oav_snapshot_plan,
Expand Down Expand Up @@ -211,8 +214,7 @@ def _rotation_scan_plan(
yield from bps.abs_set(
axis,
motion_values.start_motion_deg,
group="move_to_rotation_start",
wait=True,
group=CONST.WAIT.ROTATION_READY_FOR_DC,
)

yield from setup_zebra_for_rotation(
Expand All @@ -223,20 +225,19 @@ def _rotation_scan_plan(
shutter_opening_deg=motion_values.shutter_opening_deg,
shutter_opening_s=motion_values.shutter_time_s,
group="setup_zebra",
wait=True,
)

yield from setup_sample_environment(
composite.aperture_scatterguard,
params.selected_aperture,
composite.backlight,
group=CONST.WAIT.ROTATION_READY_FOR_DC,
)

LOGGER.info("Wait for any previous moves...")
# wait for all the setup tasks at once
yield from bps.wait(CONST.WAIT.ROTATION_READY_FOR_DC)
yield from bps.wait(CONST.WAIT.MOVE_GONIO_TO_START)
yield from bps.wait("setup_senv")
yield from bps.wait("move_to_rotation_start")

# get some information for the ispyb deposition and trigger the callback
yield from read_hardware_for_zocalo(composite.eiger)
Expand Down Expand Up @@ -352,21 +353,26 @@ def rotation_scan_plan_with_stage_and_cleanup(
eiger: EigerDetector = composite.eiger
eiger.set_detector_parameters(params.detector_params)

@bpp.stage_decorator([eiger])
@bpp.finalize_decorator(lambda: _cleanup_plan(composite))
def rotation_with_cleanup_and_stage(params: RotationScan):
LOGGER.info("setting up sample environment...")
yield from begin_sample_environment_setup(
composite.detector_motion,
composite.attenuator,
params.transmission_frac,
params.detector_params.detector_distance,
group=CONST.WAIT.ROTATION_READY_FOR_DC,
)

yield from _move_and_rotation(composite, params, oav_params)

LOGGER.info("setting up and staging eiger...")
yield from rotation_with_cleanup_and_stage(params)
yield from start_preparing_data_collection_then_do_plan(
eiger,
composite.detector_motion,
params.detector_distance_mm,
rotation_with_cleanup_and_stage(params),
group=CONST.WAIT.ROTATION_READY_FOR_DC,
)
yield from bps.unstage(eiger)

yield from rotation_scan_plan_with_stage_and_cleanup(parameters)

Expand All @@ -382,10 +388,9 @@ def multi_rotation_scan(
eiger.set_detector_parameters(parameters.detector_params)
LOGGER.info("setting up sample environment...")
yield from begin_sample_environment_setup(
composite.detector_motion,
composite.attenuator,
parameters.transmission_frac,
parameters.detector_params.detector_distance,
group=CONST.WAIT.ROTATION_READY_FOR_DC,
)

@bpp.set_run_key_decorator("multi_rotation_scan")
Expand Down Expand Up @@ -421,4 +426,10 @@ def rotation_scan_core(
yield from rotation_scan_core(single_scan)

LOGGER.info("setting up and staging eiger...")
yield from _multi_rotation_scan()
yield from start_preparing_data_collection_then_do_plan(
eiger,
composite.detector_motion,
parameters.detector_distance_mm,
_multi_rotation_scan(),
group=CONST.WAIT.ROTATION_READY_FOR_DC,
)
4 changes: 2 additions & 2 deletions src/mx_bluesky/hyperion/parameters/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class PlanNameConstants:
@dataclass(frozen=True)
class PlanGroupCheckpointConstants:
# For places to synchronise / stop and wait in plans, use as bluesky group names
# Gridscan
GRID_READY_FOR_DC = "ready_for_data_collection"
GRID_READY_FOR_DC = "grid_ready_for_data_collection"
ROTATION_READY_FOR_DC = "rotation_ready_for_data_collection"
MOVE_GONIO_TO_START = "move_gonio_to_start"


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,6 @@ def grid_detect_then_xray_centre_composite(
dcm=dcm,
flux=flux,
)
eiger.odin.fan.consumers_connected.sim_put(True)
eiger.odin.fan.on.sim_put(True)
eiger.odin.meta.initialised.sim_put(True)
oav.zoom_controller.zrst.set("1.0x")
oav.cam.array_size.array_size_x.sim_put(1024)
oav.cam.array_size.array_size_y.sim_put(768)
Expand All @@ -295,10 +292,6 @@ def grid_detect_then_xray_centre_composite(
set_mock_value(undulator.current_gap, 1.11)

unpatched_method = oav.parameters.load_microns_per_pixel
eiger.stale_params.sim_put(0)
eiger.odin.meta.ready.sim_put(1)
eiger.odin.meta.active.sim_put(1)
eiger.odin.fan.ready.sim_put(1)

unpatched_snapshot_trigger = oav.grid_snapshot.trigger

Expand Down Expand Up @@ -339,17 +332,11 @@ def mock_pin_tip_detect(_):
yield from []
return tip_x_px, tip_y_px

def mock_set_file_name(val, timeout):
eiger.odin.meta.file_name.sim_put(val) # type: ignore
eiger.odin.file_writer.id.sim_put(val) # type: ignore
return NullStatus()

@AsyncStatus.wrap
async def mock_complete_status():
pass

with (
patch.object(eiger.odin.nodes, "get_init_state", return_value=True),
patch.object(eiger, "wait_on_arming_if_started"),
# xsize, ysize will always be wrong since computed as 0 before we get here
# patch up load_microns_per_pixel connect to receive non-zero values
Expand All @@ -367,11 +354,6 @@ async def mock_complete_status():
patch("dodal.devices.areadetector.plugins.MJPG.Image.open"),
patch.object(oav.grid_snapshot, "post_processing"),
patch.object(oav.grid_snapshot, "trigger", side_effect=mock_snapshot_trigger),
patch.object(
eiger.odin.file_writer.file_name,
"set",
side_effect=mock_set_file_name,
),
patch.object(fast_grid_scan, "kickoff", return_value=NullStatus()),
patch.object(fast_grid_scan, "complete", return_value=NullStatus()),
patch.object(zocalo, "trigger", return_value=NullStatus()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,10 @@ def test_when_full_grid_scan_run_then_parameters_sent_to_fgs_as_expected(

mock_grid_detection_plan.side_effect = _fake_grid_detection

with (
patch.object(eiger.do_arm, "set", MagicMock()),
patch.object(
grid_detect_devices_with_oav_config_params.aperture_scatterguard,
"set",
MagicMock(),
),
with patch.object(
grid_detect_devices_with_oav_config_params.aperture_scatterguard,
"set",
MagicMock(),
):
RE(
ispyb_activation_wrapper(
Expand Down
Loading

0 comments on commit 3b89bc7

Please sign in to comment.