From 15313f8737d0f930c4790a0bc8c36c960c48dbf2 Mon Sep 17 00:00:00 2001 From: Robert Tuck Date: Fri, 14 Jun 2024 10:21:03 +0100 Subject: [PATCH] (#1327) ispyb omega_start, axis_start now read from hardware for gridscans --- .../callbacks/common/ispyb_mapping.py | 1 - .../callbacks/ispyb_callback_base.py | 9 +++++++++ .../callbacks/rotation/ispyb_callback.py | 6 ++++++ .../callbacks/rotation/ispyb_mapping.py | 1 + .../callbacks/xray_centre/ispyb_callback.py | 14 +++++++++++--- .../callbacks/xray_centre/ispyb_mapping.py | 7 ------- .../test_ispyb_dev_connection.py | 6 +++--- .../experiment_plans/test_rotation_scan_plan.py | 1 - .../external_interaction/callbacks/conftest.py | 2 ++ .../callbacks/xray_centre/test_ispyb_callback.py | 16 ++++++++-------- 10 files changed, 40 insertions(+), 23 deletions(-) diff --git a/src/hyperion/external_interaction/callbacks/common/ispyb_mapping.py b/src/hyperion/external_interaction/callbacks/common/ispyb_mapping.py index 57cfb5199..a45f4a183 100644 --- a/src/hyperion/external_interaction/callbacks/common/ispyb_mapping.py +++ b/src/hyperion/external_interaction/callbacks/common/ispyb_mapping.py @@ -40,7 +40,6 @@ def populate_remaining_data_collection_info( data_collection_info.parent_id = data_collection_group_id data_collection_info.sample_id = params.sample_id data_collection_info.detector_id = I03_EIGER_DETECTOR - data_collection_info.axis_start = data_collection_info.omega_start data_collection_info.comments = comment data_collection_info.detector_distance = params.detector_params.detector_distance data_collection_info.exp_time = params.detector_params.exposure_time diff --git a/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py b/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py index 473f4ef6b..532ca4524 100644 --- a/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py +++ b/src/hyperion/external_interaction/callbacks/ispyb_callback_base.py @@ -190,6 +190,9 @@ def _handle_oav_grid_snapshot_triggered(self, doc) -> Sequence[ScanDataInfo]: data_collection_id = self.ispyb_ids.data_collection_ids[ self._oav_snapshot_event_idx ] + self.populate_axis_info_for_snapshot( + data_collection_info, doc["data"]["smargon_omega"] + ) scan_data_info = ScanDataInfo( data_collection_info=data_collection_info, @@ -224,6 +227,12 @@ def _handle_ispyb_transmission_flux_read(self, doc) -> Sequence[ScanDataInfo]: ISPYB_LOGGER.info("Updating ispyb data collection after flux read.") return scan_data_infos + @abstractmethod + def populate_axis_info_for_snapshot( + self, data_collection_info: DataCollectionInfo, omega_start: float | None + ): + pass + @abstractmethod def populate_info_for_update( self, diff --git a/src/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py b/src/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py index 521bdfabc..4023d665f 100644 --- a/src/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py +++ b/src/hyperion/external_interaction/callbacks/rotation/ispyb_callback.py @@ -104,6 +104,12 @@ def activity_gated_start(self, doc: RunStart): self.uid_to_finalize_on = doc.get("uid") return super().activity_gated_start(doc) + def populate_axis_info_for_snapshot( + self, data_collection_info: DataCollectionInfo, omega_start: float | None + ): + # TODO in subsequent PR which depends on rotation snapshots 349 + pass + def populate_info_for_update( self, event_sourced_data_collection_info: DataCollectionInfo, diff --git a/src/hyperion/external_interaction/callbacks/rotation/ispyb_mapping.py b/src/hyperion/external_interaction/callbacks/rotation/ispyb_mapping.py index 4d5e0760a..4737443cd 100644 --- a/src/hyperion/external_interaction/callbacks/rotation/ispyb_mapping.py +++ b/src/hyperion/external_interaction/callbacks/rotation/ispyb_mapping.py @@ -11,6 +11,7 @@ def populate_data_collection_info_for_rotation(params: RotationScan): data_collection_number=params.detector_params.run_number, # type:ignore # the validator always makes this int n_images=params.num_images, axis_range=params.rotation_increment_deg, + axis_start=params.omega_start_deg, axis_end=(params.omega_start_deg + params.scan_width_deg), kappa_start=params.kappa_start_deg, ) 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 1d2831236..7fce8c623 100644 --- a/src/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py +++ b/src/hyperion/external_interaction/callbacks/xray_centre/ispyb_callback.py @@ -32,11 +32,10 @@ StoreInIspyb, ) from hyperion.log import ISPYB_LOGGER, set_dcgid_tag +from hyperion.parameters.components import DiffractionExperimentWithSample from hyperion.parameters.constants import CONST from hyperion.parameters.gridscan import ( GridCommon, - GridScanWithEdgeDetect, - ThreeDGridScan, ) if TYPE_CHECKING: @@ -163,11 +162,20 @@ def activity_gated_event(self, doc: Event): return doc + def populate_axis_info_for_snapshot( + self, data_collection_info: DataCollectionInfo, omega_start: float | None + ): + if omega_start is not None: + data_collection_info.omega_start = omega_start + data_collection_info.axis_start = omega_start + data_collection_info.axis_end = omega_start + data_collection_info.axis_range = 0 + def populate_info_for_update( self, event_sourced_data_collection_info: DataCollectionInfo, event_sourced_position_info: Optional[DataCollectionPositionInfo], - params: ThreeDGridScan | GridScanWithEdgeDetect, + params: DiffractionExperimentWithSample, ) -> Sequence[ScanDataInfo]: assert ( self.ispyb_ids.data_collection_ids diff --git a/src/hyperion/external_interaction/callbacks/xray_centre/ispyb_mapping.py b/src/hyperion/external_interaction/callbacks/xray_centre/ispyb_mapping.py index 1c1521c85..7ccb28262 100644 --- a/src/hyperion/external_interaction/callbacks/xray_centre/ispyb_mapping.py +++ b/src/hyperion/external_interaction/callbacks/xray_centre/ispyb_mapping.py @@ -15,23 +15,16 @@ def populate_xz_data_collection_info(detector_params: DetectorParams): detector_params.omega_start is not None and detector_params.run_number is not None ), "StoreGridscanInIspyb failed to get parameters" - omega_start = detector_params.omega_start + 90 run_number = detector_params.run_number + 1 info = DataCollectionInfo( - omega_start=omega_start, data_collection_number=run_number, - axis_range=0, - axis_end=omega_start, ) return info def populate_xy_data_collection_info(detector_params: DetectorParams): return DataCollectionInfo( - omega_start=detector_params.omega_start, data_collection_number=detector_params.run_number, - axis_range=0, - axis_end=detector_params.omega_start, ) 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 d3a680776..f5395e981 100644 --- a/tests/system_tests/external_interaction/test_ispyb_dev_connection.py +++ b/tests/system_tests/external_interaction/test_ispyb_dev_connection.py @@ -662,10 +662,10 @@ def test_ispyb_deposition_in_gridscan( assert position_id is None DC_EXPECTED_VALUES.update( { - "axisstart": 90.0, - "axisend": 90.0, + "axisstart": -90.0, + "axisend": -90.0, "datacollectionnumber": 2, - "omegastart": 90.0, + "omegastart": -90.0, "filetemplate": "file_name_2_master.h5", "numberofimages": 220, } 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 0b8687301..6f5fea455 100644 --- a/tests/unit_tests/experiment_plans/test_rotation_scan_plan.py +++ b/tests/unit_tests/experiment_plans/test_rotation_scan_plan.py @@ -8,7 +8,6 @@ import pytest from bluesky.run_engine import RunEngine from dodal.devices.aperturescatterguard import ApertureScatterguard -from dodal.devices.smargon import Smargon from dodal.devices.synchrotron import SynchrotronMode from dodal.devices.zebra import Zebra from ophyd.status import Status diff --git a/tests/unit_tests/external_interaction/callbacks/conftest.py b/tests/unit_tests/external_interaction/callbacks/conftest.py index c797f67bd..87fb08ff1 100644 --- a/tests/unit_tests/external_interaction/callbacks/conftest.py +++ b/tests/unit_tests/external_interaction/callbacks/conftest.py @@ -178,6 +178,7 @@ class TestData: "oav_grid_snapshot_last_path_full_overlay": "test_1_y", "oav_grid_snapshot_last_path_outer": "test_2_y", "oav_grid_snapshot_last_saved_path": "test_3_y", + "smargon_omega": 0, }, } test_event_document_oav_snapshot_xz: Event = { @@ -197,6 +198,7 @@ class TestData: "oav_grid_snapshot_last_saved_path": "test_3_z", "oav_grid_snapshot_microns_per_pixel_x": 1.25, "oav_grid_snapshot_microns_per_pixel_y": 1.5, + "smargon_omega": -90, }, } test_event_document_pre_data_collection: Event = { 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 92b4306ca..2deb67466 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 @@ -20,9 +20,6 @@ "parentid": TEST_DATA_COLLECTION_GROUP_ID, "sampleid": TEST_SAMPLE_ID, "detectorid": 78, - "axisstart": 0.0, - "axisrange": 0, - "axisend": 0, "data_collection_number": 1, "detector_distance": 100.0, "exp_time": 0.1, @@ -31,7 +28,6 @@ "imgsuffix": "h5", "n_passes": 1, "overlap": 0, - "omegastart": 0, "start_image_number": 1, "wavelength": None, "xbeam": 150.0, @@ -43,10 +39,6 @@ } EXPECTED_DATA_COLLECTION_3D_XZ = EXPECTED_DATA_COLLECTION_3D_XY | { - "omegastart": 90, - "axis_range": 0, - "axisend": 90, - "axisstart": 90, "data_collection_number": 2, "filetemplate": "file_name_2_master.h5", } @@ -207,6 +199,10 @@ def test_activity_gated_event_oav_snapshot_triggered(self, mock_ispyb_conn): "comments": "Hyperion: Xray centring - Diffraction grid scan of 40 by 20 " "images in 100.0 um by 120.0 um steps. Top left (px): [50,100], " "bottom right (px): [3250,1700].", + "axisstart": 0, + "omegastart": 0, + "axisend": 0, + "axisrange": 0, }, ) assert_upsert_call_with( @@ -222,6 +218,10 @@ def test_activity_gated_event_oav_snapshot_triggered(self, mock_ispyb_conn): "comments": "Hyperion: Xray centring - Diffraction grid scan of 40 by 10 " "images in 100.0 um by 120.0 um steps. Top left (px): [50,0], " "bottom right (px): [3250,800].", + "axisstart": -90, + "omegastart": -90, + "axisend": -90, + "axisrange": 0, }, ) assert_upsert_call_with(