在python中使用xarray重命名netcdf全局属性

时间:2018-12-26 06:28:37

标签: python python-xarray

是否可以使用xarray重命名全局属性名称? rename命令似乎仅重命名变量和维度,而不重命名全局属性。我尝试过:

with util.open_or_die('AA.nc', perm='r+') as hndl_nc:
    hndl_nc.rename({'src_name': 'dst_name'}, inplace=True)

但是我得到这个错误:

AttributeError: NetCDF: Attribute not found

1 个答案:

答案 0 :(得分:1)

xarray attrs属性(包含您正在访问的属性)只是一个OrderedDict。 xarray中没有明确允许这种行为的方法,但是attrs可以直接修改,例如:

hndl_nc.attrs['dst_name'] = hndl_nc.attrs.pop('src_name')