使用 xarray 添加全局属性 [英] Adding global attribute using xarray

查看:59
本文介绍了使用 xarray 添加全局属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用 xarray 将全局属性添加到 netCDF 文件?当我执行诸如 hndl_nc['global_attribute'] = 25 之类的操作时,它只会添加一个新变量.

Is there some way to add a global attribute to a netCDF file using xarray? When I do something like hndl_nc['global_attribute'] = 25, it just adds a new variable.

推荐答案

在 Xarray 中,直接索引一个 Dataset 就像 hndl_nc['variable_name'] 拉出一个 >DataArray 对象.要获取或设置属性,索引 .attrs 就像 hndl_nc.attrs['global_attribute']hndl_nc.attrs['global_attribute'] = 25.

In Xarray, directly indexing a Dataset like hndl_nc['variable_name'] pulls out a DataArray object. To get or set attributes, index .attrs like hndl_nc.attrs['global_attribute'] or hndl_nc.attrs['global_attribute'] = 25.

您可以使用 Python 的属性语法(如 hndl_nc.variable_or_attribute_name)访问变量和属性,但这是一项便利功能,仅当变量或属性名称与预先存在的方法或属性不冲突时才有效, 不能用于设置.

You can access both variables and attributes using Python's attribute syntax like hndl_nc.variable_or_attribute_name, but this is a convenience feature that only works when the variable or attribute name does not conflict with a preexisting method or property, and cannot be used for setting.

这篇关于使用 xarray 添加全局属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