netCDF python definitions
Module exports the following:
ncerror: Module exception type.
WRITE, NOWRITE: Options for nc.open()
CLOBBER, NOCLOBBER: Options for nc.create()
COMPRESS: Another option for nc.create() if znetcdf library is used.
UNLIMITED: Record dimension definition
CHAR, BYTE, SHORT, LONG, FLOAT, DOUBLE: Different netCDF data types.
open(name [,mode]) returns an ncfile object. is either WRITE or NOWRITE.
create(name [,cmode]) returns an ncfile object. is the create mode either CLOBBER or NOCLOBBER. COMPRESS can be logically ored if znetcdf library is used.
ncfile objects have the following methods:
close() closes the netCDF file.
abort() aborts definition changes to the netCDF file.
sync() syncs the file to disk.
redef() enters define mode.
endef() leaves define mode.
setfill() enables the fill mode.
setnofill() disables fill mode.
def_dim(name, length) define a dimension with <name> and <length>. Must be in define mode, ncfile opened writable and <name> not already used.
def_att(name, variable, nctype, data [,length]) define an attribute <name> of the variable named <variable>. If <variable> is "" then the attribute will be global. <data> is either a float/int, a string, or a tuple of float/ints.
def_var(name, nctype, [(dim[,dim]*)]) define a variable <name> of type nctype. The tuple of dimension names defines the variable dimensions. If a dimension tuple is not defined, the variable is scalar.
list_dim() list dimensions.
list_att([name]) returns a dictionary of the attributes of variable <name>. If <name> is not supplied it returns the global attributes.
list_var() list variables.
var(name) returns a ncvar object for variable <name>.
get_rec(rec_num) returns a dictionary of all the record variables for <rec_num> record.
put_rec(rec_num, dict) puts the values defined in the <dict> dictiontary into the <rec_num> record. Variables not defined will not be inserted or altered.
append(dict) as above but adds a new record with the <dict> var/value pairs.
ncvar objects are either pseudo-sequences or pseudo-variable. They have the following methods:
list_dim()
list_att()
use_unit(unit_str,[db_unit_str]) sets the output units to that defined in the string unit_str in udunits format. db_unit_str defines the units stored in the netcdf file in the case that the file doesn't follow the "_units" attribute convention. This is made clearer in the examples.
NetCDF attributes are treated as python attributes and can be put/get but
not created. Global attributes are attributes of the ncfile object, variable
attributes are attributes of the ncvar object. There is a namespace clash
where an attribute may have the same name as one of the above methods. In
that case, it can be put/get with a put_att() or get_att() method.