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
2 changes: 1 addition & 1 deletion doc/plans/plans.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Alternatively, we provide some very thin wrappers which construct the devices fo

[`motor_adaptive_scan`](ibex_bluesky_core.plans.motor_scan)

which wrap the above respectively. These take _names_ of blocks, rather than devices themselves, and construct a DAE and block device for you. This might be useful if you have a fairly standard DAE setup and just want to scan a block pointing at a motor such as a Sample Changer axis.
which wrap the above respectively. These take _names_ of blocks, rather than devices themselves, and construct a DAE and block device for you, using the global moving flag to determine if a motor has finished moving (in the same way as a `waitfor_move()`). This might be useful if you have a fairly standard DAE setup and just want to scan a block pointing at a motor such as a Sample Changer axis, but is not as flexible or performant as the lower-level plans.

for example if you just wanted to scan over a motor, wait for 400 frames, and perform a linear fit, you can just write this in the console:

Expand Down
26 changes: 18 additions & 8 deletions src/ibex_bluesky_core/plans/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
from ophyd_async.plan_stubs import ensure_connected

from ibex_bluesky_core.callbacks import ISISCallbacks
from ibex_bluesky_core.devices.block import BlockMot
from ibex_bluesky_core.devices.block import BlockWriteConfig, block_rw
from ibex_bluesky_core.devices.simpledae import monitor_normalising_dae
from ibex_bluesky_core.fitting import FitMethod
from ibex_bluesky_core.utils import NamedReadableAndMovable, centred_pixel, get_pv_prefix
from ibex_bluesky_core.utils import NamedReadableAndMovable, centred_pixel

if TYPE_CHECKING:
from ibex_bluesky_core.devices.simpledae import SimpleDae
Expand Down Expand Up @@ -169,9 +169,10 @@ def motor_scan( # noqa: PLR0913
save_run: bool = False,
rel: bool = False,
) -> Generator[Msg, None, ISISCallbacks]:
"""Wrap our scan() plan and create a block_mot and a DAE object.
"""Wrap our scan() plan and create a block_rw and a DAE object.

This only works with blocks that are pointing at motor records.
This essentially uses the same mechanism as a waitfor_move by using the global "moving" flag
to determine if motors are still moving after starting a move.
This is really just a wrapper around :func:`ibex_bluesky_core.plans.scan`

Args:
Expand All @@ -192,7 +193,11 @@ def motor_scan( # noqa: PLR0913
an :obj:`ibex_bluesky_core.callbacks.ISISCallbacks` instance.

"""
block = BlockMot(prefix=get_pv_prefix(), block_name=block_name)
block = block_rw(
float,
block_name=block_name,
write_config=BlockWriteConfig(use_global_moving_flag=True),
)
det_pixels = centred_pixel(det, pixel_range)
dae = monitor_normalising_dae(
det_pixels=det_pixels, frames=frames, periods=periods, save_run=save_run, monitor=mon
Expand Down Expand Up @@ -230,9 +235,10 @@ def motor_adaptive_scan( # noqa: PLR0913
save_run: bool = False,
rel: bool = False,
) -> Generator[Msg, None, ISISCallbacks]:
"""Wrap adaptive_scan() plan and create a block_mot and a DAE object.
"""Wrap adaptive_scan() plan and create a block_rw and a DAE object.

This only works with blocks that are pointing at motor records.
This essentially uses the same mechanism as a waitfor_move by using the global "moving" flag
to determine if motors are still moving after starting a move.
This is really just a wrapper around :func:`ibex_bluesky_core.plans.adaptive_scan`

Args:
Expand All @@ -255,7 +261,11 @@ def motor_adaptive_scan( # noqa: PLR0913
an :obj:`ibex_bluesky_core.callbacks.ISISCallbacks` instance.

"""
block = BlockMot(prefix=get_pv_prefix(), block_name=block_name)
block = block_rw(
float,
block_name=block_name,
write_config=BlockWriteConfig(use_global_moving_flag=True),
)
det_pixels = centred_pixel(det, pixel_range)
dae = monitor_normalising_dae(
det_pixels=det_pixels, frames=frames, periods=periods, save_run=save_run, monitor=mon
Expand Down
10 changes: 5 additions & 5 deletions tests/plans/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ophyd_async.sim import SimMotor
from ophyd_async.testing import callback_on_mock_put, set_mock_value

from ibex_bluesky_core.devices.block import BlockMot, BlockR
from ibex_bluesky_core.devices.block import BlockMot, BlockR, BlockRw
from ibex_bluesky_core.devices.simpledae import (
Controller,
MonitorNormalizer,
Expand All @@ -30,7 +30,7 @@ def test_scan_motor_creates_block_device_and_dae(RE):
prefix = "UNITTEST:"
block_name = "some_block"
with (
patch("ibex_bluesky_core.plans.get_pv_prefix", return_value=prefix),
patch("ibex_bluesky_core.devices.block.get_pv_prefix", return_value=prefix),
patch("ibex_bluesky_core.devices.simpledae.get_pv_prefix", return_value=prefix),
patch("ibex_bluesky_core.plans.scan") as scan,
):
Expand All @@ -48,15 +48,15 @@ def test_scan_motor_creates_block_device_and_dae(RE):
)
scan.assert_called_once()
assert isinstance(scan.call_args[1]["dae"], SimpleDae)
assert isinstance(scan.call_args[1]["block"], BlockMot)
assert isinstance(scan.call_args[1]["block"], BlockRw)
assert scan.call_args[1]["block"].name == block_name


def test_adaptive_scan_motor_creates_block_device_and_dae(RE):
prefix = "UNITTEST:"
block_name = "some_block"
with (
patch("ibex_bluesky_core.plans.get_pv_prefix", return_value=prefix),
patch("ibex_bluesky_core.devices.block.get_pv_prefix", return_value=prefix),
patch("ibex_bluesky_core.devices.simpledae.get_pv_prefix", return_value=prefix),
patch("ibex_bluesky_core.plans.adaptive_scan") as scan,
):
Expand All @@ -76,7 +76,7 @@ def test_adaptive_scan_motor_creates_block_device_and_dae(RE):
)
scan.assert_called_once()
assert isinstance(scan.call_args[1]["dae"], SimpleDae)
assert isinstance(scan.call_args[1]["block"], BlockMot)
assert isinstance(scan.call_args[1]["block"], BlockRw)
assert scan.call_args[1]["block"].name == block_name


Expand Down