Skip to content

Commit a29cb84

Browse files
authored
Merge pull request #192 from ISISComputingGroup/blockrw_for_motor_scans
use blockrw for motor scan instead of block_mot
2 parents cced98c + adeb294 commit a29cb84

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

doc/plans/plans.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Alternatively, we provide some very thin wrappers which construct the devices fo
6767

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

70-
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.
70+
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.
7171

7272
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:
7373

src/ibex_bluesky_core/plans/__init__.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
from ophyd_async.plan_stubs import ensure_connected
1313

1414
from ibex_bluesky_core.callbacks import ISISCallbacks
15-
from ibex_bluesky_core.devices.block import BlockMot
15+
from ibex_bluesky_core.devices.block import BlockWriteConfig, block_rw
1616
from ibex_bluesky_core.devices.simpledae import monitor_normalising_dae
1717
from ibex_bluesky_core.fitting import FitMethod
18-
from ibex_bluesky_core.utils import NamedReadableAndMovable, centred_pixel, get_pv_prefix
18+
from ibex_bluesky_core.utils import NamedReadableAndMovable, centred_pixel
1919

2020
if TYPE_CHECKING:
2121
from ibex_bluesky_core.devices.simpledae import SimpleDae
@@ -169,9 +169,10 @@ def motor_scan( # noqa: PLR0913
169169
save_run: bool = False,
170170
rel: bool = False,
171171
) -> Generator[Msg, None, ISISCallbacks]:
172-
"""Wrap our scan() plan and create a block_mot and a DAE object.
172+
"""Wrap our scan() plan and create a block_rw and a DAE object.
173173
174-
This only works with blocks that are pointing at motor records.
174+
This essentially uses the same mechanism as a waitfor_move by using the global "moving" flag
175+
to determine if motors are still moving after starting a move.
175176
This is really just a wrapper around :func:`ibex_bluesky_core.plans.scan`
176177
177178
Args:
@@ -192,7 +193,11 @@ def motor_scan( # noqa: PLR0913
192193
an :obj:`ibex_bluesky_core.callbacks.ISISCallbacks` instance.
193194
194195
"""
195-
block = BlockMot(prefix=get_pv_prefix(), block_name=block_name)
196+
block = block_rw(
197+
float,
198+
block_name=block_name,
199+
write_config=BlockWriteConfig(use_global_moving_flag=True),
200+
)
196201
det_pixels = centred_pixel(det, pixel_range)
197202
dae = monitor_normalising_dae(
198203
det_pixels=det_pixels, frames=frames, periods=periods, save_run=save_run, monitor=mon
@@ -230,9 +235,10 @@ def motor_adaptive_scan( # noqa: PLR0913
230235
save_run: bool = False,
231236
rel: bool = False,
232237
) -> Generator[Msg, None, ISISCallbacks]:
233-
"""Wrap adaptive_scan() plan and create a block_mot and a DAE object.
238+
"""Wrap adaptive_scan() plan and create a block_rw and a DAE object.
234239
235-
This only works with blocks that are pointing at motor records.
240+
This essentially uses the same mechanism as a waitfor_move by using the global "moving" flag
241+
to determine if motors are still moving after starting a move.
236242
This is really just a wrapper around :func:`ibex_bluesky_core.plans.adaptive_scan`
237243
238244
Args:
@@ -255,7 +261,11 @@ def motor_adaptive_scan( # noqa: PLR0913
255261
an :obj:`ibex_bluesky_core.callbacks.ISISCallbacks` instance.
256262
257263
"""
258-
block = BlockMot(prefix=get_pv_prefix(), block_name=block_name)
264+
block = block_rw(
265+
float,
266+
block_name=block_name,
267+
write_config=BlockWriteConfig(use_global_moving_flag=True),
268+
)
259269
det_pixels = centred_pixel(det, pixel_range)
260270
dae = monitor_normalising_dae(
261271
det_pixels=det_pixels, frames=frames, periods=periods, save_run=save_run, monitor=mon

tests/plans/test_init.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ophyd_async.sim import SimMotor
88
from ophyd_async.testing import callback_on_mock_put, set_mock_value
99

10-
from ibex_bluesky_core.devices.block import BlockMot, BlockR
10+
from ibex_bluesky_core.devices.block import BlockMot, BlockR, BlockRw
1111
from ibex_bluesky_core.devices.simpledae import (
1212
Controller,
1313
MonitorNormalizer,
@@ -30,7 +30,7 @@ def test_scan_motor_creates_block_device_and_dae(RE):
3030
prefix = "UNITTEST:"
3131
block_name = "some_block"
3232
with (
33-
patch("ibex_bluesky_core.plans.get_pv_prefix", return_value=prefix),
33+
patch("ibex_bluesky_core.devices.block.get_pv_prefix", return_value=prefix),
3434
patch("ibex_bluesky_core.devices.simpledae.get_pv_prefix", return_value=prefix),
3535
patch("ibex_bluesky_core.plans.scan") as scan,
3636
):
@@ -48,15 +48,15 @@ def test_scan_motor_creates_block_device_and_dae(RE):
4848
)
4949
scan.assert_called_once()
5050
assert isinstance(scan.call_args[1]["dae"], SimpleDae)
51-
assert isinstance(scan.call_args[1]["block"], BlockMot)
51+
assert isinstance(scan.call_args[1]["block"], BlockRw)
5252
assert scan.call_args[1]["block"].name == block_name
5353

5454

5555
def test_adaptive_scan_motor_creates_block_device_and_dae(RE):
5656
prefix = "UNITTEST:"
5757
block_name = "some_block"
5858
with (
59-
patch("ibex_bluesky_core.plans.get_pv_prefix", return_value=prefix),
59+
patch("ibex_bluesky_core.devices.block.get_pv_prefix", return_value=prefix),
6060
patch("ibex_bluesky_core.devices.simpledae.get_pv_prefix", return_value=prefix),
6161
patch("ibex_bluesky_core.plans.adaptive_scan") as scan,
6262
):
@@ -76,7 +76,7 @@ def test_adaptive_scan_motor_creates_block_device_and_dae(RE):
7676
)
7777
scan.assert_called_once()
7878
assert isinstance(scan.call_args[1]["dae"], SimpleDae)
79-
assert isinstance(scan.call_args[1]["block"], BlockMot)
79+
assert isinstance(scan.call_args[1]["block"], BlockRw)
8080
assert scan.call_args[1]["block"].name == block_name
8181

8282

0 commit comments

Comments
 (0)