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

Select aperture based on bounding box size #724

Merged
merged 9 commits into from
Jan 8, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def change_aperture_then_move_to_xtal(
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
yield from set_aperture_for_bbox_mm(
aperture_scatterguard,
bounding_box_size,
)
else:
LOGGER.warning("No bounding box size received")
Expand All @@ -49,22 +50,20 @@ def change_aperture_then_move_to_xtal(
)


def _set_aperture_for_bbox_mm(
aperture_device: ApertureScatterguard, bbox_size_mm: list[float] | numpy.ndarray
):
# TODO confirm correction factor see https://github.com/DiamondLightSource/mx-bluesky/issues/618
ASSUMED_BOX_SIZE_MM = 0.020
bbox_size_boxes = [round(mm / ASSUMED_BOX_SIZE_MM) for mm in bbox_size_mm]
yield from set_aperture_for_bbox_size(aperture_device, bbox_size_boxes)


def set_aperture_for_bbox_size(
def set_aperture_for_bbox_mm(
aperture_device: ApertureScatterguard,
bbox_size: list[int] | numpy.ndarray,
bbox_size: list[float] | numpy.ndarray,
):
"""bbox_size represents the [x,y,z] lengths, in mm, of a bounding box
shihab-dls marked this conversation as resolved.
Show resolved Hide resolved
containing a crystal. This discribes (in no particular order):
shihab-dls marked this conversation as resolved.
Show resolved Hide resolved
* The maximum width a crystal occupies
* The maximum height a crystal occupies
* The maximum depth a crystal occupies
Constructing a three dimensional cuboid, completely encapsulating the crystal."""

# bbox_size is [x,y,z], for i03 we only care about x
new_selected_aperture = (
ApertureValue.MEDIUM if bbox_size[0] < 2 else ApertureValue.LARGE
ApertureValue.MEDIUM if bbox_size[0] < 0.05 else ApertureValue.LARGE
shihab-dls marked this conversation as resolved.
Show resolved Hide resolved
)
LOGGER.info(
f"Setting aperture to {new_selected_aperture} based on bounding box size {bbox_size}."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ophyd_async.core import DeviceCollector

from mx_bluesky.hyperion.experiment_plans.change_aperture_then_move_plan import (
set_aperture_for_bbox_size,
set_aperture_for_bbox_mm,
)


Expand Down Expand Up @@ -39,5 +39,5 @@ def test_aperture_change_callback(ap_sg: ApertureScatterguard):
cb = ApertureChangeCallback()
RE = RunEngine({})
RE.subscribe(cb)
RE(set_aperture_for_bbox_size(ap_sg, [2, 2, 2]))
RE(set_aperture_for_bbox_mm(ap_sg, [2, 2, 2]))
shihab-dls marked this conversation as resolved.
Show resolved Hide resolved
assert cb.last_selected_aperture == "LARGE_APERTURE"
Loading