简体   繁体   English

保存时xarray netcdf更改数据类型

[英]xarray netcdf changing datatype when saving

When I save an xarray dataset, it is changing the datatypes of the variables when saving (or possibly when loading back in).当我保存 xarray 数据集时,它会在保存时(或者可能在重新加载时)更改变量的数据类型。 I am not able to produce a minimal working example, because I have no idea what's causing this change (the many others I have saved have worked fine).我无法制作一个最小的工作示例,因为我不知道是什么导致了这种变化(我保存的许多其他人都很好)。

My original dataset looks like:我的原始数据集如下所示:

mytest4
Out[177]:
<xarray.Dataset>
Dimensions:  (lat: 93, lon: 87, name: 31, time: 82)
Coordinates:
  * time     (time) datetime64[ns] 2019-01-01 2020-01-01 ... 2100-01-01
  * lat      (lat) float32 -10.824516 -10.788528 ... -7.532379 -7.4960403
  * lon      (lon) float32 -79.47869 -79.44204 -79.40539 ... -76.36327 -76.32662
  * name     (name) <U14 'ACCESS1-0' 'ACCESS1-3' ... 'bcc-csm1-1' 'inmcm4'
Data variables:
    pr       (name, time, lat, lon) float64 nan nan nan nan ... nan nan nan nan

I then save it using然后我使用

mytest4.to_netcdf(ETCCDI_folder+'test4.nc')

Open it again再次打开它

mytest5=xr.open_dataset(ETCCDI_folder+'test4.nc')

And now it looks like this:现在它看起来像这样:

mytest5
Out[180]:
<xarray.Dataset>
Dimensions:  (lat: 93, lon: 87, name: 31, time: 82)
Coordinates:
  * time     (time) datetime64[ns] 2019-01-01 2020-01-01 ... 2100-01-01
  * lat      (lat) float32 -10.824516 -10.788528 ... -7.532379 -7.4960403
  * lon      (lon) float32 -79.47869 -79.44204 -79.40539 ... -76.36327 -76.32662
  * name     (name) object 'ACCESS1-0' 'ACCESS1-3' ... 'bcc-csm1-1' 'inmcm4'
Data variables:
    pr       (name, time, lat, lon) timedelta64[ns] ...

where the 'name' coordinate and more importantly the 'pr' variable have changed datatype.其中“名称”坐标,更重要的是“pr”变量已更改数据类型。 If I use ncview to view 'test4' directly in ETCCDI_folder, it looks as I'd expect, but once loaded back into python it becomes nonsense.如果我使用 ncview 直接在 ETCCDI_folder 中查看“test4”,它看起来和我预期的一样,但是一旦加载回 python 就变得毫无意义。 Can anyone help?任何人都可以帮忙吗?

  1. Review all options for xr.open_dataset() , in particular decode_times and decode_timedelta查看xr.open_dataset()所有选项,特别是decode_timesdecode_timedelta
  2. If necessary, use the encoding dict option in xr.to_netcdf() -- see http://xarray.pydata.org/en/stable/generated/xarray.Dataset.to_netcdf.html如有必要,请使用xr.to_netcdf()中的encoding dict 选项——参见http://xarray.pydata.org/en/stable/generated/xarray.Dataset.to_netcdf.html
  3. Is there are reason your name var is unicode and not regular strings?您的名字 var 是 unicode 而不是常规字符串是否有原因? I don't believe NetCDF supports unicode strings as a datatype.我不相信 NetCDF 支持 unicode 字符串作为数据类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM