Skip to content

Commit e4cda75

Browse files
committed
Read OME/METADATA.xml for bioformats2raw.layout and open all series images
1 parent 4fc57d3 commit e4cda75

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

napari_ome_zarr/ome_zarr_reader.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
import zarr
66
from zarr import Group
7-
import numpy as np
7+
from zarr.core.sync import SyncMixin
8+
from zarr.core.buffer import default_buffer_prototype
9+
810
import dask.array as da
911
from typing import List
1012
from vispy.color import Colormap
13+
from xml.etree import ElementTree as ET
1114

12-
from typing import Any, Callable, Dict, List, Tuple, Union
15+
from typing import Any, Dict, List, Tuple, Union
1316

1417
LayerData = Union[Tuple[Any], Tuple[Any, Dict], Tuple[Any, Dict, str]]
1518

@@ -133,14 +136,28 @@ def matches(group: Group) -> bool:
133136
return "bioformats2raw.layout" in attrs and "plate" not in attrs
134137

135138
def children(self):
136-
# TDOO: lookup children from series of OME/METADATA.xml
137-
childnames = ["0"]
139+
# lookup children from series of OME/METADATA.xml
140+
xml_data = SyncMixin()._sync(self.group.store.get("OME/METADATA.ome.xml", prototype=default_buffer_prototype()))
141+
# print("xml_data", xml_data.to_bytes())
142+
root = ET.fromstring(xml_data.to_bytes())
138143
rv = []
139-
for name in childnames:
140-
g = self.group[name]
141-
if Multiscales.matches(g):
142-
rv.append(Multiscales(g))
144+
for child in root:
145+
# {http://www.openmicroscopy.org/Schemas/OME/2016-06}Image
146+
print(child.tag)
147+
node_id = child.attrib.get("ID", "")
148+
if child.tag.endswith("Image") and node_id.startswith("Image:"):
149+
print("Image ID", node_id)
150+
image_path = node_id.replace("Image:", "")
151+
g = self.group[image_path]
152+
if Multiscales.matches(g):
153+
rv.append(Multiscales(g))
143154
return rv
155+
156+
# override to NOT yield self since node has no data
157+
def iter_nodes(self):
158+
for child in self.children():
159+
for ch in child.iter_nodes():
160+
yield ch
144161

145162

146163
class Plate(Spec):

0 commit comments

Comments
 (0)