hydromt.data_catalog.drivers.GeoDatasetXarrayDriver#

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

Driver for GeoDataset using the xarray library: geodataset_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] = 'geodataset_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: GeoDatasetOptions [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, mask: GeoDataFrame | GeoSeries | None = None, predicate: Literal['intersects', 'within', 'contains', 'overlaps', 'crosses', 'touches'] = 'intersects', metadata: SourceMetadata | None = None) Dataset[source]#

Read in data to an xarray Dataset.

Parameters:
  • uris (list[str]) – List of URIs to read data from.

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

  • mask (Geom | None, optional) – Optional spatial mask to clip the dataset.

  • predicate (Predicate, optional) – Spatial predicate for filtering geometries. Default is “intersects”.

  • metadata (SourceMetadata | None, optional) – Optional metadata object to attach to the loaded dataset.

Returns:

The dataset read from the source, or None if no data found and strategy allows.

Return type:

xr.Dataset | None

Warning

The mask, predicate and metadata parameters are not used directly in this driver, but are included for consistency with the GeoDataFrameDriver interface.

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

Write a GeoDataset to disk in Zarr or NetCDF format.

Parameters:
  • path (Path | str) – Destination path or URI where the dataset will be written. Must end with a supported extension (‘.zarr’, ‘.nc’, or ‘.netcdf’).

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

  • write_kwargs (dict[str, Any] | None, optional) – Additional keyword arguments passed to the underlying write function. For example, encoding for NetCDF, or mode for Zarr. Default is None.

Returns:

The path where the dataset was written.

Return type:

Path

Raises:

ValueError – If the file extension is not supported.