hydromt.data_catalog.sources.DataSource#

pydantic model hydromt.data_catalog.sources.DataSource[source]#

A DataSource is a parsed section of a DataCatalog.

The DataSource, specific for a data type within HydroMT, is responsible for validating the input from the DataCatalog, to ensure the workflow fails as early as possible. A DataSource has information on the driver that the data should be read with, and is responsible for initializing this driver.

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.

field name: str [Required]#
field uri: str [Required]#
field data_adapter: DataAdapterBase [Required]#
field driver: BaseDriver [Required]#
field uri_resolver: URIResolver [Optional]#
data_type: ClassVar[DataType]#
field root: str | None = None#
field version: str | int | float | None = None#
field provider: str | None = None#
field metadata: SourceMetadata [Optional]#
summary() Dict[str, Any][source]#

Return a summary of the DataSource.

property full_uri: str#

Join root with uri.

get_time_range(detect: bool = True, strict: bool = False) TimeRange | None[source]#

Detect the time range of the dataset if applicable.

Override in subclasses if applicable.

Parameters:

detect (bool, Optional) – If True and the time range is not set in metadata, attempt to detect it. If False, only use the time range in metadata if it exists.

Returns:

range – Instance containing the start and end of the time dimension. Range is inclusive on both sides. None if not set and detect is False.

Return type:

TimeRange, optional

get_bbox(crs: CRS | None = None, detect: bool = True, strict: bool = False) Tuple[float, float, float, float], <function _validate_bbox at 0x7f793cba1d00>], int] | None[source]#

Get the bounding box and crs of the data source if applicable.

This method should be overridden in subclasses if applicable.

Returns:

bbox – The bounding box of the data source. None if not applicable.

Return type:

TotalBounds | None

Notes

TotalBounds is a tuple of (bbox, crs), where bbox is a tuple of (minx, miny, maxx, maxy) and crs is the coordinate reference system.

abstract read_data() Any | None[source]#

Read data from the source.

abstract to_stac_catalog(handle_nodata: NoDataStrategy = NoDataStrategy.IGNORE) Catalog | None[source]#

Convert source into a STAC Catalog representation.

The collection will contain an asset for each of the associated files.

Parameters:

handle_nodata (NoDataStrategy, optional) – The error handling strategy. Options are: “raise” to raise an error on failure, “skip” to skip the source on failure, and “coerce” (default) to set default values on failure.

Returns:

The STAC Catalog representation of the source, or None if the dataset was skipped.

Return type:

StacCatalog, optional

abstract to_file(file_path: Path | str) DataSource | None[source]#

Write the DataSource to a local file.

Parameters:

file_path (Path | str) – The path to write the data to.

Returns:

A new instance of the DataSource with the updated uri and driver. Or None if there is no data available.

Return type:

DataSource

model_post_init(context: Any, /) None#

This function is meant to behave like a BaseModel method to initialise private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Args:

self: The BaseModel instance. context: The context.