cf.write

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

Write a space, or sequence of spaces, to a CF compliant netCDF file.

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

It does not matter if an input space’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 space if it had to be read during the write operation. However, if the data argument equals True then any input spaces which didn’t contain their full data arrays in memory will be changed in place so that they do. For example, for a space, s:

>>> s.type()
[<type 'netCDF4.Variable'>]
>>> write(s, 'filename')
>>> s.type()
[<type 'netCDF4.Variable'>]
>>> write(s, 'filename', data=True)
>>> s.type()
[<type 'numpy.ndarray'>]

Identical grid components (as determined by their numerically tolerant 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:
  • spaces (Space or sequence of spaces) – The space or spaces to write to the file.
  • file (str) – The netCDF file to write spaces to.
  • data (bool) – Optional. If True then ensure that spaces which have been written to disk retain their data in-place as numpy arrays.
  • 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:

>>> s
[<CF Space: air_pressure(30, 24)>,
 <CF Space: u_compnt_of_wind(19, 29, 24)>,
 <CF Space: v_compnt_of_wind(19, 29, 24)>,
 <CF Space: potential_temperature(19, 30, 24)>]
>>> write(s, 'file')

Previous topic

cf.read

Next topic

cf.dump

This Page