mpas_tools.io.write_netcdf
- mpas_tools.io.write_netcdf(ds, fileName, fillValues=None, format=None, engine=None, char_dim_name=None, logger=None, nchar=None)[source]
Write an xarray.Dataset to a file with NetCDF4 fill values and the given name of the string dimension. Also adds the time and command-line to the history attribute.
Note: the
NETCDF3_64BIT_DATAformat is handled as a special case because xarray output with this format is not performant. First, the file is written inNETCDF4format, which supports larger files and variables. Then, thenckscommand is used to convert the file to theNETCDF3_64BIT_DATAformat.Note: All int64 variables are automatically converted to int32 for MPAS compatibility.
- Parameters:
ds (xarray.Dataset) – The dataset to save
fileName (str) – The path for the NetCDF file to write
fillValues (dict, optional) – A dictionary of fill values for different NetCDF types. Default is
mpas_tools.io.default_fills, which can be modified but which defaults tonetCDF4.default_fillvalsformat ({'NETCDF4', 'NETCDF4_CLASSIC', 'NETCDF3_64BIT', 'NETCDF3_CLASSIC'}, optional) – The NetCDF file format to use. Default is
mpas_tools.io.default_format, which can be modified but which defaults to'NETCDF3_64BIT'engine ({'netcdf4', 'scipy', 'h5netcdf'}, optional) – The library to use for NetCDF output. The default is the same as in
xarray.Dataset.to_netcdf()and depends onformat. You can override the default by settingmpas_tools.io.default_enginechar_dim_name (str, optional) – The name of the dimension used for character strings. Default is
mpas_tools.io.default_char_dim_name, which can be modified but which defaults to'StrLen'nchar (int, optional) – The number of characters to use for string variables. If None, the default is
mpas_tools.io.default_nchar, which can be modified but which defaults to 64.logger (logging.Logger, optional) – A logger to write messages to write the output of
ncksconversion calls to. If None,ncksoutput is suppressed. This is only relevant ifformatis ‘NETCDF3_64BIT_DATA’