hydromt.data_catalog.drivers.DatasetXarrayDriver#

pydantic model hydromt.data_catalog.drivers.DatasetXarrayDriver[source]#

Driver for Dataset using xarray: dataset_xarray.

Supports reading and writing zarr and netcdf files using xarray. zarr files will be read using xr.open_zarr and netcdf files using xr.open_mfdataset.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

name: ClassVar[str] = 'dataset_xarray'#
supports_writing: ClassVar[bool] = True#

“Whether the driver supports writing data.

SUPPORTED_EXTENSIONS: ClassVar[set[str]] = {'.nc', '.netcdf', '.zarr'}#

“Set of supported file extensions for this driver.

field options: DatasetXarrayOptions [Optional]#

Driver options that can be used to configure the behavior of the driver. DriverOptions allows for setting arbitrary kwargs. Any options not explicitly declared in the DriverOptions class are passed as kwargs to the underlying open functions.

read(uris: list[str], *, handle_nodata: NoDataStrategy = NoDataStrategy.RAISE) Dataset[source]#

Read zarr or netCDF data into an xarray Dataset.

Supports reading multiple compatible datasets and merging them into a single xarray Dataset. File format is automatically inferred from the file extension, unless overridden via the driver options. Optionally applies a preprocessor function to each dataset before merging.

Parameters:
  • uris (list[str]) – List of URIs to read data from. All files must share the same format.

  • handle_nodata (NoDataStrategy, optional) – Strategy to handle missing or empty data. Default is NoDataStrategy.RAISE.

Returns:

The dataset read from the source files.

Return type:

xr.Dataset

Raises:

ValueError – If the provided files have mixed or unsupported extensions.

write(path: Path | str, data: Dataset, *, write_kwargs: dict[str, Any] | None = None) Path[source]#

Write an xarray Dataset to disk using the xarray I/O engine.

Supports writing to both Zarr and NetCDF formats. The file format is inferred from the file extension. If the extension is not recognized, a ValueError is raised.

Parameters:
  • path (Path | str) – Destination path or URI where the Dataset will be written. The file extension determines the output format: .zarr, .nc, or .netcdf.

  • data (xr.Dataset) – The Dataset to write to disk.

  • write_kwargs (dict[str, Any], optional) – Additional keyword arguments passed to the xarray write function (Dataset.to_zarr or Dataset.to_netcdf). Default is None.

Returns:

The path where the dataset was written.

Return type:

Path

Raises:

ValueError – If the provided file extension is unsupported.