Skip to content

Commit

Permalink
reader always returns axes as list of dicts
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Oct 28, 2021
1 parent e16de4d commit 6052098
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
14 changes: 7 additions & 7 deletions ome_zarr/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from .io import ZarrLocation
from .types import JSONDict
from .writer import axes_to_dicts

LOGGER = logging.getLogger("ome_zarr.reader")

Expand Down Expand Up @@ -281,8 +282,10 @@ def __init__(self, node: Node) -> None:
"version", "0.1"
) # should this be matched with Format.version?
datasets = multiscales[0]["datasets"]
axes = multiscales[0].get("axes")
# TODO - convert each axis to dictionary (if str or None)?
# axes field introduced in 0.3. If missing (v0.1 or v0.2) data will be 5d
axes = multiscales[0].get("axes", ["t", "c", "z", "y", "x"])
# if axis is list of strings, convert to v0.4+ format, as a list of dicts
axes = axes_to_dicts(axes)
node.metadata["axes"] = axes
datasets = [d["path"] for d in datasets]
self.datasets: List[str] = datasets
Expand All @@ -298,11 +301,8 @@ def __init__(self, node: Node) -> None:
for c in data.chunks
]
LOGGER.info("resolution: %s", resolution)
if axes is not None:
axes = tuple(
axis if isinstance(axis, str) else axis.get("name") for axis in axes
)
LOGGER.info(" - shape %s = %s", axes, data.shape)
axis_names = tuple(axis.get("name") for axis in axes)
LOGGER.info(" - shape %s = %s", axis_names, data.shape)
LOGGER.info(" - chunks = %s", chunk_sizes)
LOGGER.info(" - dtype = %s", data.dtype)
node.data.append(data)
Expand Down
6 changes: 2 additions & 4 deletions ome_zarr/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
KNOWN_AXES = {"x": "space", "y": "space", "z": "space", "c": "channel", "t": "time"}


def _axes_to_dicts(
axes: Union[List[str], List[Dict[str, str]]]
) -> List[Dict[str, str]]:
def axes_to_dicts(axes: Union[List[str], List[Dict[str, str]]]) -> List[Dict[str, str]]:
"""Returns a list of axis dicts with name and type"""
axes_dicts = []
for axis in axes:
Expand Down Expand Up @@ -139,7 +137,7 @@ def _validate_axes(
axes = list(axes)

# axes may be list of 'x', 'y' or list of {'name': 'x'}
axes_dicts = _axes_to_dicts(axes)
axes_dicts = axes_to_dicts(axes)
axes_names = _axes_to_names(axes_dicts)

# check names (only enforced for version 0.3)
Expand Down

0 comments on commit 6052098

Please sign in to comment.