Reputation: 22021
Is there a way to rename global attribute names using xarray? The rename
command only seems to rename variables and dimensions and not global attributes. I tried this:
with util.open_or_die('AA.nc', perm='r+') as hndl_nc:
hndl_nc.rename({'src_name': 'dst_name'}, inplace=True)
But I get this error:
AttributeError: NetCDF: Attribute not found
Upvotes: 2
Views: 1357
Reputation: 15452
The xarray attrs
attribute (which holds the attributes you're accessing) is simply an OrderedDict. There's no method in xarray that explicitly allows this behavior, but the attrs
can be modified directly, e.g.:
hndl_nc.attrs['dst_name'] = hndl_nc.attrs.pop('src_name')
Upvotes: 1