Skip to content

Commit

Permalink
Set tranmission and turn off xbpm feedback for rotations
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed Sep 12, 2024
1 parent 055840c commit 52454e5
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 34 deletions.
10 changes: 0 additions & 10 deletions src/mx_bluesky/hyperion/device_setup_plans/manipulate_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
24 changes: 10 additions & 14 deletions src/mx_bluesky/hyperion/experiment_plans/rotation_scan_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -76,6 +79,7 @@ class RotationScanComposite(OavSnapshotComposite):
sample_shutter: ZebraShutter
zebra: Zebra
oav: OAV
xbpm_feedback: XBPMFeedback


def create_devices(context: BlueskyContext) -> RotationScanComposite:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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...")
Expand All @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions src/mx_bluesky/hyperion/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
)


Expand Down
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -610,6 +612,7 @@ def fake_create_rotation_devices(
robot=robot,
oav=oav,
sample_shutter=sample_shutter,
xbpm_feedback=xbpm_feedback,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down

0 comments on commit 52454e5

Please sign in to comment.