Skip to content

Commit ffe81b9

Browse files
Allow None in Shapes (#895)
1 parent f652399 commit ffe81b9

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ description = "Asynchronous Bluesky hardware abstraction code, compatible with c
1515
dependencies = [
1616
"numpy",
1717
"bluesky>=1.13.1rc2",
18-
"event-model>=1.22.1",
18+
# Unpin once an event-model release is made containing https://github.com/bluesky/event-model/pull/352
19+
"event-model @ git+https://github.com/bluesky/event-model@18e1168c7518401ca691d86f6c5cf5030413251f",
1920
"pyyaml",
2021
"colorlog",
2122
"pydantic>=2.0",

src/ophyd_async/core/_hdf_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class HDFDatasetDescription(BaseModel):
2323
"""The dataset name within the HDF file,
2424
e.g. /entry/data/data or /entry/instrument/NDAttributes/sum"""
2525

26-
shape: tuple[int, ...] = Field(default_factory=tuple)
26+
shape: tuple[int | None, ...] = Field(default_factory=tuple)
2727
"""The shape of a single event's data in the HDF file,
2828
e.g. (1, 768, 1024) for arrays or () for scalars"""
2929

src/ophyd_async/core/_providers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,5 +228,5 @@ async def np_datatype(self) -> str:
228228
"""Return the numpy datatype for this dataset."""
229229

230230
@abstractmethod
231-
async def shape(self) -> tuple[int, ...]:
231+
async def shape(self) -> tuple[int | None, ...]:
232232
"""Get the shape of the data collection."""

src/ophyd_async/core/_signal_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def _datakey_dtype_numpy(
176176
raise TypeError(f"Can't make dtype_numpy for {datatype}")
177177

178178

179-
def _datakey_shape(value: SignalDatatype) -> list[int]:
179+
def _datakey_shape(value: SignalDatatype) -> list[int | None]:
180180
if type(value) in _primitive_dtype or isinstance(value, EnumTypes):
181181
return []
182182
elif isinstance(value, np.ndarray):

src/ophyd_async/epics/adcore/_hdf_writer.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
from collections.abc import AsyncIterator
33
from pathlib import Path
4+
from typing import TypeGuard
45
from xml.etree import ElementTree as ET
56

67
from bluesky.protocols import StreamAsset
@@ -22,6 +23,10 @@
2223
)
2324

2425

26+
def _is_fully_described(shape: tuple[int | None, ...]) -> TypeGuard[tuple[int, ...]]:
27+
return None not in shape
28+
29+
2530
class ADHDFWriter(ADWriter[NDFileHDFIO]):
2631
"""Allow `NDFileHDFIO` to be used within `StandardDetector`."""
2732

@@ -75,6 +80,16 @@ async def open(
7580
# Determine number of frames that will be saved per HDF chunk
7681
frames_per_chunk = await self.fileio.num_frames_chunks.get_value()
7782

83+
if not _is_fully_described(detector_shape):
84+
# Questions:
85+
# - Can AreaDetector support this?
86+
# - How to deal with chunking?
87+
# Don't support for now - leave option open to support it later
88+
raise ValueError(
89+
"Datasets with partially unknown dimensionality "
90+
"are not currently supported by ADHDFWriter."
91+
)
92+
7893
# Add the main data
7994
self._datasets = [
8095
HDFDatasetDescription(

tests/epics/adcore/test_writers.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,19 @@ async def test_nd_attributes_plan_stub_gives_correct_error(RE, detectors):
296296
== f"Invalid type for ndattributes: {type(invalidObjects[0])}. "
297297
+ "Expected NDAttributePv or NDAttributeParam."
298298
)
299+
300+
301+
async def test_hdf_writer_descriptor_shape_contains_none(
302+
hdf_writer: adcore.ADHDFWriter,
303+
):
304+
async def shape_containing_none():
305+
return 10, None, 10
306+
307+
hdf_writer._dataset_describer.shape = shape_containing_none
308+
309+
with pytest.raises(
310+
ValueError,
311+
match=r"Datasets with partially unknown dimensionality "
312+
r"are not currently supported by ADHDFWriter.",
313+
):
314+
await hdf_writer.open(DETECTOR_NAME)

0 commit comments

Comments
 (0)