How to delete a variable in a Scientific.IO.NetCDF.NetCDFFile?

大憨熊 提交于 2019-12-09 18:40:18

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/6816613/how-to-delete-a-variable-in-a-scientific-io-netcdf-netcdffile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!