Skip to content

Commit 7df83de

Browse files
corrections to documentation and code
1 parent 04cb045 commit 7df83de

File tree

6 files changed

+58
-50
lines changed

6 files changed

+58
-50
lines changed

doc/plan_stubs/plan_wrappers.md

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,86 @@
1-
# Plan Wrappers
1+
# Plan wrappers
22

3-
Plan wrappers that temporarily modify [DAE (Data Acquisition Electronics)](https://isiscomputinggroup.github.io/ibex_bluesky_core/devices/dae.html#dae-data-acquisition-electronics) settings during a plan, automatically restoring the original values afterwards. This ensures that your experiments don't permanently change instrument configuration.
3+
Plan wrappers that temporarily modify [DAE (Data Acquisition Electronics)](/devices/dae.md) settings during a plan, automatically restoring the original values afterwards. This ensures that your experiments don't permanently change instrument configuration.
44

55
## Available Wrappers
66

77
### DAE Table
88

9-
:py:obj:`dae_table_wrapper <ibex_bluesky_core.plan_stubs.dae_table_wrapper>`
9+
A function that wraps a plan to temporarily modify the DAE table.
10+
11+
API reference: {py:obj}`dae_table_wrapper<ibex_bluesky_core.plan_stubs.with_dae_tables>`
1012

1113
```python
1214
RE(
13-
_with_dae_tables(
15+
with_dae_tables(
1416
bps.null(),
1517
dae=dae,
1618
new_settings=modified_settings
17-
)
1819
)
20+
)
21+
```
22+
```python
23+
def plan():
24+
yield from with_dae_tables(scan(...), dae=dae, new_settings=modified_settings)
1925
```
2026

21-
Where `modified_settings` is a dataset in the form :py:obj:`DaeSettingsData < ibex_bluesky_core.devices.dae.DaeSettingsData>`
27+
(where `modified_settings` is a dataset in the form {py:obj}`DaeSettingsData <ibex_bluesky_core.devices.dae.DaeSettingsData>`)
28+
2229

23-
A function that wraps a plan to temporarily modify the DAE table.
2430

2531
### Num Periods
26-
:py:obj:`num_periods_wrapper <ibex_bluesky_core.plan_stubs.num_periods_wrapper>`
32+
33+
A function that wraps a plan to temporarily modify the number of periods.
34+
35+
API reference: {py:obj}`num_periods_wrapper<ibex_bluesky_core.plan_stubs.with_num_periods>`
2736

2837
```python
2938
RE(
30-
_with_num_periods(
39+
with_num_periods(
3140
bps.null(),
3241
dae=dae,
3342
number_of_periods=1000
34-
)
3543
)
44+
)
45+
```
46+
```python
47+
def plan():
48+
yield from with_num_periods(scan(...), dae=dae, number_of_periods=1000)
3649
```
37-
A function that wraps a plan to temporarily modify the number of periods.
50+
3851

3952
### Time Channels
40-
:py:obj:`time_channels_wrapper <ibex_bluesky_core.plan_stubs.time_channels_wrapper>`:
53+
A function that wraps a plan to temporarily modify the time channels boundaries.
54+
55+
API reference: {py:obj}`time_channels_wrapper<ibex_bluesky_core.plan_stubs.with_time_channels>`
4156

4257
```python
4358
RE(
44-
_with_time_channels(
59+
with_time_channels(
4560
bps.null(),
4661
dae=dae,
4762
new_settings=modified_settings
48-
)
4963
)
64+
)
5065
```
51-
Where `modified_settings` is a dataset in the form :py:obj:`DaeTCBSettingsData < ibex_bluesky_core.devices.dae.DaeTCBSettingsData>`
52-
53-
A function that wraps a plan to temporarily modify the time channels boundaries.
66+
```python
67+
def plan():
68+
yield from with_time_channels(scan(...), dae=dae, new_settings=modified_settings)
69+
```
70+
(where `modified_settings` is a dataset in the form {py:obj}`DaeTCBSettingsData<ibex_bluesky_core.devices.dae.DaeTCBSettingsData>`)
5471

5572
## Usage
5673

5774
To use these wrappers, the plan written by the user must be wrapped by the function within the RunEngine:
5875

5976
``` python
60-
61-
from bluesky import RunEngine
62-
from ibex_bluesky_core.plan_stubs import _with_num_periods
77+
from ibex_bluesky_core.plan_stubs import with_num_periods
6378
from ibex_bluesky_core.devices.simpledae import SimpleDae
6479

6580
dae = SimpleDae() # Give your DAE options here
66-
RE = RunEngine()
67-
68-
RE(
69-
_with_num_periods(
70-
bps.null(), # Default plan to run
71-
dae=dae,
72-
number_of_periods=1000 # Temporary number of periods to run
73-
)
74-
)
7581

82+
def plan():
83+
yield from with_num_periods(scan(...), dae=dae, number_of_periods=1000)
7684
```
7785

7886
the plan with the modified DAE settings, restoring the original settings afterwards.

src/ibex_bluesky_core/plan_stubs/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
from ophyd_async.epics.motor import Motor, UseSetMode
1313

1414
from ibex_bluesky_core.devices.reflectometry import ReflParameter
15-
from ibex_bluesky_core.plan_stubs.dae_table_wrapper import _with_dae_tables
16-
from ibex_bluesky_core.plan_stubs.num_periods_wrapper import _with_num_periods
17-
from ibex_bluesky_core.plan_stubs.time_channels_wrapper import _with_time_channels
15+
from ibex_bluesky_core.plan_stubs._dae_table_wrapper import with_dae_tables
16+
from ibex_bluesky_core.plan_stubs._num_periods_wrapper import with_num_periods
17+
from ibex_bluesky_core.plan_stubs._time_channels_wrapper import with_time_channels
1818
from ibex_bluesky_core.utils import NamedReadableAndMovable
1919

2020
logger = logging.getLogger(__name__)
@@ -28,9 +28,9 @@
2828

2929

3030
__all__ = [
31-
"_with_dae_tables",
32-
"_with_num_periods",
33-
"_with_time_channels",
31+
"with_dae_tables",
32+
"with_num_periods",
33+
"with_time_channels",
3434
"call_qt_aware",
3535
"call_sync",
3636
"polling_plan",

src/ibex_bluesky_core/plan_stubs/dae_table_wrapper.py renamed to src/ibex_bluesky_core/plan_stubs/_dae_table_wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ibex_bluesky_core.devices.dae import Dae, DaeSettingsData
1111

1212

13-
def _with_dae_tables(
13+
def with_dae_tables(
1414
plan: Generator[Msg, None, None], dae: Dae, new_settings: DaeSettingsData
1515
) -> Generator[Msg, None, None]:
1616
"""Wrap a plan with temporary modification to DAE Settings.
@@ -35,7 +35,7 @@ def _inner() -> Generator[Msg, None, None]:
3535

3636
yield from bps.mv(dae.dae_settings, new_settings)
3737

38-
yield from plan
38+
return (yield from plan)
3939

4040
def _cleanup() -> Generator[Msg, None, None]:
4141
yield from bps.mv(dae.dae_settings, original_dae_setting)

src/ibex_bluesky_core/plan_stubs/num_periods_wrapper.py renamed to src/ibex_bluesky_core/plan_stubs/_num_periods_wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ibex_bluesky_core.devices.dae import Dae
1111

1212

13-
def _with_num_periods(
13+
def with_num_periods(
1414
plan: Generator[Msg, None, None], dae: Dae, number_of_periods: int
1515
) -> Generator[Msg, None, None]:
1616
"""Wrap a plan with temporary modification to Periods Settings.
@@ -34,7 +34,7 @@ def _inner() -> Generator[Msg, None, None]:
3434

3535
yield from bps.mv(dae.number_of_periods, number_of_periods)
3636

37-
yield from plan
37+
return (yield from plan)
3838

3939
def _cleanup() -> Generator[Msg, None, None]:
4040
yield from bps.mv(dae.number_of_periods, original_num_periods)

src/ibex_bluesky_core/plan_stubs/time_channels_wrapper.py renamed to src/ibex_bluesky_core/plan_stubs/_time_channels_wrapper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ibex_bluesky_core.devices.dae import Dae, DaeTCBSettingsData
1111

1212

13-
def _with_time_channels(
13+
def with_time_channels(
1414
plan: Generator[Msg, None, None], dae: Dae, new_tcb_settings: DaeTCBSettingsData
1515
) -> Generator[Msg, None, None]:
1616
"""Wrap a plan with temporary modification to Time Channel Settings.
@@ -35,7 +35,7 @@ def _inner() -> Generator[Msg, None, None]:
3535

3636
yield from bps.mv(dae.tcb_settings, new_tcb_settings)
3737

38-
yield from plan
38+
return (yield from plan)
3939

4040
def _cleanup() -> Generator[Msg, None, None]:
4141
yield from bps.mv(dae.tcb_settings, original_time_channels)

tests/test_plan_stubs.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
from ibex_bluesky_core.devices.reflectometry import ReflParameter
2727
from ibex_bluesky_core.plan_stubs import (
2828
CALL_QT_AWARE_MSG_KEY,
29-
_with_dae_tables,
30-
_with_num_periods,
31-
_with_time_channels,
29+
with_dae_tables,
30+
with_num_periods,
31+
with_time_channels,
3232
call_qt_aware,
3333
call_sync,
3434
prompt_user_for_choice,
@@ -202,9 +202,9 @@ def test_num_periods_wrapper(dae: Dae, RE: RunEngine):
202202

203203
set_mock_value(dae.number_of_periods.signal, original_settings)
204204

205-
with patch("ibex_bluesky_core.plan_stubs.num_periods_wrapper.ensure_connected"):
205+
with patch("ibex_bluesky_core.plan_stubs._num_periods_wrapper.ensure_connected"):
206206
RE(
207-
_with_num_periods(
207+
with_num_periods(
208208
bps.null(),
209209
dae=dae,
210210
number_of_periods=80,
@@ -480,8 +480,8 @@ def test_time_channels_wrapper(dae: Dae, RE: RunEngine):
480480
dae.tcb_settings._raw_tcb_settings, compress_and_hex(original_tcb_settings).decode()
481481
)
482482

483-
with patch("ibex_bluesky_core.plan_stubs.time_channels_wrapper.ensure_connected"):
484-
RE(_with_time_channels(bps.null(), dae=dae, new_tcb_settings=modified_settings))
483+
with patch("ibex_bluesky_core.plan_stubs._time_channels_wrapper.ensure_connected"):
484+
RE(with_time_channels(bps.null(), dae=dae, new_tcb_settings=modified_settings))
485485

486486
mock_set_calls = get_mock_put(dae.tcb_settings._raw_tcb_settings).call_args_list
487487

@@ -556,8 +556,8 @@ def test_dae_table_wrapper(dae: Dae, RE: RunEngine):
556556

557557
set_mock_value(dae.dae_settings._raw_dae_settings, original_settings)
558558

559-
with patch("ibex_bluesky_core.plan_stubs.dae_table_wrapper.ensure_connected"):
560-
RE(_with_dae_tables(bps.null(), dae=dae, new_settings=modified_settings))
559+
with patch("ibex_bluesky_core.plan_stubs._dae_table_wrapper.ensure_connected"):
560+
RE(with_dae_tables(bps.null(), dae=dae, new_settings=modified_settings))
561561

562562
mock_set_calls = get_mock_put(dae.dae_settings._raw_dae_settings).call_args_list
563563

0 commit comments

Comments
 (0)