Skip to content

Commit c7eeb73

Browse files
committed
Allow None in Shapes
1 parent 9300a2c commit c7eeb73

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-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: 14 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 cast
45
from xml.etree import ElementTree as ET
56

67
from bluesky.protocols import StreamAsset
@@ -75,6 +76,19 @@ async def open(
7576
# Determine number of frames that will be saved per HDF chunk
7677
frames_per_chunk = await self.fileio.num_frames_chunks.get_value()
7778

79+
if None in detector_shape:
80+
# Questions:
81+
# - Can AreaDetector support this?
82+
# - How to deal with chunking?
83+
# Don't support for now - leave option open to support it later
84+
raise ValueError(
85+
"Datasets with partially unknown dimensionality "
86+
"are not currently supported by ADHDFWriter."
87+
)
88+
89+
# Pyright doesn't understand the above check as a type-narrowing expression
90+
detector_shape = cast(tuple[int, ...], detector_shape)
91+
7892
# Add the main data
7993
self._datasets = [
8094
HDFDatasetDescription(

0 commit comments

Comments
 (0)