Skip to content
Merged
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
32 changes: 32 additions & 0 deletions src/test_rig_bluesky/plans.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
from typing import Any

from bluesky import plan_stubs as bps
Expand Down Expand Up @@ -42,3 +43,34 @@ def spectroscopy(
spec = spec or Line(sample_stage.x, 0, 5, 5)

yield from spec_scan({spectroscopy_detector, sample_stage}, spec, metadata=metadata)


def demo_spectroscopy(
spectroscopy_detector: AravisDetector = spectroscopy_detector,
sample_stage: XYZStage = sample_stage,
total_number_of_scan_points: int = 25,
grid_size: float = 5.0,
grid_origin_x: float = 0.0,
grid_origin_y: float = 0.0,
exposure_time: float = 0.1,
metadata: dict[str, Any] | None = None,
) -> MsgGenerator[None]:
"""Spectroscopy plan intended for use in Visr demonstrations to visitors.
The time taken to scan is approximately linear in total_numbers_of_grid_points.
All other parameters can be left at their defaults.
"""
xsteps = ysteps = int(round(math.sqrt(max(total_number_of_scan_points, 1))))
xmin = grid_origin_x
xmax = grid_origin_x + grid_size
ymin = grid_origin_y
ymax = grid_origin_y + grid_size
grid = Line(sample_stage.y, ymin, ymax, ysteps) * Line(
sample_stage.x, xmin, xmax, xsteps
)
yield from spectroscopy(
spectroscopy_detector=spectroscopy_detector,
sample_stage=sample_stage,
spec=grid,
exposure_time=exposure_time,
metadata=metadata,
)
14 changes: 14 additions & 0 deletions tests/system_tests/test_plans_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,17 @@ def test_spectroscopy(
timeout=10,
)
assert events["FINISHED"][0]["scanDimensions"] == [5]


def test_demo_spectroscopy(
bluesky_plan_runner: BlueskyPlanRunner, latest_commissioning_instrument_session: str
):
events = bluesky_plan_runner.run(
TaskRequest(
name="demo_spectroscopy",
params={},
instrument_session=latest_commissioning_instrument_session,
),
timeout=10,
)
assert events["FINISHED"][0]["scanDimensions"] == [5, 5]
27 changes: 26 additions & 1 deletion tests/unit_tests/test_plans.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import unittest.mock
from collections import defaultdict

from bluesky import RunEngine
Expand All @@ -7,7 +8,7 @@
from ophyd_async.testing import assert_emitted, callback_on_mock_put, set_mock_value
from scanspec.specs import Line

from test_rig_bluesky.plans import snapshot, spectroscopy
from test_rig_bluesky.plans import demo_spectroscopy, snapshot, spectroscopy


def mock_detector_behavior(detector: AravisDetector) -> None:
Expand Down Expand Up @@ -132,3 +133,27 @@ def test_spectroscopy_prepares_and_waits_before_doing_anything_else(RE: RunEngin

assert message_1.command == "prepare"
assert message_2.command == "wait"


def test_demo_spectroscopy():
fake_detector = unittest.mock.MagicMock(name="fake_detector")
fake_stage = unittest.mock.MagicMock(name="fake_stage")
with unittest.mock.patch("test_rig_bluesky.plans.spectroscopy") as mock_spec:
# Call the generator function and exhaust it
generator = demo_spectroscopy(
spectroscopy_detector=fake_detector,
sample_stage=fake_stage,
total_number_of_scan_points=25,
)

# Consume the generator so that the spectroscopy call is made
for _ in generator:
pass

mock_spec.assert_called_once()
called_kwargs = mock_spec.call_args.kwargs
assert called_kwargs["spectroscopy_detector"] is fake_detector
assert called_kwargs["sample_stage"] is fake_stage
assert called_kwargs["spec"] == Line(fake_stage.y, 0.0, 5.0, 5) * Line(
fake_stage.x, 0.0, 5.0, 5
)