Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/microsim/cosem/_tstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"precomputed": "neuroglancer_precomputed",
"n5": "n5",
"zarr": "zarr",
"zarr3": "zarr3",
}


Expand Down
14 changes: 12 additions & 2 deletions src/microsim/cosem/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
ImageFormat = Literal[
"n5",
"zarr",
"zarr3",
"precomputed",
"neuroglancer_precomputed",
"neuroglancer_multilod_draco",
Expand Down Expand Up @@ -103,8 +104,11 @@ def scales(self) -> list[str]:
"""Fetch all available scales for the image from s3."""
if not getattr(self, "_scales", None):
scales = []
# n5/zarr v2 multiscale lives at the top level, while zarr v3
# (OME-NGFF 0.5) nests it under the "ome" namespace.
ome = self.attrs.get("ome", {})
# n5 multiscale
if multi := self.attrs.get("multiscales"):
if multi := (self.attrs.get("multiscales") or ome.get("multiscales")):
for scale in multi:
if dsets := scale.get("datasets"):
for dset in dsets:
Expand Down Expand Up @@ -184,10 +188,16 @@ def attrs(self) -> dict[str, Any]:
attr = "/attributes.json"
elif self.format == "zarr":
attr = "/.zattrs"
elif self.format == "zarr3":
attr = "/zarr.json"
elif self.format == "precomputed":
attr = "/info"
try:
self._attrs = json.load(fetch_s3(self.url + attr))
data = json.load(fetch_s3(self.url + attr))
# zarr v3 nests user attributes under an "attributes" namespace
if self.format == "zarr3":
data = data.get("attributes", {})
self._attrs = data
except Exception:
self._attrs = {}
return self._attrs # type: ignore [no-any-return]
Expand Down
14 changes: 14 additions & 0 deletions tests/test_cosem.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ def test_cosem_image() -> None:
img = dataset.image(name="not real")


@skipif_no_internet
def test_cosem_zarr3() -> None:
# COSEM now serves some images as zarr v3; make sure we can validate,
# resolve scales, and read them. See #140 / #141.
dataset = CosemDataset.fetch("jrc_mus-skel-muscle-1")
img = dataset.image(name="fibsem-uint8")
assert img.format == "zarr3"
assert img.scales # multiscale metadata nested under the "ome" namespace
# read a mid-pyramid level (all dims > 1) to exercise the zarr3 driver
store = img.read(level=8, bin_mode="standard")
assert isinstance(store, ts.TensorStore)
assert store.ndim == 3


@skipif_no_internet
def test_cosem_view() -> None:
orgs = organelles()
Expand Down
Loading