From 76774755a7cdc238dc27e5b67edc3ce6a2271e1f Mon Sep 17 00:00:00 2001 From: Robert Tuck Date: Fri, 24 May 2024 13:07:53 +0100 Subject: [PATCH 1/4] (#1303) read position for rotation scans in ispyb, remove position from ispyb_params --- .../read_hardware_for_setup.py | 5 ++ .../flyscan_xray_centre_plan.py | 1 + .../panda_flyscan_xray_centre_plan.py | 1 + .../experiment_plans/rotation_scan_plan.py | 1 + .../callbacks/common/ispyb_mapping.py | 11 ----- .../callbacks/ispyb_callback_base.py | 11 ++++- .../callbacks/rotation/ispyb_callback.py | 14 +++--- .../callbacks/xray_centre/ispyb_callback.py | 4 +- src/hyperion/parameters/components.py | 9 ++-- src/hyperion/parameters/rotation.py | 2 - .../experiment_plans/test_fgs_plan.py | 29 +++++------ .../experiment_plans/test_plan_system.py | 9 +++- .../test_ispyb_dev_connection.py | 2 +- .../good_test_rotation_scan_parameters.json | 5 -- ..._test_rotation_scan_parameters_nomove.json | 5 -- tests/unit_tests/experiment_plans/conftest.py | 3 ++ .../test_flyscan_xray_centre_plan.py | 7 ++- .../test_panda_flyscan_xray_centre_plan.py | 7 ++- .../test_rotation_scan_plan.py | 48 +++++++++++++++++++ .../callbacks/conftest.py | 3 ++ .../callbacks/rotation/test_ispyb_callback.py | 6 +-- .../parameters/test_parameter_model.py | 8 +--- 22 files changed, 119 insertions(+), 72 deletions(-) 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 1e6aeb111..3a2cb960c 100644 --- a/src/hyperion/device_setup_plans/read_hardware_for_setup.py +++ b/src/hyperion/device_setup_plans/read_hardware_for_setup.py @@ -8,6 +8,7 @@ from dodal.devices.flux import Flux from dodal.devices.robot import BartRobot from dodal.devices.s4_slit_gaps import S4SlitGaps +from dodal.devices.smargon import Smargon from dodal.devices.synchrotron import Synchrotron from dodal.devices.undulator import Undulator @@ -21,6 +22,7 @@ def read_hardware_for_ispyb_pre_collection( s4_slit_gaps: S4SlitGaps, aperture_scatterguard: ApertureScatterguard, robot: BartRobot, + smargon: Smargon, ): LOGGER.info("Reading status of beamline for ispyb deposition, pre collection.") yield from bps.create( @@ -31,6 +33,9 @@ def read_hardware_for_ispyb_pre_collection( 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) yield from bps.save() diff --git a/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py b/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py index 204eb89f5..adc5d23e6 100755 --- a/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py +++ b/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py @@ -237,6 +237,7 @@ def run_gridscan( 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 diff --git a/src/hyperion/experiment_plans/panda_flyscan_xray_centre_plan.py b/src/hyperion/experiment_plans/panda_flyscan_xray_centre_plan.py index 0764f91ed..59c9ebd3f 100755 --- a/src/hyperion/experiment_plans/panda_flyscan_xray_centre_plan.py +++ b/src/hyperion/experiment_plans/panda_flyscan_xray_centre_plan.py @@ -100,6 +100,7 @@ def run_gridscan( 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 diff --git a/src/hyperion/experiment_plans/rotation_scan_plan.py b/src/hyperion/experiment_plans/rotation_scan_plan.py index 5e3405ce6..2fef90706 100644 --- a/src/hyperion/experiment_plans/rotation_scan_plan.py +++ b/src/hyperion/experiment_plans/rotation_scan_plan.py @@ -212,6 +212,7 @@ def _rotation_scan_plan( 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 diff --git a/src/hyperion/external_interaction/callbacks/common/ispyb_mapping.py b/src/hyperion/external_interaction/callbacks/common/ispyb_mapping.py index e26d6d635..9241d56f2 100644 --- a/src/hyperion/external_interaction/callbacks/common/ispyb_mapping.py +++ b/src/hyperion/external_interaction/callbacks/common/ispyb_mapping.py @@ -8,7 +8,6 @@ from hyperion.external_interaction.ispyb.data_model import ( DataCollectionGroupInfo, DataCollectionInfo, - DataCollectionPositionInfo, ) from hyperion.external_interaction.ispyb.ispyb_dataclass import IspybParams from hyperion.external_interaction.ispyb.ispyb_store import ( @@ -32,16 +31,6 @@ def populate_data_collection_group(params: DiffractionExperimentWithSample): return dcg_info -def populate_data_collection_position_info(ispyb_params): - # explicit cast to float because numpy int64, grrr... - dc_pos_info = DataCollectionPositionInfo( - float(ispyb_params.position[0]), - float(ispyb_params.position[1]), - float(ispyb_params.position[2]), - ) - return dc_pos_info - - def populate_remaining_data_collection_info( comment, data_collection_group_id, diff --git a/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py b/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py index 3f1ec053e..9129aa6d5 100644 --- a/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py +++ b/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py @@ -18,6 +18,7 @@ from hyperion.external_interaction.ispyb.data_model import ( DataCollectionGridInfo, DataCollectionInfo, + DataCollectionPositionInfo, ScanDataInfo, ) from hyperion.external_interaction.ispyb.ispyb_dataclass import Orientation @@ -123,8 +124,13 @@ def _handle_ispyb_hardware_read(self, doc) -> Sequence[ScanDataInfo]: slitgap_horizontal=doc["data"]["s4_slit_gaps_xgap"], slitgap_vertical=doc["data"]["s4_slit_gaps_ygap"], ) + hwscan_position_info = DataCollectionPositionInfo( + pos_x=doc["data"]["smargon_x"], + pos_y=doc["data"]["smargon_y"], + pos_z=doc["data"]["smargon_z"], + ) scan_data_infos = self.populate_info_for_update( - hwscan_data_collection_info, self.params + hwscan_data_collection_info, hwscan_position_info, self.params ) ISPYB_LOGGER.info("Updating ispyb data collection after hardware read.") return scan_data_infos @@ -193,7 +199,7 @@ def _handle_ispyb_transmission_flux_read(self, doc) -> Sequence[ScanDataInfo]: self.params.detector_params.detector_distance, ) scan_data_infos = self.populate_info_for_update( - hwscan_data_collection_info, self.params + hwscan_data_collection_info, None, self.params ) ISPYB_LOGGER.info("Updating ispyb data collection after flux read.") return scan_data_infos @@ -202,6 +208,7 @@ def _handle_ispyb_transmission_flux_read(self, doc) -> Sequence[ScanDataInfo]: def populate_info_for_update( self, event_sourced_data_collection_info: DataCollectionInfo, + event_sourced_position_info: Optional[DataCollectionPositionInfo], params: DiffractionExperimentWithSample, ) -> Sequence[ScanDataInfo]: pass diff --git a/src/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py b/src/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py index fd226936f..48d249e27 100644 --- a/src/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py +++ b/src/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py @@ -1,11 +1,10 @@ from __future__ import annotations from collections.abc import Sequence -from typing import TYPE_CHECKING, Any, Callable, cast +from typing import TYPE_CHECKING, Any, Callable, Optional from hyperion.external_interaction.callbacks.common.ispyb_mapping import ( populate_data_collection_group, - populate_data_collection_position_info, populate_remaining_data_collection_info, ) from hyperion.external_interaction.callbacks.ispyb_callback_base import ( @@ -16,6 +15,7 @@ ) from hyperion.external_interaction.ispyb.data_model import ( DataCollectionInfo, + DataCollectionPositionInfo, ScanDataInfo, ) from hyperion.external_interaction.ispyb.ispyb_store import ( @@ -102,19 +102,19 @@ def activity_gated_start(self, doc: RunStart): return super().activity_gated_start(doc) def populate_info_for_update( - self, event_sourced_data_collection_info: DataCollectionInfo, params + self, + event_sourced_data_collection_info: DataCollectionInfo, + event_sourced_position_info: Optional[DataCollectionPositionInfo], + params, ) -> Sequence[ScanDataInfo]: assert ( self.ispyb_ids.data_collection_ids ), "Expect an existing DataCollection to update" - params = cast(RotationScan, params) return [ ScanDataInfo( data_collection_info=event_sourced_data_collection_info, - data_collection_position_info=populate_data_collection_position_info( - params.ispyb_params - ), data_collection_id=self.ispyb_ids.data_collection_ids[0], + data_collection_position_info=event_sourced_position_info, ) ] diff --git a/src/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py b/src/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py index 73703fe17..1d2831236 100644 --- a/src/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py +++ b/src/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py @@ -2,7 +2,7 @@ from collections.abc import Sequence from time import time -from typing import TYPE_CHECKING, Any, Callable, List +from typing import TYPE_CHECKING, Any, Callable, List, Optional import numpy as np from blueapi.core import MsgGenerator @@ -24,6 +24,7 @@ from hyperion.external_interaction.exceptions import ISPyBDepositionNotMade from hyperion.external_interaction.ispyb.data_model import ( DataCollectionInfo, + DataCollectionPositionInfo, ScanDataInfo, ) from hyperion.external_interaction.ispyb.ispyb_store import ( @@ -165,6 +166,7 @@ def activity_gated_event(self, doc: Event): def populate_info_for_update( self, event_sourced_data_collection_info: DataCollectionInfo, + event_sourced_position_info: Optional[DataCollectionPositionInfo], params: ThreeDGridScan | GridScanWithEdgeDetect, ) -> Sequence[ScanDataInfo]: assert ( diff --git a/src/hyperion/parameters/components.py b/src/hyperion/parameters/components.py index 25a937e33..dfc0fa8ce 100644 --- a/src/hyperion/parameters/components.py +++ b/src/hyperion/parameters/components.py @@ -119,11 +119,11 @@ def __hash__(self) -> int: @validator("parameter_model_version") def _validate_version(cls, version: ParameterVersion): - assert ( - version >= ParameterVersion(major=PARAMETER_VERSION.major) + assert version >= ParameterVersion( + major=PARAMETER_VERSION.major ), f"Parameter version too old! This version of hyperion uses {PARAMETER_VERSION}" - assert ( - version <= ParameterVersion(major=PARAMETER_VERSION.major + 1) + assert version <= ParameterVersion( + major=PARAMETER_VERSION.major + 1 ), f"Parameter version too new! This version of hyperion uses {PARAMETER_VERSION}" return version @@ -251,7 +251,6 @@ class Config: arbitrary_types_allowed = True extra = Extra.forbid - position: list[float] = None xtal_snapshots_omega_start: list[str] | None = None xtal_snapshots_omega_end: list[str] | None = None xtal_snapshots: list[str] | None = None diff --git a/src/hyperion/parameters/rotation.py b/src/hyperion/parameters/rotation.py index fd20aa265..64efeca3d 100644 --- a/src/hyperion/parameters/rotation.py +++ b/src/hyperion/parameters/rotation.py @@ -2,7 +2,6 @@ import os -import numpy as np from dodal.devices.detector import DetectorParams from dodal.devices.detector.det_dist_to_beam_converter import ( DetectorDistanceToBeamXYConverter, @@ -79,7 +78,6 @@ def detector_params(self): def ispyb_params(self): # pyright: ignore return RotationIspybParams( visit_path=str(self.visit_directory), - position=np.array(self.ispyb_extras.position), comment=self.comment, xtal_snapshots_omega_start=self.ispyb_extras.xtal_snapshots_omega_start, xtal_snapshots_omega_end=self.ispyb_extras.xtal_snapshots_omega_end, diff --git a/tests/system_tests/experiment_plans/test_fgs_plan.py b/tests/system_tests/experiment_plans/test_fgs_plan.py index c18b42ddf..953cf3edf 100644 --- a/tests/system_tests/experiment_plans/test_fgs_plan.py +++ b/tests/system_tests/experiment_plans/test_fgs_plan.py @@ -137,36 +137,29 @@ def test_read_hardware_for_ispyb_pre_collection( RE: RunEngine, fxc_composite: FlyScanXRayCentreComposite, ): - undulator = fxc_composite.undulator - synchrotron = fxc_composite.synchrotron - slit_gaps = fxc_composite.s4_slit_gaps - attenuator = fxc_composite.attenuator - flux = fxc_composite.flux - dcm = fxc_composite.dcm - aperture_scatterguard = fxc_composite.aperture_scatterguard - robot = fxc_composite.robot - @bpp.run_decorator() - def read_run(u, s, g, r, a, f, dcm, ap_sg): + 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, ) yield from read_hardware_for_ispyb_during_collection(a, f, dcm) RE( read_run( - undulator, - synchrotron, - slit_gaps, - robot, - attenuator, - flux, - dcm, - aperture_scatterguard, + fxc_composite.undulator, + fxc_composite.synchrotron, + fxc_composite.s4_slit_gaps, + fxc_composite.robot, + fxc_composite.attenuator, + fxc_composite.flux, + fxc_composite.dcm, + fxc_composite.aperture_scatterguard, + fxc_composite.smargon, ) ) diff --git a/tests/system_tests/experiment_plans/test_plan_system.py b/tests/system_tests/experiment_plans/test_plan_system.py index 8a1d9aeeb..583f62fe8 100644 --- a/tests/system_tests/experiment_plans/test_plan_system.py +++ b/tests/system_tests/experiment_plans/test_plan_system.py @@ -27,6 +27,7 @@ async def test_getting_data_for_ispyb(): aperture_scatterguard = ApertureScatterguard( prefix=f"{CONST.SIM.BEAMLINE}-AL-APSG-04:", name="ao_sg" ) + smargon = i03.smargon(fake_with_ophyd_sim=True) undulator.wait_for_connection() await synchrotron.connect() @@ -34,13 +35,16 @@ async def test_getting_data_for_ispyb(): attenuator.wait_for_connection() flux.wait_for_connection() aperture_scatterguard.wait_for_connection() + smargon.wait_for_connection() robot = i03.robot(fake_with_ophyd_sim=True) RE = RunEngine() @bpp.run_decorator() - def standalone_read_hardware(und, syn, slits, robot, att, flux, ap_sg): - yield from read_hardware_for_ispyb_pre_collection(und, syn, slits, robot, ap_sg) + 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 + ) yield from read_hardware_for_ispyb_during_collection(att, flux, dcm) RE( @@ -52,5 +56,6 @@ def standalone_read_hardware(und, syn, slits, robot, att, flux, ap_sg): attenuator, flux, aperture_scatterguard, + smargon, ) ) diff --git a/tests/system_tests/external_interaction/test_ispyb_dev_connection.py b/tests/system_tests/external_interaction/test_ispyb_dev_connection.py index 19514ac47..39bd9b6d9 100644 --- a/tests/system_tests/external_interaction/test_ispyb_dev_connection.py +++ b/tests/system_tests/external_interaction/test_ispyb_dev_connection.py @@ -845,7 +845,7 @@ def test_ispyb_deposition_in_rotation_plan( position_id = fetch_datacollection_attribute( dcid, DATA_COLLECTION_COLUMN_MAP["positionid"] ) - expected_values = {"posX": 10.0, "posY": 20.0, "posZ": 30.0} + expected_values = {"posX": 1.0, "posY": 2.0, "posZ": 3.0} compare_actual_and_expected( position_id, expected_values, fetch_datacollection_position_attribute ) diff --git a/tests/test_data/parameter_json_files/good_test_rotation_scan_parameters.json b/tests/test_data/parameter_json_files/good_test_rotation_scan_parameters.json index b89e3691a..b05a6f97f 100644 --- a/tests/test_data/parameter_json_files/good_test_rotation_scan_parameters.json +++ b/tests/test_data/parameter_json_files/good_test_rotation_scan_parameters.json @@ -26,11 +26,6 @@ "y_start_um": 2.0, "z_start_um": 3.0, "ispyb_extras": { - "position": [ - 10.0, - 20.0, - 30.0 - ], "xtal_snapshots_omega_start": [ "test_1_y", "test_2_y", diff --git a/tests/test_data/parameter_json_files/good_test_rotation_scan_parameters_nomove.json b/tests/test_data/parameter_json_files/good_test_rotation_scan_parameters_nomove.json index ca0b04c16..ae9a36940 100644 --- a/tests/test_data/parameter_json_files/good_test_rotation_scan_parameters_nomove.json +++ b/tests/test_data/parameter_json_files/good_test_rotation_scan_parameters_nomove.json @@ -21,11 +21,6 @@ "zocalo_environment": "dev_artemis", "transmission_frac": 0.1, "ispyb_extras": { - "position": [ - 10.0, - 20.0, - 30.0 - ], "xtal_snapshots_omega_start": [ "test_1_y", "test_2_y", diff --git a/tests/unit_tests/experiment_plans/conftest.py b/tests/unit_tests/experiment_plans/conftest.py index 1546bad2d..1f8bac03b 100644 --- a/tests/unit_tests/experiment_plans/conftest.py +++ b/tests/unit_tests/experiment_plans/conftest.py @@ -48,6 +48,9 @@ def make_event_doc(data, descriptor="abc123") -> Event: "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 = { 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 7606f2af7..9e40bae03 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 @@ -91,9 +91,11 @@ def ispyb_plan(test_fgs_params): } ) def standalone_read_hardware_for_ispyb( - und, syn, slits, robot, attn, fl, dcm, ap_sg + und, syn, slits, robot, attn, fl, dcm, ap_sg, sm ): - yield from read_hardware_for_ispyb_pre_collection(und, syn, slits, ap_sg, robot) + 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) return standalone_read_hardware_for_ispyb @@ -237,6 +239,7 @@ def test_read_hardware_for_ispyb_updates_from_ophyd_devices( fake_fgs_composite.flux, fake_fgs_composite.dcm, fake_fgs_composite.aperture_scatterguard, + fake_fgs_composite.smargon, ) ) # fmt: off diff --git a/tests/unit_tests/experiment_plans/test_panda_flyscan_xray_centre_plan.py b/tests/unit_tests/experiment_plans/test_panda_flyscan_xray_centre_plan.py index 2ad0c032f..830e129ad 100644 --- a/tests/unit_tests/experiment_plans/test_panda_flyscan_xray_centre_plan.py +++ b/tests/unit_tests/experiment_plans/test_panda_flyscan_xray_centre_plan.py @@ -86,9 +86,11 @@ def ispyb_plan(test_panda_fgs_params): } ) def standalone_read_hardware_for_ispyb( - und, syn, slits, robot, attn, fl, dcm, ap_sg + und, syn, slits, robot, attn, fl, dcm, ap_sg, sm ): - yield from read_hardware_for_ispyb_pre_collection(und, syn, slits, ap_sg, robot) + 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) return standalone_read_hardware_for_ispyb @@ -173,6 +175,7 @@ def test_read_hardware_for_ispyb_updates_from_ophyd_devices( fake_fgs_composite.flux, fake_fgs_composite.dcm, fake_fgs_composite.aperture_scatterguard, + fake_fgs_composite.smargon, ) ) # fmt: off diff --git a/tests/unit_tests/experiment_plans/test_rotation_scan_plan.py b/tests/unit_tests/experiment_plans/test_rotation_scan_plan.py index dcf0dd39f..eab89e86f 100644 --- a/tests/unit_tests/experiment_plans/test_rotation_scan_plan.py +++ b/tests/unit_tests/experiment_plans/test_rotation_scan_plan.py @@ -1,12 +1,14 @@ from __future__ import annotations from functools import partial +from itertools import takewhile from typing import TYPE_CHECKING, Callable from unittest.mock import DEFAULT, MagicMock, call, patch import pytest from bluesky.run_engine import RunEngine from dodal.devices.smargon import Smargon +from dodal.devices.synchrotron import SynchrotronMode from dodal.devices.zebra import Zebra from ophyd.status import Status @@ -17,6 +19,7 @@ rotation_scan, rotation_scan_plan, ) +from hyperion.parameters.constants import CONST from hyperion.parameters.rotation import RotationScan from .conftest import fake_read @@ -260,3 +263,48 @@ class MyTestException(Exception): RE(rotation_scan(fake_create_rotation_devices, test_rotation_params)) assert "Experiment fails because this is a test" in exc.value.args[0] cleanup_plan.assert_called_once() + + +def test_rotation_plan_reads_hardware( + RE: RunEngine, + fake_create_rotation_devices: RotationScanComposite, + test_rotation_params, + motion_values, + sim_run_engine, +): + sim_run_engine.add_handler( + "read", + "synchrotron-synchrotron_mode", + lambda msg: {"values": {"value": SynchrotronMode.USER}}, + ) + sim_run_engine.add_handler( + "read", + "synchrotron-topup_start_countdown", + lambda msg: {"values": {"value": -1}}, + ) + fake_create_rotation_devices.smargon.omega.user_readback.sim_put(0) + sim_run_engine.add_handler( + "read", "smargon_omega", lambda msg: {"values": {"value": -1}} + ) + + msgs = sim_run_engine.simulate_plan( + rotation_scan_plan( + fake_create_rotation_devices, test_rotation_params, motion_values + ) + ) + + msgs = sim_run_engine.assert_message_and_return_remaining( + msgs, + lambda msg: msg.command == "create" + and msg.kwargs["name"] == CONST.DESCRIPTORS.ISPYB_HARDWARE_READ, + ) + msgs_in_event = list(takewhile(lambda msg: msg.command != "save", msgs)) + sim_run_engine.assert_message_and_return_remaining( + msgs_in_event, lambda msg: msg.command == "read" and msg.obj.name == "smargon_x" + ) + sim_run_engine.assert_message_and_return_remaining( + msgs_in_event, lambda msg: msg.command == "read" and msg.obj.name == "smargon_y" + ) + sim_run_engine.assert_message_and_return_remaining( + msgs_in_event, lambda msg: msg.command == "read" and msg.obj.name == "smargon_z" + ) diff --git a/tests/unit_tests/external_interaction/callbacks/conftest.py b/tests/unit_tests/external_interaction/callbacks/conftest.py index 1f2382f75..4a648044a 100644 --- a/tests/unit_tests/external_interaction/callbacks/conftest.py +++ b/tests/unit_tests/external_interaction/callbacks/conftest.py @@ -200,6 +200,9 @@ class TestData: "radius_microns": 50, "location": (15, 16, 2, 18, 19), }, + "smargon_x": 10.0, + "smargon_y": 20.0, + "smargon_z": 30.0, }, "timestamps": {"det1": 1666604299.8220396, "det2": 1666604299.8235943}, "seq_num": 1, 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 672d9acfa..407ee5515 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 @@ -116,9 +116,9 @@ def test_hardware_read_events( mx.get_dc_position_params(), { "id": TEST_DATA_COLLECTION_IDS[0], - "pos_x": dummy_rotation_params.ispyb_params.position[0], - "pos_y": dummy_rotation_params.ispyb_params.position[1], - "pos_z": dummy_rotation_params.ispyb_params.position[2], + "pos_x": 10, + "pos_y": 20, + "pos_z": 30, }, ) diff --git a/tests/unit_tests/parameters/test_parameter_model.py b/tests/unit_tests/parameters/test_parameter_model.py index ad6e7d8a7..7a0284894 100644 --- a/tests/unit_tests/parameters/test_parameter_model.py +++ b/tests/unit_tests/parameters/test_parameter_model.py @@ -26,9 +26,7 @@ def minimal_3d_gridscan_params(): "y_steps": 7, "z_steps": 9, "storage_directory": "/tmp/dls/i03/data/2024/cm31105-4/xraycentring/123456/", - "ispyb_extras": { - "position": [0, 0, 0], - }, + "ispyb_extras": {}, } @@ -78,9 +76,7 @@ def test_robot_load_then_centre_params(): "visit": "cm12345", "file_name": "file_name", "storage_directory": "/tmp/dls/i03/data/2024/cm31105-4/xraycentring/123456/", - "ispyb_extras": { - "position": [0, 0, 0], - }, + "ispyb_extras": {}, } params["detector_distance_mm"] = 200 test_params = RobotLoadThenCentre(**params) From c63401ddcfcb18b96e214d55c2b55da7bbb9d5f5 Mon Sep 17 00:00:00 2001 From: Robert Tuck Date: Fri, 24 May 2024 13:17:55 +0100 Subject: [PATCH 2/4] Make pyright happy --- tests/unit_tests/experiment_plans/test_rotation_scan_plan.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit_tests/experiment_plans/test_rotation_scan_plan.py b/tests/unit_tests/experiment_plans/test_rotation_scan_plan.py index eab89e86f..d88816a2d 100644 --- a/tests/unit_tests/experiment_plans/test_rotation_scan_plan.py +++ b/tests/unit_tests/experiment_plans/test_rotation_scan_plan.py @@ -282,7 +282,7 @@ def test_rotation_plan_reads_hardware( "synchrotron-topup_start_countdown", lambda msg: {"values": {"value": -1}}, ) - fake_create_rotation_devices.smargon.omega.user_readback.sim_put(0) + fake_create_rotation_devices.smargon.omega.user_readback.sim_put(0) # type: ignore sim_run_engine.add_handler( "read", "smargon_omega", lambda msg: {"values": {"value": -1}} ) From 5323e703055520b0d231a87f75e7c4040d67af73 Mon Sep 17 00:00:00 2001 From: Robert Tuck Date: Fri, 24 May 2024 13:52:00 +0100 Subject: [PATCH 3/4] Make ruff happy --- .../external_interaction/callbacks/test_external_callbacks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/system_tests/external_interaction/callbacks/test_external_callbacks.py b/tests/system_tests/external_interaction/callbacks/test_external_callbacks.py index ee95c5a43..e7b5719d9 100644 --- a/tests/system_tests/external_interaction/callbacks/test_external_callbacks.py +++ b/tests/system_tests/external_interaction/callbacks/test_external_callbacks.py @@ -5,6 +5,7 @@ import signal import subprocess import threading +from genericpath import isfile from time import sleep from unittest.mock import MagicMock, patch @@ -17,7 +18,6 @@ from bluesky.callbacks.zmq import Publisher from bluesky.run_engine import RunEngine from dodal.devices.zocalo import ZocaloResults -from genericpath import isfile from zmq.utils.monitor import recv_monitor_message from hyperion.experiment_plans.flyscan_xray_centre_plan import ( From ad39944f08e57ce5bc2f1010c0ee92ba60a95be5 Mon Sep 17 00:00:00 2001 From: Robert Tuck Date: Fri, 24 May 2024 13:08:20 +0100 Subject: [PATCH 4/4] Fix broken system tests --- tests/system_tests/external_interaction/test_nexgen.py | 2 +- .../nexus_files/rotation/ins_8_5_expected_output.txt | 6 +++--- .../rotation_unicode_metafile/ins_8_5_expected_output.txt | 6 +++--- .../ispyb_gridscan_system_test_parameters.json | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/system_tests/external_interaction/test_nexgen.py b/tests/system_tests/external_interaction/test_nexgen.py index c91b6dd25..cb4c9ba38 100644 --- a/tests/system_tests/external_interaction/test_nexgen.py +++ b/tests/system_tests/external_interaction/test_nexgen.py @@ -156,7 +156,7 @@ def _fake_rotation_scan( @bpp.run_decorator( # attach experiment metadata to the start document md={ "subplan_name": CONST.PLAN.ROTATION_OUTER, - "hyperion_internal_parameters": parameters.json(), + "hyperion_parameters": parameters.json(), "activate_callbacks": "RotationNexusFileCallback", } ) diff --git a/tests/test_data/nexus_files/rotation/ins_8_5_expected_output.txt b/tests/test_data/nexus_files/rotation/ins_8_5_expected_output.txt index a1b8b422d..548b48b69 100644 --- a/tests/test_data/nexus_files/rotation/ins_8_5_expected_output.txt +++ b/tests/test_data/nexus_files/rotation/ins_8_5_expected_output.txt @@ -42,8 +42,8 @@ rotation axis = "OMEGA" Sweep-1 : - from image 1 : Omega= 0.000 .. 0.100 Kappa= 0.000 .. 0.000 Chi= 0.000 .. 0.000 Phi= 0.000 .. 0.000 2-Theta= 0.000 .. 0.000 - to image 3600 : Omega= 359.900 .. 360.000 Kappa= 0.000 .. 0.000 Chi= 0.000 .. 0.000 Phi= 0.000 .. 0.000 2-Theta= 0.000 .. 0.000 + from image 1 : Omega= 0.000 .. 0.100 Kappa= 0.000 .. 0.000 Chi= 23.850 .. 23.850 Phi= 0.000 .. 0.000 2-Theta= 0.000 .. 0.000 + to image 3600 : Omega= 359.900 .. 360.000 Kappa= 0.000 .. 0.000 Chi= 23.850 .. 23.850 Phi= 0.000 .. 0.000 2-Theta= 0.000 .. 0.000 Image number 1/3600 @@ -56,7 +56,7 @@ Phi-angle [degree] = 0.00000 Omega-angle (start, end) [degree] = 0.00000 0.10000 Oscillation-angle in Omega [degree] = 0.10000 - Chi-angle [degree] = 0.00000 + Chi-angle [degree] = 23.85000 Pixel size in X [mm] = 0.075000 Pixel size in Y [mm] = 0.075000 Number of pixels in X = 4148 diff --git a/tests/test_data/nexus_files/rotation_unicode_metafile/ins_8_5_expected_output.txt b/tests/test_data/nexus_files/rotation_unicode_metafile/ins_8_5_expected_output.txt index a1b8b422d..548b48b69 100644 --- a/tests/test_data/nexus_files/rotation_unicode_metafile/ins_8_5_expected_output.txt +++ b/tests/test_data/nexus_files/rotation_unicode_metafile/ins_8_5_expected_output.txt @@ -42,8 +42,8 @@ rotation axis = "OMEGA" Sweep-1 : - from image 1 : Omega= 0.000 .. 0.100 Kappa= 0.000 .. 0.000 Chi= 0.000 .. 0.000 Phi= 0.000 .. 0.000 2-Theta= 0.000 .. 0.000 - to image 3600 : Omega= 359.900 .. 360.000 Kappa= 0.000 .. 0.000 Chi= 0.000 .. 0.000 Phi= 0.000 .. 0.000 2-Theta= 0.000 .. 0.000 + from image 1 : Omega= 0.000 .. 0.100 Kappa= 0.000 .. 0.000 Chi= 23.850 .. 23.850 Phi= 0.000 .. 0.000 2-Theta= 0.000 .. 0.000 + to image 3600 : Omega= 359.900 .. 360.000 Kappa= 0.000 .. 0.000 Chi= 23.850 .. 23.850 Phi= 0.000 .. 0.000 2-Theta= 0.000 .. 0.000 Image number 1/3600 @@ -56,7 +56,7 @@ Phi-angle [degree] = 0.00000 Omega-angle (start, end) [degree] = 0.00000 0.10000 Oscillation-angle in Omega [degree] = 0.10000 - Chi-angle [degree] = 0.00000 + Chi-angle [degree] = 23.85000 Pixel size in X [mm] = 0.075000 Pixel size in Y [mm] = 0.075000 Number of pixels in X = 4148 diff --git a/tests/test_data/parameter_json_files/ispyb_gridscan_system_test_parameters.json b/tests/test_data/parameter_json_files/ispyb_gridscan_system_test_parameters.json index 50912db3f..d34ff020e 100644 --- a/tests/test_data/parameter_json_files/ispyb_gridscan_system_test_parameters.json +++ b/tests/test_data/parameter_json_files/ispyb_gridscan_system_test_parameters.json @@ -15,7 +15,7 @@ "omega_start_deg": 0.0, "grid_width_um": 400, "oav_centring_file": "tests/test_data/test_OAVCentring.json", - "transmission_frac": 1.0, + "transmission_frac": 0.49118, "visit": "cm31105-4", "demand_energy_ev": 12700, "ispyb_extras": {