diff --git a/src/mx_bluesky/common/external_interaction/callbacks/common/aperture_change_callback.py b/src/mx_bluesky/common/external_interaction/callbacks/common/aperture_change_callback.py deleted file mode 100644 index f86f32b52..000000000 --- a/src/mx_bluesky/common/external_interaction/callbacks/common/aperture_change_callback.py +++ /dev/null @@ -1,22 +0,0 @@ -from bluesky.callbacks import CallbackBase -from event_model.documents.run_start import RunStart - -from mx_bluesky.common.utils.log import LOGGER - -from .logging_callback import format_doc_for_log - - -class ApertureChangeCallback(CallbackBase): - """A callback that's used to send the selected aperture back to GDA""" - - def __init__(self, *args, **kwargs) -> None: - super().__init__(*args, **kwargs) - self.last_selected_aperture: str = "NONE" - - def start(self, doc: RunStart): - if doc.get("subplan_name") == "change_aperture": - LOGGER.debug(f"START: {format_doc_for_log(doc)}") - ap_size = doc.get("aperture_size") - assert isinstance(ap_size, str) - LOGGER.info(f"Updating most recent in-plan aperture change to {ap_size}.") - self.last_selected_aperture = ap_size diff --git a/src/mx_bluesky/hyperion/__main__.py b/src/mx_bluesky/hyperion/__main__.py index edf5171a4..e6f12046f 100755 --- a/src/mx_bluesky/hyperion/__main__.py +++ b/src/mx_bluesky/hyperion/__main__.py @@ -16,9 +16,6 @@ from flask_restful import Api, Resource from pydantic.dataclasses import dataclass -from mx_bluesky.common.external_interaction.callbacks.common.aperture_change_callback import ( - ApertureChangeCallback, -) from mx_bluesky.common.external_interaction.callbacks.common.log_uid_tag_callback import ( LogUidTaggingCallback, ) @@ -86,13 +83,11 @@ def __init__( self.command_queue: Queue[Command] = Queue() self.current_status: StatusAndMessage = StatusAndMessage(Status.IDLE) self.last_run_aborted: bool = False - self.aperture_change_callback = ApertureChangeCallback() self.logging_uid_tag_callback = LogUidTaggingCallback() self.context: BlueskyContext self.RE = RE self.context = context - RE.subscribe(self.aperture_change_callback) RE.subscribe(self.logging_uid_tag_callback) LOGGER.info("Connecting to external callback ZMQ proxy...") @@ -172,10 +167,7 @@ def wait_on_queue(self): with TRACER.start_span("do_run"): self.RE(command.experiment(command.devices, command.parameters)) - self.current_status = StatusAndMessage( - Status.IDLE, - self.aperture_change_callback.last_selected_aperture, - ) + self.current_status = StatusAndMessage(Status.IDLE) self.last_run_aborted = False except WarningException as exception: diff --git a/src/mx_bluesky/hyperion/experiment_plans/change_aperture_then_move_plan.py b/src/mx_bluesky/hyperion/experiment_plans/change_aperture_then_move_plan.py index 5d7829e42..4891c4e4c 100644 --- a/src/mx_bluesky/hyperion/experiment_plans/change_aperture_then_move_plan.py +++ b/src/mx_bluesky/hyperion/experiment_plans/change_aperture_then_move_plan.py @@ -1,5 +1,4 @@ import bluesky.plan_stubs as bps -import bluesky.preprocessors as bpp import numpy from dodal.devices.aperturescatterguard import ApertureScatterguard, ApertureValue from dodal.devices.smargon import Smargon, StubPosition @@ -21,17 +20,13 @@ def change_aperture_then_move_to_xtal( * Change the aperture so that the beam size is comparable to the crystal size * Centre on the centre-of-mass * Reset the stub offsets if specified by params""" - if best_hit.bounding_box_mm is not None: - bounding_box_size = numpy.abs( - best_hit.bounding_box_mm[1] - best_hit.bounding_box_mm[0] - ) - with TRACER.start_span("change_aperture"): - yield from set_aperture_for_bbox_mm( - aperture_scatterguard, - bounding_box_size, - ) - else: - LOGGER.warning("No bounding box size received") + bounding_box_size = numpy.abs( + best_hit.bounding_box_mm[1] - best_hit.bounding_box_mm[0] + ) + yield from set_aperture_for_bbox_mm( + aperture_scatterguard, + bounding_box_size, + ) # once we have the results, go to the appropriate position LOGGER.info("Moving to centre of mass.") @@ -56,12 +51,12 @@ def set_aperture_for_bbox_mm( ): """Sets aperture size based on bbox_size. - This function determines the aperture size needed to accomodate the bounding box + This function determines the aperture size needed to accommodate the bounding box of a crystal. The x-axis length of the bounding box is used, setting the aperture to Medium if this is less than 50um, and Large otherwise. Args: - aperture_device: The aperture scatter gaurd device we are controlling. + aperture_device: The aperture scatter guard device we are controlling. bbox_size_mm: The [x,y,z] lengths, in mm, of a bounding box containing a crystal. This describes (in no particular order): * The maximum width a crystal occupies @@ -81,14 +76,4 @@ def set_aperture_for_bbox_mm( f"Setting aperture to {new_selected_aperture} based on bounding box size {bbox_size_mm}." ) - @bpp.set_run_key_decorator("change_aperture") - @bpp.run_decorator( - md={ - "subplan_name": "change_aperture", - "aperture_size": new_selected_aperture.value, - } - ) - def set_aperture(): - yield from bps.abs_set(aperture_device, new_selected_aperture) - - yield from set_aperture() + yield from bps.abs_set(aperture_device, new_selected_aperture) diff --git a/tests/system_tests/hyperion/test_aperturescatterguard_system.py b/tests/system_tests/hyperion/test_aperturescatterguard_system.py index 3205b66ba..97291701a 100644 --- a/tests/system_tests/hyperion/test_aperturescatterguard_system.py +++ b/tests/system_tests/hyperion/test_aperturescatterguard_system.py @@ -10,10 +10,6 @@ ) from ophyd_async.core import init_devices -from mx_bluesky.hyperion.experiment_plans.change_aperture_then_move_plan import ( - set_aperture_for_bbox_mm, -) - @pytest.fixture def ap_sg(): @@ -26,28 +22,3 @@ def ap_sg(): tolerances=AperturePosition.tolerances_from_gda_params(params), ) return ap_sg - - -@pytest.mark.s03() -@pytest.mark.parametrize( - "bbox, expected_aperture", - [ - ([0.05, 0.05, 0.05], "LARGE_APERTURE"), - ([0.02, 0.02, 0.02], "MEDIUM_APERTURE"), - ], - ids=["large_aperture", "medium_aperture"], -) -def test_aperture_change_callback( - ap_sg: ApertureScatterguard, bbox: list[float], expected_aperture: str -): - from bluesky.run_engine import RunEngine - - from mx_bluesky.hyperion.external_interaction.callbacks.aperture_change_callback import ( - ApertureChangeCallback, - ) - - cb = ApertureChangeCallback() - RE = RunEngine({}) - RE.subscribe(cb) - RE(set_aperture_for_bbox_mm(ap_sg, bbox)) - assert cb.last_selected_aperture == expected_aperture