Skip to content

Commit

Permalink
Add metadata dictionary to Spec class
Browse files Browse the repository at this point in the history
Store both version and axes values
  • Loading branch information
sbesson committed Nov 16, 2021
1 parent 9a77877 commit 857f4fb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ome_zarr/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ def matches(zarr: ZarrLocation) -> bool:

def __init__(self, node: Node) -> None:
self.node = node
self.metadata: JSONDict = dict()
self.zarr = node.zarr
LOGGER.debug(f"treating {self.zarr} as {self.__class__.__name__}")
for k, v in self.zarr.root_attrs.items():
Expand All @@ -189,6 +190,7 @@ def matches(zarr: ZarrLocation) -> bool:
def __init__(self, node: Node) -> None:
super().__init__(node)
label_names = self.lookup("labels", [])
self.metadata["version"] = label_names.get("version", "")
for name in label_names:
child_zarr = self.zarr.create(name)
if child_zarr.exists():
Expand All @@ -208,6 +210,7 @@ def __init__(self, node: Node) -> None:
super().__init__(node)

image_label = self.lookup("image-label", {})
self.metadata["version"] = image_label.get("version", None)

image = image_label.get("source", {}).get("image", None)
parent_zarr = None
Expand Down Expand Up @@ -278,14 +281,15 @@ def __init__(self, node: Node) -> None:
axes_values = {"t", "c", "z", "y", "x"}
try:
multiscales = self.lookup("multiscales", [])
version = multiscales[0].get(
self.metadata["version"] = multiscales[0].get(
"version", "0.1"
) # should this be matched with Format.version?
datasets = multiscales[0]["datasets"]
# axes field was introduced in 0.3, before all data was 5d
axes = tuple(multiscales[0].get("axes", ["t", "c", "z", "y", "x"]))
if len(set(axes) - axes_values) > 0:
raise RuntimeError(f"Invalid axes names: {set(axes) - axes_values}")
self.metadata["axes"] = axes
node.metadata["axes"] = axes
datasets = [d["path"] for d in datasets]
self.datasets: List[str] = datasets
Expand All @@ -295,7 +299,8 @@ def __init__(self, node: Node) -> None:
return # EARLY EXIT

for resolution in self.datasets:
data: da.core.Array = self.array(resolution, version)
data: da.core.Array = self.array(
resolution, self.metadata["version"])
chunk_sizes = [
str(c[0]) + (" (+ %s)" % c[-1] if c[-1] != c[0] else "")
for c in data.chunks
Expand Down Expand Up @@ -325,6 +330,7 @@ def __init__(self, node: Node) -> None:
super().__init__(node)
# TODO: start checking metadata version
self.image_data = self.lookup("omero", {})
self.metadata["version"] = self.image_data.get("version", "")

try:
model = "unknown"
Expand Down Expand Up @@ -393,6 +399,7 @@ def matches(zarr: ZarrLocation) -> bool:
def __init__(self, node: Node) -> None:
super().__init__(node)
self.well_data = self.lookup("well", {})
self.metadata["version"] = self.well_data.get("version", "")
LOGGER.info("well_data: %s", self.well_data)

image_paths = [image["path"] for image in self.well_data.get("images")]
Expand Down Expand Up @@ -462,6 +469,7 @@ def get_pyramid_lazy(self, node: Node) -> None:
"""
self.plate_data = self.lookup("plate", {})
LOGGER.info("plate_data", self.plate_data)
self.metadata["version"] = self.plate_data.get("version", "")
self.rows = self.plate_data.get("rows")
self.columns = self.plate_data.get("columns")
self.first_field = "0"
Expand Down

0 comments on commit 857f4fb

Please sign in to comment.