问题描述
是否可以从Scientific.IO.NetCDF.NetCDFFile
中删除变量?如果这样打开文件:
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")
都不是
del nc.variables["var"]
也
nc.variables["var"] = None
将删除变量var
.
事先感谢,以获取任何见识.
will delete the variable var
.
Thx in advance for any insight.
推荐答案
简单的答案是您不能删除变量.这是NetCDF C-API的功能",并不是Scientific.IO.NetCDF或任何其他python 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.
从官方 NetCDF用户指南:属性比变量或维度更具动态性.创建变量后,可以将其删除并更改其类型,长度和值,而netCDF接口则无法删除变量或更改其类型或形状.
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.
可以通过将有问题的变量以外的所有内容复制到新的NetCDF文件中来间接解决该问题.
The problem can be solved indirectly, by copying everything except the offending variable to a new NetCDF file.
这篇关于如何删除Scientific.IO.NetCDF.NetCDFFile中的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!