Retriever#
- The
retrieversfolder ofweathermartcontains a series of specificRetrieverobjects, designed to fetch data from multiple data sources using an existing API or, when it does not exist, reading data from a local file. If the user wants to add a new data source, they might create a newRetrieverobject which should have a
retrievemethod (with multiple custom arguments);a coordinate reference system
crsattribute under the form of an epsg code or a pyproj string;a
sourcesattribute displaying the possible muliple sources accessible with theRetrieverobject (for example, theNWPRetrievercan fetch data from COSMO-1E or ICON-CH1-EPS models);a
variablesattribute showing the mapping between source variables and their ICON-CH1-EPS or COSMO-1E counterparts (see https://meteoswiss.atlassian.net/wiki/spaces/Nowcasting/pages/370049179/Data+model+for+output+parameters).
The DataRetriever iterates through its subretrievers attribute to find the right Retriever object to call for the given source and dates.
- class DataRetriever(subretrievers: tuple[weathermart.base.BaseRetriever, ...])
Retrieve data from available sub-retrievers.
This class iterates through provided sub-retrievers and attempts to retrieve data for a given source, variables, and dates. It checks if a retriever supports the source and then delegates the retrieval. The resulting dataset is renamed based on the retriever’s variable mappings.
- Parameters:
subretrievers (list of classes that inherit from BaseRetriever) – A list of retriever instances used to fetch data.
- retrieve(source: str, variables: list[tuple[str, dict]], dates: datetime.date | str | pandas._libs.tslibs.timestamps.Timestamp | list[Any], rename: bool = False, **kwargs: Any) Dataset
Retrieve data for a given source, set of variables, and dates.
The method iterates over the sub-retrievers to find one that supports the specified source. For the matching retriever, it filters and validates requested variables, calls the retriever’s retrieve method, renames the variables in the returned dataset, and returns the dataset with only the successfully retrieved data variables.
- Parameters:
source (str) – The source identifier for which data should be retrieved.
variables (list of tuple of (str, dict)) – List of variable definitions, where each tuple contains the variable name and associated properties.
dates (list of datetime.date or datetime.date) – A single date or list of dates for data retrieval.
rename (bool, optional) – If True, the retrieved dataset’s variables will be renamed according to the retriever’s variable mappings. Defaults to True.
**kwargs (dict) – Additional keyword arguments to be passed to each subretriever’s retrieve method.
- Returns:
Dataset containing the retrieved data, with variable names renamed and filtered.
- Return type:
xarray.Dataset
- Raises:
ValueError – If a variable is not defined for the source or if no retriever supports the given source.
RuntimeError – If the retrieved dataset’s time coordinate is not sorted.