metobs_toolkit.dataset.Dataset.to_netcdf#
- Dataset.to_netcdf(filepath: str | PathLike | None = None, overwrite: bool = False, **kwargs) None[source]#
Save the Dataset as a netCDF file.
This method converts the Dataset to an xarray Dataset and saves it as a netCDF file.
- Parameters:
filepath (str or path-like or None, optional) – Path where the netCDF file will be saved. If None, defaults to ‘dataset.nc’ in the current working directory. Default is None.
overwrite (bool, optional) – If True, overwrites existing file. Default is False.
**kwargs – Additional keyword arguments passed to xarray.Dataset.to_netcdf(). Common options include: - format : str, netCDF format (‘NETCDF4’, ‘NETCDF4_CLASSIC’, ‘NETCDF3_64BIT’, ‘NETCDF3_CLASSIC’) - engine : str, netCDF engine to use (‘netcdf4’, ‘scipy’, ‘h5netcdf’) - encoding : dict, variable-specific encoding parameters
Examples
>>> dataset.to_netcdf('my_observations.nc') >>> dataset.to_netcdf('data.nc', format='NETCDF4_CLASSIC')
Notes
This method is an export method. It is not possible to convert a netCDF to a metobs_toolkit.Dataset object.
The method uses the ‘netcdf4’ engine by default for better Unicode string compatibility. The scipy engine has limitations with certain Unicode datatypes.