openstef 3.4.53__py3-none-any.whl → 3.4.55__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ from pydantic.v1 import BaseModel
9
9
  from openstef.data_classes.data_prep import DataPrepDataClass
10
10
  from openstef.data_classes.model_specifications import ModelSpecificationDataClass
11
11
  from openstef.data_classes.split_function import SplitFuncDataClass
12
- from openstef.enums import PipelineType, BiddingZone
12
+ from openstef.enums import PipelineType, BiddingZone, AggregateFunction
13
13
 
14
14
 
15
15
  class PredictionJobDataClass(BaseModel):
@@ -83,6 +83,8 @@ class PredictionJobDataClass(BaseModel):
83
83
  data_balancing_ratio: Optional[float] = None
84
84
  """If data balancing is enabled, the data will be balanced with data from 1 year
85
85
  ago in the future."""
86
+ rolling_aggregate_features: Optional[list[AggregateFunction]] = None
87
+ """If not None, rolling aggregate(s) of load will be used as features in the model."""
86
88
  depends_on: Optional[list[Union[int, str]]]
87
89
  """Link to another prediction job on which this prediction job might depend."""
88
90
  sid: Optional[str]
openstef/enums.py CHANGED
@@ -108,6 +108,13 @@ class BiddingZone(Enum):
108
108
  DE_AMP_LU = "DE_AMP_LU"
109
109
 
110
110
 
111
+ class AggregateFunction(Enum):
112
+ MEAN = "mean"
113
+ MEDIAN = "median"
114
+ MAX = "max"
115
+ MIN = "min"
116
+
117
+
111
118
  class ModelType(Enum):
112
119
  XGB = "xgb"
113
120
  XGB_QUANTILE = "xgb_quantile"
@@ -22,6 +22,7 @@ from openstef.feature_engineering.lag_features import generate_lag_feature_funct
22
22
  from openstef.feature_engineering.bidding_zone_to_country_mapping import (
23
23
  BIDDING_ZONE_TO_COUNTRY_CODE_MAPPING,
24
24
  )
