zarr 不尊重 xarray 的块大小并恢复到原始块大小

问题描述

我正在打开一个 zarr 文件,然后将其重新分块,然后将其写回另一个 zarr 存储。然而,当我重新打开它时,它不尊重我之前编写的块大小。这是 jupyter 的代码输出。知道我在这里做错了什么吗?

<!DOCTYPE html>

<html>
    <head><title>TextAhnaf</title></head> 
    <link rel="stylesheet" href="Styles.css">
  <body>
    
    <header>
        <nav>
            <ul>
                <li><a href="Login.html">Login</a></li>
                <h4>Contact</h4>
            </ul>
        </nav>
        <h1>Text</h1>
    </header>
  </body>
</html>

enter image description here

bathy_ds = xr.open_zarr('data/bathy_store')
bathy_ds.elevation

enter image description here

bathy_ds.chunk(5000).elevation

enter image description here

它正在恢复到原始分块,好像我没有完全覆盖它或更改其他一些需要更改的设置。

解决方法

这似乎是一个已知的 issue,并且在该问题的线程和 recently merged PR 中进行了相当多的讨论。

基本上,数据集在 .encoding 属性中携带原始分块。因此,当您调用第二个写操作时,ds[var].encoding['chunks'] 中定义的块(如果存在)将用于将 var 写入 zarr。

根据GH issue中的对话,目前最好的解决方案是手动删除相关变量的块编码:

for var in ds:
    del ds[var].encoding['chunks']

但是,应该注意的是,这似乎是一个不断发展的情况,最好检查进度以调整最终解决方案。

这是一个展示问题和解决方案的小例子:

import xarray as xr

# load data and write to initial chunking 
x = xr.tutorial.load_dataset("air_temperature")
x.chunk({"time":500,"lat":-1,"lon":-1}).to_zarr("zarr1.zarr")

# display initial chunking
xr.open_zarr("zarr1.zarr/").air

enter image description here

# rechunk
y = xr.open_zarr("zarr1.zarr/").chunk({"time": -1})

# display
y.air

enter image description here

#write w/o modifying .encoding
y.to_zarr("zarr2.zarr")

# display
xr.open_zarr("zarr2.zarr/").air

enter image description here

# delete encoding and store
del y.air.encoding['chunks']
y.to_zarr("zarr3.zarr")

# display
xr.open_zarr("zarr3.zarr/").air

enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...