openstef 3.4.64__tar.gz → 3.4.65__tar.gz
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.
- {openstef-3.4.64 → openstef-3.4.65}/PKG-INFO +1 -1
- {openstef-3.4.64 → openstef-3.4.65}/openstef/data_classes/prediction_job.py +4 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/exceptions.py +2 -2
- {openstef-3.4.64 → openstef-3.4.65}/openstef/pipeline/create_basecase_forecast.py +3 -3
- {openstef-3.4.64 → openstef-3.4.65}/openstef/pipeline/create_forecast.py +3 -2
- {openstef-3.4.64 → openstef-3.4.65}/openstef/pipeline/optimize_hyperparameters.py +2 -1
- {openstef-3.4.64 → openstef-3.4.65}/openstef/pipeline/train_create_forecast_backtest.py +1 -1
- {openstef-3.4.64 → openstef-3.4.65}/openstef/pipeline/train_model.py +4 -3
- {openstef-3.4.64 → openstef-3.4.65}/openstef/tasks/create_forecast.py +8 -8
- {openstef-3.4.64 → openstef-3.4.65}/openstef/tasks/train_model.py +6 -6
- {openstef-3.4.64 → openstef-3.4.65}/openstef/validation/validation.py +36 -13
- {openstef-3.4.64 → openstef-3.4.65}/openstef.egg-info/PKG-INFO +1 -1
- {openstef-3.4.64 → openstef-3.4.65}/setup.py +1 -1
- {openstef-3.4.64 → openstef-3.4.65}/LICENSE +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/README.md +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/__main__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/app_settings.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/data/NL_terrestrial_radiation.csv +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/data/NL_terrestrial_radiation.csv.license +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/data/dazls_model_3.4.24/dazls_stored_3.4.24_baseline_model.z +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/data/dazls_model_3.4.24/dazls_stored_3.4.24_baseline_model.z.license +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/data/dazls_model_3.4.24/dazls_stored_3.4.24_model_card.md +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/data/dazls_model_3.4.24/dazls_stored_3.4.24_model_card.md.license +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/data/dutch_holidays.csv +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/data/dutch_holidays.csv.license +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/data/pv_single_coefs.csv +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/data/pv_single_coefs.csv.license +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/data_classes/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/data_classes/data_prep.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/data_classes/model_specifications.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/data_classes/split_function.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/enums.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/feature_engineering/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/feature_engineering/apply_features.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/feature_engineering/bidding_zone_to_country_mapping.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/feature_engineering/cyclic_features.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/feature_engineering/data_preparation.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/feature_engineering/feature_adder.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/feature_engineering/feature_applicator.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/feature_engineering/general.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/feature_engineering/holiday_features.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/feature_engineering/lag_features.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/feature_engineering/missing_values_transformer.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/feature_engineering/rolling_features.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/feature_engineering/weather_features.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/metrics/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/metrics/figure.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/metrics/metrics.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/metrics/reporter.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/basecase.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/confidence_interval_applicator.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/fallback.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/metamodels/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/metamodels/feature_clipper.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/metamodels/grouped_regressor.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/metamodels/missing_values_handler.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/model_creator.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/objective.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/objective_creator.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/regressors/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/regressors/arima.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/regressors/custom_regressor.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/regressors/dazls.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/regressors/flatliner.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/regressors/gblinear_quantile.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/regressors/lgbm.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/regressors/linear.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/regressors/linear_quantile.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/regressors/regressor.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/regressors/xgb.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/regressors/xgb_multioutput_quantile.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/regressors/xgb_quantile.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/serializer.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model/standard_deviation_generator.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model_selection/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/model_selection/model_selection.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/monitoring/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/monitoring/performance_meter.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/monitoring/teams.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/pipeline/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/pipeline/create_component_forecast.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/pipeline/utils.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/plotting/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/plotting/load_forecast_plotter.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/postprocessing/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/postprocessing/postprocessing.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/preprocessing/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/preprocessing/preprocessing.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/settings.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/tasks/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/tasks/calculate_kpi.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/tasks/create_basecase_forecast.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/tasks/create_components_forecast.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/tasks/create_solar_forecast.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/tasks/create_wind_forecast.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/tasks/optimize_hyperparameters.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/tasks/split_forecast.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/tasks/utils/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/tasks/utils/dependencies.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/tasks/utils/predictionjobloop.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/tasks/utils/taskcontext.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef/validation/__init__.py +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef.egg-info/SOURCES.txt +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef.egg-info/dependency_links.txt +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef.egg-info/requires.txt +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/openstef.egg-info/top_level.txt +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/pyproject.toml +0 -0
- {openstef-3.4.64 → openstef-3.4.65}/setup.cfg +0 -0
@@ -96,6 +96,10 @@ class PredictionJobDataClass(BaseModel):
|
|
96
96
|
1440,
|
97
97
|
description="Number of minutes that the load has to be constant to detect a flatliner.",
|
98
98
|
)
|
99
|
+
detect_non_zero_flatliner: bool = Field(
|
100
|
+
False,
|
101
|
+
description="If True, flatliners are also detected on non-zero values (median of the load).",
|
102
|
+
)
|
99
103
|
data_balancing_ratio: Optional[float] = Field(
|
100
104
|
None,
|
101
105
|
description="If data balancing is enabled, the data will be balanced with data from 1 year ago in the future.",
|
@@ -44,8 +44,8 @@ class InputDataWrongColumnOrderError(InputDataInvalidError):
|
|
44
44
|
"""Wrong column order input data."""
|
45
45
|
|
46
46
|
|
47
|
-
class
|
48
|
-
"""All recent load measurements are
|
47
|
+
class InputDataOngoingFlatlinerError(InputDataInvalidError):
|
48
|
+
"""All recent load measurements are constant."""
|
49
49
|
|
50
50
|
|
51
51
|
class OldModelHigherScoreError(Exception):
|
@@ -8,7 +8,7 @@ import pandas as pd
|
|
8
8
|
import structlog
|
9
9
|
|
10
10
|
from openstef.data_classes.prediction_job import PredictionJobDataClass
|
11
|
-
from openstef.exceptions import
|
11
|
+
from openstef.exceptions import NoRealisedLoadError
|
12
12
|
from openstef.feature_engineering.feature_applicator import (
|
13
13
|
OperationalPredictFeatureApplicator,
|
14
14
|
)
|
@@ -58,12 +58,12 @@ def create_basecase_forecast_pipeline(
|
|
58
58
|
if not isinstance(input_data.index, pd.DatetimeIndex):
|
59
59
|
raise ValueError("Input dataframe does not have a datetime index.")
|
60
60
|
|
61
|
-
|
61
|
+
flatliner_ongoing = validation.detect_ongoing_flatliner(
|
62
62
|
load=input_data.iloc[:, 0],
|
63
63
|
duration_threshold_minutes=pj.flatliner_threshold_minutes,
|
64
64
|
)
|
65
65
|
|
66
|
-
if
|
66
|
+
if flatliner_ongoing:
|
67
67
|
# Set historic load to zero to force the basecase forecasts to be zero.
|
68
68
|
input_data.loc[input_data.index < forecast_start, "load"] = 0
|
69
69
|
|
@@ -45,7 +45,7 @@ def create_forecast_pipeline(
|
|
45
45
|
DataFrame with the forecast
|
46
46
|
|
47
47
|
Raises:
|
48
|
-
|
48
|
+
InputDataOngoingFlatlinerError: When all recent load measurements are constant.
|
49
49
|
LookupError: When no model is found for the given prediction job in MLflow.
|
50
50
|
|
51
51
|
"""
|
@@ -85,7 +85,7 @@ def create_forecast_pipeline_core(
|
|
85
85
|
Forecast
|
86
86
|
|
87
87
|
Raises:
|
88
|
-
|
88
|
+
InputDataOngoingFlatlinerError: When all recent load measurements are constant.
|
89
89
|
|
90
90
|
"""
|
91
91
|
structlog.configure(
|
@@ -103,6 +103,7 @@ def create_forecast_pipeline_core(
|
|
103
103
|
input_data,
|
104
104
|
pj["flatliner_threshold_minutes"],
|
105
105
|
pj["resolution_minutes"],
|
106
|
+
detect_non_zero_flatliner=pj["detect_non_zero_flatliner"],
|
106
107
|
)
|
107
108
|
|
108
109
|
# Custom data prep or legacy behavior
|
@@ -132,7 +132,7 @@ def optimize_hyperparameters_pipeline_core(
|
|
132
132
|
InputDataInsufficientError: If the input dataframe is empty.
|
133
133
|
InputDataWrongColumnOrderError: If the load column is missing in the input dataframe.
|
134
134
|
OldModelHigherScoreError: When old model is better than new model.
|
135
|
-
|
135
|
+
InputDataOngoingFlatlinerError: If all recent load measurements are constant.
|
136
136
|
|
137
137
|
Returns:
|
138
138
|
- Best model,
|
@@ -157,6 +157,7 @@ def optimize_hyperparameters_pipeline_core(
|
|
157
157
|
input_data,
|
158
158
|
pj["flatliner_threshold_minutes"],
|
159
159
|
pj["resolution_minutes"],
|
160
|
+
detect_non_zero_flatliner=pj["detect_non_zero_flatliner"],
|
160
161
|
)
|
161
162
|
)
|
162
163
|
|
@@ -60,7 +60,7 @@ def train_model_and_forecast_back_test(
|
|
60
60
|
InputDataInsufficientError: when input data is insufficient.
|
61
61
|
InputDataWrongColumnOrderError: when input data has a invalid column order.
|
62
62
|
ValueError: when the horizon is a string and the corresponding column in not in the input data
|
63
|
-
|
63
|
+
InputDataOngoingFlatlinerError: If all recent load measurements are constant.
|
64
64
|
|
65
65
|
"""
|
66
66
|
if pj.backtest_split_func is None:
|
@@ -177,7 +177,7 @@ def train_model_pipeline_core(
|
|
177
177
|
InputDataInsufficientError: when input data is insufficient.
|
178
178
|
InputDataWrongColumnOrderError: when input data has a invalid column order.
|
179
179
|
OldModelHigherScoreError: When old model is better than new model.
|
180
|
-
|
180
|
+
InputDataOngoingFlatlinerError: If all recent load measurements are constant.
|
181
181
|
|
182
182
|
Returns:
|
183
183
|
- Fitted_model (OpenstfRegressor)
|
@@ -272,7 +272,7 @@ def train_pipeline_common(
|
|
272
272
|
InputDataInsufficientError: when input data is insufficient.
|
273
273
|
InputDataWrongColumnOrderError: when input data has a invalid column order.
|
274
274
|
'load' column should be first and 'horizon' column last.
|
275
|
-
|
275
|
+
InputDataOngoingFlatlinerError: If all recent load measurements are constant.
|
276
276
|
|
277
277
|
"""
|
278
278
|
data_with_features = train_pipeline_step_compute_features(
|
@@ -363,7 +363,7 @@ def train_pipeline_step_compute_features(
|
|
363
363
|
InputDataInsufficientError: when input data is insufficient.
|
364
364
|
InputDataWrongColumnOrderError: when input data has a invalid column order.
|
365
365
|
ValueError: when the horizon is a string and the corresponding column in not in the input data
|
366
|
-
|
366
|
+
InputDataOngoingFlatlinerError: If all recent load measurements are constant.
|
367
367
|
|
368
368
|
"""
|
369
369
|
if input_data.empty:
|
@@ -389,6 +389,7 @@ def train_pipeline_step_compute_features(
|
|
389
389
|
input_data,
|
390
390
|
pj["flatliner_threshold_minutes"],
|
391
391
|
pj["resolution_minutes"],
|
392
|
+
detect_non_zero_flatliner=pj["detect_non_zero_flatliner"],
|
392
393
|
)
|
393
394
|
)
|
394
395
|
# Check if sufficient data is left after cleaning
|
@@ -25,11 +25,11 @@ from pathlib import Path
|
|
25
25
|
|
26
26
|
from openstef.data_classes.prediction_job import PredictionJobDataClass
|
27
27
|
from openstef.enums import BiddingZone, ModelType, PipelineType
|
28
|
-
from openstef.exceptions import
|
28
|
+
from openstef.exceptions import InputDataOngoingFlatlinerError
|
29
29
|
from openstef.pipeline.create_forecast import create_forecast_pipeline
|
30
30
|
from openstef.tasks.utils.predictionjobloop import PredictionJobLoop
|
31
31
|
from openstef.tasks.utils.taskcontext import TaskContext
|
32
|
-
from openstef.validation.validation import
|
32
|
+
from openstef.validation.validation import detect_ongoing_flatliner
|
33
33
|
|
34
34
|
T_BEHIND_DAYS: int = 14
|
35
35
|
|
@@ -94,7 +94,7 @@ def create_forecast_task(
|
|
94
94
|
forecast = create_forecast_pipeline(
|
95
95
|
pj, input_data, mlflow_tracking_uri=mlflow_tracking_uri
|
96
96
|
)
|
97
|
-
except (
|
97
|
+
except (InputDataOngoingFlatlinerError, LookupError) as e:
|
98
98
|
if (
|
99
99
|
context.config.known_zero_flatliners
|
100
100
|
and pj.id in context.config.known_zero_flatliners
|
@@ -103,18 +103,18 @@ def create_forecast_task(
|
|
103
103
|
"No forecasts were made for this known zero flatliner prediction job. No forecasts need to be made either, since the fallback forecasts are sufficient."
|
104
104
|
)
|
105
105
|
return
|
106
|
-
elif isinstance(e,
|
107
|
-
raise
|
108
|
-
'All recent load measurements are
|
106
|
+
elif isinstance(e, InputDataOngoingFlatlinerError):
|
107
|
+
raise InputDataOngoingFlatlinerError(
|
108
|
+
'All recent load measurements are constant. Check the load profile of this pid as well as related/neighbouring prediction jobs. Afterwards, consider adding this pid to the "known_zero_flatliners" app_setting and possibly removing other pids from the same app_setting.'
|
109
109
|
) from e
|
110
110
|
elif isinstance(e, LookupError):
|
111
|
-
zero_flatliner_ongoing =
|
111
|
+
zero_flatliner_ongoing = detect_ongoing_flatliner(
|
112
112
|
load=input_data.iloc[:, 0],
|
113
113
|
duration_threshold_minutes=pj.flatliner_threshold_minutes,
|
114
114
|
)
|
115
115
|
if zero_flatliner_ongoing:
|
116
116
|
raise LookupError(
|
117
|
-
'Model not found. Consider checking for a
|
117
|
+
'Model not found. Consider checking for a flatliner and adding this pid to the "known_zero_flatliners" app_setting. For flatliners, no model can be trained.'
|
118
118
|
) from e
|
119
119
|
else:
|
120
120
|
raise e
|
@@ -27,7 +27,7 @@ import pandas as pd
|
|
27
27
|
from openstef.data_classes.prediction_job import PredictionJobDataClass
|
28
28
|
from openstef.enums import ModelType, PipelineType
|
29
29
|
from openstef.exceptions import (
|
30
|
-
|
30
|
+
InputDataOngoingFlatlinerError,
|
31
31
|
SkipSaveTrainingForecasts,
|
32
32
|
)
|
33
33
|
from openstef.model.serializer import MLflowSerializer
|
@@ -67,7 +67,7 @@ def train_model_task(
|
|
67
67
|
|
68
68
|
Raises:
|
69
69
|
SkipSaveTrainingForecasts: If old model is better or too young, you don't need to save the traing forcast.
|
70
|
-
|
70
|
+
InputDataOngoingFlatlinerError: If all recent load measurements are constant.
|
71
71
|
|
72
72
|
"""
|
73
73
|
# Check pipeline types
|
@@ -187,18 +187,18 @@ def train_model_task(
|
|
187
187
|
context.logger.debug("Saved Forecasts from trained model on datasets")
|
188
188
|
except SkipSaveTrainingForecasts:
|
189
189
|
context.logger.debug("Skip saving forecasts")
|
190
|
-
except
|
190
|
+
except InputDataOngoingFlatlinerError:
|
191
191
|
if (
|
192
192
|
context.config.known_zero_flatliners
|
193
193
|
and pj.id in context.config.known_zero_flatliners
|
194
194
|
):
|
195
195
|
context.logger.info(
|
196
|
-
"No model was trained for this known
|
196
|
+
"No model was trained for this known flatliner. No model needs to be trained either, since the fallback forecasts are sufficient."
|
197
197
|
)
|
198
198
|
return
|
199
199
|
else:
|
200
|
-
raise
|
201
|
-
'All recent load measurements are
|
200
|
+
raise InputDataOngoingFlatlinerError(
|
201
|
+
'All recent load measurements are constant. Check the load profile of this pid as well as related/neighbouring prediction jobs. Afterwards, consider adding this pid to the "known_zero_flatliners" app_setting and possibly removing other pids from the same app_setting.'
|
202
202
|
)
|
203
203
|
|
204
204
|
|
@@ -10,7 +10,8 @@ import numpy as np
|
|
10
10
|
import pandas as pd
|
11
11
|
import structlog
|
12
12
|
|
13
|
-
from openstef.
|
13
|
+
from openstef.data_classes.prediction_job import PredictionJobDataClass
|
14
|
+
from openstef.exceptions import InputDataOngoingFlatlinerError
|
14
15
|
from openstef.model.regressors.regressor import OpenstfRegressor
|
15
16
|
from openstef.preprocessing.preprocessing import replace_repeated_values_with_nan
|
16
17
|
from openstef.settings import Settings
|
@@ -21,12 +22,15 @@ def validate(
|
|
21
22
|
data: pd.DataFrame,
|
22
23
|
flatliner_threshold_minutes: Union[int, None],
|
23
24
|
resolution_minutes: int,
|
25
|
+
*,
|
26
|
+
detect_non_zero_flatliner: bool = False,
|
24
27
|
) -> pd.DataFrame:
|
25
28
|
"""Validate prediction job and timeseries data.
|
26
29
|
|
27
30
|
Steps:
|
28
31
|
1. Check if input dataframe has a datetime index.
|
29
|
-
1. Check if a
|
32
|
+
1. Check if a flatliner pattern is ongoing (i.e. all recent measurements are constant,
|
33
|
+
0 in case detect_non_zero_flatliner = True).
|
30
34
|
2. Replace repeated values for longer than flatliner_threshold_minutes with NaN.
|
31
35
|
|
32
36
|
Args:
|
@@ -35,12 +39,14 @@ def validate(
|
|
35
39
|
flatliner_threshold_minutes: int indicating the number of minutes after which constant load is considered a flatline.
|
36
40
|
if None, the validation is effectively skipped
|
37
41
|
resolution_minutes: The forecasting resolution in minutes.
|
42
|
+
detect_non_zero_flatliner: If True, a flatliner is detected for non-zero values. If False,
|
43
|
+
a flatliner is detected for zero values only.
|
38
44
|
|
39
45
|
Returns:
|
40
46
|
Dataframe where repeated values are set to None
|
41
47
|
|
42
48
|
Raises:
|
43
|
-
|
49
|
+
InputDataOngoingFlatlinerError: If all recent load measurements are constant.
|
44
50
|
|
45
51
|
"""
|
46
52
|
structlog.configure(
|
@@ -57,13 +63,15 @@ def validate(
|
|
57
63
|
logger.info("Skipping validation of input data", pj_id=pj_id)
|
58
64
|
return data
|
59
65
|
|
60
|
-
|
61
|
-
load=data.iloc[:, 0],
|
66
|
+
flatliner_ongoing = detect_ongoing_flatliner(
|
67
|
+
load=data.iloc[:, 0],
|
68
|
+
duration_threshold_minutes=flatliner_threshold_minutes,
|
69
|
+
detect_non_zero_flatliner=detect_non_zero_flatliner,
|
62
70
|
)
|
63
71
|
|
64
|
-
if
|
65
|
-
raise
|
66
|
-
"All recent load measurements are
|
72
|
+
if flatliner_ongoing:
|
73
|
+
raise InputDataOngoingFlatlinerError(
|
74
|
+
"All recent load measurements are constant."
|
67
75
|
)
|
68
76
|
|
69
77
|
flatliner_threshold_repetitions = math.ceil(
|
@@ -228,18 +236,22 @@ def calc_completeness_features(
|
|
228
236
|
return completeness
|
229
237
|
|
230
238
|
|
231
|
-
def
|
239
|
+
def detect_ongoing_flatliner(
|
232
240
|
load: pd.Series,
|
233
241
|
duration_threshold_minutes: int,
|
242
|
+
*,
|
243
|
+
detect_non_zero_flatliner: bool = False,
|
234
244
|
) -> bool:
|
235
|
-
"""Detects if the latest measurements follow a
|
245
|
+
"""Detects if the latest measurements follow a flatliner pattern.
|
236
246
|
|
237
247
|
Args:
|
238
248
|
load (pd.Series): A timeseries of measured load with a datetime index.
|
239
|
-
duration_threshold_minutes (int): A
|
249
|
+
duration_threshold_minutes (int): A flatliner is only detected if it exceeds the threshold duration.
|
250
|
+
detect_non_zero_flatliner (bool): If True, a flatliner is detected for non-zero values. If False,
|
251
|
+
a flatliner is detected for zero values only.
|
240
252
|
|
241
253
|
Returns:
|
242
|
-
bool: Indicating whether or not there is a
|
254
|
+
bool: Indicating whether or not there is a flatliner ongoing for the given load.
|
243
255
|
|
244
256
|
"""
|
245
257
|
# remove all timestamps in the future
|
@@ -249,7 +261,18 @@ def detect_ongoing_zero_flatliner(
|
|
249
261
|
latest_measurement_time - timedelta(minutes=duration_threshold_minutes) :
|
250
262
|
].dropna()
|
251
263
|
|
252
|
-
|
264
|
+
flatliner_value = latest_measurements.median() if detect_non_zero_flatliner else 0
|
265
|
+
|
266
|
+
# check if all values are within a relative tolerance of each other
|
267
|
+
flatline_condition = np.isclose(
|
268
|
+
latest_measurements,
|
269
|
+
flatliner_value,
|
270
|
+
atol=0,
|
271
|
+
rtol=1e-5,
|
272
|
+
).all()
|
273
|
+
non_empty_condition = not latest_measurements.empty
|
274
|
+
|
275
|
+
return flatline_condition & non_empty_condition
|
253
276
|
|
254
277
|
|
255
278
|
def calc_completeness_dataframe(
|
@@ -33,7 +33,7 @@ def read_long_description_from_readme():
|
|
33
33
|
|
34
34
|
setup(
|
35
35
|
name="openstef",
|
36
|
-
version="3.4.
|
36
|
+
version="3.4.65",
|
37
37
|
packages=find_packages(include=["openstef", "openstef.*"]),
|
38
38
|
description="Open short term energy forecaster",
|
39
39
|
long_description=read_long_description_from_readme(),
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{openstef-3.4.64 → openstef-3.4.65}/openstef/feature_engineering/bidding_zone_to_country_mapping.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{openstef-3.4.64 → openstef-3.4.65}/openstef/feature_engineering/missing_values_transformer.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|