[Python] How to make xarray.DataArray.to_zarr readable by napari?

Discussão em 'Python' iniciado por Stack, Fevereiro 12, 2025.

  1. Stack

    Stack Membro Participativo

    I have big TIFF-arrays that I want to save with xarray and view in napari. However, napari seems unable to read the zarr-format produced by xarray. Is there a way that I can specify the arguments of xarray.DataArray.to_zarr to make it readable by napari?

    I know that dask.array.to_zarr is an option but I would prefer to use xarray.

    Minimum reproducible example:

    import os
    import numpy as np
    import xarray as xa

    arr = np.random.randint(0, 2**16-1, size=(100, 400, 400))
    coords = {'z': np.arange(0, 100), 'y': np.arange(0, 400), 'x': np.arange(0, 400)}
    da = xa.DataArray(arr, dims=['z', 'y', 'x'], coords=coords)
    dir_save = os.getcwd()
    path_save = os.path.join(dir_save, 'test.zarr')
    da.to_zarr(path_save)


    The traceback of the error that I get when I drag-and-drop it into napari is longer than the allowed length of posts, but maybe this part is a clue?


    File C:\ProgramData\anaconda3\envs\napari_env\lib\site-packages\napari\layers\image_image_utils.py:94, in guess_multiscale(data=[dask.array<from-zarr, shape=(100, 400, 400), dty...hunksize=(25, 100, 100), chunktype=numpy.ndarray>, dask.array<from-zarr, shape=(400,), dtype=int64, chunksize=(400,), chunktype=numpy.ndarray>, dask.array<from-zarr, shape=(400,), dtype=int64, chunksize=(400,), chunktype=numpy.ndarray>, dask.array<from-zarr, shape=(100,), dtype=int64, chunksize=(100,), chunktype=numpy.ndarray>]) 93 if not consistent: ---> 94 raise ValueError( trans = <napari.utils.translations.TranslationBundle object at 0x000002492857E5E0> sizes = [16000000, 400, 400, 100] 95 trans._( 96 'Input data should be an array-like object, or a sequence of arrays of decreasing size. Got arrays in incorrect order, sizes: {sizes}', 97 deferred=True, 98 sizes=sizes, 99 ) 100 ) 102 return True, MultiScaleData(data)

    ValueError: Input data should be an array-like object, or a sequence of arrays of decreasing size. Got arrays in incorrect order, sizes: [16000000, 400, 400, 100]
    ​

    Package versions:

    • conda-forge napari 0.5.5 hd8ed1ab_0
    • conda-forge napari-base 0.5.5 pyh9208f05_0
    • conda-forge napari-console 0.1.3 pyh73487a3_0
    • conda-forge napari-plugin-engine 0.2.0 pyha07c04f_3
    • conda-forge napari-plugin-manager 0.1.4 pyha07c04f_0
    • conda-forge napari-svg 0.2.1 pyha07c04f_0
    • conda-forge xarray 2025.1.1 pyhd8ed1ab_0

    Continue reading...

Compartilhe esta Página