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
15 changes: 15 additions & 0 deletions src/mx_bluesky/beamlines/i24/web_gui_plans/oav_plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,18 @@ def focus_on_oav_view(
magnitude = -magnitude

yield from bps.abs_set(pmac.z, magnitude, wait=True)


def move_on_oav_view_click(
Comment thread
adaudon marked this conversation as resolved.
position: tuple[int, int], oav=inject("oav"), pmac: PMAC = inject("pmac")
) -> MsgGenerator:
x = position[0]
y = position[1]

x_microns_per_pixel = yield from bps.rd(oav.microns_per_pixel_x)
y_microns_per_pixel = yield from bps.rd(oav.microns_per_pixel_y)

x_mm = (x * x_microns_per_pixel) / 1000
y_mm = (y * y_microns_per_pixel) / 1000

yield from bps.mv(pmac.x, x_mm, pmac.y, y_mm, wait=True)
41 changes: 41 additions & 0 deletions tests/unit_tests/beamlines/i24/web_gui/test_oav_plans.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
focus_on_oav_view,
move_block_on_arrow_click,
move_nudge_on_arrow_click,
move_on_oav_view_click,
move_window_on_arrow_click,
)

Expand Down Expand Up @@ -103,3 +104,43 @@ async def test_focus_on_oav_view(
):
run_engine(focus_on_oav_view(FocusDirection(direction), MoveSize(move_size), pmac))
assert await pmac.z.user_readback.get_value() == expected_value


@pytest.mark.parametrize(
"coordinates, microns_per_pixel_x, microns_per_pixel_y, expected_x, expected_y",
[
((568, 321), 1.0, 1.0, 0.568, 0.321),
((123, 789), 1.0, 1.0, 0.123, 0.789),
((568, 321), 0.5, 2.0, 0.284, 0.642),
((123, 789), 2.0, 0.5, 0.246, 0.3945),
],
)
def test_move_on_oav_view_click(
coordinates,
microns_per_pixel_x,
microns_per_pixel_y,
expected_x,
expected_y,
oav,
pmac,
run_engine,
):
def fake_rd(_signal):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to parametrize here on a couple of different values of microns per pixel x/y just to ensure that the calculation does actually use them correctly

if _signal == oav.microns_per_pixel_x:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should really be _signal is oav.microns_per_pixel_x

return microns_per_pixel_x
if _signal == oav.microns_per_pixel_y:
return microns_per_pixel_y
return 1.0
yield

with (
patch(
"mx_bluesky.beamlines.i24.web_gui_plans.oav_plans.bps.mv",
) as mock_bps_mv,
patch(
"mx_bluesky.beamlines.i24.web_gui_plans.oav_plans.bps.rd",
side_effect=fake_rd,
),
):
run_engine(move_on_oav_view_click(coordinates, oav, pmac))
mock_bps_mv.assert_any_call(pmac.x, expected_x, pmac.y, expected_y, wait=True)
Loading