cf.write

cf.write(fields, file, format='NETCDF3_CLASSIC', verbose=False)

Write fields to a CF-netCDF file.

NetCDF dimension and variable names will be taken from variables’ ncvar attributes and the space attribute nc_dimensions if present, otherwise they are inferred from standard names or set to defaults. NetCDF names may be automatically given a numerical suffix to avoid duplication.

Output netCDF file global attributes are those which occur in the set of CF global attributes and non-standard data variable attributes and which have equal values across all input fields.

Logically identical field components are only written to the file once, apart from when they need to fulfil both dimension coordinate and auxiliary coordinate roles for different data variables.

Parameters :
fields : (sequence of) Field or FieldList

The field or fields to write to the file.

file : str

The netCDF file to write fields to.

format : str, optional

The format of the output netCDF file. Valid formats are those supported by the netCDF4 module: ‘NETCDF3_CLASSIC’, ‘NETCDF3_64BIT’ ‘NETCDF4_CLASSIC’ and ‘NETCDF4’. The default format is ‘NETCDF3_CLASSIC’. Certain write operations may be considerably faster using ‘NETCDF4_CLASSIC’ or ‘NETCDF4’.

verbose : bool, optional

If True then print information to stdout.

Returns :

None

Raises :
ValueError :

If a field does not have information required to write certain aspects of a CF-netCDF file.

Examples

>>> f
[<CF Field: air_pressure(30, 24)>,
 <CF Field: u_compnt_of_wind(19, 29, 24)>,
 <CF Field: v_compnt_of_wind(19, 29, 24)>,
 <CF Field: potential_temperature(19, 30, 24)>]
>>> write(f, 'file')
>>> type(f)
<class 'cf.field.FieldList'>
>>> type(g)
<class 'cf.field.Field'>
>>> cf.write([f, g], 'file.nc', verbose=True)
[<CF Field: air_pressure(30, 24)>,
 <CF Field: u_compnt_of_wind(19, 29, 24)>,
 <CF Field: v_compnt_of_wind(19, 29, 24)>,
 <CF Field: potential_temperature(19, 30, 24)>]

Previous topic

cf.read

Next topic

Classes

This Page