Skip to content

Commit be9557e

Browse files
committed
add example script to load the data
1 parent 7241b1a commit be9557e

File tree

3 files changed

+164
-3
lines changed

3 files changed

+164
-3
lines changed

pyproject.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ classifiers = [
2323
"Programming Language :: Python :: 3.14",
2424
]
2525
dependencies = [
26-
# "ome-zarr-models ",
26+
"graphviz>=0.21",
27+
# "ome-zarr-models ",
2728
"ome-zarr-models @ git+https://github.com/ome-zarr-models/ome-zarr-models-py@rfc5",
28-
# for debug logging (referenced from the issue template)
29-
"session-info2",
29+
"pillow>=12.0.0",
30+
# for debug logging (referenced from the issue template)
31+
"session-info2",
3032
]
3133
optional-dependencies.dev = [
3234
"pre-commit",

sandbox/generate_graph.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# adapted from https://raw.githubusercontent.com/ome-zarr-models/ome-zarr-models-py/refs/heads/rfc5/scripts/generate_transform_graphs.py
2+
from pathlib import Path
3+
4+
import zarr
5+
6+
from ome_zarr_models._v06.collection import Collection
7+
from ome_zarr_models._v06.image import Image
8+
9+
EXAMPLE_PATH = (
10+
Path(__file__).parent.parent
11+
/ "data"
12+
/ "ngff-rfc5-coordinate-transformation-examples"
13+
)
14+
15+
16+
def get_all_zarrs(directory: Path) -> list[Path]:
17+
"""
18+
Get all Zarr sub-directories.
19+
"""
20+
zarrs: list[Path] = []
21+
for f in directory.glob("*"):
22+
if f.is_dir():
23+
if f.suffix == ".zarr":
24+
# Found a Zarr group
25+
zarrs.append(f)
26+
else:
27+
# Recurse
28+
zarrs += get_all_zarrs(f)
29+
30+
return sorted(zarrs)
31+
32+
33+
for zarr_path in get_all_zarrs(EXAMPLE_PATH):
34+
relative_path = zarr_path.relative_to(EXAMPLE_PATH)
35+
36+
group: Collection | Image
37+
try:
38+
if relative_path.parts[0] == "user_stories":
39+
group = Collection.from_zarr(zarr.open_group(zarr_path, mode="r"))
40+
else:
41+
group = Image.from_zarr(zarr.open_group(zarr_path, mode="r"))
42+
except Exception:
43+
print(f"😢 Failed to load group at {zarr_path.relative_to(EXAMPLE_PATH)}")
44+
continue
45+
46+
print(f"📈 Rendering transform graph for {zarr_path.relative_to(EXAMPLE_PATH)}")
47+
graph = group.transform_graph()
48+
graphviz_graph = graph.to_graphviz()
49+
from PIL import Image as PILImage
50+
import io
51+
52+
png_bytes = graphviz_graph.pipe(format="png")
53+
54+
PILImage.open(io.BytesIO(png_bytes)).show() # uses default image viewer
55+
56+
pass
57+
58+
59+

0 commit comments

Comments
 (0)