ophyd-async 0.3a5__py3-none-any.whl → 0.3rc2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. ophyd_async/_version.py +1 -1
  2. ophyd_async/core/__init__.py +7 -5
  3. ophyd_async/core/async_status.py +11 -28
  4. ophyd_async/core/detector.py +1 -1
  5. ophyd_async/core/device.py +2 -4
  6. ophyd_async/core/flyer.py +1 -1
  7. ophyd_async/core/mock_signal_backend.py +5 -8
  8. ophyd_async/core/mock_signal_utils.py +10 -14
  9. ophyd_async/core/signal.py +23 -17
  10. ophyd_async/core/signal_backend.py +1 -1
  11. ophyd_async/core/utils.py +11 -0
  12. ophyd_async/epics/areadetector/drivers/ad_base.py +1 -7
  13. ophyd_async/epics/areadetector/writers/hdf_writer.py +3 -2
  14. ophyd_async/epics/areadetector/writers/nd_file_hdf.py +0 -2
  15. ophyd_async/epics/areadetector/writers/nd_plugin.py +9 -0
  16. ophyd_async/epics/demo/__init__.py +30 -26
  17. ophyd_async/epics/motion/motor.py +35 -29
  18. ophyd_async/panda/__init__.py +2 -0
  19. ophyd_async/panda/writers/_hdf_writer.py +4 -4
  20. ophyd_async/{planstubs → plan_stubs}/__init__.py +5 -1
  21. ophyd_async/plan_stubs/fly.py +149 -0
  22. ophyd_async/sim/demo/sim_motor.py +56 -86
  23. {ophyd_async-0.3a5.dist-info → ophyd_async-0.3rc2.dist-info}/METADATA +1 -1
  24. {ophyd_async-0.3a5.dist-info → ophyd_async-0.3rc2.dist-info}/RECORD +29 -29
  25. ophyd_async/planstubs/prepare_trigger_and_dets.py +0 -57
  26. /ophyd_async/{planstubs → plan_stubs}/ensure_connected.py +0 -0
  27. {ophyd_async-0.3a5.dist-info → ophyd_async-0.3rc2.dist-info}/LICENSE +0 -0
  28. {ophyd_async-0.3a5.dist-info → ophyd_async-0.3rc2.dist-info}/WHEEL +0 -0
  29. {ophyd_async-0.3a5.dist-info → ophyd_async-0.3rc2.dist-info}/entry_points.txt +0 -0
  30. {ophyd_async-0.3a5.dist-info → ophyd_async-0.3rc2.dist-info}/top_level.txt +0 -0
ophyd_async/_version.py CHANGED
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.3a5'
15
+ __version__ = version = '0.3rc2'
16
16
  __version_tuple__ = version_tuple = (0, 3)
@@ -24,12 +24,10 @@ from .device_save_loader import (
24
24
  walk_rw_signals,
25
25
  )
26
26
  from .flyer import HardwareTriggeredFlyable, TriggerLogic
27
- from .mock_signal_backend import (
28
- MockSignalBackend,
29
- )
27
+ from .mock_signal_backend import MockSignalBackend
30
28
  from .mock_signal_utils import (
31
- assert_mock_put_called_with,
32
29
  callback_on_mock_put,
30
+ get_mock_put,
33
31
  mock_puts_blocked,
34
32
  reset_mock_put_calls,
35
33
  set_mock_put_proceeds,
@@ -57,6 +55,8 @@ from .soft_signal_backend import SoftSignalBackend
57
55
  from .standard_readable import ConfigSignal, HintedSignal, StandardReadable
58
56
  from .utils import (
59
57
  DEFAULT_TIMEOUT,
58
+ CalculatableTimeout,
59
+ CalculateTimeout,
60
60
  Callback,
61
61
  NotConnected,
62
62
  ReadingValueCallback,
@@ -68,7 +68,7 @@ from .utils import (
68
68
  )
69
69
 
70
70
  __all__ = [
71
- "assert_mock_put_called_with",
71
+ "get_mock_put",
72
72
  "callback_on_mock_put",
73
73
  "mock_puts_blocked",
74
74
  "set_mock_values",
@@ -108,6 +108,8 @@ __all__ = [
108
108
  "TriggerInfo",
109
109
  "TriggerLogic",
110
110
  "HardwareTriggeredFlyable",
111
+ "CalculateTimeout",
112
+ "CalculatableTimeout",
111
113
  "DEFAULT_TIMEOUT",
112
114
  "Callback",
113
115
  "NotConnected",
@@ -9,7 +9,6 @@ from typing import (
9
9
  Awaitable,
10
10
  Callable,
11
11
  Generic,
12
- SupportsFloat,
13
12
  Type,
14
13
  TypeVar,
15
14
  cast,
@@ -27,15 +26,11 @@ WAS = TypeVar("WAS", bound="WatchableAsyncStatus")
27
26
  class AsyncStatusBase(Status):
28
27
  """Convert asyncio awaitable to bluesky Status interface"""
29
28
 
30
- def __init__(self, awaitable: Awaitable, timeout: SupportsFloat | None = None):
31
- if isinstance(timeout, SupportsFloat):
32
- timeout = float(timeout)
29
+ def __init__(self, awaitable: Awaitable):
33
30
  if isinstance(awaitable, asyncio.Task):
34
31
  self.task = awaitable
35
32
  else:
36
- self.task = asyncio.create_task(
37
- asyncio.wait_for(awaitable, timeout=timeout)
38
- )
33
+ self.task = asyncio.create_task(awaitable)
39
34
  self.task.add_done_callback(self._run_callbacks)
40
35
  self._callbacks: list[Callback[Status]] = []
41
36
 
@@ -49,9 +44,8 @@ class AsyncStatusBase(Status):
49
44
  self._callbacks.append(callback)
50
45
 
51
46
  def _run_callbacks(self, task: asyncio.Task):
52
- if not task.cancelled():
53
- for callback in self._callbacks:
54
- callback(self)
47
+ for callback in self._callbacks:
48
+ callback(self)
55
49
 
56
50
  def exception(self, timeout: float | None = 0.0) -> BaseException | None:
57
51
  if timeout != 0.0:
@@ -93,14 +87,11 @@ class AsyncStatusBase(Status):
93
87
  class AsyncStatus(AsyncStatusBase):
94
88
  @classmethod
95
89
  def wrap(cls: Type[AS], f: Callable[P, Awaitable]) -> Callable[P, AS]:
90
+ """Wrap an async function in an AsyncStatus."""
91
+
96
92
  @functools.wraps(f)
97
93
  def wrap_f(*args: P.args, **kwargs: P.kwargs) -> AS:
98
- # We can't type this more properly because Concatenate/ParamSpec doesn't
99
- # yet support keywords
100
- # https://peps.python.org/pep-0612/#concatenating-keyword-parameters
101
- timeout = kwargs.get("timeout")
102
- assert isinstance(timeout, SupportsFloat) or timeout is None
103
- return cls(f(*args, **kwargs), timeout=timeout)
94
+ return cls(f(*args, **kwargs))
104
95
 
105
96
  # type is actually functools._Wrapped[P, Awaitable, P, AS]
106
97
  # but functools._Wrapped is not necessarily available
@@ -110,15 +101,11 @@ class AsyncStatus(AsyncStatusBase):
110
101
  class WatchableAsyncStatus(AsyncStatusBase, Generic[T]):
111
102
  """Convert AsyncIterator of WatcherUpdates to bluesky Status interface."""
112
103
 
113
- def __init__(
114
- self,
115
- iterator: AsyncIterator[WatcherUpdate[T]],
116
- timeout: SupportsFloat | None = None,
117
- ):
104
+ def __init__(self, iterator: AsyncIterator[WatcherUpdate[T]]):
118
105
  self._watchers: list[Watcher] = []
119
106
  self._start = time.monotonic()
120
107
  self._last_update: WatcherUpdate[T] | None = None
121
- super().__init__(self._notify_watchers_from(iterator), timeout)
108
+ super().__init__(self._notify_watchers_from(iterator))
122
109
 
123
110
  async def _notify_watchers_from(self, iterator: AsyncIterator[WatcherUpdate[T]]):
124
111
  async for update in iterator:
@@ -146,14 +133,10 @@ class WatchableAsyncStatus(AsyncStatusBase, Generic[T]):
146
133
  cls: Type[WAS],
147
134
  f: Callable[P, AsyncIterator[WatcherUpdate[T]]],
148
135
  ) -> Callable[P, WAS]:
149
- """Wrap an AsyncIterator in a WatchableAsyncStatus. If it takes
150
- 'timeout' as an argument, this must be a float or None, and it
151
- will be propagated to the status."""
136
+ """Wrap an AsyncIterator in a WatchableAsyncStatus."""
152
137
 
153
138
  @functools.wraps(f)
154
139
  def wrap_f(*args: P.args, **kwargs: P.kwargs) -> WAS:
155
- timeout = kwargs.get("timeout")
156
- assert isinstance(timeout, SupportsFloat) or timeout is None
157
- return cls(f(*args, **kwargs), timeout=timeout)
140
+ return cls(f(*args, **kwargs))
158
141
 
159
142
  return cast(Callable[P, WAS], wrap_f)
@@ -332,7 +332,7 @@ class StandardDetector(
332
332
  # Collect stream datum documents for all indices written.
333
333
  # The index is optional, and provided for fly scans, however this needs to be
334
334
  # retrieved for step scans.
335
- if not index:
335
+ if index is None:
336
336
  index = await self.writer.get_indices_written()
337
337
  async for doc in self.writer.collect_stream_docs(index):
338
338
  yield doc
@@ -1,7 +1,5 @@
1
1
  """Base device"""
2
2
 
3
- from __future__ import annotations
4
-
5
3
  import asyncio
6
4
  import sys
7
5
  from functools import cached_property
@@ -32,7 +30,7 @@ class Device(HasName):
32
30
 
33
31
  _name: str = ""
34
32
  #: The parent Device if it exists
35
- parent: Optional[Device] = None
33
+ parent: Optional["Device"] = None
36
34
  # None if connect hasn't started, a Task if it has
37
35
  _connect_task: Optional[asyncio.Task] = None
38
36
  _connect_mock_arg: bool = False
@@ -51,7 +49,7 @@ class Device(HasName):
51
49
  getLogger("ophyd_async.devices"), {"ophyd_async_device_name": self.name}
52
50
  )
53
51
 
54
- def children(self) -> Iterator[Tuple[str, Device]]:
52
+ def children(self) -> Iterator[Tuple[str, "Device"]]:
55
53
  for attr_name, attr in self.__dict__.items():
56
54
  if attr_name != "parent" and isinstance(attr, Device):
57
55
  yield attr_name, attr
ophyd_async/core/flyer.py CHANGED
@@ -39,7 +39,7 @@ class HardwareTriggeredFlyable(
39
39
  def __init__(
40
40
  self,
41
41
  trigger_logic: TriggerLogic[T],
42
- configuration_signals: Sequence[SignalR],
42
+ configuration_signals: Sequence[SignalR] = (),
43
43
  name: str = "",
44
44
  ):
45
45
  self._trigger_logic = trigger_logic
@@ -1,6 +1,6 @@
1
1
  import asyncio
2
2
  from functools import cached_property
3
- from typing import Optional, Type
3
+ from typing import Callable, Optional, Type
4
4
  from unittest.mock import Mock
5
5
 
6
6
  from bluesky.protocols import Descriptor, Reading
@@ -10,7 +10,7 @@ from ophyd_async.core.soft_signal_backend import SoftSignalBackend
10
10
  from ophyd_async.core.utils import DEFAULT_TIMEOUT, ReadingValueCallback, T
11
11
 
12
12
 
13
- class MockSignalBackend(SignalBackend):
13
+ class MockSignalBackend(SignalBackend[T]):
14
14
  def __init__(
15
15
  self,
16
16
  datatype: Optional[Type[T]] = None,
@@ -31,11 +31,11 @@ class MockSignalBackend(SignalBackend):
31
31
 
32
32
  if not isinstance(self.initial_backend, SoftSignalBackend):
33
33
  # If the backend is a hard signal backend, or not provided,
34
- # then we create a soft signal to mimick it
34
+ # then we create a soft signal to mimic it
35
35
 
36
36
  self.soft_backend = SoftSignalBackend(datatype=datatype)
37
37
  else:
38
- self.soft_backend = initial_backend
38
+ self.soft_backend = self.initial_backend
39
39
 
40
40
  def source(self, name: str) -> str:
41
41
  if self.initial_backend:
@@ -47,7 +47,7 @@ class MockSignalBackend(SignalBackend):
47
47
 
48
48
  @cached_property
49
49
  def put_mock(self) -> Mock:
50
- return Mock(name="put")
50
+ return Mock(name="put", spec=Callable)
51
51
 
52
52
  @cached_property
53
53
  def put_proceeds(self) -> asyncio.Event:
@@ -65,9 +65,6 @@ class MockSignalBackend(SignalBackend):
65
65
  def set_value(self, value: T):
66
66
  self.soft_backend.set_value(value)
67
67
 
68
- async def get_descriptor(self, source: str) -> Descriptor:
69
- return await self.soft_backend.get_descriptor(source)
70
-
71
68
  async def get_reading(self) -> Reading:
72
69
  return await self.soft_backend.get_reading()
73
70
 
@@ -1,6 +1,6 @@
1
1
  from contextlib import asynccontextmanager, contextmanager
2
- from typing import Any, Callable, Generator, Iterable, Iterator, List
3
- from unittest.mock import ANY, Mock
2
+ from typing import Any, Callable, Iterable
3
+ from unittest.mock import Mock
4
4
 
5
5
  from ophyd_async.core.signal import Signal
6
6
  from ophyd_async.core.utils import T
@@ -22,7 +22,7 @@ def set_mock_value(signal: Signal[T], value: T):
22
22
  backend.set_value(value)
23
23
 
24
24
 
25
- def set_mock_put_proceeds(signal: Signal[T], proceeds: bool):
25
+ def set_mock_put_proceeds(signal: Signal, proceeds: bool):
26
26
  """Allow or block a put with wait=True from proceeding"""
27
27
  backend = _get_mock_signal_backend(signal)
28
28
 
@@ -33,7 +33,7 @@ def set_mock_put_proceeds(signal: Signal[T], proceeds: bool):
33
33
 
34
34
 
35
35
  @asynccontextmanager
36
- async def mock_puts_blocked(*signals: List[Signal]):
36
+ async def mock_puts_blocked(*signals: Signal):
37
37
  for signal in signals:
38
38
  set_mock_put_proceeds(signal, False)
39
39
  yield
@@ -41,9 +41,9 @@ async def mock_puts_blocked(*signals: List[Signal]):
41
41
  set_mock_put_proceeds(signal, True)
42
42
 
43
43
 
44
- def assert_mock_put_called_with(signal: Signal, value: Any, wait=ANY, timeout=ANY):
45
- backend = _get_mock_signal_backend(signal)
46
- backend.put_mock.assert_called_with(value, wait=wait, timeout=timeout)
44
+ def get_mock_put(signal: Signal) -> Mock:
45
+ """Get the mock associated with the put call on the signal."""
46
+ return _get_mock_signal_backend(signal).put_mock
47
47
 
48
48
 
49
49
  def reset_mock_put_calls(signal: Signal):
@@ -79,7 +79,7 @@ class _SetValuesIterator:
79
79
  return next_value
80
80
 
81
81
  def __del__(self):
82
- if self.require_all_consumed and self.index != len(self.values):
82
+ if self.require_all_consumed and self.index != len(list(self.values)):
83
83
  raise AssertionError("Not all values have been consumed.")
84
84
 
85
85
 
@@ -87,7 +87,7 @@ def set_mock_values(
87
87
  signal: Signal,
88
88
  values: Iterable[Any],
89
89
  require_all_consumed: bool = False,
90
- ) -> Iterator[Any]:
90
+ ) -> _SetValuesIterator:
91
91
  """Iterator to set a signal to a sequence of values, optionally repeating the
92
92
  sequence.
93
93
 
@@ -127,11 +127,7 @@ def _unset_side_effect_cm(put_mock: Mock):
127
127
  put_mock.side_effect = None
128
128
 
129
129
 
130
- # linting isn't smart enought to realize @contextmanager will give use a
131
- # ContextManager[None]
132
- def callback_on_mock_put(
133
- signal: Signal, callback: Callable[[T], None]
134
- ) -> Generator[None, None, None]:
130
+ def callback_on_mock_put(signal: Signal[T], callback: Callable[[T], None]):
135
131
  """For setting a callback when a backend is put to.
136
132
 
137
133
  Can either be used in a context, with the callback being
@@ -32,7 +32,7 @@ from .async_status import AsyncStatus
32
32
  from .device import Device
33
33
  from .signal_backend import SignalBackend
34
34
  from .soft_signal_backend import SoftSignalBackend
35
- from .utils import DEFAULT_TIMEOUT, Callback, T
35
+ from .utils import DEFAULT_TIMEOUT, CalculatableTimeout, CalculateTimeout, Callback, T
36
36
 
37
37
 
38
38
  def _add_timeout(func):
@@ -213,15 +213,14 @@ class SignalR(Signal[T], AsyncReadable, AsyncStageable, Subscribable):
213
213
  self._del_cache(self._get_cache().set_staged(False))
214
214
 
215
215
 
216
- USE_DEFAULT_TIMEOUT = "USE_DEFAULT_TIMEOUT"
217
-
218
-
219
216
  class SignalW(Signal[T], Movable):
220
217
  """Signal that can be set"""
221
218
 
222
- def set(self, value: T, wait=True, timeout=USE_DEFAULT_TIMEOUT) -> AsyncStatus:
219
+ def set(
220
+ self, value: T, wait=True, timeout: CalculatableTimeout = CalculateTimeout
221
+ ) -> AsyncStatus:
223
222
  """Set the value and return a status saying when it's done"""
224
- if timeout is USE_DEFAULT_TIMEOUT:
223
+ if timeout is CalculateTimeout:
225
224
  timeout = self._timeout
226
225
 
227
226
  async def do_set():
@@ -248,9 +247,11 @@ class SignalRW(SignalR[T], SignalW[T], Locatable):
248
247
  class SignalX(Signal):
249
248
  """Signal that puts the default value"""
250
249
 
251
- def trigger(self, wait=True, timeout=USE_DEFAULT_TIMEOUT) -> AsyncStatus:
250
+ def trigger(
251
+ self, wait=True, timeout: CalculatableTimeout = CalculateTimeout
252
+ ) -> AsyncStatus:
252
253
  """Trigger the action and return a status saying when it's done"""
253
- if timeout is USE_DEFAULT_TIMEOUT:
254
+ if timeout is CalculateTimeout:
254
255
  timeout = self._timeout
255
256
  coro = self._backend.put(None, wait=wait, timeout=timeout)
256
257
  return AsyncStatus(coro)
@@ -270,7 +271,7 @@ def soft_signal_r_and_setter(
270
271
  datatype: Optional[Type[T]] = None,
271
272
  initial_value: Optional[T] = None,
272
273
  name: str = "",
273
- ) -> Tuple[SignalR[T], Callable[[T]]]:
274
+ ) -> Tuple[SignalR[T], Callable[[T], None]]:
274
275
  """Returns a tuple of a read-only Signal and a callable through
275
276
  which the signal can be internally modified within the device. Use
276
277
  soft_signal_rw if you want a device that is externally modifiable
@@ -394,7 +395,7 @@ def assert_emitted(docs: Mapping[str, list[dict]], **numbers: int):
394
395
 
395
396
 
396
397
  async def observe_value(
397
- signal: SignalR[T], timeout=None, done_status: Status | None = None
398
+ signal: SignalR[T], timeout: float | None = None, done_status: Status | None = None
398
399
  ) -> AsyncGenerator[T, None]:
399
400
  """Subscribe to the value of a signal so it can be iterated from.
400
401
 
@@ -403,8 +404,12 @@ async def observe_value(
403
404
  signal:
404
405
  Call subscribe_value on this at the start, and clear_sub on it at the
405
406
  end
407
+ timeout:
408
+ If given, how long to wait for each updated value in seconds. If an update
409
+ is not produced in this time then raise asyncio.TimeoutError
406
410
  done_status:
407
411
  If this status is complete, stop observing and make the iterator return.
412
+ If it raises an exception then this exception will be raised by the iterator.
408
413
 
409
414
  Notes
410
415
  -----
@@ -414,9 +419,7 @@ async def observe_value(
414
419
  do_something_with(value)
415
420
  """
416
421
 
417
- class StatusIsDone: ...
418
-
419
- q: asyncio.Queue[T | StatusIsDone] = asyncio.Queue()
422
+ q: asyncio.Queue[T | Status] = asyncio.Queue()
420
423
  if timeout is None:
421
424
  get_value = q.get
422
425
  else:
@@ -425,16 +428,19 @@ async def observe_value(
425
428
  return await asyncio.wait_for(q.get(), timeout)
426
429
 
427
430
  if done_status is not None:
428
- done_status.add_callback(lambda _: q.put_nowait(StatusIsDone()))
431
+ done_status.add_callback(q.put_nowait)
429
432
 
430
433
  signal.subscribe_value(q.put_nowait)
431
434
  try:
432
435
  while True:
433
436
  item = await get_value()
434
- if not isinstance(item, StatusIsDone):
435
- yield item
437
+ if done_status and item is done_status:
438
+ if exc := done_status.exception():
439
+ raise exc
440
+ else:
441
+ break
436
442
  else:
437
- break
443
+ yield item
438
444
  finally:
439
445
  signal.clear_sub(q.put_nowait)
440
446
 
@@ -14,7 +14,7 @@ class SignalBackend(Generic[T]):
14
14
 
15
15
  #: Like ca://PV_PREFIX:SIGNAL
16
16
  @abstractmethod
17
- def source(name: str) -> str:
17
+ def source(self, name: str) -> str:
18
18
  """Return source of signal. Signals may pass a name to the backend, which can be
19
19
  used or discarded."""
20
20
 
ophyd_async/core/utils.py CHANGED
@@ -31,6 +31,17 @@ DEFAULT_TIMEOUT = 10.0
31
31
  ErrorText = Union[str, Dict[str, Exception]]
32
32
 
33
33
 
34
+ class CalculateTimeout:
35
+ """Sentinel class used to implement ``myfunc(timeout=CalculateTimeout)``
36
+
37
+ This signifies that the function should calculate a suitable non-zero
38
+ timeout itself
39
+ """
40
+
41
+
42
+ CalculatableTimeout = float | None | Type[CalculateTimeout]
43
+
44
+
34
45
  class NotConnected(Exception):
35
46
  """Exception to be raised if a `Device.connect` is cancelled"""
36
47
 
@@ -9,7 +9,7 @@ from ophyd_async.core import (
9
9
  set_and_wait_for_value,
10
10
  )
11
11
 
12
- from ...signal.signal import epics_signal_r, epics_signal_rw, epics_signal_rw_rbv
12
+ from ...signal.signal import epics_signal_r, epics_signal_rw_rbv
13
13
  from ..utils import ImageMode
14
14
  from ..writers.nd_plugin import NDArrayBase
15
15
 
@@ -43,18 +43,12 @@ DEFAULT_GOOD_STATES: FrozenSet[DetectorState] = frozenset(
43
43
  class ADBase(NDArrayBase):
44
44
  def __init__(self, prefix: str, name: str = "") -> None:
45
45
  # Define some signals
46
- self.acquire = epics_signal_rw_rbv(bool, prefix + "Acquire")
47
46
  self.acquire_time = epics_signal_rw_rbv(float, prefix + "AcquireTime")
48
47
  self.num_images = epics_signal_rw_rbv(int, prefix + "NumImages")
49
48
  self.image_mode = epics_signal_rw_rbv(ImageMode, prefix + "ImageMode")
50
- self.array_counter = epics_signal_rw_rbv(int, prefix + "ArrayCounter")
51
- self.array_size_x = epics_signal_r(int, prefix + "ArraySizeX_RBV")
52
- self.array_size_y = epics_signal_r(int, prefix + "ArraySizeY_RBV")
53
49
  self.detector_state = epics_signal_r(
54
50
  DetectorState, prefix + "DetectorState_RBV"
55
51
  )
56
- # There is no _RBV for this one
57
- self.wait_for_plugins = epics_signal_rw(bool, prefix + "WaitForPlugins")
58
52
  super().__init__(prefix, name=name)
59
53
 
60
54
 
@@ -43,12 +43,13 @@ class HDFWriter(DetectorWriter):
43
43
  async def open(self, multiplier: int = 1) -> Dict[str, DataKey]:
44
44
  self._file = None
45
45
  info = self._directory_provider()
46
+ file_path = str(info.root / info.resource_dir)
46
47
  await asyncio.gather(
47
48
  self.hdf.num_extra_dims.set(0),
48
49
  self.hdf.lazy_open.set(True),
49
50
  self.hdf.swmr_mode.set(True),
50
51
  # See https://github.com/bluesky/ophyd-async/issues/122
51
- self.hdf.file_path.set(str(info.root / info.resource_dir)),
52
+ self.hdf.file_path.set(file_path),
52
53
  self.hdf.file_name.set(f"{info.prefix}{self.hdf.name}{info.suffix}"),
53
54
  self.hdf.file_template.set("%s/%s.h5"),
54
55
  self.hdf.file_write_mode.set(FileWriteMode.stream),
@@ -59,7 +60,7 @@ class HDFWriter(DetectorWriter):
59
60
 
60
61
  assert (
61
62
  await self.hdf.file_path_exists.get_value()
62
- ), f"File path {self.hdf.file_path.get_value()} for hdf plugin does not exist"
63
+ ), f"File path {file_path} for hdf plugin does not exist"
63
64
 
64
65
  # Overwrite num_capture to go forever
65
66
  await self.hdf.num_capture.set(0)
@@ -36,7 +36,5 @@ class NDFileHDF(NDPluginBase):
36
36
  self.lazy_open = epics_signal_rw_rbv(bool, prefix + "LazyOpen")
37
37
  self.capture = epics_signal_rw_rbv(bool, prefix + "Capture")
38
38
  self.flush_now = epics_signal_rw(bool, prefix + "FlushNow")
39
- self.array_size0 = epics_signal_r(int, prefix + "ArraySize0_RBV")
40
- self.array_size1 = epics_signal_r(int, prefix + "ArraySize1_RBV")
41
39
  self.xml_file_name = epics_signal_rw_rbv(str, prefix + "XMLFileName")
42
40
  super().__init__(prefix, name)
@@ -14,6 +14,13 @@ class NDArrayBase(Device):
14
14
  def __init__(self, prefix: str, name: str = "") -> None:
15
15
  self.unique_id = epics_signal_r(int, prefix + "UniqueId_RBV")
16
16
  self.nd_attributes_file = epics_signal_rw(str, prefix + "NDAttributesFile")
17
+ self.acquire = epics_signal_rw_rbv(bool, prefix + "Acquire")
18
+ self.array_size_x = epics_signal_r(int, prefix + "ArraySizeX_RBV")
19
+ self.array_size_y = epics_signal_r(int, prefix + "ArraySizeY_RBV")
20
+ self.array_counter = epics_signal_rw_rbv(int, prefix + "ArrayCounter")
21
+ # There is no _RBV for this one
22
+ self.wait_for_plugins = epics_signal_rw(bool, prefix + "WaitForPlugins")
23
+
17
24
  super().__init__(name=name)
18
25
 
19
26
 
@@ -22,6 +29,8 @@ class NDPluginBase(NDArrayBase):
22
29
  self.nd_array_port = epics_signal_rw_rbv(str, prefix + "NDArrayPort")
23
30
  self.enable_callback = epics_signal_rw_rbv(Callback, prefix + "EnableCallbacks")
24
31
  self.nd_array_address = epics_signal_rw_rbv(int, prefix + "NDArrayAddress")
32
+ self.array_size0 = epics_signal_r(int, prefix + "ArraySize0_RBV")
33
+ self.array_size1 = epics_signal_r(int, prefix + "ArraySize1_RBV")
25
34
  super().__init__(prefix, name)
26
35
 
27
36
 
@@ -6,7 +6,6 @@ import random
6
6
  import string
7
7
  import subprocess
8
8
  import sys
9
- from dataclasses import replace
10
9
  from enum import Enum
11
10
  from pathlib import Path
12
11
 
@@ -22,7 +21,13 @@ from ophyd_async.core import (
22
21
  WatchableAsyncStatus,
23
22
  observe_value,
24
23
  )
25
- from ophyd_async.core.utils import WatcherUpdate
24
+ from ophyd_async.core.async_status import AsyncStatus
25
+ from ophyd_async.core.utils import (
26
+ DEFAULT_TIMEOUT,
27
+ CalculatableTimeout,
28
+ CalculateTimeout,
29
+ WatcherUpdate,
30
+ )
26
31
 
27
32
  from ..signal.signal import epics_signal_r, epics_signal_rw, epics_signal_x
28
33
 
@@ -66,11 +71,9 @@ class Mover(StandardReadable, Movable, Stoppable):
66
71
  # Define some signals
67
72
  with self.add_children_as_readables(HintedSignal):
68
73
  self.readback = epics_signal_r(float, prefix + "Readback")
69
-
70
74
  with self.add_children_as_readables(ConfigSignal):
71
75
  self.velocity = epics_signal_rw(float, prefix + "Velocity")
72
76
  self.units = epics_signal_r(str, prefix + "Readback.EGU")
73
-
74
77
  self.setpoint = epics_signal_rw(float, prefix + "Setpoint")
75
78
  self.precision = epics_signal_r(int, prefix + "Readback.PREC")
76
79
  # Signals that collide with standard methods should have a trailing underscore
@@ -85,41 +88,42 @@ class Mover(StandardReadable, Movable, Stoppable):
85
88
  # Readback should be named the same as its parent in read()
86
89
  self.readback.set_name(name)
87
90
 
88
- async def _move(self, new_position: float):
91
+ @WatchableAsyncStatus.wrap
92
+ async def set(
93
+ self, new_position: float, timeout: CalculatableTimeout = CalculateTimeout
94
+ ):
89
95
  self._set_success = True
90
- # time.monotonic won't go backwards in case of NTP corrections
91
- old_position, units, precision = await asyncio.gather(
96
+ old_position, units, precision, velocity = await asyncio.gather(
92
97
  self.setpoint.get_value(),
93
98
  self.units.get_value(),
94
99
  self.precision.get_value(),
100
+ self.velocity.get_value(),
95
101
  )
102
+ if timeout is CalculateTimeout:
103
+ assert velocity > 0, "Mover has zero velocity"
104
+ timeout = abs(new_position - old_position) / velocity + DEFAULT_TIMEOUT
105
+ # Make an Event that will be set on completion, and a Status that will
106
+ # error if not done in time
107
+ done = asyncio.Event()
108
+ done_status = AsyncStatus(asyncio.wait_for(done.wait(), timeout))
96
109
  # Wait for the value to set, but don't wait for put completion callback
97
- move_status = self.setpoint.set(new_position, wait=True)
98
- if not self._set_success:
99
- raise RuntimeError("Motor was stopped")
100
- # return a template to set() which it can use to yield progress updates
101
- return (
102
- WatcherUpdate(
110
+ await self.setpoint.set(new_position, wait=False)
111
+ async for current_position in observe_value(
112
+ self.readback, done_status=done_status
113
+ ):
114
+ yield WatcherUpdate(
115
+ current=current_position,
103
116
  initial=old_position,
104
- current=old_position,
105
117
  target=new_position,
118
+ name=self.name,
106
119
  unit=units,
107
120
  precision=precision,
108
- ),
109
- move_status,
110
- )
111
-
112
- @WatchableAsyncStatus.wrap # uses the timeout argument from the function it wraps
113
- async def set(self, new_position: float, timeout: float | None = None):
114
- update, _ = await self._move(new_position)
115
- async for current_position in observe_value(self.readback):
116
- yield replace(
117
- update,
118
- name=self.name,
119
- current=current_position,
120
121
  )
121
122
  if np.isclose(current_position, new_position):
123
+ done.set()
122
124
  break
125
+ if not self._set_success:
126
+ raise RuntimeError("Motor was stopped")
123
127
 
124
128
  async def stop(self, success=True):
125
129
  self._set_success = success