I have a few lists in Python that I am trying to write to NetCDF files, but I am unsure how to get it to work.
An example of how the lists are structured is:
Each list consists of a number of lists itself, say 17, each having 3 elements. The first element species a year, so just an integer or a string, the second element consists of 36 arrays, and the third element consists of 5 arrays.
Based on other guides, I tried to write the code in this manner:
fn = 'mean_yearly_list.nc'
ds = nc.Dataset(fn, 'w', format='NETCDF4')
year = ds.createDimension('date', None)
lat = ds.createDimension('lat', 36)
clim = ds.createDimension('clim', 5)
years = ds.createVariable('date', 'f4', ('year',))
lats = ds.createVariable('lat', 'f4', ('lat',))
clims = ds.createVariable('clim', 'f4', ('clim',))
value1 = ds.createVariable('value_lat', 'f4', ('years', 'lat',))
value2 = ds.createVariable('value_clim', 'f4', ('years', 'clim',))
But now I am unsure of how to exactly write my lists/arrays to these variables in the NetCDF file. Does anyone know how this is easiest done? Thanks for any help!