scverse / napari-spatialdata

Interactive visualization of spatial omics data
https://spatialdata.scverse.org/projects/napari/en/latest/
BSD 3-Clause "New" or "Revised" License
41 stars 17 forks source link

Issues displaying multiscale data #100

Closed melonora closed 7 months ago

melonora commented 1 year ago

Using the blobs dataset I ran into the issue that the multiscale data cannot be displayed. The trace is long so won't copy it here. What ultimately happens for multiscale labels is that when getting the shapes of individual elements of the data (DataTree), the data is a string:

File ~\Anaconda3\envs\spatial\lib\site-packages\napari\layers\image\_image_utils.py:67, in <listcomp>(.0=<itertools.chain object>)
     63 if isinstance(data, (list, tuple)) and len(data) == 1:
     64     # pyramid with only one level, unwrap
     65     return False, data[0]
---> 67 shapes = [d.shape for d in data]
        d = 'scale0'
     68 sizes = np.array([np.prod(shape, dtype=np.uint64) for shape in shapes])
     69 if len(sizes) <= 1:

For the multiscale blobs image the end of the trace gives this:

File ~\Anaconda3\envs\spatial\lib\site-packages\datatree\treenode.py:448, in TreeNode._get_item(self=DataTree('scale0', parent="None")
    Dimensions...k.array<chunksize=(3, 256, 256), meta=np.ndarray>, path=NodePath('blobs_multiscale_image'))
    446 else:
    447     if current_node.get(part) is None:
--> 448         raise KeyError(f"Could not find node at {path}")
        path = NodePath('blobs_multiscale_image')
    449     else:
    450         current_node = current_node.get(part)

KeyError: 'Could not find node at blobs_multiscale_image'

Minimal reproducable example:

from napari_spatialdata import Interactive
from spatialdata.transformations import set_transformation, Identity
from spatialdata.datasets import blobs

sdata=blobs()
interactive = Interactive(sdata)
interactive.run()

After that, select the global coordinate system and try to load a multiscale element.

LucaMarconato commented 1 year ago

Thanks for reporting. Multiscale images are supported in the spatialdata branch using this function (see the last if): https://github.com/scverse/napari-spatialdata/blob/2590e1e8191091820478b470ef7aee8bfd322be8/src/napari_spatialdata/interactive.py#L101. Actually I realized that I think I never tried displaying multiscale labels as I made the blobs multiscale element only recently. I think it should work but needs to be tried.

melonora commented 1 year ago

Will pick it up

melonora commented 7 months ago

This issue is fixed in the meantime and is not present with current and next release so I am closing this.