admin管理员组文章数量:1122846
I have a 3D xarray DataArray that I've saved to to zarr using DataArray.to_zarr(). However, the resulting format is not readable by my tools, in this case napari. The structure of the zarr has one folder per dimension. However, if I make it into a dask array and save it with dask.array.to_zarr(), the result is readable in napari, and the result has a single folder.
I would prefer not to have to convert my array to a dask array. Is there a way that I can make xarray write the zarr to the same format as dask.array.to_zarr()?
Minimum reproducible example:
import dask.array as darr
import xarray as xa
import numpy as np
import os
import shutil
data = np.random.randint(0, (2**16)-1, (7000, 512, 512))
array_darr = darr.array(data)
array_xa = xa.DataArray(data, dims=['z', 'y', 'x'], coords={'z': np.arange(data.shape[0]),
'y': np.arange(data.shape[1]), 'x': np.arange(data.shape[2])})
dir_sup = os.getcwd()
path_darr = os.path.join(dir_sup, 'dask_example.zarr')
if os.path.exists(path_darr):
shutil.rmtree(path_darr)
array_darr.to_zarr(path_darr)
print(array_xa)
path_xa = os.path.join(dir_sup, 'xarray_example.zarr')
if os.path.exists(path_xa):
shutil.rmtree(path_xa)
array_xa.to_zarr(path_xa)
本文标签: How to make xarraytozarr write the same way as daskarraytozarrStack Overflow
版权声明:本文标题:How to make xarray.to_zarr write the same way as dask.array.to_zarr? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305102a1932472.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论