flexmeasures.data.models.planning.utils

Functions

flexmeasures.data.models.planning.utils.add_tiny_price_slope(prices: DataFrame, col_name: str = 'event_value', d: float = 0.001) DataFrame

Add tiny price slope to col_name to represent e.g. inflation as a simple linear price increase. This is meant to break ties, when multiple time slots have equal prices, in favour of acting sooner. We penalise the future with at most d times the price spread (1 per thousand by default).

flexmeasures.data.models.planning.utils.fallback_charging_policy(sensor: Sensor, device_constraints: DataFrame, start: datetime, end: datetime, resolution: timedelta) Series

This fallback charging policy is to just start charging or discharging, or do neither, depending on the first target state of charge and the capabilities of the Charge Point. Note that this ignores any cause of the infeasibility and, while probably a decent policy for Charge Points, should not be considered a robust policy for other asset types.

flexmeasures.data.models.planning.utils.get_market(sensor: Sensor) Sensor

Get market sensor from the sensor’s attributes.

flexmeasures.data.models.planning.utils.get_power_values(query_window: Tuple[datetime, datetime], resolution: timedelta, beliefs_before: datetime | None, sensor: Sensor) ndarray

Get measurements or forecasts of an inflexible device represented by a power sensor.

If the requested schedule lies in the future, the returned data will consist of (the most recent) forecasts (if any exist). If the requested schedule lies in the past, the returned data will consist of (the most recent) measurements (if any exist). The latter amounts to answering “What if we could have scheduled under perfect foresight?”.

Parameters:
  • query_window – datetime window within which events occur (equal to the scheduling window)

  • resolution – timedelta used to resample the forecasts to the resolution of the schedule

  • beliefs_before – datetime used to indicate we are interested in the state of knowledge at that time

  • sensor – power sensor representing an energy flow out of the device

Returns:

power measurements or forecasts (consumption is positive, production is negative)

flexmeasures.data.models.planning.utils.get_prices(query_window: Tuple[datetime, datetime], resolution: timedelta, beliefs_before: datetime | None, price_sensor: Sensor | None = None, sensor: Sensor | None = None, allow_trimmed_query_window: bool = True) Tuple[DataFrame, Tuple[datetime, datetime]]

Check for known prices or price forecasts.

If so allowed, the query window is trimmed according to the available data. If not allowed, prices are extended to the edges of the query window: - The first available price serves as a naive backcast. - The last available price serves as a naive forecast.

flexmeasures.data.models.planning.utils.idle_after_reaching_target(schedule: Series, target: Series, initial_state: float = 0) Series

Stop planned (dis)charging after target is reached (or constraint is met).

flexmeasures.data.models.planning.utils.initialize_df(columns: List[str], start: datetime, end: datetime, resolution: timedelta, inclusive: str = 'left') DataFrame
flexmeasures.data.models.planning.utils.initialize_index(start: date | datetime | str, end: date | datetime | str, resolution: timedelta | str, inclusive: str = 'left') DatetimeIndex
flexmeasures.data.models.planning.utils.initialize_series(data: Series | List[float] | ndarray | float | None, start: datetime, end: datetime, resolution: timedelta, inclusive: str = 'left') Series