Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

netcdf

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.

like image 437
Woltan Avatar asked Jan 19 '23 03:01

Woltan


1 Answers

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.

like image 190
badland Avatar answered Mar 05 '23 07:03

badland