如何删除 Scientific.IO.NetCDF.NetCDFFile 中的变量?

发布于 2024-11-26 14:13:42 字数 329 浏览 3 评论 0原文

是否可以从 Scientific.IO.NetCDF.NetCDFFile 中删除变量?如果像这样打开文件:

nc = Scientific.IO.NetCDF.NetCDFFile("File.nc", "a")

a

del nc.variables["var"]

和 a

nc.variables["var"] = None

都不会删除变量 var
提前感谢您的任何见解。

Is it possible to delete a variable from a Scientific.IO.NetCDF.NetCDFFile? If a file is opened like so:

nc = Scientific.IO.NetCDF.NetCDFFile("File.nc", "a")

neither a

del nc.variables["var"]

nor a

nc.variables["var"] = None

will delete the variable var.
Thx in advance for any insight.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

非要怀念 2024-12-03 14:13:42

简单的答案是您无法删除变量。这是 NetCDF C-API 的一个“功能”,而不是 Scientific.IO.NetCDF 或任何其他 python netcdf 模块的缺点。

来自官方 NetCDF 用户指南:
属性比变量或维度更具动态性;它们可以在创建后被删除并更改其类型、长度和值,而 netCDF 接口无法提供删除变量或更改其类型或形状的方法。

通过将除有问题的变量之外的所有内容复制到新的 NetCDF 文件中,可以间接解决该问题。

The simple answer is that you can not delete a variable. This is a "feature" of the NetCDF C-API and is not a shortcoming of Scientific.IO.NetCDF or any of the other python netcdf modules.

From the official NetCDF user guide:
Attributes are more dynamic than variables or dimensions; they can be deleted and have their type, length, and values changed after they are created, whereas the netCDF interface provides no way to delete a variable or to change its type or shape.

The problem can be solved indirectly, by copying everything except the offending variable to a new NetCDF file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文