25
+ from openstef.feature_engineering.rolling_features import add_rolling_aggregate_features
25
26
  from openstef.feature_engineering.weather_features import (
26
27
  add_additional_solar_features,
27
28
  add_additional_wind_features,
@@ -130,5 +131,8 @@ def apply_features(
130
131
  # Adds daylight terrestrial feature
131
132
  data = add_daylight_terrestrial_feature(data)
132
133
 
134
+ if pj.get("rolling_aggregate_features") is not None:
135
+ data = add_rolling_aggregate_features(data, pj=pj)
136
+
133
137
  # Return dataframe including all requested features
134
138
  return data
@@ -24,7 +24,9 @@ from openstef.feature_engineering.general import (
24
24
  remove_non_requested_feature_columns,
25
25
  )
26
26
 
27
- LATENCY_CONFIG = {"APX": 24} # A specific latency is part of a specific feature.
27
+ LATENCY_CONFIG = {
28
+ "day_ahead_electricity_price": 24
29
+ } # A specific latency is part of a specific feature.
28
30
 
29
31
 
30
32
  class AbstractFeatureApplicator(ABC):
@@ -94,7 +96,7 @@ class TrainFeatureApplicator(AbstractFeatureApplicator):
94
96
  if not specified a default location is used
95
97
  latency_config: (Optional) Invalidate certain features that are not
96
98
  available for a specific horizon due to data latency. Defaults to
97
- ``{"APX": 24}``.
99
+ ``{"day_ahead_electricity_price": 24}``.
98
100
 
99
101
  Returns:
100
102
  Input DataFrame with an extra column for every added feature and sorted on the datetime index.
@@ -0,0 +1,43 @@
1
+ # SPDX-FileCopyrightText: 2017-2023 Contributors to the OpenSTEF project <korte.termijn.prognoses@alliander.com> # noqa E501>
2
+ #
3
+ # SPDX-License-Identifier: MPL-2.0
4
+ from datetime import timedelta
5
+
6
+ import pandas as pd
7
+
8
+ from openstef.data_classes.prediction_job import PredictionJobDataClass
9
+
10
+
11
+ def add_rolling_aggregate_features(
12
+ data: pd.DataFrame,
13
+ pj: PredictionJobDataClass,
14
+ rolling_window: timedelta = timedelta(hours=24),
15
+ ) -> pd.DataFrame:
16
+ """
17
+ Adds rolling aggregate features to the input dataframe.
18
+
19
+ These features are calculated with an aggregation over a rolling window of the data.
20
+ A list of requested features is used to determine whether to add the rolling features
21
+ or not.
22
+
23
+ Args:
24
+ data: Input dataframe to which the rolling features will be added.
25
+ pj: Prediction job data.
26
+ rolling_window: Rolling window size for the aggregation.
27
+
28
+ Returns:
29
+ DataFrame with added rolling features.
30
+ """
31
+ # Ensure the index is a DatetimeIndex
32
+ if not isinstance(data.index, pd.DatetimeIndex):
33
+ raise ValueError("The DataFrame index must be a DatetimeIndex.")
34
+
35
+ if "load" not in data.columns:
36
+ raise ValueError("The DataFrame must contain a 'load' column.")
37
+ rolling_window_load = data["load"].rolling(window=rolling_window)
38
+
39
+ for aggregate_func in pj["rolling_aggregate_features"]:
40
+ data[
41
+ f"rolling_{aggregate_func.value}_load_{rolling_window}"
42
+ ] = rolling_window_load.aggregate(aggregate_func.value)
43
+ return data
@@ -93,7 +93,7 @@ class LinearQuantileOpenstfRegressor(OpenstfRegressor, RegressorMixin):
93
93
  )
94
94
 
95
95
  if clipped_features is None:
96
- clipped_features = ["APX"]
96
+ clipped_features = ["day_ahead_electricity_price"]
97
97
 
98
98
  self.quantiles = quantiles
99
99
  self.alpha = alpha
@@ -6,7 +6,7 @@
6
6
  This code assumes trained models are available from the persistent storage.
7
7
  If these are not available run model_train.py to train all models.
8
8
  To provide the prognoses the following steps are carried out:
9
- 1. Get historic training data (TDCV, Load, Weather and APX price data)
9
+ 1. Get historic training data (TDCV, Load, Weather and day_ahead_electricity_price price data)
10
10
  2. Apply features
11
11
  3. Load model
12
12
  4. Make component prediction
@@ -6,7 +6,7 @@
6
6
  This code assumes trained models are available from the persistent storage. If these
7
7
  are not available run model_train.py to train all models.
8
8
  To provide the prognoses the folowing steps are carried out:
9
- 1. Get historic training data (TDCV, Load, Weather and APX price data)
9
+ 1. Get historic training data (TDCV, Load, Weather and day_ahead_electricity_price price data)
10
10
  2. Apply features
11
11
  3. Load model
12
12
  4. Make prediction
@@ -24,7 +24,7 @@ from datetime import datetime, timedelta
24
24
  from pathlib import Path
25
25
 
26
26
  from openstef.data_classes.prediction_job import PredictionJobDataClass
27
- from openstef.enums import ModelType, PipelineType
27
+ from openstef.enums import BiddingZone, ModelType, PipelineType
28
28
  from openstef.exceptions import InputDataOngoingZeroFlatlinerError
29
29
  from openstef.pipeline.create_forecast import create_forecast_pipeline
30
30
  from openstef.tasks.utils.predictionjobloop import PredictionJobLoop
@@ -82,8 +82,13 @@ def create_forecast_task(
82
82
  location=[pj["lat"], pj["lon"]],
83
83
  datetime_start=datetime_start,
84
84
  datetime_end=datetime_end,
85
+ market_price=pj.electricity_bidding_zone.value,
85
86
  )
86
87
 
88
+ # Add APX price to the input data for backward compatibility,remove this line when all models are retrained
89
+ if pj.electricity_bidding_zone == BiddingZone.NL:
90
+ input_data["APX"] = input_data["day_ahead_electricity_price"]
91
+
87
92
  try:
88
93
  # Make forecast with the forecast pipeline
89
94
  forecast = create_forecast_pipeline(
@@ -4,7 +4,7 @@
4
4
  """This module contains the CRON job that is periodically executed to retrain the prognosis models.
5
5
 
6
6
  For this the folowing steps are caried out:
7
- 1. Get historic training data (TDCV, Load, Weather and APX price data)
7
+ 1. Get historic training data (TDCV, Load, Weather and day_ahead_electricity_price price data)
8
8
  2. Apply features
9
9
  3. Train and Test the new model
10
10
  4. Check if new model performs better than the old model
@@ -313,9 +313,9 @@ def calc_completeness_dataframe(
313
313
  expected_numbers_timedelayed=value,
314
314
  )
315
315
 
316
- # Correct for APX being only expected to be available up to 24h
317
- if "APX" in non_na_count.index:
318
- non_na_count["APX"] += max([len(df) - 96, 0])
316
+ # Correct for day_ahead_electricity_price being only expected to be available up to 24h
317
+ if "day_ahead_electricity_price" in non_na_count.index:
318
+ non_na_count["day_ahead_electricity_price"] += max([len(df) - 96, 0])
319
319
 
320
320
  completeness_per_column_dataframe = non_na_count / (len(df))
321
321
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: openstef
3
- Version: 3.4.53
3
+ Version: 3.4.55
4
4
  Summary: Open short term energy forecaster
5
5
  Home-page: https://github.com/OpenSTEF/openstef
6
6
  Author: Alliander N.V
@@ -1,7 +1,7 @@
1
1
  openstef/__init__.py,sha256=93UM6m0LLQhO69-mSqLuUy73jgs4W7Iuxfo3Lm8c98g,419
2
2
  openstef/__main__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
3
3
  openstef/app_settings.py,sha256=EJTDtimctFQQ-3f7ZcOQaRYohpZk3JD6aZBWPFYM2_A,582
4
- openstef/enums.py,sha256=wToJV56CAqgl-UY2DU1Zf12Ft9WsSiUNMrHYLnULOhQ,2724
4
+ openstef/enums.py,sha256=FrP0m_Tk0kV7gSZ2hTY_8iD45KIKnexHrjNufhpKXpE,2829
5
5
  openstef/exceptions.py,sha256=U4u2LTcdT6cmzpipT2Jh7kq9nCjT_-6gntn8yjuhGU0,1993
6
6
  openstef/settings.py,sha256=nSgkBqFxuqB3w7Rwo60i8j37c5ngDbt6vpjHS6QtJXQ,354
7
7
  openstef/data/NL_terrestrial_radiation.csv,sha256=A4kbW56GDzWi4tWUwY2C-4PiOvcKJCwkWQQtdg4ekPE,820246
@@ -17,19 +17,20 @@ openstef/data/dazls_model_3.4.24/dazls_stored_3.4.24_model_card.md.license,sha25
17
17
  openstef/data_classes/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
18
18
  openstef/data_classes/data_prep.py,sha256=gRSL7UiHvZis8m8z7VoTCZc0Ccffhef5_hmSyApnqK0,3417
19
19
  openstef/data_classes/model_specifications.py,sha256=Uod1W3QzhRqVLb6zvXwxh9wRL3EHCzSvX0oDNd28cFk,1197
20
- openstef/data_classes/prediction_job.py,sha256=hJNwLkCIIVsG5nzOmu_yY6rqTYzjuMt8FiLi7Aei3n4,5691
20
+ openstef/data_classes/prediction_job.py,sha256=OFGg6h0XQZOIkJEYr1EoT3LE2oV6YULaCCxhkaES4wA,5874
21
21
  openstef/data_classes/split_function.py,sha256=ljQIQQu1t1Y_CVWGAy25jrM6wG9odIVVQVimrT1n-1s,3358
22
22
  openstef/feature_engineering/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
23
- openstef/feature_engineering/apply_features.py,sha256=EIxP9fvmnAjFRehQpVGBhZHt35GACL-HhDm65_ktHc0,5121
23
+ openstef/feature_engineering/apply_features.py,sha256=9Yzg61Whd4n0osQBfrcW8cI0gaUiv7u8KnQIQPR40fY,5327
24
24
  openstef/feature_engineering/bidding_zone_to_country_mapping.py,sha256=u9aabjFDImydkO6_cXiaQxBT4gb5zy0gGTg2EoIUO_Y,2106
25
25
  openstef/feature_engineering/cyclic_features.py,sha256=0Z3wZeF_qrkmEcOq91gtdSMZucAq99kUoBuFDV0SHqk,5962
26
26
  openstef/feature_engineering/data_preparation.py,sha256=htca9LBO3ZN1D-iX4vXf0UN1fw_rRO7y6N3AuYVMpfk,5628
27
27
  openstef/feature_engineering/feature_adder.py,sha256=aSqDl_gUrB3H2TD3cNvU5JniY_KOb4u4a2A6J7zB2BQ,6835
28
- openstef/feature_engineering/feature_applicator.py,sha256=DR7jayrEMlra4BFL1Ps5WV2fxbkQ6VaOTa5RIKM-YNk,7447
28
+ openstef/feature_engineering/feature_applicator.py,sha256=bU1Pu5V1fxMCQCwh6HG66nmctBjrNa7gHUYqOqPmLTU,7501
29
29
  openstef/feature_engineering/general.py,sha256=tgU4_1stag9jJmaQAfWCMhfBscznVuQvW5hPK_z9_9g,4438
30
30
  openstef/feature_engineering/holiday_features.py,sha256=CbolIP5bfiQkqDct-9TbD828-lhC48bfeNQ2-VFnsJA,8274
31
31
  openstef/feature_engineering/lag_features.py,sha256=Dr6qS8UhdgEHPZZSe-w6ibtjl_lcbcQohhqdZN9fqEU,5652
32
32
  openstef/feature_engineering/missing_values_transformer.py,sha256=o_zCVEOCPn2tWzvlY44XZuDysV0TuxqeVYhilYU54YY,5010
33
+ openstef/feature_engineering/rolling_features.py,sha256=596UWr0VIEgD2t5UhgPRjvOvcUI9v477M9yRaoYsnSk,1536
33
34
  openstef/feature_engineering/weather_features.py,sha256=Lr9DItyHvJ2CpWQ1r6A83tJKtR2k_Wwn32FdFTGblO0,15750
34
35
  openstef/metrics/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
35
36
  openstef/metrics/figure.py,sha256=KDoezYem9wdS13kUx7M7FOy-4u88Sg3OX1DuhNT6kgQ,9751
@@ -56,7 +57,7 @@ openstef/model/regressors/flatliner.py,sha256=T9u-ukhqFcatQmlgUtBL_G-1b_wQzgdVRq
56
57
  openstef/model/regressors/gblinear_quantile.py,sha256=DSRjL_kadBfDKrDEgrOfU1N60grTiAovtcBszBa41TI,11271
57
58
  openstef/model/regressors/lgbm.py,sha256=zCdn1euEdSFxYJzH8XqQFFnb6R4JVUnmineKjX_Gy-g,800
58
59
  openstef/model/regressors/linear.py,sha256=uOvZMLGZH_9nXfmS5honCMfyVeyGXP1Cza9A_BdXlVw,3665
59
- openstef/model/regressors/linear_quantile.py,sha256=VAyIhp7GPayqbk8Vj_ONqPLNYuaOvxkFKDrRxx6yGY0,10510
60
+ openstef/model/regressors/linear_quantile.py,sha256=sI5cl6_W-hh13mg4Gf09LQ1caZmBy7COc8_5BBJxySQ,10534
60
61
  openstef/model/regressors/regressor.py,sha256=uJcx59AyCPE9f_yPcAQ59h2ZS7eNsDpIHJrladKvHIw,3461
61
62
  openstef/model/regressors/xgb.py,sha256=SH-UiYJtMbfmRBK6738dU0ZRfYfzNynnikwbxINCE7Q,1467
62
63
  openstef/model/regressors/xgb_multioutput_quantile.py,sha256=xWzA7tymC_o-F1OS3I7vUKf9zP6RR1ZglEeY4NAgjU0,9146
@@ -81,21 +82,21 @@ openstef/preprocessing/preprocessing.py,sha256=bM_cSSSb2vGTD79RGzUrI6KoELbzlCyJw
81
82
  openstef/tasks/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
82
83
  openstef/tasks/calculate_kpi.py,sha256=O8m-K7lmkU3tY2H4E3gLqRAhhALZ75Y18x8Y_-D8Htw,11876
83
84
  openstef/tasks/create_basecase_forecast.py,sha256=rexAt6jGbW3YTXvDo606rzJvYETCoLVYCsBRihZas9U,4213
84
- openstef/tasks/create_components_forecast.py,sha256=Gyhrb_l3HGLBD5loUZt_3bYoPqMlmcVGJbEd5I8_A38,6155
85
- openstef/tasks/create_forecast.py,sha256=gLH3Z-t3fkFjYUyxiLXlywZ2fd9Dnhqq84C0UEO31g4,5766
85
+ openstef/tasks/create_components_forecast.py,sha256=bhBVN1v8mhBQhYP1fBfbhag58DmQlxSKDTSz5YfTYGc,6179
86
+ openstef/tasks/create_forecast.py,sha256=OOXfM3wTPEMa5CnlFPXNPe9kNN4LQG-3fHbeAUsiOKo,6096
86
87
  openstef/tasks/create_solar_forecast.py,sha256=cZiIoCVHlLlDrsWeH3ZX4zfcMMrgGgqkG2CmbCp8lqM,15074
87
88
  openstef/tasks/create_wind_forecast.py,sha256=RhshkmNSyFWx4Y6yQn02GzHjWTREbN5A5GAeWv0JpcE,2907
88
89
  openstef/tasks/optimize_hyperparameters.py,sha256=meiOn5S4yBrk5ANCFwcBCfTZIhm-b1rdh9TFh7KFr3E,4754
89
90
  openstef/tasks/split_forecast.py,sha256=AF_AwFcD6BqOrfvNLhIm_8gb7SpyKxEx60mymoxohPg,9323
90
- openstef/tasks/train_model.py,sha256=o8QVPReJ71BZVCOL6Rs3PFD9Zg4LT16dPcbf87xnXpA,8494
91
+ openstef/tasks/train_model.py,sha256=PLkZMMZppsHuc2miCKDeVKoPhrwZi68xXL0axH2cDoA,8518
91
92
  openstef/tasks/utils/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
92
93
  openstef/tasks/utils/dependencies.py,sha256=Jy9dtV_G7lTEa5Cdy--wvMxJuAb0adb3R0X4QDjVteM,3077
93
94
  openstef/tasks/utils/predictionjobloop.py,sha256=Ysy3zF5lzPMz_asYDKeF5m0qgVT3tCtwSPihqMjnI5Q,9580
94
95
  openstef/tasks/utils/taskcontext.py,sha256=L9K14ycwgVxbIVUjH2DIn_QWbnu-OfxcGtQ1K9T6sus,5630
95
96
  openstef/validation/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
96
- openstef/validation/validation.py,sha256=HVgreHvcZvPazfwC3NNE8_3lsMsZEd_42osCAg1_6W4,11128
97
- openstef-3.4.53.dist-info/LICENSE,sha256=7Pm2fWFFHHUG5lDHed1vl5CjzxObIXQglnYsEdtjo_k,14907
98
- openstef-3.4.53.dist-info/METADATA,sha256=MCAC7JnwfKToob21A5_a-eFE4CkG7PJ3Wov0BIDJ6Uc,8305
99
- openstef-3.4.53.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
100
- openstef-3.4.53.dist-info/top_level.txt,sha256=kD0H4PqrQoncZ957FvqwfBxa89kTrun4Z_RAPs_HhLs,9
101
- openstef-3.4.53.dist-info/RECORD,,
97
+ openstef/validation/validation.py,sha256=6FY-mD7bWxM7NpM9y-RcGZJt-kyyOmPl8QSemYRY11w,11200
98
+ openstef-3.4.55.dist-info/LICENSE,sha256=7Pm2fWFFHHUG5lDHed1vl5CjzxObIXQglnYsEdtjo_k,14907
99
+ openstef-3.4.55.dist-info/METADATA,sha256=c9Fc6xo3AyhI00vDWHrEzuFsCXfJbdPKAAgMRJ8DYcY,8305
100
+ openstef-3.4.55.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
101
+ openstef-3.4.55.dist-info/top_level.txt,sha256=kD0H4PqrQoncZ957FvqwfBxa89kTrun4Z_RAPs_HhLs,9
102
+ openstef-3.4.55.dist-info/RECORD,,