Skip to content

Commit 87b88a3

Browse files
authored
Update to latest ophyd async (#1143)
* Fix import errors * Fix tests * Remove ophyd-async pin * Skip broken test * Fix types for amplifiers * Fix minor typing issue * Use Motor types in motor_utils
1 parent 5f715e9 commit 87b88a3

File tree

16 files changed

+44
-84
lines changed

16 files changed

+44
-84
lines changed

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ description = "Ophyd devices and other utils that could be used across DLS beaml
1515
dependencies = [
1616
"click",
1717
"ophyd",
18-
# Pinned due to https://github.com/DiamondLightSource/dodal/issues/1141
19-
"ophyd-async == 0.9.0",
18+
"ophyd-async>=0.10.0a1",
2019
"bluesky",
2120
"pyepics",
2221
"dataclasses-json",

src/dodal/devices/current_amplifiers/current_amplifier.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@ def __init__(self, gain_conversion_table: type[Enum], name: str = "") -> None:
2323
super().__init__(name)
2424

2525
@abstractmethod
26-
@AsyncStatus.wrap
2726
async def increase_gain(self, value: int = 1) -> None:
2827
"""Increase gain, increment by 1 by default.
2928
3029
Returns:
3130
bool: True if success.
3231
"""
3332

34-
@AsyncStatus.wrap
3533
@abstractmethod
3634
async def decrease_gain(self, value: int = 1) -> None:
3735
"""Decrease gain, decrement by 1 by default.
@@ -40,21 +38,18 @@ async def decrease_gain(self, value: int = 1) -> None:
4038
bool: True if success.
4139
"""
4240

43-
@AsyncStatus.wrap
4441
@abstractmethod
45-
async def get_gain(self) -> type[Enum]:
42+
async def get_gain(self) -> Enum:
4643
"""Get the current gain setting
4744
4845
Returns:
4946
Enum: The member name of the current gain setting in gain_conversion_table.
5047
"""
5148

52-
@AsyncStatus.wrap
5349
@abstractmethod
5450
async def get_upperlimit(self) -> float:
5551
"""Get the upper limit of the current amplifier"""
5652

57-
@AsyncStatus.wrap
5853
@abstractmethod
5954
async def get_lowerlimit(self) -> float:
6055
"""Get the lower limit of the current amplifier"""

src/dodal/devices/current_amplifiers/current_amplifier_detector.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ async def get_corrected_current(self) -> float:
9292
self.current_amp().get_gain(),
9393
self.counter().get_voltage_per_sec(),
9494
)
95-
correction_factor = current_gain.value
96-
corrected_current = voltage_per_sec / correction_factor
95+
assert isinstance(current_gain.value, float)
96+
corrected_current = voltage_per_sec / current_gain.value
9797
return corrected_current
9898

9999
@AsyncStatus.wrap

src/dodal/devices/current_amplifiers/femto.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,30 +114,25 @@ async def set(self, value) -> None:
114114
# wait for current amplifier's bandpass filter to settle.
115115
await asyncio.sleep(self.raise_timetable[SEN_setting].value)
116116

117-
@AsyncStatus.wrap
118117
async def increase_gain(self, value: int = 1) -> None:
119118
current_gain = int((await self.get_gain()).name.split("_")[-1])
120119
current_gain += value
121120
if current_gain > len(self.gain_table):
122121
raise ValueError("Gain at max value")
123122
await self.set(self.gain_conversion_table[f"SEN_{current_gain}"])
124123

125-
@AsyncStatus.wrap
126124
async def decrease_gain(self, value: int = 1) -> None:
127125
current_gain = int((await self.get_gain()).name.split("_")[-1])
128126
current_gain -= value
129127
if current_gain < 1:
130128
raise ValueError("Gain at min value")
131129
await self.set(self.gain_conversion_table[f"SEN_{current_gain}"])
132130

133-
@AsyncStatus.wrap
134131
async def get_gain(self) -> Enum:
135132
return self.gain_conversion_table[(await self.gain.get_value()).name]
136133

137-
@AsyncStatus.wrap
138134
async def get_upperlimit(self) -> float:
139135
return self.upperlimit
140136

141-
@AsyncStatus.wrap
142137
async def get_lowerlimit(self) -> float:
143138
return self.lowerlimit

src/dodal/devices/current_amplifiers/sr570.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ async def set(self, value) -> None:
178178
)
179179
await asyncio.sleep(self.raise_timetable[coarse_gain.name].value)
180180

181-
@AsyncStatus.wrap
182181
async def increase_gain(self, value=3) -> None:
183182
current_gain = int((await self.get_gain()).name.split("_")[-1])
184183
current_gain += value
@@ -189,7 +188,6 @@ async def increase_gain(self, value=3) -> None:
189188
raise ValueError("Gain at max value")
190189
await self.set(self.gain_conversion_table[f"SEN_{current_gain}"])
191190

192-
@AsyncStatus.wrap
193191
async def decrease_gain(self, value=3) -> None:
194192
current_gain = int((await self.get_gain()).name.split("_")[-1])
195193
current_gain -= value
@@ -198,17 +196,14 @@ async def decrease_gain(self, value=3) -> None:
198196
raise ValueError("Gain at min value")
199197
await self.set(self.gain_conversion_table[f"SEN_{current_gain}"])
200198

201-
@AsyncStatus.wrap
202199
async def get_gain(self) -> Enum:
203200
result = await asyncio.gather(
204201
self.coarse_gain.get_value(), self.fine_gain.get_value()
205202
)
206203
return self.gain_conversion_table[self.combined_table(result).name]
207204

208-
@AsyncStatus.wrap
209205
async def get_upperlimit(self) -> float:
210206
return self.upperlimit
211207

212-
@AsyncStatus.wrap
213208
async def get_lowerlimit(self) -> float:
214209
return self.lowerlimit

src/dodal/devices/i13_1/merlin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from dodal.common.beamlines.device_helpers import CAM_SUFFIX, HDF5_SUFFIX
55
from dodal.devices.i13_1.merlin_controller import MerlinController
6-
from dodal.devices.i13_1.merlin_io import MerlinDriverIO
76

87

98
class Merlin(StandardDetector):
@@ -18,7 +17,7 @@ def __init__(
1817
fileio_suffix=HDF5_SUFFIX,
1918
name: str = "",
2019
):
21-
self.drv = MerlinDriverIO(prefix + drv_suffix)
20+
self.drv = adcore.ADBaseIO(prefix + drv_suffix)
2221
self.hdf = adcore.NDFileHDFIO(prefix + fileio_suffix)
2322

2423
super().__init__(

src/dodal/devices/i13_1/merlin_controller.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,21 @@
66
AsyncStatus,
77
TriggerInfo,
88
)
9-
from ophyd_async.epics import adcore
10-
from ophyd_async.epics.adcore import ADBaseController
11-
12-
from dodal.devices.i13_1.merlin_io import MerlinDriverIO, MerlinImageMode
9+
from ophyd_async.epics.adcore import (
10+
DEFAULT_GOOD_STATES,
11+
ADBaseController,
12+
ADBaseIO,
13+
ADImageMode,
14+
ADState,
15+
stop_busy_record,
16+
)
1317

1418

1519
class MerlinController(ADBaseController):
1620
def __init__(
1721
self,
18-
driver: MerlinDriverIO,
19-
good_states: frozenset[adcore.DetectorState] = adcore.DEFAULT_GOOD_STATES,
22+
driver: ADBaseIO,
23+
good_states: frozenset[ADState] = DEFAULT_GOOD_STATES,
2024
) -> None:
2125
self.driver = driver
2226
self.good_states = good_states
@@ -34,7 +38,7 @@ async def prepare(self, trigger_info: TriggerInfo):
3438
)
3539
await asyncio.gather(
3640
self.driver.num_images.set(trigger_info.total_number_of_triggers),
37-
self.driver.image_mode.set(MerlinImageMode.MULTIPLE),
41+
self.driver.image_mode.set(ADImageMode.MULTIPLE),
3842
)
3943

