This is a simple example that creates a NetCDF file for 1 degree global 2m temperature. There is no time coordinate.
For this portion of code:
ds = xr.DataArray(data, ...)
data
is a NumPy array, assumed to have a shape of num_lats x num_lons
You can put whatever attributes you want in the attrs
dictionary (eg. 'email': '[email protected]'
, etc.).
You can name the dataset whatever you want (eg. 'tmean'
as above).
This portion of code:
encoding={var: dict(zlib=True, complevel=9) for var in ds.data_vars}
sets the compression of all the variables. The compression is NetCDF4 compression, from 1-9.