You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When writing an image with a name which contains slashes, it is stored in a Zarr subgroup. However, the ome_zarrReader does not descend into zgroups that do not match a spec, and thus returns no images to spatialdata._io.io_zarr._read_multiscale.
deftest_read_spatialdata_with_nested_zgroups(tmp_path: str):
importnumpyasnpsdata=SpatialData()
sdata.add_image(
name="slide1/well1/image",
image=Image2DModel.parse(np.random.random((2, 10, 10))),
)
path=Path(tmp_path) /"tmp.zarr"sdata.write(path, overwrite=True)
# This should probably not raise:# "ValueError: len(nodes) = 0, expected 1. Unable to read the NGFF file. Please report this bug and attach a minimal data example."sdata_parsed=SpatialData.read(str(path))
assertlen(sdata_parsed.images) ==1
A work-around is to use a flat hierarchy with e.g. . delimiters instead of slashes.
This could be an upstream issue in ome_zarr, or SpatialData could forbid and validate that there are no slashes.
Hi @aeisenbarth, thanks for reporting this. @giovp is working on an improvement of the IO and after that PR is merged we want to work on supporting parsing arbitrarily nested NGFF objects. We will keep in mind the case you mentioned and add a test for it.
A use case that I was playing around with is to store high-content screening data using the NGFF Plate spec (currently not possible due to various issues).
where image_name is in our case the acquisition name (it is not clear to me whether ome-zarr-py means acquisitions or field of views, currently it only supports integer names).
In that use case, another issue would be that the Plate spec expects labels to reside under the images, whereas in SpatialData, we would need to replicate the plate hierarchy under spatialdata.zarr/labels without images (ome-zarr-py cannot read plates of only labels).
Furthermore, ome-zarr-py reads all wells of a plate into single fused Dask array (better for performance in Napari), but that would likely produce same label integers for different label instances which cannot be matched to annotations.
All in all, I think arbitrary nesting could be too complex and a Pandora's box.
In that use case, another issue would be that the Plate spec expects labels to reside under the images, whereas in SpatialData, we would need to replicate the plate hierarchy under spatialdata.zarr/labels without images (ome-zarr-py cannot read plates of only labels).
I think that this can be handled easily as we are using only portions of ome-zarr-py for IO and we could read labels from anywhere without restrictions, also it would be possible to store images and labels in a mixed way without having to replicate the hierarchy, because we could drop the parent folders images and `labels.
Furthermore, ome-zarr-py reads all wells of a plate into single fused Dask array (better for performance in Napari), but that would likely produce same label integers for different label instances which cannot be matched to annotations.
This would be instead more problematic. Do you know already some plugin that can handle table annotations on such a merged Dask representation?
All in all, I think arbitrary nesting could be too complex and a Pandora's box.
I think that nested support should be done with care, but I think it's worth exploring. Maybe just not with high priority.
With the new #501 we allow only element names that don't contain slashes. I will reintroduce the possibility to have slashes (writing nested hierarchies was initially not the intended behavior) in a PR for this more general issue: #398 (that we will try to make follow soon). Closing this issue as with the new incremental PR nested NGFF images won't be able to be written.
Activity
LucaMarconato commentedon Aug 23, 2023
Hi @aeisenbarth, thanks for reporting this. @giovp is working on an improvement of the IO and after that PR is merged we want to work on supporting parsing arbitrarily nested NGFF objects. We will keep in mind the case you mentioned and add a test for it.
aeisenbarth commentedon Aug 24, 2023
A use case that I was playing around with is to store high-content screening data using the NGFF Plate spec (currently not possible due to various issues).
It would look like:
where
image_nameis in our case the acquisition name (it is not clear to me whether ome-zarr-py means acquisitions or field of views, currently it only supports integer names).spatialdata.zarr/labelswithout images (ome-zarr-py cannot read plates of only labels).All in all, I think arbitrary nesting could be too complex and a Pandora's box.
LucaMarconato commentedon Aug 26, 2023
Thanks for providing the use case.
I think that this can be handled easily as we are using only portions of
ome-zarr-pyfor IO and we could read labels from anywhere without restrictions, also it would be possible to store images and labels in a mixed way without having to replicate the hierarchy, because we could drop the parent foldersimagesand `labels.This would be instead more problematic. Do you know already some plugin that can handle table annotations on such a merged Dask representation?
LucaMarconato commentedon Mar 23, 2024
With the new #501 we allow only element names that don't contain slashes. I will reintroduce the possibility to have slashes (writing nested hierarchies was initially not the intended behavior) in a PR for this more general issue: #398 (that we will try to make follow soon). Closing this issue as with the new incremental PR nested NGFF images won't be able to be written.