Skip to content

Commit

Permalink
(DiamondLightSource/mx-bluesky#475) Method to allow access to full zo…
Browse files Browse the repository at this point in the history
…calo results
  • Loading branch information
rtuck99 committed Oct 4, 2024
1 parent 6babfc5 commit 20fd5b4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/dodal/devices/zocalo/zocalo_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import numpy as np
import workflows.recipe
import workflows.transport
from bluesky import Msg
from bluesky.protocols import Descriptor, Triggerable
from deepdiff import DeepDiff
from numpy.typing import NDArray
Expand Down Expand Up @@ -381,3 +382,21 @@ def get_processing_result(
bbox_size = None if len(bbox_sizes) == 0 else bbox_sizes[0] # type: ignore
LOGGER.debug(f"Top bbox size: {bbox_size}")
return centre_of_mass, bbox_size


def _corrected_xrc_result(uncorrected: XrcResult) -> XrcResult:
corrected = XrcResult(**uncorrected)
corrected["centre_of_mass"] = [
coord - 0.5 for coord in uncorrected["centre_of_mass"]
]
return corrected


def get_full_processing_results(
zocalo: ZocaloResults,
) -> Generator[Msg, Any, Sequence[XrcResult]]:
"""A plan that will return the raw zocalo results, ranked in descending order according to the sort key.
Returns empty list in the event no results found."""
LOGGER.info("Retrieving raw zocalo processing results")
raw_results = yield from bps.rd(zocalo.results, default_value=[])
return [_corrected_xrc_result(r) for r in raw_results]
22 changes: 22 additions & 0 deletions tests/devices/unit_tests/test_zocalo_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
XrcResult,
ZocaloResults,
ZocaloSource,
get_full_processing_results,
get_processing_result,
)

Expand Down Expand Up @@ -174,6 +175,27 @@ def plan():
RE(plan())


async def test_get_full_processing_results(mocked_zocalo_device, RE) -> None:
zocalo_device: ZocaloResults = await mocked_zocalo_device(
TEST_RESULTS, run_setup=False
)

def plan():
yield from bps.trigger(zocalo_device)
full_results = yield from get_full_processing_results(zocalo_device)
assert len(full_results) == 3
centres_of_mass = [xrc_result["centre_of_mass"] for xrc_result in full_results]
bbox = [xrc_result["bounding_box"] for xrc_result in full_results]
assert centres_of_mass == [[0.5, 1.5, 2.5], [1.5, 2.5, 3.5], [3.5, 4.5, 5.5]]
assert bbox == [
[[1, 2, 3], [3, 4, 4]],
[[1, 2, 3], [3, 4, 4]],
[[1, 2, 3], [3, 4, 4]],
]

RE(plan())


@patch(
"dodal.devices.zocalo.zocalo_results.workflows.recipe.wrap_subscribe", autospec=True
)
Expand Down

0 comments on commit 20fd5b4

Please sign in to comment.