From 52454e56e2d42da164a7089379666fc7079a787c Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Thu, 12 Sep 2024 20:58:48 +0100 Subject: [PATCH] Set tranmission and turn off xbpm feedback for rotations --- .../device_setup_plans/manipulate_sample.py | 10 ------- .../experiment_plans/rotation_scan_plan.py | 24 +++++++--------- src/mx_bluesky/hyperion/utils/validation.py | 2 ++ tests/conftest.py | 3 ++ .../callbacks/test_external_callbacks.py | 2 ++ .../test_rotation_scan_plan.py | 28 ++++++++++++------- 6 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/mx_bluesky/hyperion/device_setup_plans/manipulate_sample.py b/src/mx_bluesky/hyperion/device_setup_plans/manipulate_sample.py index 56fa9d55f..b071a7588 100644 --- a/src/mx_bluesky/hyperion/device_setup_plans/manipulate_sample.py +++ b/src/mx_bluesky/hyperion/device_setup_plans/manipulate_sample.py @@ -5,7 +5,6 @@ ApertureScatterguard, ApertureValue, ) -from dodal.devices.attenuator import Attenuator from dodal.devices.backlight import Backlight, BacklightPosition from dodal.devices.detector.detector_motion import DetectorMotion from dodal.devices.smargon import Smargon @@ -15,15 +14,6 @@ LOWER_DETECTOR_SHUTTER_AFTER_SCAN = True -def begin_sample_environment_setup( - attenuator: Attenuator, - transmission_fraction: float, - group="setup_senv", -): - """Start all sample environment changes that can be initiated before OAV snapshots are taken""" - yield from bps.abs_set(attenuator, transmission_fraction, group=group) - - def setup_sample_environment( aperture_scatterguard: ApertureScatterguard, aperture_position_gda_name: str | None, diff --git a/src/mx_bluesky/hyperion/experiment_plans/rotation_scan_plan.py b/src/mx_bluesky/hyperion/experiment_plans/rotation_scan_plan.py index 9d26fdb5f..b8fec808e 100644 --- a/src/mx_bluesky/hyperion/experiment_plans/rotation_scan_plan.py +++ b/src/mx_bluesky/hyperion/experiment_plans/rotation_scan_plan.py @@ -19,12 +19,12 @@ from dodal.devices.smargon import Smargon from dodal.devices.synchrotron import Synchrotron from dodal.devices.undulator import Undulator +from dodal.devices.xbpm_feedback import XBPMFeedback from dodal.devices.zebra import RotationDirection, Zebra from dodal.devices.zebra_controlled_shutter import ZebraShutter from dodal.plans.check_topup import check_topup_and_wait_if_necessary from mx_bluesky.hyperion.device_setup_plans.manipulate_sample import ( - begin_sample_environment_setup, cleanup_sample_environment, move_phi_chi_omega, move_x_y_z, @@ -43,6 +43,9 @@ from mx_bluesky.hyperion.device_setup_plans.utils import ( start_preparing_data_collection_then_do_plan, ) +from mx_bluesky.hyperion.device_setup_plans.xbpm_feedback import ( + transmission_and_xbpm_feedback_for_collection_decorator, +) from mx_bluesky.hyperion.experiment_plans.oav_snapshot_plan import ( OavSnapshotComposite, oav_snapshot_plan, @@ -76,6 +79,7 @@ class RotationScanComposite(OavSnapshotComposite): sample_shutter: ZebraShutter zebra: Zebra oav: OAV + xbpm_feedback: XBPMFeedback def create_devices(context: BlueskyContext) -> RotationScanComposite: @@ -201,6 +205,11 @@ def rotation_scan_plan( "scan_points": [params.scan_points], } ) + @transmission_and_xbpm_feedback_for_collection_decorator( + composite.xbpm_feedback, + composite.attenuator, + params.transmission_frac, + ) def _rotation_scan_plan( motion_values: RotationMotionProfile, composite: RotationScanComposite, @@ -359,13 +368,6 @@ def rotation_scan_plan_with_stage_and_cleanup( @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.attenuator, - params.transmission_frac, - group=CONST.WAIT.ROTATION_READY_FOR_DC, - ) - yield from _move_and_rotation(composite, params, oav_params) LOGGER.info("setting up and staging eiger...") @@ -390,12 +392,6 @@ def multi_rotation_scan( oav_params = OAVParameters(context="xrayCentring") eiger: EigerDetector = composite.eiger eiger.set_detector_parameters(parameters.detector_params) - LOGGER.info("setting up sample environment...") - yield from begin_sample_environment_setup( - composite.attenuator, - parameters.transmission_frac, - group=CONST.WAIT.ROTATION_READY_FOR_DC, - ) @bpp.set_run_key_decorator("multi_rotation_scan") @bpp.run_decorator( diff --git a/src/mx_bluesky/hyperion/utils/validation.py b/src/mx_bluesky/hyperion/utils/validation.py index 096a56c47..11a62ecaa 100644 --- a/src/mx_bluesky/hyperion/utils/validation.py +++ b/src/mx_bluesky/hyperion/utils/validation.py @@ -98,6 +98,7 @@ def fake_create_rotation_devices(): zoom_params_file=ZOOM_LEVELS_XML, display_config=DISPLAY_CONFIGURATION ), ) + xbpm_feedback = i03.xbpm_feedback(fake_with_ophyd_sim=True) set_mock_value(smargon.omega.max_velocity, 131) set_mock_value(dcm.energy_in_kev.user_readback, 12700) @@ -119,6 +120,7 @@ def fake_create_rotation_devices(): robot=robot, oav=oav, sample_shutter=i03.sample_shutter(fake_with_ophyd_sim=True), + xbpm_feedback=xbpm_feedback, ) diff --git a/tests/conftest.py b/tests/conftest.py index 3e0faca1e..483a593c2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -43,6 +43,7 @@ from dodal.devices.undulator import Undulator from dodal.devices.util.test_utils import patch_motor as oa_patch_motor from dodal.devices.webcam import Webcam +from dodal.devices.xbpm_feedback import XBPMFeedback from dodal.devices.zebra import Zebra from dodal.devices.zebra_controlled_shutter import ZebraShutter from dodal.log import LOGGER as dodal_logger @@ -589,6 +590,7 @@ def fake_create_rotation_devices( robot: BartRobot, oav: OAV, sample_shutter: ZebraShutter, + xbpm_feedback: XBPMFeedback, ): set_mock_value(smargon.omega.max_velocity, 131) oav.zoom_controller.onst.sim_put("1.0x") # type: ignore @@ -610,6 +612,7 @@ def fake_create_rotation_devices( robot=robot, oav=oav, sample_shutter=sample_shutter, + xbpm_feedback=xbpm_feedback, ) diff --git a/tests/system_tests/hyperion/external_interaction/callbacks/test_external_callbacks.py b/tests/system_tests/hyperion/external_interaction/callbacks/test_external_callbacks.py index 47c6077ed..e132c854f 100644 --- a/tests/system_tests/hyperion/external_interaction/callbacks/test_external_callbacks.py +++ b/tests/system_tests/hyperion/external_interaction/callbacks/test_external_callbacks.py @@ -203,6 +203,7 @@ def test_remote_callbacks_write_to_dev_ispyb_for_rotation( aperture_scatterguard, fake_create_devices, sample_shutter, + xbpm_feedback, ): test_wl = 0.71 test_bs_x = 0.023 @@ -230,6 +231,7 @@ def test_remote_callbacks_write_to_dev_ispyb_for_rotation( robot=robot, oav=fake_create_devices["oav"], sample_shutter=sample_shutter, + xbpm_feedback=xbpm_feedback, ) with patch("bluesky.preprocessors.__read_and_stash_a_motor", fake_read): diff --git a/tests/unit_tests/hyperion/experiment_plans/test_rotation_scan_plan.py b/tests/unit_tests/hyperion/experiment_plans/test_rotation_scan_plan.py index 9e8112a4c..499d4dd8a 100644 --- a/tests/unit_tests/hyperion/experiment_plans/test_rotation_scan_plan.py +++ b/tests/unit_tests/hyperion/experiment_plans/test_rotation_scan_plan.py @@ -365,24 +365,32 @@ def test_rotation_scan_initialises_detector_distance_shutter_and_tx_fraction( and msg.obj.name == "detector_motion-shutter" and msg.kwargs["group"] == CONST.WAIT.ROTATION_READY_FOR_DC, ) - msgs = assert_message_and_return_remaining( + assert_message_and_return_remaining( msgs, - lambda msg: msg.command == "set" - and msg.obj.name == "attenuator" - and msg.args[0] == test_rotation_params.transmission_frac + lambda msg: msg.command == "wait" and msg.kwargs["group"] == CONST.WAIT.ROTATION_READY_FOR_DC, ) + + +def test_rotation_scan_triggers_xbpm_then_pauses_xbpm_and_sets_tranmission( + rotation_scan_simulated_messages, + test_rotation_params: RotationScan, +): + msgs = assert_message_and_return_remaining( + rotation_scan_simulated_messages, + lambda msg: msg.command == "trigger" and msg.obj.name == "xbpm_feedback", + ) msgs = assert_message_and_return_remaining( msgs, lambda msg: msg.command == "set" - and msg.obj.name == "attenuator" - and msg.args[0] == test_rotation_params.transmission_frac - and msg.kwargs["group"] == CONST.WAIT.ROTATION_READY_FOR_DC, + and msg.obj.name == "xbpm_feedback-pause_feedback" + and msg.args[0] == "Paused", ) - assert_message_and_return_remaining( + msgs = assert_message_and_return_remaining( msgs, - lambda msg: msg.command == "wait" - and msg.kwargs["group"] == CONST.WAIT.ROTATION_READY_FOR_DC, + lambda msg: msg.command == "set" + and msg.obj.name == "attenuator" + and msg.args[0] == test_rotation_params.transmission_frac, )