问题描述
我已经创建了xarray.DataArray
,并使用xarray.DataArray.to_netcdf
保存了它.
I've created a xarray.DataArray
and I save it using xarray.DataArray.to_netcdf
.
我使用以下方法创建它:
I create it using:
datatmp = np.full([nens, len(modanom.coords['time'].values), len(modanom.coords['latitude'].values), len(modanom.coords['longitude'].values)], np.nan)
b = xr.DataArray(datatmp, coords=[range(1,nens + 1), modanom.coords['time'], modanom.coords['latitude'], modanom.coords['longitude']], dims=['ensemble', 'time', 'latitude', 'longitude'])
即我没有指定名称,例如:
i.e. I don't specify a name such as:
b = xr.DataArray({'windspeed': (('ensemble', 'time', 'latitude', 'longitude'), datatmp)}, coords=[range(1,nens + 1), modanom.coords['time'], modanom.coords['latitude'], modanom.coords['longitude']], dims=['ensemble', 'time', 'latitude', 'longitude'])
我对该文件进行了一些处理,并获得了均方根误差,所得的xarray.Dataset
是
I do some manipulation of this file and obtain root mean square error and the resultant xarray.Dataset
is
<xarray.DataArray (latitude: 81, longitude: 131, time: 1)>
array([[[ nan],
[ nan],
...,
[ nan],
[ nan]],
[[ nan],
[ nan],
...,
[ nan],
[ nan]],
...,
[[ nan],
[ 0.843295],
...,
[ 0.794338],
[ nan]],
[[ nan],
[ nan],
...,
[ nan],
[ nan]]])
Coordinates:
* latitude (latitude) float64 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 ...
* longitude (longitude) float64 260.0 261.0 262.0 263.0 264.0 265.0 266.0 ..
* time (time) datetime64[ns] 1983-01-15T12:00:00
在读取netCDF文件时,我有一个xarray.Dataset
When reading in the netCDF file I have a xarray.Dataset
如下所示:
<xarray.Dataset>
Dimensions: (latitude: 81, longitude: 131, time: 1)
Coordinates:
* latitude (latitude) float64 0.0 1.0 2.0 3.0 4.0 ...
* longitude (longitude) float64 260.0 261.0 262.0 ...
* time (time) datetime64[ns] 1983-01-15T12:00:00
Data variables:
__xarray_dataarray_variable__ (latitude, longitude, time) float64 nan ...
Attributes:
_NCProperties: version=1|netcdflibversion=4.4.1|hdf5libversion=1.8.18
我可以重命名__xarray_dataarray_variable__
吗?
我问的原因是因为我有创建xarray.Dataset
的函数,因此我没有指定数据变量名称.但是,我想在绘图之前重命名它.
The reason I ask is because as I have functions which create xarray.Dataset
's and therefore I don't specify a data variable name. However, I would like to rename it before plotting.
推荐答案
DataArray.rename
这就是我想要的
这篇关于python-xarray重命名数据变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!