4044
async def wait_for_idle(self):
@@ -44,4 +48,4 @@ async def wait_for_idle(self):
4448
async def disarm(self):
4549
# We can't use caput callback as we already used it in arm() and we can't have
4650
# 2 or they will deadlock
47-
await adcore.stop_busy_record(self.driver.acquire, False, timeout=1)
51+
await stop_busy_record(self.driver.acquire, False, timeout=1)

src/dodal/devices/i13_1/merlin_io.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/dodal/devices/i22/nxsas.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from bluesky.protocols import Reading
77
from event_model.documents.event_descriptor import DataKey
88
from ophyd_async.core import PathProvider
9-
from ophyd_async.epics.adaravis import AravisController, AravisDetector
9+
from ophyd_async.epics.adaravis import AravisDetector
1010
from ophyd_async.epics.adpilatus import PilatusDetector
1111

1212
ValueAndUnits = tuple[float, str]
@@ -149,7 +149,6 @@ def __init__(
149149
fileio_suffix: str,
150150
metadata_holder: NXSasMetadataHolder,
151151
name: str = "",
152-
gpio_number: AravisController.GPIO_NUMBER = 1,
153152
):
154153
"""Extends detector with configuration metadata required or desired
155154
to comply with the NXsas application definition.
@@ -162,7 +161,6 @@ def __init__(
162161
drv_suffix=drv_suffix,
163162
fileio_suffix=fileio_suffix,
164163
name=name,
165-
gpio_number=gpio_number,
166164
)
167165
self._metadata_holder = metadata_holder
168166

src/dodal/plan_stubs/motor_utils.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import uuid
22
from collections.abc import Generator
3-
from typing import Any, TypeVar, cast
3+
from typing import Any
44

55
from bluesky import plan_stubs as bps
66
from bluesky.preprocessors import finalize_wrapper, pchain
77
from bluesky.utils import Msg, MsgGenerator, make_decorator
88
from ophyd_async.core import Device
99
from ophyd_async.epics.motor import Motor
1010

11-
from dodal.utils import MovableReadable
12-
13-
MovableReadableDevice = TypeVar("MovableReadableDevice", bound=MovableReadable)
14-
1511

1612
class MoveTooLarge(Exception):
1713
def __init__(
18-
self, axis: MovableReadable, maximum_move: float, position: float, *args: object
14+
self,
15+
axis: Motor,
16+
maximum_move: float,
17+
position: float,
18+
*args: object,
1919
) -> None:
2020
self.axis = axis
2121
self.maximum_move = maximum_move
@@ -24,10 +24,10 @@ def __init__(
2424

2525

2626
def check_and_cache_values(
27-
devices_and_positions: dict[MovableReadableDevice, float],
27+
devices_and_positions: dict[Motor, float],
2828
smallest_move: float,
2929
maximum_move: float,
30-
) -> Generator[Msg, Any, dict[MovableReadableDevice, float]]:
30+
) -> Generator[Msg, Any, dict[Motor, float]]:
3131
"""Caches the positions of all Motors on specified device if they are within
3232
smallest_move of home_position. Throws MoveTooLarge if they are outside maximum_move
3333
of the home_position
@@ -51,9 +51,7 @@ def home_and_reset_wrapper(
5151
wait_for_all: bool = True,
5252
) -> MsgGenerator:
5353
home_positions = {
54-
cast(MovableReadable, axis): 0.0
55-
for _, axis in device.children()
56-
if isinstance(axis, Motor)
54+
axis: 0.0 for _, axis in device.children() if isinstance(axis, Motor)
5755
}
5856
return move_and_reset_wrapper(
5957
plan, home_positions, smallest_move, maximum_move, group, wait_for_all
@@ -62,7 +60,7 @@ def home_and_reset_wrapper(
6260

6361
def move_and_reset_wrapper(
6462
plan: MsgGenerator,
65-
device_and_positions: dict[MovableReadable, float],
63+
device_and_positions: dict[Motor, float],
6664
smallest_move: float,
6765
maximum_move: float,
6866
group: str | None = None,

0 commit comments

Comments
 (0)