hydromt.data_catalog.drivers.RasterDatasetXarrayDriver#

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

Driver for RasterDataset using the xarray library: raster_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] = 'raster_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: RasterXarrayOptions [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, variables: str | List[str] | None = None, zoom: int | Tuple[float, str] | None = None, chunks: dict[str, Any] | None = None, metadata: SourceMetadata | None = None) Dataset[source]#

Read zarr or netCDF raster data into an xarray Dataset.

Supports both zarr archives and NetCDF datasets via xr.open_zarr and xr.open_mfdataset. Optionally applies a preprocessing function defined in the driver options. Unused parameters (e.g., mask, zoom) are ignored but logged for transparency.

Parameters:
  • uris (list[str]) – List of URIs pointing to zarr or netCDF files.

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

  • mask (Geom | None, optional) – Spatial mask or geometry (currently unused). Default is None.

  • variables (Variables | None, optional) – List of variables to select from the dataset (currently unused). Default is None.

  • zoom (Zoom | None, optional) – Zoom level or resolution (currently unused). Default is None.

  • chunks (dict[str, Any] | None, optional) – Chunking configuration for Dask-based reading (currently unused). Default is None.

  • metadata (SourceMetadata | None, optional) – Optional metadata about the dataset source (currently unused). Default is None.

Returns:

The merged xarray Dataset.

Return type:

xr.Dataset

Raises:

ValueError – If the file extension is unsupported.

Warning

The mask, variables, zoom, chunks 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 RasterDataset to disk using Zarr or NetCDF format.

Supports writing datasets to .zarr, .nc, or .netcdf formats depending on the file extension. If an unsupported extension is provided, defaults to Zarr.

Parameters:
  • path (Path | str) – Destination path for the dataset.

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

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

Returns:

The path to the written dataset.

Return type:

Path

Raises:

ValueError – If the file extension is not recognized or supported.