cf.write

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

Write a field, or sequence of fields, to a CF compliant netCDF file.

NetCDF dimension and variable names will be taken from variables’ private attributes ncvar 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.

It does not matter if an input field’s data has not yet been read into memory. The write operation will automatically read the data array from disk if required, but the default is for it not to be saved in the input field if it had to be read during the write operation. However, if the repoint argument equals True then any data array elements of an input field and its components which are specified as file pointers (as opposed to arrays in memory) will be changed in place so that they are arrays in memory. For example, for a field, f:

>>> f.type()
[<type 'netCDF4.Variable'>]
>>> write(f, 'filename', repoint=True)
>>> f.type()
[<type 'netCDF4.Variable'>]
>>> write(f, 'filename', repoint=False)
>>> f.type()
[<type 'numpy.ndarray'>]

Identical field components (as determined by their equals methods) 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 (Field or sequence of fields) – The field or fields to write to the file.
  • file (str) – The netCDF file to write fields to.
  • repoint (bool) – Optional. If False then any data array elements of an input field and its components which are file pointers will be changed in place so that they are arrays in memory. If True then any data array elements of an input field and its components which are file pointers will be remain as file pointers.
  • delete (bool) – Optional. If True then delete each input field from memory after it has been written to disk.
  • 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 is “NETCDF3_CLASSIC”. Certain write operations may be considerably faster using “NETCDF4_CLASSIC”.
  • verbose (bool) – Optional. If True then print information to stdout.
Returns:

None

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')

Previous topic

cf.read

Next topic

cf.dump

This Page