diff --git a/src/artemis/experiment_plans/fast_grid_scan_plan.py b/src/artemis/experiment_plans/fast_grid_scan_plan.py index fac4ee27d..f140b94e6 100755 --- a/src/artemis/experiment_plans/fast_grid_scan_plan.py +++ b/src/artemis/experiment_plans/fast_grid_scan_plan.py @@ -11,6 +11,7 @@ from dodal.beamlines import i03 from dodal.beamlines.i03 import ( ApertureScatterguard, + Attenuator, Backlight, EigerDetector, FastGridScan, @@ -61,6 +62,7 @@ class FGSComposite: synchrotron: Synchrotron undulator: Undulator zebra: Zebra + attenuator: Attenuator def __init__( self, @@ -82,6 +84,7 @@ def __init__( self.undulator = i03.undulator(fake_with_ophyd_sim=fake) self.synchrotron = i03.synchrotron(fake_with_ophyd_sim=fake) self.zebra = i03.zebra(fake_with_ophyd_sim=fake) + self.attenuator = i03.attenuator(fake_with_ophyd_sim=fake) fast_grid_scan_composite: FGSComposite | None = None @@ -131,6 +134,7 @@ def read_hardware_for_ispyb( undulator: Undulator, synchrotron: Synchrotron, s4_slit_gaps: S4SlitGaps, + attenuator: Attenuator, flux: Flux, ): artemis.log.LOGGER.info( @@ -143,6 +147,7 @@ def read_hardware_for_ispyb( yield from bps.read(synchrotron.machine_status.synchrotron_mode) yield from bps.read(s4_slit_gaps.xgap) yield from bps.read(s4_slit_gaps.ygap) + yield from bps.read(attenuator.actual_transmission) yield from bps.read(flux.flux_reading) yield from bps.save() @@ -213,6 +218,7 @@ def run_gridscan( fgs_composite.undulator, fgs_composite.synchrotron, fgs_composite.s4_slit_gaps, + fgs_composite.attenuator, fgs_composite.flux, ) @@ -233,6 +239,8 @@ def do_fgs(): yield from bps.kickoff(fgs_motors) yield from bps.complete(fgs_motors, wait=True) + # Wait for arming to finish + yield from bps.wait("ready_for_data_collection") yield from bps.stage(fgs_composite.eiger) with TRACER.start_span("do_fgs"): diff --git a/src/artemis/experiment_plans/full_grid_scan.py b/src/artemis/experiment_plans/full_grid_scan.py index 07e420041..86436e1c6 100644 --- a/src/artemis/experiment_plans/full_grid_scan.py +++ b/src/artemis/experiment_plans/full_grid_scan.py @@ -8,6 +8,7 @@ from bluesky import preprocessors as bpp from dodal.beamlines import i03 from dodal.devices.aperturescatterguard import AperturePositions, ApertureScatterguard +from dodal.devices.attenuator import Attenuator from dodal.devices.backlight import Backlight from dodal.devices.detector_motion import DetectorMotion from dodal.devices.eiger import EigerDetector @@ -80,6 +81,7 @@ def create_parameters_for_fast_grid_scan( def start_arming_then_do_grid( parameters: GridScanWithEdgeDetectInternalParameters, + attenuator: Attenuator, backlight: Backlight, eiger: EigerDetector, aperture_scatterguard: ApertureScatterguard, @@ -87,7 +89,12 @@ def start_arming_then_do_grid( oav_params: OAVParameters, ): # Start stage with asynchronous arming here - yield from bps.abs_set(eiger.do_arm, 1, group="arming") + yield from bps.abs_set(eiger.do_arm, 1, group="ready_for_data_collection") + yield from bps.abs_set( + attenuator, + parameters.artemis_params.ispyb_params.transmission, + group="ready_for_data_collection", + ) yield from bpp.contingency_wrapper( detect_grid_and_do_gridscan( @@ -181,6 +188,7 @@ def get_plan( eiger: EigerDetector = i03.eiger() aperture_scatterguard: ApertureScatterguard = i03.aperture_scatterguard() detector_motion: DetectorMotion = i03.detector_motion() + attenuator: Attenuator = i03.attenuator() eiger.set_detector_parameters(parameters.artemis_params.detector_params) @@ -188,6 +196,7 @@ def get_plan( return start_arming_then_do_grid( parameters, + attenuator, backlight, eiger, aperture_scatterguard, diff --git a/src/artemis/experiment_plans/tests/test_fast_grid_scan_plan.py b/src/artemis/experiment_plans/tests/test_fast_grid_scan_plan.py index 60e6ac42d..2a1be4688 100644 --- a/src/artemis/experiment_plans/tests/test_fast_grid_scan_plan.py +++ b/src/artemis/experiment_plans/tests/test_fast_grid_scan_plan.py @@ -79,6 +79,9 @@ def test_read_hardware_for_ispyb_updates_from_ophyd_devices( synchrotron_test_value ) + transmission_test_value = 0.5 + fake_fgs_composite.attenuator.actual_transmission.sim_put(transmission_test_value) + xgap_test_value = 0.1234 ygap_test_value = 0.2345 fake_fgs_composite.s4_slit_gaps.xgap.user_readback.sim_put(xgap_test_value) @@ -91,9 +94,9 @@ def test_read_hardware_for_ispyb_updates_from_ophyd_devices( test_ispyb_callback.ispyb = MagicMock() RE.subscribe(test_ispyb_callback) - def standalone_read_hardware_for_ispyb(und, syn, slits, fl): + def standalone_read_hardware_for_ispyb(und, syn, slits, attn, fl): yield from bps.open_run() - yield from read_hardware_for_ispyb(und, syn, slits, fl) + yield from read_hardware_for_ispyb(und, syn, slits, attn, fl) yield from bps.close_run() RE( @@ -101,6 +104,7 @@ def standalone_read_hardware_for_ispyb(und, syn, slits, fl): fake_fgs_composite.undulator, fake_fgs_composite.synchrotron, fake_fgs_composite.s4_slit_gaps, + fake_fgs_composite.attenuator, fake_fgs_composite.flux, ) ) @@ -110,6 +114,8 @@ def standalone_read_hardware_for_ispyb(und, syn, slits, fl): assert params.artemis_params.ispyb_params.synchrotron_mode == synchrotron_test_value assert params.artemis_params.ispyb_params.slit_gap_size_x == xgap_test_value assert params.artemis_params.ispyb_params.slit_gap_size_y == ygap_test_value + assert params.artemis_params.ispyb_params.transmission == transmission_test_value + assert params.artemis_params.ispyb_params.flux == flux_test_value @patch( diff --git a/src/artemis/experiment_plans/tests/test_full_grid_scan_plan.py b/src/artemis/experiment_plans/tests/test_full_grid_scan_plan.py index b8793261e..6f53b8b80 100644 --- a/src/artemis/experiment_plans/tests/test_full_grid_scan_plan.py +++ b/src/artemis/experiment_plans/tests/test_full_grid_scan_plan.py @@ -242,6 +242,7 @@ class DetectException(Exception): RE( start_arming_then_do_grid( parameters=test_full_grid_scan_params, + attenuator=MagicMock(), backlight=MagicMock(), eiger=eiger, aperture_scatterguard=MagicMock(), @@ -254,3 +255,29 @@ class DetectException(Exception): eiger.async_stage.assert_called_once() eiger.disarm_detector.assert_called_once() + + +@patch("artemis.experiment_plans.full_grid_scan.detect_grid_and_do_gridscan") +def test_when_start_arming_then_transmission_set( + mock_grid_detection_plan: MagicMock, + RE: RunEngine, + test_full_grid_scan_params: GridScanWithEdgeDetectInternalParameters, + test_config_files: Dict, +): + attenuator = MagicMock() + RE( + start_arming_then_do_grid( + parameters=test_full_grid_scan_params, + attenuator=attenuator, + backlight=MagicMock(), + eiger=MagicMock(), + aperture_scatterguard=MagicMock(), + detector_motion=MagicMock(), + oav_params=OAVParameters("xrayCentring", **test_config_files), + ) + ) + + # Check transmission set + attenuator.set.assert_called_once_with( + test_full_grid_scan_params.artemis_params.ispyb_params.transmission + ) diff --git a/src/artemis/external_interaction/callbacks/fgs/ispyb_callback.py b/src/artemis/external_interaction/callbacks/fgs/ispyb_callback.py index 0fc002042..c612ec3c3 100644 --- a/src/artemis/external_interaction/callbacks/fgs/ispyb_callback.py +++ b/src/artemis/external_interaction/callbacks/fgs/ispyb_callback.py @@ -81,6 +81,9 @@ def event(self, doc: dict): self.params.artemis_params.ispyb_params.slit_gap_size_y = doc["data"][ "s4_slit_gaps_ygap" ] + self.params.artemis_params.ispyb_params.transmission = doc["data"][ + "attenuator_actual_transmission" + ] LOGGER.info("Creating ispyb entry.") self.ispyb_ids = self.ispyb.begin_deposition() diff --git a/src/artemis/external_interaction/callbacks/fgs/tests/conftest.py b/src/artemis/external_interaction/callbacks/fgs/tests/conftest.py index cad9600dd..735049a42 100644 --- a/src/artemis/external_interaction/callbacks/fgs/tests/conftest.py +++ b/src/artemis/external_interaction/callbacks/fgs/tests/conftest.py @@ -96,6 +96,7 @@ class TestData: "s4_slit_gaps_ygap": 0.2345, "synchrotron_machine_status_synchrotron_mode": "test", "undulator_gap": 1.234, + "attenuator_actual_transmission": 1, }, "timestamps": {"det1": 1666604299.8220396, "det2": 1666604299.8235943}, "seq_num": 1, diff --git a/src/artemis/system_tests/test_main_system.py b/src/artemis/system_tests/test_main_system.py index 021187f92..345f1108b 100644 --- a/src/artemis/system_tests/test_main_system.py +++ b/src/artemis/system_tests/test_main_system.py @@ -300,6 +300,7 @@ def test_cli_args_parse(): assert test_args == ("DEBUG", True, True, True) +@patch("dodal.beamlines.i03.Attenuator") @patch("dodal.beamlines.i03.Flux") @patch("dodal.beamlines.i03.DetectorMotion") @patch("dodal.beamlines.i03.OAV") @@ -328,6 +329,7 @@ def test_when_blueskyrunner_initiated_then_plans_are_setup_and_devices_connected aperture_scatterguard, oav, detector_motion, + attenuator, flux, ): type_comparison.return_value = True @@ -343,6 +345,7 @@ def test_when_blueskyrunner_initiated_then_plans_are_setup_and_devices_connected aperture_scatterguard.return_value.wait_for_connection.assert_called() oav.return_value.wait_for_connection.assert_called() detector_motion.return_value.wait_for_connection.assert_called() + attenuator.return_value.wait_for_connection.assert_called() flux.return_value.wait_for_connection.assert_called()