Skip to content

Nested NGFF images can be written, not read #340

Closed

Description

@aeisenbarth

When writing an image with a name which contains slashes, it is stored in a Zarr subgroup. However, the ome_zarr Reader does not descend into zgroups that do not match a spec, and thus returns no images to spatialdata._io.io_zarr._read_multiscale.

def test_read_spatialdata_with_nested_zgroups(tmp_path: str):
    import numpy as np

    sdata = 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))
    assert len(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.

Activity

  1. LucaMarconato commented on Aug 23, 2023

    @LucaMarconato
    Member

    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.

  2. aeisenbarth commented on Aug 24, 2023

    @aeisenbarth
    ContributorAuthor

    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:

    spatialdata.zarr/images/plate1/A/1/image_name
    spatialdata.zarr/images/plate1/A/2/image_name
    spatialdata.zarr/images/plate2/…
    

    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.

  3. LucaMarconato commented on Aug 26, 2023

    @LucaMarconato
    Member

    Thanks for providing the use case.

    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.

  4. LucaMarconato commented on Mar 23, 2024

    @LucaMarconato
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions