有没有办法使用 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
xarray attrs
属性(包含您正在访问的属性)只是一个 OrderedDict。xarray 中没有明确允许此行为的方法,但可以直接修改attrs
,例如:
hndl_nc.attrs['dst_name'] = hndl_nc.attrs.pop('src_name')