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

Is it possible to remove a variable from Scientific.IO.NetCDF.NetCDFFile ? If the file opens as follows:

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

nor a

 del nc.variables["var"] 

and

 nc.variables["var"] = None 

will remove the var variable.
Thanks in advance for any understanding.

+4
source share
1 answer

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

From the official NetCDF User Guide: Attributes are more dynamic than variables or sizes; they can be deleted and their type, length and values ​​changed after they are created, while the netCDF interface does not allow you to delete a variable or change its type or shape.

The problem can be solved indirectly by copying everything except the offensive variable into a new NetCDF file.

+7
source

All Articles