rcatool.utils.file_io.write2netcdf

rcatool.utils.file_io.write2netcdf(filename, filedir, dim, variables, global_attr=None, nc_format='NETCDF4', compress=False, complevel=4)[source]

Opens a new NetCDF file to write the input data to. For nc_format, you can choose from ‘NETCDF3_CLASSIC’, ‘NETCDF3_64BIT’, ‘NETCDF4_CLASSIC’, and ‘NETCDF4’ (default)

Parameters:
  • filename (str) – name of netcdf file to write to

  • filedir (str) – directory path to put the file

  • dim (dict) – dimensions to be used

  • variables (dict) – variables with their values and attributes

  • global_attr (dict) – global attributes (optional)

  • nc_format (str) – Specify netCDF format

  • compress (boolean) – Whether to compress (using ‘zlib=True’ in the write call).

  • complevel (int) – An integer between 1-9 representing the degree of compression to be used.

The dictionaries should be structured as described by the examples below:

dims_dict = {} dims_dict[‘x’] = 154 dims_dict[‘y’] = 192 dims_dict[‘nv’] = 4 dims_dict[‘time’] = None

vars_dict = {} vars_dict = {‘lon’: {‘values’: lons, ‘dims’: (‘y’, ‘x’),

‘attributes’: {‘long_name’: ‘longitude’,

‘standard_name’: ‘longitude’, ‘units’: ‘degrees_east’, ‘_CoordinateAxisType’: ‘Lon’}},

‘lat’: {‘values’: lats, ‘dims’: (‘y’, ‘x’),
‘attributes’: {‘long_name’: ‘latitude’,

‘standard_name’: ‘latitude’, ‘units’: ‘degrees_north’, ‘_CoordinateAxisType’: ‘Lat’}},

‘pr’: {‘values’: pr, ‘dims’: (‘time’, ‘y’, ‘x’),
‘attributes’: {‘long_name’: ‘precipitation’,
‘standard_name’: ‘precipitation flux’,

‘units’: ‘kg m-2 s-1’, ‘coordinates’: ‘lon lat’, ‘_FillValue’: -9999.}}}

glob_attr = {‘description’: ‘some description of file’,

‘history’: ‘Created ‘ + time.ctime(time.time()), ‘experiment’: ‘Fractions Skill Score analysis’, ‘contact’: ‘petter.lind@smhi.se’, ‘references’: ‘http://journals.ametsoc.org/doi/abs/ 10.1175/2007MWR2123.1’}