如何删除 Scientific.IO.NetCDF.NetCDFFile 中的变量?
是否可以从 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简单的答案是您无法删除变量。这是 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.