Skip to content

Commit cd68373

Browse files
committed
Convert annotations to match odin PVI
1 parent 27c9149 commit cd68373

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

src/ophyd_async/fastcs/odin/_odin_io.py

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
PathProvider,
1313
SignalR,
1414
SignalRW,
15+
SignalW,
1516
StrictEnum,
1617
observe_value,
17-
set_and_wait_for_value,
18+
set_and_wait_for_other_value,
1819
)
1920
from ophyd_async.fastcs.core import fastcs_connector
2021

@@ -29,17 +30,18 @@ class OdinNode(Device):
2930

3031

3132
class OdinHdfIO(Device):
32-
capture: SignalRW[Writing]
33-
num_captured: SignalR[int]
34-
num_to_capture: SignalRW[int]
35-
image_height: SignalRW[int]
36-
image_width: SignalRW[int]
37-
num_row_chunks: SignalRW[int]
38-
num_col_chunks: SignalRW[int]
39-
num_frames_chunks: SignalRW[int]
40-
file_path: SignalRW[str]
41-
file_name: SignalRW[str]
42-
data_type: SignalRW[str]
33+
writing: SignalR[Writing]
34+
config_hdf_write: SignalW[Writing]
35+
frames_written: SignalR[int]
36+
config_hdf_frames: SignalRW[int]
37+
dataset_data_dims_0: SignalRW[int]
38+
dataset_data_dims_1: SignalRW[int]
39+
dataset_data_chunks_0: SignalRW[int]
40+
dataset_data_chunks_1: SignalRW[int]
41+
dataset_data_chunks_2: SignalRW[int]
42+
config_hdf_file_path: SignalRW[str]
43+
config_hdf_file_prefix: SignalRW[str]
44+
dataset_data_datatype: SignalRW[str]
4345
nodes = DeviceVector[OdinNode]
4446

4547
def __init__(self, uri: str, name: str = ""):
@@ -62,26 +64,27 @@ async def open(self, multiplier: int = 1) -> dict[str, DataKey]:
6264
info = self._path_provider(device_name=self._name_provider())
6365

6466
await asyncio.gather(
65-
self._drv.file_path.set(str(info.directory_path)),
66-
self._drv.file_name.set(info.filename),
67-
self._drv.data_type.set(
67+
self._drv.config_hdf_file_path.set(str(info.directory_path)),
68+
self._drv.config_hdf_file_prefix.set(info.filename),
69+
self._drv.dataset_data_datatype.set(
6870
"uint16"
6971
), # TODO: Get from eiger https://github.com/bluesky/ophyd-async/issues/529
70-
self._drv.num_to_capture.set(0),
72+
self._drv.config_hdf_frames.set(0),
7173
)
7274

73-
await self._drv.capture.set(Writing.ON)
75+
await self._drv.config_hdf_write.set(Writing.ON)
7476

7577
return await self._describe()
7678

7779
async def _describe(self) -> dict[str, DataKey]:
7880
data_shape = await asyncio.gather(
79-
self._drv.image_height.get_value(), self._drv.image_width.get_value()
81+
self._drv.dataset_data_dims_0.get_value(),
82+
self._drv.dataset_data_dims_1.get_value(),
8083
)
8184

8285
return {
8386
"data": DataKey(
84-
source=self._drv.file_name.source,
87+
source=self._drv.config_hdf_file_prefix.source,
8588
shape=list(data_shape),
8689
dtype="array",
8790
# TODO: Use correct type based on eiger https://github.com/bluesky/ophyd-async/issues/529
@@ -93,15 +96,17 @@ async def _describe(self) -> dict[str, DataKey]:
9396
async def observe_indices_written(
9497
self, timeout: float
9598
) -> AsyncGenerator[int, None]:
96-
async for num_captured in observe_value(self._drv.num_captured, timeout):
99+
async for num_captured in observe_value(self._drv.frames_written, timeout):
97100
yield num_captured
98101

99102
async def get_indices_written(self) -> int:
100-
return await self._drv.num_captured.get_value()
103+
return await self._drv.frames_written.get_value()
101104

102105
def collect_stream_docs(self, indices_written: int) -> AsyncIterator[StreamAsset]:
103106
# TODO: Correctly return stream https://github.com/bluesky/ophyd-async/issues/530
104107
raise NotImplementedError()
105108

106109
async def close(self) -> None:
107-
await set_and_wait_for_value(self._drv.capture, Writing.OFF)
110+
await set_and_wait_for_other_value(
111+
self._drv.config_hdf_write, Writing.OFF, self._drv.writing, Writing.OFF
112+
)

tests/fastcs/odin/test_odin_io.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ async def test_when_open_called_then_file_correctly_set(
2929

3030
await writer.open()
3131

32-
get_mock_put(driver.file_path).assert_called_once_with(str(tmp_path), wait=ANY)
33-
get_mock_put(driver.file_name).assert_called_once_with(expected_filename, wait=ANY)
32+
get_mock_put(driver.config_hdf_file_path).assert_called_once_with(
33+
str(tmp_path), wait=ANY
34+
)
35+
get_mock_put(driver.config_hdf_file_prefix).assert_called_once_with(
36+
expected_filename, wait=ANY
37+
)
3438

3539

3640
async def test_when_open_called_then_all_expected_signals_set(
@@ -39,18 +43,20 @@ async def test_when_open_called_then_all_expected_signals_set(
3943
driver, writer = odin_driver_and_writer
4044
await writer.open()
4145

42-
get_mock_put(driver.data_type).assert_called_once_with("uint16", wait=ANY)
43-
get_mock_put(driver.num_to_capture).assert_called_once_with(0, wait=ANY)
46+
get_mock_put(driver.dataset_data_datatype).assert_called_once_with(
47+
"uint16", wait=ANY
48+
)
49+
get_mock_put(driver.config_hdf_frames).assert_called_once_with(0, wait=ANY)
4450

45-
get_mock_put(driver.capture).assert_called_once_with(Writing.ON, wait=ANY)
51+
get_mock_put(driver.config_hdf_write).assert_called_once_with(Writing.ON, wait=ANY)
4652

4753

4854
async def test_given_data_shape_set_when_open_called_then_describe_has_correct_shape(
4955
odin_driver_and_writer: OdinDriverAndWriter,
5056
):
5157
driver, writer = odin_driver_and_writer
52-
set_mock_value(driver.image_width, 1024)
53-
set_mock_value(driver.image_height, 768)
58+
set_mock_value(driver.dataset_data_dims_1, 1024)
59+
set_mock_value(driver.dataset_data_dims_0, 768)
5460
description = await writer.open()
5561
assert description["data"]["shape"] == [768, 1024]
5662

@@ -60,4 +66,4 @@ async def test_when_closed_then_data_capture_turned_off(
6066
):
6167
driver, writer = odin_driver_and_writer
6268
await writer.close()
63-
get_mock_put(driver.capture).assert_called_once_with(Writing.OFF, wait=ANY)
69+
get_mock_put(driver.config_hdf_write).assert_called_once_with(Writing.OFF, wait=ANY)

0 commit comments

Comments
 (0)