使用 xarray to_netcdf 写入磁盘会丢失坐标变量
我正在尝试使用 xarray to_netcdf 保存数据集,但是当我将数据集写入磁盘然后读回时,坐标已更改。这只是一个偶然的问题,我无法重现它。
编辑:我已经发现问题与附加到变量的编码有关,现在可以用一个虚拟示例重现该问题:
lon = [[-99.83, -99.32], [-99.79, -99.23]]
lat = [[42.25, 42.21], [42.63, 42.59]]
time = pd.date_range("2014-09-06", periods=3)
ds = xr.Dataset(
data_vars=dict(
temperature=(["x", "y", "time"], temperature),),
coords=dict(
lon=(["x", "y"], lon),
lat=(["x", "y"], lat),
time=time,),
attrs=dict(description="Weather related data."),)
ds.temperature.encoding={'zlib': False,
'shuffle': False,
'complevel': 0,
'fletcher32': False,
'contiguous': True,
'chunksizes': None,
'source': 'fileloc/file.nc',
'original_shape': (3, 2, 2),
'coordinates': 'time, lat, lon'}
print(ds)
给出了我期望的坐标,但是 ds.to_netcdf('dummy.nc')
、ds2=xr.open_dataset('dummy.nc')
丢失 'lon' 作为坐标并设置它作为数据变量。
有谁知道这种编码中的什么导致“lon”坐标发生变化?我看不到任何与“lon”具体相关的内容。
我已经更新到最新版本的 xarray 并尝试了decode_coords='all',但仍然看到这个问题。
I am trying to save a dataset using xarray to_netcdf, but when I write the dataset to disk then read it back in, the coordinates have changed. This is only an occasional problem and I am unable to reproduce it.
EDIT: I have worked out that the problem is to do with the encoding attached to the variable, and can now reproduce the problem with a dummy example:
lon = [[-99.83, -99.32], [-99.79, -99.23]]
lat = [[42.25, 42.21], [42.63, 42.59]]
time = pd.date_range("2014-09-06", periods=3)
ds = xr.Dataset(
data_vars=dict(
temperature=(["x", "y", "time"], temperature),),
coords=dict(
lon=(["x", "y"], lon),
lat=(["x", "y"], lat),
time=time,),
attrs=dict(description="Weather related data."),)
ds.temperature.encoding={'zlib': False,
'shuffle': False,
'complevel': 0,
'fletcher32': False,
'contiguous': True,
'chunksizes': None,
'source': 'fileloc/file.nc',
'original_shape': (3, 2, 2),
'coordinates': 'time, lat, lon'}
print(ds)
gives the coordinates as I'd expect, but ds.to_netcdf('dummy.nc')
, ds2=xr.open_dataset('dummy.nc')
loses 'lon' as a coordinate and sets it as a data variable.
Does anybody know what in this encoding causes the 'lon' coordinate to shift? I can't see anything relating to 'lon' specifically.
I have updated to the latest version of xarray and tried decode_coords='all' but am still seeing this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论