flexmeasures.data.models.planning
Modules
Classes
- class flexmeasures.data.models.planning.Commitment(name: str, device: Series | None = None, index: DatetimeIndex | None = None, _type: str = 'each', quantity: Series = 0, upwards_deviation_price: Series = 0, downwards_deviation_price: Series = 0)
Contractual commitment specifying prices for deviating from a given position.
- Attributes:
name: Name of the commitment. device: Device to which the commitment pertains. If None, the commitment pertains to the EMS. index: Pandas DatetimeIndex defining the time slots to which the commitment applies.
The index is shared by the group, quantity, upwards_deviation_price and downwards_deviation_price Pandas Series.
_type: ‘any’ or ‘each’. Any deviation is penalized via 1 group, whereas each deviation is penalized via n groups. group: Each time slot is assigned to a group. Deviations are determined for each group.
The deviation of a group is determined by the time slot with the maximum deviation within that group.
- quantity: The deviation for each group is determined with respect to this quantity.
Can be initialized with a constant value, but always returns a Pandas Series (see also the index parameter).
- upwards_deviation_price:
The deviation in the upwards direction is priced against this price. Use a positive price to set a penalty. Can be initialized with a constant value, but always returns a Pandas Series (see also the index parameter).
- downwards_deviation_price:
The deviation in the downwards direction is priced against this price. Use a negative price to set a penalty. Can be initialized with a constant value, but always returns a Pandas Series (see also the index parameter).
- __init__(name: str, device: Series | None = None, index: DatetimeIndex | None = None, _type: str = 'each', quantity: Series = 0, upwards_deviation_price: Series = 0, downwards_deviation_price: Series = 0) None
- to_frame() DataFrame
Contains all info apart from the name.
- class flexmeasures.data.models.planning.FlowCommitment(name: str, device: Series | None = None, index: DatetimeIndex | None = None, _type: str = 'each', quantity: Series = 0, upwards_deviation_price: Series = 0, downwards_deviation_price: Series = 0)
NB index contains event start, while quantity applies to average flow between event start and end.
- class flexmeasures.data.models.planning.Scheduler(sensor: Sensor | None = None, start: datetime | None = None, end: datetime | None = None, resolution: timedelta | None = None, belief_time: datetime | None = None, asset_or_sensor: Asset | Sensor | None = None, round_to_decimals: int | None = 6, flex_model: dict | None = None, flex_context: dict | None = None, return_multiple: bool = False)
Superclass for all FlexMeasures Schedulers.
A scheduler currently computes the schedule for one flexible asset. TODO: extend to multiple flexible assets.
The scheduler knows the power sensor of the flexible asset. It also knows the basic timing parameter of the schedule (start, end, resolution), including the point in time when knowledge can be assumed to be available (belief_time).
Furthermore, the scheduler needs to have knowledge about the asset’s flexibility model (under what constraints can the schedule be optimized?) and the system’s flexibility context (which other sensors are relevant, e.g. prices). These two flexibility configurations are usually fed in from outside, so the scheduler should check them. The deserialize_flex_config function can be used for that.
- __init__(sensor: Sensor | None = None, start: datetime | None = None, end: datetime | None = None, resolution: timedelta | None = None, belief_time: datetime | None = None, asset_or_sensor: Asset | Sensor | None = None, round_to_decimals: int | None = 6, flex_model: dict | None = None, flex_context: dict | None = None, return_multiple: bool = False)
Initialize a new Scheduler.
- TODO: We might adapt the class design, so that a Scheduler object is initialized with configuration parameters,
- and can then be used multiple times (via compute()) to compute schedules of different kinds, e.g.
If we started later (put in a later start), what would the schedule be? If we could change set points less often (put in a coarser resolution), what would the schedule be? If we knew what was going to happen (put in a later belief_time), what would the schedule have been?
For now, we don’t see the best separation between config and state parameters (esp. within flex models) E.g. start and flex_model[soc_at_start] are intertwined.
- collect_flex_config()
Merge the flex-config from the db (from the asset and its ancestors) with the initialization flex-config.
Note that self.flex_context overrides db_flex_context (from the asset and its ancestors). # todo: also fetch db_flex_model once that exists
- compute() Series | List[Dict[str, Any]] | None
Overwrite with the actual computation of your schedule.
- compute_schedule() pd.Series | None
Overwrite with the actual computation of your schedule.
Deprecated method in v0.14. As an alternative, use Scheduler.compute().
- deserialize_config()
Check all configurations we have, throwing either ValidationErrors or ValueErrors. Other code can decide if/how to handle those.
- deserialize_flex_config()
Check if the flex model and flex context are valid. Should be overwritten.
Ideas: - Apply a schema to check validity (see in-built flex model schemas) - Check for inconsistencies between settings (can also happen in Marshmallow) - fill in missing values from the scheduler’s knowledge (e.g. sensor attributes)
Raises ValidationErrors or ValueErrors.
- deserialize_timing_config()
Check if the timing of the schedule is valid. Raises ValueErrors.
- classmethod get_data_source_info() dict
Create and return the data source info, from which a data source lookup/creation is possible. See for instance get_data_source_for_job().
- persist_flex_model()
If useful, (parts of) the flex model can be persisted here, e.g. as asset attributes, sensor attributes or as sensor data (beliefs).
- class flexmeasures.data.models.planning.StockCommitment(name: str, device: Series | None = None, index: DatetimeIndex | None = None, _type: str = 'each', quantity: Series = 0, upwards_deviation_price: Series = 0, downwards_deviation_price: Series = 0)
NB index contains event start, while quantity applies to stock at event end.