Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
(#842) Move the ispyb activation so that messages can be logged from …
Browse files Browse the repository at this point in the history
…pin tip detection
  • Loading branch information
rtuck99 committed Jul 30, 2024
1 parent 4cbcc13 commit 801a531
Show file tree
Hide file tree
Showing 7 changed files with 283 additions and 102 deletions.
19 changes: 6 additions & 13 deletions src/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,6 @@ def detect_grid_and_do_gridscan(
composite: GridDetectThenXRayCentreComposite,
parameters: GridScanWithEdgeDetect,
oav_params: OAVParameters,
):
yield from ispyb_activation_wrapper(
_detect_grid_and_do_gridscan(composite, parameters, oav_params), parameters
)


def _detect_grid_and_do_gridscan(
composite: GridDetectThenXRayCentreComposite,
parameters: GridScanWithEdgeDetect,
oav_params: OAVParameters,
):
assert composite.aperture_scatterguard.aperture_positions is not None

Expand Down Expand Up @@ -202,10 +192,13 @@ def grid_detect_then_xray_centre(

oav_params = OAVParameters("xrayCentring", oav_config)

plan_to_perform = detect_grid_and_do_gridscan(
composite,
plan_to_perform = ispyb_activation_wrapper(
detect_grid_and_do_gridscan(
composite,
parameters,
oav_params,
),
parameters,
oav_params,
)

return start_preparing_data_collection_then_do_plan(
Expand Down
30 changes: 18 additions & 12 deletions src/hyperion/experiment_plans/pin_centre_then_xray_centre_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
PinTipCentringComposite,
pin_tip_centre_plan,
)
from hyperion.external_interaction.callbacks.xray_centre.ispyb_callback import (
ispyb_activation_wrapper,
)
from hyperion.log import LOGGER
from hyperion.parameters.constants import CONST
from hyperion.parameters.gridscan import (
Expand Down Expand Up @@ -61,21 +64,24 @@ def pin_centre_then_xray_centre_plan(
pin_tip_detection=composite.pin_tip_detection,
)

yield from pin_tip_centre_plan(
pin_tip_centring_composite,
parameters.tip_offset_um,
oav_config_file,
)
def _pin_centre_then_xray_centre_plan():
yield from pin_tip_centre_plan(
pin_tip_centring_composite,
parameters.tip_offset_um,
oav_config_file,
)

grid_detect_params = create_parameters_for_grid_detection(parameters)
grid_detect_params = create_parameters_for_grid_detection(parameters)

oav_params = OAVParameters("xrayCentring", oav_config_file)
oav_params = OAVParameters("xrayCentring", oav_config_file)

yield from detect_grid_and_do_gridscan(
composite,
grid_detect_params,
oav_params,
)
yield from detect_grid_and_do_gridscan(
composite,
grid_detect_params,
oav_params,
)

yield from ispyb_activation_wrapper(_pin_centre_then_xray_centre_plan(), parameters)


def pin_tip_centre_then_xray_centre(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ def test_ispyb_deposition_in_rotation_plan(
assert dcid is not None
assert (
fetch_comment(dcid)
== "Sample position: (1.0, 2.0, 3.0) test Aperture: Small. "
== "Sample position (µm): (1000, 2000, 3000) test Aperture: Small. "
)

expected_values = EXPECTED_DATACOLLECTION_FOR_ROTATION | {
Expand Down
57 changes: 57 additions & 0 deletions tests/unit_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from unittest.mock import patch

import pytest
from event_model import Event, EventDescriptor

from hyperion.parameters.constants import CONST

BANNED_PATHS = [Path("/dls"), Path("/dls_sw")]

Expand All @@ -21,3 +24,57 @@ def patched_open(*args, **kwargs):

with patch("builtins.open", side_effect=patched_open):
yield []


class OavGridSnapshotTestEvents:
test_descriptor_document_oav_snapshot: EventDescriptor = {
"uid": "b5ba4aec-de49-4970-81a4-b4a847391d34",
"run_start": "d8bee3ee-f614-4e7a-a516-25d6b9e87ef3",
"name": CONST.DESCRIPTORS.OAV_GRID_SNAPSHOT_TRIGGERED,
} # type: ignore
test_event_document_oav_snapshot_xy: Event = {
"descriptor": "b5ba4aec-de49-4970-81a4-b4a847391d34",
"time": 1666604299.828203,
"timestamps": {},
"seq_num": 1,
"uid": "29033ecf-e052-43dd-98af-c7cdd62e8174",
"data": {
"oav_grid_snapshot_top_left_x": 50,
"oav_grid_snapshot_top_left_y": 100,
"oav_grid_snapshot_num_boxes_x": 40,
"oav_grid_snapshot_num_boxes_y": 20,
"oav_grid_snapshot_microns_per_pixel_x": 1.25,
"oav_grid_snapshot_microns_per_pixel_y": 1.5,
"oav_grid_snapshot_box_width": 0.1 * 1000 / 1.25, # size in pixels
"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,
"smargon-x": 0,
"smargon-y": 0,
"smargon-z": 0,
},
}
test_event_document_oav_snapshot_xz: Event = {
"descriptor": "b5ba4aec-de49-4970-81a4-b4a847391d34",
"time": 1666604299.828203,
"timestamps": {},
"seq_num": 1,
"uid": "29033ecf-e052-43dd-98af-c7cdd62e8174",
"data": {
"oav_grid_snapshot_top_left_x": 50,
"oav_grid_snapshot_top_left_y": 0,
"oav_grid_snapshot_num_boxes_x": 40,
"oav_grid_snapshot_num_boxes_y": 10,
"oav_grid_snapshot_box_width": 0.1 * 1000 / 1.25, # size in pixels
"oav_grid_snapshot_last_path_full_overlay": "test_1_z",
"oav_grid_snapshot_last_path_outer": "test_2_z",
"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,
"smargon-x": 0,
"smargon-y": 0,
"smargon-z": 0,
},
}
Loading

0 comments on commit 801a531

Please sign in to comment.