diff --git a/src/hyperion/device_setup_plans/read_hardware_for_setup.py b/src/hyperion/device_setup_plans/read_hardware_for_setup.py index 3a2cb960c..3e7b5cb48 100644 --- a/src/hyperion/device_setup_plans/read_hardware_for_setup.py +++ b/src/hyperion/device_setup_plans/read_hardware_for_setup.py @@ -20,7 +20,6 @@ def read_hardware_for_ispyb_pre_collection( undulator: Undulator, synchrotron: Synchrotron, s4_slit_gaps: S4SlitGaps, - aperture_scatterguard: ApertureScatterguard, robot: BartRobot, smargon: Smargon, ): @@ -32,7 +31,6 @@ def read_hardware_for_ispyb_pre_collection( yield from bps.read(synchrotron.synchrotron_mode) yield from bps.read(s4_slit_gaps.xgap) yield from bps.read(s4_slit_gaps.ygap) - yield from bps.read(aperture_scatterguard) yield from bps.read(smargon.x) yield from bps.read(smargon.y) yield from bps.read(smargon.z) @@ -40,12 +38,14 @@ def read_hardware_for_ispyb_pre_collection( def read_hardware_for_ispyb_during_collection( + aperture_scatterguard: ApertureScatterguard, attenuator: Attenuator, flux: Flux, dcm: DCM, ): LOGGER.info("Reading status of beamline for ispyb deposition, during collection.") yield from bps.create(name=CONST.DESCRIPTORS.ISPYB_TRANSMISSION_FLUX_READ) + yield from bps.read(aperture_scatterguard) yield from bps.read(attenuator.actual_transmission) yield from bps.read(flux.flux_reading) yield from bps.read(dcm.energy_in_kev) diff --git a/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py b/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py index a4d26b386..dd2de7c2a 100755 --- a/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py +++ b/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py @@ -269,13 +269,17 @@ def run_gridscan( fgs_composite.undulator, fgs_composite.synchrotron, fgs_composite.s4_slit_gaps, - fgs_composite.aperture_scatterguard, fgs_composite.robot, fgs_composite.smargon, ) - yield from read_hardware_for_ispyb_during_collection( - fgs_composite.attenuator, fgs_composite.flux, fgs_composite.dcm - ) + + read_during_collection = partial( + read_hardware_for_ispyb_during_collection, + fgs_composite.aperture_scatterguard, + fgs_composite.attenuator, + fgs_composite.flux, + fgs_composite.dcm, + ) LOGGER.info("Setting fgs params") yield from feature_controlled.set_flyscan_params() @@ -284,7 +288,7 @@ def run_gridscan( yield from wait_for_gridscan_valid(feature_controlled.fgs_motors) LOGGER.info("Waiting for arming to finish") - yield from bps.wait("ready_for_data_collection") + yield from bps.wait(CONST.WAIT.GRID_READY_FOR_DC) yield from bps.stage(fgs_composite.eiger) # This needs to occur after eiger is armed so that @@ -299,6 +303,7 @@ def run_gridscan( parameters.zocalo_environment, [parameters.scan_points_first_grid, parameters.scan_points_second_grid], parameters.scan_indices, + do_during_run=read_during_collection, ) yield from bps.abs_set(feature_controlled.fgs_motors.z_steps, 0, wait=False) @@ -310,6 +315,7 @@ def kickoff_and_complete_gridscan( zocalo_environment: str, scan_points: list[AxesPoints[Axis]], scan_start_indices: list[int], + do_during_run: Callable[[], MsgGenerator] | None = None, ): @TRACER.start_as_current_span(CONST.PLAN.DO_FGS) @bpp.set_run_key_decorator(CONST.PLAN.DO_FGS) @@ -345,6 +351,9 @@ def do_fgs(): yield from bps.wait( ZOCALO_STAGE_GROUP ) # Make sure ZocaloResults queue is clear and ready to accept our new data + if do_during_run: + LOGGER.info(f"Running {do_during_run} during FGS") + yield from do_during_run() LOGGER.info("completing FGS") yield from bps.complete(gridscan, wait=True) diff --git a/src/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py b/src/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py index e2e9b4c5d..88910bc9e 100644 --- a/src/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py +++ b/src/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py @@ -49,6 +49,7 @@ ispyb_activation_wrapper, ) from hyperion.log import LOGGER +from hyperion.parameters.constants import CONST from hyperion.parameters.gridscan import GridScanWithEdgeDetect, ThreeDGridScan from hyperion.utils.aperturescatterguard import ( load_default_aperture_scatterguard_positions_if_unset, @@ -154,7 +155,9 @@ def run_grid_detection_plan( yield from bps.abs_set(composite.backlight, BacklightPosition.OUT) yield from move_aperture_if_required( - composite.aperture_scatterguard, parameters.selected_aperture + composite.aperture_scatterguard, + parameters.selected_aperture, + group=CONST.WAIT.GRID_READY_FOR_DC, ) yield from flyscan_xray_centre( @@ -210,4 +213,5 @@ def grid_detect_then_xray_centre( composite.detector_motion, parameters.detector_params.detector_distance, plan_to_perform, + group=CONST.WAIT.GRID_READY_FOR_DC, ) diff --git a/src/hyperion/experiment_plans/pin_centre_then_xray_centre_plan.py b/src/hyperion/experiment_plans/pin_centre_then_xray_centre_plan.py index 7873cb115..d0c769aea 100644 --- a/src/hyperion/experiment_plans/pin_centre_then_xray_centre_plan.py +++ b/src/hyperion/experiment_plans/pin_centre_then_xray_centre_plan.py @@ -18,6 +18,7 @@ pin_tip_centre_plan, ) from hyperion.log import LOGGER +from hyperion.parameters.constants import CONST from hyperion.parameters.gridscan import ( GridScanWithEdgeDetect, PinTipCentreThenXrayCentre, @@ -93,4 +94,5 @@ def pin_tip_centre_then_xray_centre( composite.detector_motion, parameters.detector_params.detector_distance, pin_centre_then_xray_centre_plan(composite, parameters, oav_config_file), + group=CONST.WAIT.GRID_READY_FOR_DC, ) diff --git a/src/hyperion/experiment_plans/robot_load_then_centre_plan.py b/src/hyperion/experiment_plans/robot_load_then_centre_plan.py index 3f0ed83c4..3e62409a5 100644 --- a/src/hyperion/experiment_plans/robot_load_then_centre_plan.py +++ b/src/hyperion/experiment_plans/robot_load_then_centre_plan.py @@ -224,4 +224,5 @@ def robot_load_then_centre( composite.detector_motion, parameters.detector_distance_mm, robot_load_then_centre_plan(composite, parameters), + group=CONST.WAIT.GRID_READY_FOR_DC, ) diff --git a/src/hyperion/experiment_plans/rotation_scan_plan.py b/src/hyperion/experiment_plans/rotation_scan_plan.py index f1f01c754..39a470a72 100644 --- a/src/hyperion/experiment_plans/rotation_scan_plan.py +++ b/src/hyperion/experiment_plans/rotation_scan_plan.py @@ -210,7 +210,6 @@ def _rotation_scan_plan( yield from bps.wait("setup_senv") yield from bps.wait("move_gonio_to_start") yield from bps.wait("move_to_rotation_start") - yield from bps.wait("setup_zebra") # get some information for the ispyb deposition and trigger the callback yield from read_hardware_for_zocalo(composite.eiger) @@ -219,19 +218,18 @@ def _rotation_scan_plan( composite.undulator, composite.synchrotron, composite.s4_slit_gaps, - composite.aperture_scatterguard, composite.robot, composite.smargon, ) - yield from read_hardware_for_ispyb_during_collection( - composite.attenuator, composite.flux, composite.dcm - ) + yield from read_hardware_for_nexus_writer(composite.eiger) # Get ready for the actual scan yield from bps.abs_set( axis.velocity, motion_values.speed_for_rotation_deg_s, wait=True ) + + yield from bps.wait("setup_zebra") yield from arm_zebra(composite.zebra) # Check topup gate @@ -244,6 +242,13 @@ def _rotation_scan_plan( LOGGER.info("Executing rotation scan") yield from bps.rel_set(axis, motion_values.distance_to_move_deg, wait=True) + yield from read_hardware_for_ispyb_during_collection( + composite.aperture_scatterguard, + composite.attenuator, + composite.flux, + composite.dcm, + ) + yield from _rotation_scan_plan(motion_values, composite) diff --git a/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py b/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py index b841f86c2..e7c74eca4 100644 --- a/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py +++ b/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py @@ -103,17 +103,8 @@ def _handle_ispyb_hardware_read(self, doc) -> Sequence[ScanDataInfo]: synchrotron_mode := doc["data"]["synchrotron-synchrotron_mode"], SynchrotronMode, ) - aperture_size = SingleAperturePosition( - **doc["data"]["aperture_scatterguard-selected_aperture"] - ) - beamsize = beam_size_from_aperture(aperture_size) - beamsize_x_mm = beamsize.x_um / 1000 if beamsize.x_um else None - beamsize_y_mm = beamsize.y_um / 1000 if beamsize.y_um else None + hwscan_data_collection_info = DataCollectionInfo( - beamsize_at_samplex=beamsize_x_mm, - beamsize_at_sampley=beamsize_y_mm, - focal_spot_size_at_samplex=beamsize_x_mm, - focal_spot_size_at_sampley=beamsize_y_mm, undulator_gap1=doc["data"]["undulator-current_gap"], synchrotron_mode=synchrotron_mode.value, slitgap_horizontal=doc["data"]["s4_slit_gaps_xgap"], @@ -132,8 +123,18 @@ def _handle_ispyb_hardware_read(self, doc) -> Sequence[ScanDataInfo]: def _handle_ispyb_transmission_flux_read(self, doc) -> Sequence[ScanDataInfo]: assert self.params + aperture_size = SingleAperturePosition( + **doc["data"]["aperture_scatterguard-selected_aperture"] + ) + beamsize = beam_size_from_aperture(aperture_size) + beamsize_x_mm = beamsize.x_um / 1000 if beamsize.x_um else None + beamsize_y_mm = beamsize.y_um / 1000 if beamsize.y_um else None hwscan_data_collection_info = DataCollectionInfo( - flux=doc["data"]["flux_flux_reading"] + beamsize_at_samplex=beamsize_x_mm, + beamsize_at_sampley=beamsize_y_mm, + focal_spot_size_at_samplex=beamsize_x_mm, + focal_spot_size_at_sampley=beamsize_y_mm, + flux=doc["data"]["flux_flux_reading"], ) if transmission := doc["data"]["attenuator-actual_transmission"]: # Ispyb wants the transmission in a percentage, we use fractions @@ -152,6 +153,7 @@ def _handle_ispyb_transmission_flux_read(self, doc) -> Sequence[ScanDataInfo]: hwscan_data_collection_info, None, self.params ) ISPYB_LOGGER.info("Updating ispyb data collection after flux read.") + self.append_to_comment(f"Aperture: {aperture_size.name}. ") return scan_data_infos @abstractmethod diff --git a/src/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py b/src/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py index b1bb06b0d..d57a8c0f2 100644 --- a/src/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py +++ b/src/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py @@ -3,8 +3,6 @@ from collections.abc import Sequence from typing import TYPE_CHECKING, Any, Callable, Optional -from dodal.devices.aperturescatterguard import SingleAperturePosition - from hyperion.external_interaction.callbacks.common.ispyb_mapping import ( populate_data_collection_group, populate_remaining_data_collection_info, @@ -125,10 +123,6 @@ def populate_info_for_update( def _handle_ispyb_hardware_read(self, doc: Event): """Use the hardware read values to create the ispyb comment""" scan_data_infos = super()._handle_ispyb_hardware_read(doc) - aperture_size = SingleAperturePosition( - **doc["data"]["aperture_scatterguard-selected_aperture"] - ) - motor_positions = [ doc["data"]["smargon-x"], doc["data"]["smargon-y"], @@ -137,7 +131,7 @@ def _handle_ispyb_hardware_read(self, doc: Event): assert ( self.params ), "handle_ispyb_hardware_read triggered beore activity_gated_start" - comment = f"Sample position: ({motor_positions[0]}, {motor_positions[1]}, {motor_positions[2]}) {self.params.comment} Aperture: {aperture_size.name}" + comment = f"Sample position: ({motor_positions[0]}, {motor_positions[1]}, {motor_positions[2]}) {self.params.comment} " scan_data_infos[0].data_collection_info.comments = comment return scan_data_infos diff --git a/src/hyperion/parameters/constants.py b/src/hyperion/parameters/constants.py index 4f8ebc89e..9a1b85a78 100644 --- a/src/hyperion/parameters/constants.py +++ b/src/hyperion/parameters/constants.py @@ -34,6 +34,13 @@ class PlanNameConstants: ROTATION_MAIN = "rotation_scan_main" +@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" + + @dataclass(frozen=True) class DocDescriptorNames: # Robot load event descriptor @@ -106,6 +113,7 @@ class HyperionConstants: I03 = I03Constants() PARAM = ExperimentParamConstants() PLAN = PlanNameConstants() + WAIT = PlanGroupCheckpointConstants() SIM = SimConstants() TRIGGER = TriggerConstants() CALLBACK_0MQ_PROXY_PORTS = (5577, 5578) diff --git a/src/hyperion/snapshot_plan.py b/src/hyperion/snapshot_plan.py deleted file mode 100644 index be0cd352c..000000000 --- a/src/hyperion/snapshot_plan.py +++ /dev/null @@ -1,46 +0,0 @@ -import bluesky.plan_stubs as bps -import bluesky.preprocessors as bpp -from bluesky.run_engine import RunEngine -from dodal.devices.aperture import Aperture -from dodal.devices.backlight import Backlight -from dodal.devices.oav.oav_detector import OAV - - -def prepare_for_snapshot(backlight: Backlight, aperture: Aperture): - yield from bps.abs_set(backlight, Backlight.IN, group="A") - # TODO get from beamlineParameters miniap_y_ROBOT_LOAD - aperture_y_snapshot_position = 31.40 - aperture.wait_for_connection() - if (yield from bps.rd(aperture.y)) > aperture_y_snapshot_position: - yield from bps.abs_set(aperture.y, aperture_y_snapshot_position, group="A") - yield from bps.wait("A") - - -def take_snapshot(oav: OAV, snapshot_filename, snapshot_directory): - oav.wait_for_connection() - yield from bps.abs_set(oav.grid_snapshot.filename, snapshot_filename) - yield from bps.abs_set(oav.grid_snapshot.directory, snapshot_directory) - yield from bps.trigger(oav.grid_snapshot, wait=True) - - -@bpp.run_decorator() -def snapshot_plan( - oav: OAV, - backlight: Backlight, - aperture: Aperture, - snapshot_filename: str, - snapshot_directory: str, -): - yield from prepare_for_snapshot(backlight, aperture) - yield from take_snapshot(oav, snapshot_filename, snapshot_directory) - - -if __name__ == "__main__": - beamline = "BL03I" - backlight = Backlight(name="Backlight", prefix=f"{beamline}") - aperture = Aperture(name="Aperture", prefix=f"{beamline}-MO-MAPT-01:") - oav = OAV(name="oav", prefix=f"{beamline}-DI-OAV-01") - snapshot_filename = "snapshot" - snapshot_directory = "." - RE = RunEngine() - RE(snapshot_plan(oav, backlight, aperture, snapshot_filename, snapshot_directory)) diff --git a/src/hyperion/utils/validation.py b/src/hyperion/utils/validation.py index 65811fdf0..010747321 100644 --- a/src/hyperion/utils/validation.py +++ b/src/hyperion/utils/validation.py @@ -64,7 +64,10 @@ def fake_rotation_scan( ) def plan(): yield from read_hardware_for_ispyb_during_collection( - rotation_devices.attenuator, rotation_devices.flux, rotation_devices.dcm + rotation_devices.aperture_scatterguard, + rotation_devices.attenuator, + rotation_devices.flux, + rotation_devices.dcm, ) yield from read_hardware_for_nexus_writer(rotation_devices.eiger) diff --git a/tests/system_tests/experiment_plans/test_fgs_plan.py b/tests/system_tests/experiment_plans/test_fgs_plan.py index 1ad10928f..5993bd4e6 100644 --- a/tests/system_tests/experiment_plans/test_fgs_plan.py +++ b/tests/system_tests/experiment_plans/test_fgs_plan.py @@ -141,14 +141,9 @@ def test_read_hardware_for_ispyb_pre_collection( @bpp.run_decorator() def read_run(u, s, g, r, a, f, dcm, ap_sg, sm): yield from read_hardware_for_ispyb_pre_collection( - undulator=u, - synchrotron=s, - s4_slit_gaps=g, - aperture_scatterguard=ap_sg, - robot=r, - smargon=sm, + undulator=u, synchrotron=s, s4_slit_gaps=g, robot=r, smargon=sm ) - yield from read_hardware_for_ispyb_during_collection(a, f, dcm) + yield from read_hardware_for_ispyb_during_collection(ap_sg, a, f, dcm) RE( read_run( diff --git a/tests/system_tests/experiment_plans/test_plan_system.py b/tests/system_tests/experiment_plans/test_plan_system.py index 583f62fe8..2dceca8bf 100644 --- a/tests/system_tests/experiment_plans/test_plan_system.py +++ b/tests/system_tests/experiment_plans/test_plan_system.py @@ -29,13 +29,13 @@ async def test_getting_data_for_ispyb(): ) smargon = i03.smargon(fake_with_ophyd_sim=True) - undulator.wait_for_connection() + await undulator.connect() await synchrotron.connect() slit_gaps.wait_for_connection() - attenuator.wait_for_connection() + await attenuator.connect() flux.wait_for_connection() - aperture_scatterguard.wait_for_connection() - smargon.wait_for_connection() + await aperture_scatterguard.connect() + await smargon.connect() robot = i03.robot(fake_with_ophyd_sim=True) RE = RunEngine() @@ -43,9 +43,9 @@ async def test_getting_data_for_ispyb(): @bpp.run_decorator() def standalone_read_hardware(und, syn, slits, robot, att, flux, ap_sg, sm): yield from read_hardware_for_ispyb_pre_collection( - und, syn, slits, robot, ap_sg, smargon=sm + und, syn, slits, robot, smargon=sm ) - yield from read_hardware_for_ispyb_during_collection(att, flux, dcm) + yield from read_hardware_for_ispyb_during_collection(ap_sg, att, flux, dcm) RE( standalone_read_hardware( diff --git a/tests/system_tests/external_interaction/test_nexgen.py b/tests/system_tests/external_interaction/test_nexgen.py index cb4c9ba38..8cf49bc32 100644 --- a/tests/system_tests/external_interaction/test_nexgen.py +++ b/tests/system_tests/external_interaction/test_nexgen.py @@ -162,7 +162,10 @@ def _fake_rotation_scan( ) def plan(): yield from read_hardware_for_ispyb_during_collection( - rotation_devices.attenuator, rotation_devices.flux, rotation_devices.dcm + rotation_devices.aperture_scatterguard, + rotation_devices.attenuator, + rotation_devices.flux, + rotation_devices.dcm, ) yield from read_hardware_for_nexus_writer(rotation_devices.eiger) diff --git a/tests/unit_tests/experiment_plans/conftest.py b/tests/unit_tests/experiment_plans/conftest.py index 6bc36f08b..9dc5c2c90 100644 --- a/tests/unit_tests/experiment_plans/conftest.py +++ b/tests/unit_tests/experiment_plans/conftest.py @@ -42,18 +42,18 @@ def make_event_doc(data, descriptor="abc123") -> Event: "synchrotron-synchrotron_mode": SynchrotronMode.USER, "s4_slit_gaps_xgap": 0, "s4_slit_gaps_ygap": 0, - "aperture_scatterguard-selected_aperture": { - "name": "Robot_load", - "GDA_name": "ROBOT_LOAD", - "radius_microns": None, - "location": (15, 16, 2, 18, 19), - }, "smargon-x": 10.0, "smargon-y": 20.0, "smargon-z": 30.0, } BASIC_POST_SETUP_DOC = { + "aperture_scatterguard-selected_aperture": { + "name": "Robot_load", + "GDA_name": "ROBOT_LOAD", + "radius_microns": None, + "location": (15, 16, 2, 18, 19), + }, "attenuator-actual_transmission": 0, "flux_flux_reading": 10, "dcm-energy_in_kev": 11.105, diff --git a/tests/unit_tests/experiment_plans/test_flyscan_xray_centre_plan.py b/tests/unit_tests/experiment_plans/test_flyscan_xray_centre_plan.py index 4f8569299..e2552a0de 100644 --- a/tests/unit_tests/experiment_plans/test_flyscan_xray_centre_plan.py +++ b/tests/unit_tests/experiment_plans/test_flyscan_xray_centre_plan.py @@ -104,10 +104,8 @@ def ispyb_plan(test_fgs_params: ThreeDGridScan): def standalone_read_hardware_for_ispyb( und, syn, slits, robot, attn, fl, dcm, ap_sg, sm ): - yield from read_hardware_for_ispyb_pre_collection( - und, syn, slits, ap_sg, robot, sm - ) - yield from read_hardware_for_ispyb_during_collection(attn, fl, dcm) + yield from read_hardware_for_ispyb_pre_collection(und, syn, slits, robot, sm) + yield from read_hardware_for_ispyb_during_collection(ap_sg, attn, fl, dcm) return standalone_read_hardware_for_ispyb @@ -270,12 +268,12 @@ def test_read_hardware_for_ispyb_updates_from_ophyd_devices( "synchrotron-synchrotron_mode": synchrotron_test_value.value, "s4_slit_gaps_xgap": xgap_test_value, "s4_slit_gaps_ygap": ygap_test_value, - 'aperture_scatterguard-selected_aperture': ap_sg_test_value }, ) assert_event( test_ispyb_callback.activity_gated_event.mock_calls[1], # pyright: ignore { + 'aperture_scatterguard-selected_aperture': ap_sg_test_value, "attenuator-actual_transmission": transmission_test_value, "flux_flux_reading": flux_test_value, "dcm-energy_in_kev": current_energy_kev_test_value, @@ -514,8 +512,10 @@ def _wrapped_gridscan_and_move(): ) app_to_comment: MagicMock = ispyb_cb.ispyb.append_to_comment # type:ignore app_to_comment.assert_called() - call = app_to_comment.call_args_list[0] - assert "Crystal 1: Strength 999999" in call.args[1] + append_aperture_call = app_to_comment.call_args_list[0].args[1] + append_zocalo_call = app_to_comment.call_args_list[-1].args[1] + assert "Aperture:" in append_aperture_call + assert "Crystal 1: Strength 999999" in append_zocalo_call @patch( "hyperion.experiment_plans.flyscan_xray_centre_plan.check_topup_and_wait_if_necessary", @@ -602,8 +602,10 @@ def wrapped_gridscan_and_move(): ) app_to_comment: MagicMock = ispyb_cb.ispyb.append_to_comment # type:ignore app_to_comment.assert_called() - call = app_to_comment.call_args_list[0] - assert "Zocalo found no crystals in this gridscan" in call.args[1] + append_aperture_call = app_to_comment.call_args_list[0].args[1] + append_zocalo_call = app_to_comment.call_args_list[-1].args[1] + assert "Aperture:" in append_aperture_call + assert "Zocalo found no crystals in this gridscan" in append_zocalo_call @patch( "hyperion.experiment_plans.flyscan_xray_centre_plan.bps.complete", autospec=True @@ -982,7 +984,7 @@ def test_kickoff_and_complete_gridscan_triggers_zocalo( @patch( "hyperion.experiment_plans.flyscan_xray_centre_plan.kickoff_and_complete_gridscan", - new=MagicMock(side_effect=lambda *_: iter([Msg("kickoff_gridscan")])), + new=MagicMock(side_effect=lambda *_, **__: iter([Msg("kickoff_gridscan")])), ) def test_read_hardware_for_nexus_occurs_after_eiger_arm( self, diff --git a/tests/unit_tests/experiment_plans/test_pin_centre_then_xray_centre_plan.py b/tests/unit_tests/experiment_plans/test_pin_centre_then_xray_centre_plan.py index d7e352753..2f3f476ac 100644 --- a/tests/unit_tests/experiment_plans/test_pin_centre_then_xray_centre_plan.py +++ b/tests/unit_tests/experiment_plans/test_pin_centre_then_xray_centre_plan.py @@ -11,6 +11,7 @@ pin_centre_then_xray_centre_plan, pin_tip_centre_then_xray_centre, ) +from hyperion.parameters.constants import CONST from hyperion.parameters.gridscan import PinTipCentreThenXrayCentre from ...conftest import raw_params_from_file @@ -116,7 +117,7 @@ def add_handlers_to_simulate_detector_motion(msg: Msg): ) sim_run_engine.add_wait_handler( - add_handlers_to_simulate_detector_motion, "ready_for_data_collection" + add_handlers_to_simulate_detector_motion, CONST.WAIT.GRID_READY_FOR_DC ) messages = sim_run_engine.simulate_plan( @@ -131,14 +132,14 @@ def add_handlers_to_simulate_detector_motion(msg: Msg): messages, lambda msg: msg.obj is simple_beamline.detector_motion.z ) assert messages[0].args[0] == 100 - assert messages[0].kwargs["group"] == "ready_for_data_collection" + assert messages[0].kwargs["group"] == CONST.WAIT.GRID_READY_FOR_DC assert messages[1].obj is simple_beamline.detector_motion.shutter assert messages[1].args[0] == 1 - assert messages[1].kwargs["group"] == "ready_for_data_collection" + assert messages[1].kwargs["group"] == CONST.WAIT.GRID_READY_FOR_DC messages = sim_run_engine.assert_message_and_return_remaining( messages[2:], lambda msg: msg.command == "wait" - and msg.kwargs["group"] == "ready_for_data_collection", + and msg.kwargs["group"] == CONST.WAIT.GRID_READY_FOR_DC, ) sim_run_engine.assert_message_and_return_remaining( messages[2:], diff --git a/tests/unit_tests/external_interaction/callbacks/conftest.py b/tests/unit_tests/external_interaction/callbacks/conftest.py index 50eec51e0..92c6c4d5e 100644 --- a/tests/unit_tests/external_interaction/callbacks/conftest.py +++ b/tests/unit_tests/external_interaction/callbacks/conftest.py @@ -86,6 +86,12 @@ class TestData: "descriptor": "bd45c2e5-2b85-4280-95d7-a9a15800a78b", "time": 2666604299.928203, "data": { + "aperture_scatterguard-selected_aperture": { + "name": "Medium", + "GDA_name": "MEDIUM", + "radius_microns": 50, + "location": (15, 16, 2, 18, 19), + }, "attenuator-actual_transmission": 0.98, "flux_flux_reading": 9.81, "dcm-energy_in_kev": 11.105, @@ -209,12 +215,6 @@ class TestData: "s4_slit_gaps_ygap": 0.2345, "synchrotron-synchrotron_mode": SynchrotronMode.USER, "undulator-current_gap": 1.234, - "aperture_scatterguard-selected_aperture": { - "name": "Medium", - "GDA_name": "MEDIUM", - "radius_microns": 50, - "location": (15, 16, 2, 18, 19), - }, "smargon-x": 10.0, "smargon-y": 20.0, "smargon-z": 30.0, @@ -228,6 +228,12 @@ class TestData: "descriptor": "bd45c2e5-2b85-4280-95d7-a9a15800a78b", "time": 2666604299.928203, "data": { + "aperture_scatterguard-selected_aperture": { + "name": "Medium", + "GDA_name": "MEDIUM", + "radius_microns": 50, + "location": (15, 16, 2, 18, 19), + }, "attenuator-actual_transmission": 1, "flux_flux_reading": 10, "dcm-energy_in_kev": 11.105, diff --git a/tests/unit_tests/external_interaction/callbacks/rotation/test_ispyb_callback.py b/tests/unit_tests/external_interaction/callbacks/rotation/test_ispyb_callback.py index 86e55c83b..8810f7d5c 100644 --- a/tests/unit_tests/external_interaction/callbacks/rotation/test_ispyb_callback.py +++ b/tests/unit_tests/external_interaction/callbacks/rotation/test_ispyb_callback.py @@ -149,11 +149,7 @@ def test_hardware_read_events( "slitgapvertical": 0.2345, "synchrotronmode": "User", "undulatorgap1": 1.234, - "focal_spot_size_at_samplex": 0.05, - "focal_spot_size_at_sampley": 0.02, - "beamsize_at_samplex": 0.05, - "beamsize_at_sampley": 0.02, - "comments": "Sample position: (10.0, 20.0, 30.0) test Aperture: Medium", + "comments": "Sample position: (10.0, 20.0, 30.0) test ", }, ) assert_upsert_call_with( @@ -201,6 +197,10 @@ def test_flux_read_events( { "parentid": TEST_DATA_COLLECTION_GROUP_ID, "id": TEST_DATA_COLLECTION_IDS[0], + "focal_spot_size_at_samplex": 0.05, + "focal_spot_size_at_sampley": 0.02, + "beamsize_at_samplex": 0.05, + "beamsize_at_sampley": 0.02, "wavelength": 1.1164718451643736, "transmission": 98, "flux": 9.81, @@ -327,10 +327,6 @@ def test_comment_correct_after_hardware_read( "slitgapvertical": 0.2345, "synchrotronmode": "User", "undulatorgap1": 1.234, - "focal_spot_size_at_samplex": 0.05, - "focal_spot_size_at_sampley": 0.02, - "beamsize_at_samplex": 0.05, - "beamsize_at_sampley": 0.02, - "comments": "Sample position: (10.0, 20.0, 30.0) a lovely unit test Aperture: Medium", + "comments": "Sample position: (10.0, 20.0, 30.0) a lovely unit test ", }, ) diff --git a/tests/unit_tests/external_interaction/callbacks/test_rotation_callbacks.py b/tests/unit_tests/external_interaction/callbacks/test_rotation_callbacks.py index 4ea1abc44..d8e75c12a 100644 --- a/tests/unit_tests/external_interaction/callbacks/test_rotation_callbacks.py +++ b/tests/unit_tests/external_interaction/callbacks/test_rotation_callbacks.py @@ -42,6 +42,9 @@ from hyperion.parameters.components import IspybExperimentType from hyperion.parameters.constants import CONST from hyperion.parameters.rotation import RotationScan +from hyperion.utils.aperturescatterguard import ( + load_default_aperture_scatterguard_positions_if_unset, +) from ....conftest import raw_params_from_file @@ -90,6 +93,8 @@ def fake_rotation_scan( flux = make_fake_device(Flux)(name="flux") eiger = make_fake_device(EigerDetector)(name="eiger") dcm = i03.dcm(fake_with_ophyd_sim=True) + ap_sg = i03.aperture_scatterguard(fake_with_ophyd_sim=True) + load_default_aperture_scatterguard_positions_if_unset(ap_sg) set_mock_value(dcm.energy_in_kev.user_readback, 12.1) @bpp.subs_decorator(list(subscriptions)) @@ -114,7 +119,9 @@ def plan(): } ) def fake_main_plan(): - yield from read_hardware_for_ispyb_during_collection(attenuator, flux, dcm) + yield from read_hardware_for_ispyb_during_collection( + ap_sg, attenuator, flux, dcm + ) yield from read_hardware_for_nexus_writer(eiger) yield from read_hardware_for_zocalo(eiger) if after_main_do: diff --git a/tests/unit_tests/external_interaction/callbacks/xray_centre/test_ispyb_callback.py b/tests/unit_tests/external_interaction/callbacks/xray_centre/test_ispyb_callback.py index ec9bd51c1..9c1fcdd7f 100644 --- a/tests/unit_tests/external_interaction/callbacks/xray_centre/test_ispyb_callback.py +++ b/tests/unit_tests/external_interaction/callbacks/xray_centre/test_ispyb_callback.py @@ -100,10 +100,6 @@ def test_hardware_read_event_3d(self, mock_ispyb_conn): "slitgapvertical": 0.2345, "synchrotronmode": "User", "undulatorgap1": 1.234, - "focal_spot_size_at_samplex": 0.05, - "focal_spot_size_at_sampley": 0.02, - "beamsize_at_samplex": 0.05, - "beamsize_at_sampley": 0.02, }, ) assert_upsert_call_with( @@ -116,10 +112,6 @@ def test_hardware_read_event_3d(self, mock_ispyb_conn): "slitgapvertical": 0.2345, "synchrotronmode": "User", "undulatorgap1": 1.234, - "focal_spot_size_at_samplex": 0.05, - "focal_spot_size_at_sampley": 0.02, - "beamsize_at_samplex": 0.05, - "beamsize_at_sampley": 0.02, }, ) @@ -153,6 +145,10 @@ def test_flux_read_events_3d(self, mock_ispyb_conn): "transmission": 100, "flux": 10, "resolution": 1.1830593328548429, + "focal_spot_size_at_samplex": 0.05, + "focal_spot_size_at_sampley": 0.02, + "beamsize_at_samplex": 0.05, + "beamsize_at_sampley": 0.02, }, ) assert_upsert_call_with( @@ -165,6 +161,10 @@ def test_flux_read_events_3d(self, mock_ispyb_conn): "transmission": 100, "flux": 10, "resolution": 1.1830593328548429, + "focal_spot_size_at_samplex": 0.05, + "focal_spot_size_at_sampley": 0.02, + "beamsize_at_samplex": 0.05, + "beamsize_at_sampley": 0.02, }, ) mx_acq.update_dc_position.assert_not_called() diff --git a/tests/unit_tests/external_interaction/test_write_rotation_nexus.py b/tests/unit_tests/external_interaction/test_write_rotation_nexus.py index 3ebf80528..7f9011bfa 100644 --- a/tests/unit_tests/external_interaction/test_write_rotation_nexus.py +++ b/tests/unit_tests/external_interaction/test_write_rotation_nexus.py @@ -63,7 +63,10 @@ def fake_rotation_scan( ) def plan(): yield from read_hardware_for_ispyb_during_collection( - rotation_devices.attenuator, rotation_devices.flux, rotation_devices.dcm + rotation_devices.aperture_scatterguard, + rotation_devices.attenuator, + rotation_devices.flux, + rotation_devices.dcm, ) yield from read_hardware_for_nexus_writer(rotation_devices.eiger)