hydromt.io.write_nc#

hydromt.io.write_nc(ds: DataArray | Dataset, file_path: Path, *, compress: bool = False, gdal_compliant: bool = False, rename_dims: bool = False, force_sn: bool = False, force_overwrite: bool = False, **kwargs) DeferredFileClose | None[source]#

Write xarray.Dataset and/or xarray.DataArray to netcdf file.

Possibility to update the xarray objects attributes to get GDAL compliant NetCDF files, using gdal_compliant(). The function will first try to directly write to file. In case of PermissionError, it will first write a temporary file and move the file over.

key-word arguments are passed to xarray.Dataset.to_netcdf()

Parameters:
  • ds (xr.DataArray | xr.Dataset) – Dataset to be written to the drive

  • file_path (Path) – Full path to the outgoing file

  • compress (bool, optional) – Whether or not to compress the data, by default False

  • gdal_compliant (bool, optional) – If True, convert xarray.Dataset and/or xarray.DataArray to gdal compliant format using gdal_compliant(), by default False

  • rename_dims (bool, optional) – If True, rename x_dim and y_dim to standard names depending on the CRS (x/y for projected and lat/lon for geographic). Only used if gdal_compliant is set to True. By default False

  • force_sn (bool, optional) – If True, forces the dataset to have South -> North orientation. Only used if gdal_compliant is set to True. By default False

  • **kwargs (dict) – Additional keyword arguments that are passed to the to_netcdf function