Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove aperture change callback #852

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

10 changes: 1 addition & 9 deletions src/mx_bluesky/hyperion/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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...")
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.")
Expand All @@ -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
Expand All @@ -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)
29 changes: 0 additions & 29 deletions tests/system_tests/hyperion/test_aperturescatterguard_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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