commonpower.data_forecasting.base.DataProvider

class DataProvider(data_source: DataSource, forecaster: Forecaster, observable_features: list[str] | None = None)[source]

Bases: object

DataProviders combine a DataSource with a Forecaster.

Parameters:
  • data_source (DataSource) – Data source to obtain data from.

  • forecaster (Forecaster) – Forecaster used for predictions.

  • observable_features (list[str], optional) – List of features from the data source that are observable. All other features are only used by the forecaster. If not given, all existing features are observed. Forecasts can only be generated for observable features. The forecaster must implement that accordingly. Defaults to None.

Methods

empty_copy

Returns a copy of the DataProvider.

get_date_range

Returns the date range data is available for.

get_variables

Returns the list of element names that data is available for.

observation_bounds

Returns the observation bounds for all elements in the data source.

observe

Returns the observations for all variables of the data provider. The observations span the forecast horizon. If the forecaster returns values outside the limits of the data source, they are clipped.

set_perfect_knowledge

Activate or deactivate perfect knowledge override.

_clip_obs(obs: dict[str, ndarray]) dict[str, ndarray][source]

Clip the observations to the limits of the data source.

Parameters:

obs (dict[str, np.ndarray]) – Observations to clip.

Returns:

dict[str, np.ndarray] – Clipped observations.

_filter_observed_features(data: ndarray) ndarray[source]

Filter the data to only include observable features.

Parameters:

data (np.ndarray) – Data to filter.

Returns:

np.ndarray – Filtered data.

_get_current_obs_and_forecast(time: datetime) List[np.ndarray, np.ndarray][source]

Returns the current observations and the forecast for the current time.

Parameters:

time (datetime) – Current time.

Returns:

List[np.ndarray, np.ndarray] – [current_obs, forecast]

empty_copy() DataProvider[source]

Returns a copy of the DataProvider.

Returns:

DataProvider – Copy of the DataProvider.

get_date_range() List[datetime][source]

Returns the date range data is available for.

Returns:

List[datetime] – [start_date, end_date]

get_variables() List[str][source]

Returns the list of element names that data is available for.

Returns:

List[str] – List of available elements.

observation_bounds(time: datetime) dict[str, list[tuple[float]]][source]

Returns the observation bounds for all elements in the data source. The default is “guaranteed symmetrical bounds”, i.e., the bounds are based on the absolute difference between forecast and true value. Accordingly, the true value is always either the upper or lower limit of the forecast bounds. This only works if the true data is available. We return bounds for each time step in the forecast horizon.

Parameters:

time (datetime) – Current time.

Returns:

dict (dict[str, list[tuple[float]]]) – {“element1”: [(lb_0, ub_0), (lb_1, ub_1)], “element2”: [(lb_0, ub_0), (lb_1, ub_1)]}

observe(time: datetime) dict[str, ndarray][source]

Returns the observations for all variables of the data provider. The observations span the forecast horizon. If the forecaster returns values outside the limits of the data source,

they are clipped.

Parameters:

time (datetime) – Current time.

Returns:

dict – {“<element1>”: np.ndarray, “<element2>”: np.ndarray}.

set_perfect_knowledge(perfect_knowledge_active: bool = False)[source]

Activate or deactivate perfect knowledge override.

Parameters:

perfect_knowledge_active (bool, optional) – State of the override. Defaults to False.