我已经使用xarray concat命令创建了xarray数据数组。这导致了一个名为__xarray_dataarray_variable__的数据数组。但是,我似乎不能使用rename命令重命名它。还有别的方法来重命名它吗?
我试过这个:
da.rename({'__xarray_dataarray_variable__': 'new'})但是我得到了一个错误:*** ValueError: cannot rename '__xarray_dataarray_variable__' because it is not a variable or dimension in this dataset
这就是数据数组的样子:
<xarray.DataArray (time: 2, band: 1, y: 2334, x: 4258)>
dask.array<shape=(2, 1, 2334, 4258), dtype=float32, chunksize=(1, 1, 2334, 4258)>
Coordinates:
* band (band) int32 1
* y (y) float64 4.406e+06 4.406e+06 4.406e+06 4.406e+06 4.406e+06 ...
* x (x) float64 1.125e+05 1.126e+05 1.127e+05 1.128e+05 1.129e+05 ...
* time (time) datetime64[ns] 2005-12-31 2006-12-31
Attributes:
transform: (90.0, 0.0, 112500.0, 0.0, -90.0, 4406400.0, 0.0, 0.0, 1.0)
crs: +ellps=GRS80 +no_defs +proj=utm +towgs84=0,0,0,0,0,0,0 +unit...
res: (90.0, 90.0)
is_tiled: 1
nodatavals: (-9999.0,)从netcdf.html中,只能将xarray.Dataset对象写入netCDF文件,因此将xarray.DataArray转换为包含单个变量的xarray.Dataset对象。如果该名称没有名称,或者名称与协调名称相同,那么它将被命名为‘xarray_dataarray_variable’.。
发布于 2018-05-01 21:22:42
我认为您正在寻找to_dataset方法:
ds = da.to_dataset(name='new')https://stackoverflow.com/questions/50109822
复制相似问题