-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added AsyncReadable, AsyncConfigurable and AsyncPausable Also replaced imports of bluesky.protocols for each with their new async counterparts. * Fixed describe() in core/detector.py to be async * Sorted imports * Add tests * Removed test_mypy * Removed ophyd sim imports, replace with ophyd_async equivalents (requires make_detector) * Move protocols.py into src/ophyd_async --------- Co-authored-by: Oliver Copping <ryi58813@diamtl04.diamond.ac.uk> Co-authored-by: Tom C (DLS) <101418278+coretl@users.noreply.github.com>
- Loading branch information
1 parent
caecb59
commit 610d2d1
Showing
5 changed files
with
127 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from abc import abstractmethod | ||
from typing import Dict, Protocol, runtime_checkable | ||
|
||
from bluesky.protocols import Descriptor, HasName, Reading | ||
|
||
|
||
@runtime_checkable | ||
class AsyncReadable(HasName, Protocol): | ||
@abstractmethod | ||
async def read(self) -> Dict[str, Reading]: | ||
"""Return an OrderedDict mapping string field name(s) to dictionaries | ||
of values and timestamps and optional per-point metadata. | ||
Example return value: | ||
.. code-block:: python | ||
OrderedDict(('channel1', | ||
{'value': 5, 'timestamp': 1472493713.271991}), | ||
('channel2', | ||
{'value': 16, 'timestamp': 1472493713.539238})) | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
async def describe(self) -> Dict[str, Descriptor]: | ||
"""Return an OrderedDict with exactly the same keys as the ``read`` | ||
method, here mapped to per-scan metadata about each field. | ||
Example return value: | ||
.. code-block:: python | ||
OrderedDict(('channel1', | ||
{'source': 'XF23-ID:SOME_PV_NAME', | ||
'dtype': 'number', | ||
'shape': []}), | ||
('channel2', | ||
{'source': 'XF23-ID:SOME_PV_NAME', | ||
'dtype': 'number', | ||
'shape': []})) | ||
""" | ||
... | ||
|
||
|
||
@runtime_checkable | ||
class AsyncConfigurable(Protocol): | ||
@abstractmethod | ||
async def read_configuration(self) -> Dict[str, Reading]: | ||
"""Same API as ``read`` but for slow-changing fields related to configuration. | ||
e.g., exposure time. These will typically be read only once per run. | ||
""" | ||
... | ||
|
||
@abstractmethod | ||
async def describe_configuration(self) -> Dict[str, Descriptor]: | ||
"""Same API as ``describe``, but corresponding to the keys in | ||
``read_configuration``. | ||
""" | ||
... | ||
|
||
|
||
@runtime_checkable | ||
class AsyncPausable(Protocol): | ||
@abstractmethod | ||
async def pause(self) -> None: | ||
"""Perform device-specific work when the RunEngine pauses.""" | ||
... | ||
|
||
@abstractmethod | ||
async def resume(self) -> None: | ||
"""Perform device-specific work when the RunEngine resumes after a pause.""" | ||
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from pathlib import Path | ||
|
||
from bluesky.utils import new_uid | ||
|
||
from ophyd_async import protocols as bs_protocols | ||
from ophyd_async.core import ( | ||
DeviceCollector, | ||
StaticDirectoryProvider, | ||
set_sim_callback, | ||
set_sim_value, | ||
) | ||
from ophyd_async.core.flyer import HardwareTriggeredFlyable | ||
from ophyd_async.epics.areadetector.drivers import ADBase | ||
from ophyd_async.epics.areadetector.writers import NDFileHDF | ||
from ophyd_async.epics.demo.demo_ad_sim_detector import DemoADSimDetector | ||
from ophyd_async.sim.demo import SimMotor | ||
|
||
|
||
async def make_detector(prefix: str, name: str, tmp_path: Path): | ||
dp = StaticDirectoryProvider(tmp_path, f"test-{new_uid()}") | ||
|
||
async with DeviceCollector(sim=True): | ||
drv = ADBase(f"{prefix}DRV:") | ||
hdf = NDFileHDF(f"{prefix}HDF:") | ||
det = DemoADSimDetector( | ||
drv, hdf, dp, config_sigs=[drv.acquire_time, drv.acquire], name=name | ||
) | ||
|
||
def _set_full_file_name(_, val): | ||
set_sim_value(hdf.full_file_name, str(tmp_path / val)) | ||
|
||
set_sim_callback(hdf.file_name, _set_full_file_name) | ||
|
||
return det | ||
|
||
|
||
async def test_readable(): | ||
async with DeviceCollector(sim=True): | ||
det = await make_detector("test", "test det", Path("/tmp")) | ||
assert isinstance(SimMotor, bs_protocols.AsyncReadable) | ||
assert isinstance(det, bs_protocols.AsyncReadable) | ||
assert not isinstance(HardwareTriggeredFlyable, bs_protocols.AsyncReadable) |