openstef 3.4.62__py3-none-any.whl → 3.4.64__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.
@@ -306,7 +306,7 @@ class GBLinearQuantileOpenstfRegressor(OpenstfRegressor):
306
306
  feature_names = booster.feature_names
307
307
 
308
308
  # Get importance
309
- feature_importance = [score.get(f, 0.0) for f in feature_names]
309
+ feature_importance = [np.abs(score.get(f, 0.0)) for f in feature_names]
310
310
  # Convert to array
311
311
  features_importance_array = np.array(feature_importance, dtype=np.float32)
312
312
 
@@ -0,0 +1,3 @@
1
+ # SPDX-FileCopyrightText: 2017-2025 Contributors to the OpenSTEF project <korte.termijn.prognoses@alliander.com> # noqa E501>
2
+ #
3
+ # SPDX-License-Identifier: MPL-2.0
@@ -0,0 +1,216 @@
1
+ # SPDX-FileCopyrightText: 2017-2025 Contributors to the OpenSTEF project <korte.termijn.prognoses@alliander.com> # noqa E501>
2
+ #
3
+ # SPDX-License-Identifier: MPL-2.0
4
+
5
+ from typing import Tuple, Optional
6
+
7
+ import numpy as np
8
+ from pydantic import BaseModel
9
+ import pandas as pd
10
+ import plotly.graph_objects as go
11
+ import plotly.express as px
12
+
13
+
14
+ class LoadForecastPlotter(BaseModel):
15
+ colormap: str = "Blues"
16
+ colormap_range: Tuple[float, float] = (0.2, 0.8)
17
+
18
+ fill_opacity: float = 0.5
19
+ stroke_opacity: float = 0.8
20
+ stroke_width: float = 1.5
21
+
22
+ def _get_color_by_value(self, value: float) -> str:
23
+ """Maps a normalized value to a color using the specified colormap.
24
+
25
+ Args:
26
+ value (float): A value between 0 and 1 to be mapped to a color.
27
+
28
+ Returns:
29
+ str: A color in the rgba format.
30
+ """
31
+ rescaled = self.colormap_range[0] + value * (
32
+ self.colormap_range[1] - self.colormap_range[0]
33
+ )
34
+ rescaled = min(1.0, max(0.0, rescaled))
35
+
36
+ return px.colors.sample_colorscale(
37
+ colorscale=self.colormap, samplepoints=[rescaled]
38
+ )[0]
39
+
40
+ def _get_quantile_colors(self, quantile: float) -> Tuple[str, str]:
41
+ """Generate fill and stroke colors for a given quantile using a colorscale.
42
+
43
+ Colors are determined based on the distance from the median (50th percentile).
44
+
45
+ Args:
46
+ quantile (float): The quantile value (0-100) to generate colors for.
47
+
48
+ Returns:
49
+ Tuple[str, str]: A tuple containing (fill_color, stroke_color).
50
+ """
51
+ fill_value = 1 - abs(quantile - 50.0) / 50.0
52
+ stroke_value = 1 - abs(quantile + 5.0 - 50.0) / 50.0
53
+ return (
54
+ self._get_color_by_value(fill_value),
55
+ self._get_color_by_value(stroke_value),
56
+ )
57
+
58
+ def _add_quantile_band(
59
+ self,
60
+ figure: go.Figure,
61
+ lower_quantile_data: pd.Series,
62
+ lower_quantile: float,
63
+ upper_quantile_data: pd.Series,
64
+ upper_quantile: float,
65
+ ):
66
+ """Add a quantile band to the plotly figure.
67
+
68
+ Creates a filled polygon representing the area between lower and upper quantiles,
69
+ and adds it to the provided figure along with hover information.
70
+
71
+ Args:
72
+ figure (go.Figure): The plotly figure to add the quantile band to.
73
+ lower_quantile_data (pd.Series): Series with data for the lower quantile.
74
+ lower_quantile (float): The percentile value of the lower quantile.
75
+ upper_quantile_data (pd.Series): Series with data for the upper quantile.
76
+ upper_quantile (float): The percentile value of the upper quantile.
77
+
78
+ Returns:
79
+ None: The figure is modified in place.
80
+ """
81
+ # Create polygon shape for the quantile band in counterclockwise order
82
+ x = list(lower_quantile_data.index) + list(upper_quantile_data.index[::-1])
83
+ y = list(lower_quantile_data) + list(upper_quantile_data[::-1])
84
+
85
+ # Get colors for the band
86
+ fill_color, stroke_color = self._get_quantile_colors(lower_quantile)
87
+
88
+ # Group traces by quantile range
89
+ legendgroup = f"quantile_{lower_quantile}_{upper_quantile}"
90
+
91
+ # Add a single trace that forms a filled polygon
92
+ figure.add_trace(
93
+ go.Scatter(
94
+ x=x,
95
+ y=y,
96
+ fill="toself",
97
+ fillcolor=f"rgba{fill_color[3:-1]}, {self.fill_opacity})",
98
+ line=dict(
99
+ color=f"rgba{stroke_color[3:-1]}, {self.stroke_opacity})",
100
+ width=self.stroke_width,
101
+ ),
102
+ name=f"{lower_quantile}%-{upper_quantile}%",
103
+ showlegend=True,
104
+ hoverinfo="skip",
105
+ legendgroup=legendgroup,
106
+ )
107
+ )
108
+
109
+ # Add an (invisible) line around the filled area to make quantile
110
+ # values selectable/hover-able.
111
+ # Hovering on filled area values is not supported by plotly.
112
+ figure.add_trace(
113
+ go.Scatter(
114
+ x=lower_quantile_data.index,
115
+ y=lower_quantile_data.values,
116
+ mode="lines",
117
+ line=dict(
118
+ width=self.stroke_width,
119
+ color=f"rgba{stroke_color[3:-1]}, {self.stroke_opacity})",
120
+ ),
121
+ customdata=np.column_stack(
122
+ (lower_quantile_data.values, upper_quantile_data.values)
123
+ ),
124
+ hovertemplate=(
125
+ f"{lower_quantile}%: %{{customdata[0]:,.4s}}<br>"
126
+ f"{upper_quantile}%: %{{customdata[1]:,.4s}}"
127
+ "<extra></extra>"
128
+ ),
129
+ name=f"{lower_quantile}%-{upper_quantile}% Hover Info",
130
+ showlegend=False,
131
+ legendgroup=legendgroup,
132
+ )
133
+ )
134
+
135
+ def plot(
136
+ self,
137
+ realized: Optional[pd.Series] = None,
138
+ forecast: Optional[pd.Series] = None,
139
+ quantiles: Optional[pd.DataFrame] = None,
140
+ ):
141
+ """Create a plot showing forecast quantiles and realized values.
142
+
143
+ Generates an interactive plotly figure displaying the forecast distribution
144
+ through quantile bands, the median forecast, and the actual realized values.
145
+
146
+ Args:
147
+ realized (pd.Series): Time series of realized (actual) values.
148
+ forecast (pd.Series): Time series of forecast values (typically the median).
149
+ quantiles (pd.DataFrame): DataFrame containing quantile predictions.
150
+ Column names should follow the format 'quantile_P{percentile:02d}',
151
+ e.g., 'quantile_P10', 'quantile_P90'.
152
+
153
+ Returns:
154
+ go.Figure: A plotly figure object with the configured visualization.
155
+ """
156
+ figure = go.Figure()
157
+
158
+ if quantiles is not None:
159
+ # Extract and sort quantile percentages
160
+ quantile_cols = [
161
+ col for col in quantiles.columns if col.startswith("quantile_P")
162
+ ]
163
+ percentiles = sorted([int(col.split("P")[1]) for col in quantile_cols])
164
+
165
+ # Add quantile bands from widest to narrowest
166
+ for i in range(len(percentiles) // 2):
167
+ lower_quantile, upper_quantile = percentiles[i], percentiles[-(i + 1)]
168
+ if float(lower_quantile) == 50.0:
169
+ continue
170
+
171
+ self._add_quantile_band(
172
+ figure=figure,
173
+ lower_quantile_data=quantiles[f"quantile_P{lower_quantile:02d}"],
174
+ lower_quantile=lower_quantile,
175
+ upper_quantile_data=quantiles[f"quantile_P{upper_quantile:02d}"],
176
+ upper_quantile=upper_quantile,
177
+ )
178
+
179
+ if forecast is not None:
180
+ # Add forecast line (50th percentile)
181
+ figure.add_trace(
182
+ go.Scatter(
183
+ x=forecast.index,
184
+ y=forecast,
185
+ mode="lines",
186
+ line=dict(color="blue", width=self.stroke_width),
187
+ name="Forecast (50th)",
188
+ customdata=forecast.values,
189
+ hovertemplate="Forecast (50th): %{customdata:,.4s}<extra></extra>",
190
+ )
191
+ )
192
+
193
+ if realized is not None:
194
+ # Add realized values on top
195
+ figure.add_trace(
196
+ go.Scatter(
197
+ x=realized.index,
198
+ y=realized,
199
+ mode="lines",
200
+ line=dict(color="red", width=self.stroke_width),
201
+ customdata=realized.values,
202
+ hovertemplate="Realized: %{customdata:,.4s}<extra></extra>",
203
+ name="Realized",
204
+ )
205
+ )
206
+
207
+ # Styling configuration
208
+ figure.update_layout(
209
+ title=f"Load Forecast vs Actual",
210
+ xaxis_title="Datetime [UTC]",
211
+ yaxis_title="Load [W]",
212
+ template="plotly_white",
213
+ hovermode="x unified",
214
+ )
215
+
216
+ return figure
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: openstef
3
- Version: 3.4.62
3
+ Version: 3.4.64
4
4
  Summary: Open short term energy forecaster
5
5
  Home-page: https://github.com/OpenSTEF/openstef
6
6
  Author: Alliander N.V
@@ -33,7 +33,11 @@ Requires-Dist: scikit-learn<1.6,>=1.3
33
33
  Requires-Dist: scipy~=1.10
34
34
  Requires-Dist: statsmodels<1.0.0,>=0.13.5
35
35
  Requires-Dist: structlog<25,>=23.1
36
- Requires-Dist: xgboost~=2.0
36
+ Requires-Dist: xgboost~=2.0; extra == "gpu"
37
+ Provides-Extra: cpu
38
+ Requires-Dist: xgboost-cpu~=2.0; extra == "cpu"
39
+ Provides-Extra: gpu
40
+ Requires-Dist: xgboost; extra == "gpu"
37
41
  Dynamic: author
38
42
  Dynamic: author-email
39
43
  Dynamic: classifier
@@ -42,6 +46,7 @@ Dynamic: description-content-type
42
46
  Dynamic: home-page
43
47
  Dynamic: keywords
44
48
  Dynamic: license
49
+ Dynamic: provides-extra
45
50
  Dynamic: requires-dist
46
51
  Dynamic: requires-python
47
52
  Dynamic: summary
@@ -53,11 +58,15 @@ SPDX-License-Identifier: MPL-2.0
53
58
  -->
54
59
 
55
60
  # OpenSTEF
61
+
56
62
  <!-- Badges -->
63
+
57
64
  [![Downloads](https://static.pepy.tech/badge/openstef)](https://pepy.tech/project/openstef)
58
65
  [![Downloads](https://static.pepy.tech/badge/openstef/month)](https://pepy.tech/project/openstef)
59
66
  [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/5585/badge)](https://bestpractices.coreinfrastructure.org/projects/5585)
67
+
60
68
  <!-- SonarCloud badges -->
69
+
61
70
  [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=OpenSTEF_openstef&metric=bugs)](https://sonarcloud.io/dashboard?id=OpenSTEF_openstef)
62
71
  [![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=OpenSTEF_openstef&metric=code_smells)](https://sonarcloud.io/dashboard?id=OpenSTEF_openstef)
63
72
  [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=OpenSTEF_openstef&metric=coverage)](https://sonarcloud.io/dashboard?id=OpenSTEF_openstef)
@@ -71,19 +80,21 @@ SPDX-License-Identifier: MPL-2.0
71
80
  OpenSTEF is a Python package designed for generating short-term forecasts in the energy sector. The repository includes all the essential components required for machine learning pipelines that facilitate the forecasting process. To utilize the package, users are required to furnish their own data storage and retrieval interface.
72
81
 
73
82
  # Table of contents
83
+
74
84
  - [OpenSTEF](#openstef)
75
85
  - [Table of contents](#table-of-contents)
76
86
  - [External information sources](#external-information-sources)
77
87
  - [Installation](#installation)
78
88
  - [Usage](#usage)
79
- - [Example notebooks](#example-notebooks)
80
- - [Reference Implementation](#reference-implementation)
81
- - [Database connector for OpenSTEF](#database-connector-for-openstef)
89
+ - [Example notebooks](#example-notebooks)
90
+ - [Reference Implementation](#reference-implementation)
91
+ - [Database connector for OpenSTEF](#database-connector-for-openstef)
82
92
  - [License](license)
83
93
  - [Contributing](#contributing)
84
94
  - [Contact](#contact)
85
95
 
86
96
  # External information sources
97
+
87
98
  - [Documentation website](https://openstef.github.io/openstef/index.html);
88
99
  - [Python package](https://pypi.org/project/openstef/);
89
100
  - [Linux Foundation project page](https://www.lfenergy.org/projects/openstef/);
@@ -101,9 +112,11 @@ pip install openstef
101
112
  ### Remark regarding installation within a **conda environment on Windows**
102
113
 
103
114
  A version of the pywin32 package will be installed as a secondary dependency along with the installation of the openstef package. Since conda relies on an old version of pywin32, the new installation can break conda's functionality. The following command can solve this issue:
115
+
104
116
  ```shell
105
117
  pip install pywin32==300
106
118
  ```
119
+
107
120
  For more information on this issue see the [readme of pywin32](https://github.com/mhammond/pywin32#installing-via-pip) or [this Github issue](https://github.com/mhammond/pywin32/issues/1865#issue-1212752696).
108
121
 
109
122
  ## Remark regarding installation on Apple Silicon
@@ -112,19 +125,31 @@ If you want to install the `openstef` package on Apple Silicon (Mac with M1-chip
112
125
 
113
126
  1. Run `brew install libomp` (if you haven’t installed Homebrew: [follow instructions here](https://brew.sh/))
114
127
  2. If your interpreter can not find the `libomp` installation in `/usr/local/bin`, it is probably in `/opt/brew/Cellar`. Run:
128
+
115
129
  ```sh
116
130
  mkdir -p /usr/local/opt/libomp/
117
131
  ln -s /opt/brew/Cellar/libomp/{your_version}/lib /usr/local/opt/libomp/lib
118
132
  ```
133
+
119
134
  3. Uninstall `xgboost` with `pip` (`pip uninstall xgboost`) and install with `conda-forge` (`conda install -c conda-forge xgboost`)
120
135
  4. If you encounter similar issues with `lightgbm`: uninstall `lightgbm` with `pip` (`pip uninstall lightgbm`) and install later version with `conda-forge` (`conda install -c conda-forge 'lightgbm>=4.2.0'`)
121
136
 
137
+ ### Remark regarding installation with minimal XGBoost dependency
138
+
139
+ It is possible to install openSTEF with a minimal XGBoost (CPU-only) package. This only works on x86_64 (amd64) Linux and Windows platforms. Advantage is that significantly smaller dependencies are installed. In that case run:
140
+
141
+ ```shell
142
+ pip install openstef[cpu]
143
+ ```
144
+
122
145
  # Usage
123
146
 
124
147
  ## Example notebooks
148
+
125
149
  To help you get started, a set of fundamental example notebooks has been created. You can access these offline examples [here](https://github.com/OpenSTEF/openstef-offline-example).
126
150
 
127
151
  ## Reference Implementation
152
+
128
153
  A complete implementation including databases, user interface, example data, etc. is available at: https://github.com/OpenSTEF/openstef-reference
129
154
 
130
155
  ![screenshot](https://user-images.githubusercontent.com/60883372/146760483-29af3ac7-62af-4f13-98c7-982a79c517d1.jpg)
@@ -138,17 +163,21 @@ python -m openstef task <task_name>
138
163
  ```
139
164
 
140
165
  ## Database connector for openstef
166
+
141
167
  This repository provides an interface to OpenSTEF (reference) databases. The repository can be found [here](https://github.com/OpenSTEF/openstef-dbc).
142
168
 
143
169
  # License
170
+
144
171
  This project is licensed under the Mozilla Public License, version 2.0 - see LICENSE for details.
145
172
 
146
173
  ## Licenses third-party libraries
174
+
147
175
  This project includes third-party libraries, which are licensed under their own respective Open-Source licenses. SPDX-License-Identifier headers are used to show which license is applicable. The concerning license files can be found in the LICENSES directory.
148
176
 
149
177
  # Contributing
178
+
150
179
  Please read [CODE_OF_CONDUCT.md](https://github.com/OpenSTEF/.github/blob/main/CODE_OF_CONDUCT.md), [CONTRIBUTING.md](https://github.com/OpenSTEF/.github/blob/main/CONTRIBUTING.md) and [PROJECT_GOVERNANCE.md](https://github.com/OpenSTEF/.github/blob/main/PROJECT_GOVERNANCE.md) for details on the process for submitting pull requests to us.
151
180
 
152
181
  # Contact
182
+
153
183
  Please read [SUPPORT.md](https://github.com/OpenSTEF/.github/blob/main/SUPPORT.md) for how to connect and get into contact with the OpenSTEF project
154
-
@@ -54,7 +54,7 @@ openstef/model/regressors/arima.py,sha256=wt7FVykjSvljpl7vjtliq61SiyjQ7KKtw8PF9x
54
54
  openstef/model/regressors/custom_regressor.py,sha256=T4JdJ-oTTt1PHQV0DdIEIhALvEEh07WCFlWxl8EFih0,1765
55
55
  openstef/model/regressors/dazls.py,sha256=Xt89yFHjkwpIUTkkhPmPZ74F8_tht_XV88INuP5GU2E,3994
56
56
  openstef/model/regressors/flatliner.py,sha256=T9u-ukhqFcatQmlgUtBL_G-1b_wQzgdVRq0ac64GnjQ,2789
57
- openstef/model/regressors/gblinear_quantile.py,sha256=gQZJtRoHP56gFHXokssdGYNVXbss_NQNv5rFNqutIcI,11255
57
+ openstef/model/regressors/gblinear_quantile.py,sha256=9O6w-4OAq0opOxbOFFxoMWn2gtNUcmrffQy9DdHCS0I,11263
58
58
  openstef/model/regressors/lgbm.py,sha256=zCdn1euEdSFxYJzH8XqQFFnb6R4JVUnmineKjX_Gy-g,800
59
59
  openstef/model/regressors/linear.py,sha256=uOvZMLGZH_9nXfmS5honCMfyVeyGXP1Cza9A_BdXlVw,3665
60
60
  openstef/model/regressors/linear_quantile.py,sha256=sI5cl6_W-hh13mg4Gf09LQ1caZmBy7COc8_5BBJxySQ,10534
@@ -75,6 +75,8 @@ openstef/pipeline/optimize_hyperparameters.py,sha256=3SLkcLR7XC4IeN48C-XT_lxlfCq
75
75
  openstef/pipeline/train_create_forecast_backtest.py,sha256=-kZqCWal5zYLL0k0Sapks1zTmU5unNAooVPaPos1_7E,6050
76
76
  openstef/pipeline/train_model.py,sha256=ThZwPo5otikVqVe6NdXkYcxkVFh-kegRVxMsQg1lbFc,19743
77
77
  openstef/pipeline/utils.py,sha256=23mB31p19FoGWelLJzxNmqlzGwEr3fCDBEA37V2kpYY,2167
78
+ openstef/plotting/__init__.py,sha256=KQjXzyafCt1bE7XDrSeV4TDUIO7MkwN_Br4ASOcNI2g,163
79
+ openstef/plotting/load_forecast_plotter.py,sha256=n-dB2dQnqjWCvV3kBjnOZYQ03J-9jSIHVovJy3nGSnQ,8129
78
80
  openstef/postprocessing/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
79
81
  openstef/postprocessing/postprocessing.py,sha256=6x_2ZcZaHEKMg_kxBAuKUlA_dDEs-KaO5SgGqGWHK14,8997
80
82
  openstef/preprocessing/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
@@ -95,8 +97,8 @@ openstef/tasks/utils/predictionjobloop.py,sha256=Ysy3zF5lzPMz_asYDKeF5m0qgVT3tCt
95
97
  openstef/tasks/utils/taskcontext.py,sha256=L9K14ycwgVxbIVUjH2DIn_QWbnu-OfxcGtQ1K9T6sus,5630
96
98
  openstef/validation/__init__.py,sha256=bIyGTSA4V5VoOLTwdaiJJAnozmpSzvQooVYlsf8H4eU,163
97
99
  openstef/validation/validation.py,sha256=DfnT7f29n9AbduJy9I6mXYQSnjt241Pn36Fp9SGehR0,11225
98
- openstef-3.4.62.dist-info/LICENSE,sha256=7Pm2fWFFHHUG5lDHed1vl5CjzxObIXQglnYsEdtjo_k,14907
99
- openstef-3.4.62.dist-info/METADATA,sha256=0pRWB-8qu1Zb38dXwq7Cs3IOT2QbMmMwypIlGDdDfMc,8305
100
- openstef-3.4.62.dist-info/WHEEL,sha256=nn6H5-ilmfVryoAQl3ZQ2l8SH5imPWFpm1A5FgEuFV4,91
101
- openstef-3.4.62.dist-info/top_level.txt,sha256=kD0H4PqrQoncZ957FvqwfBxa89kTrun4Z_RAPs_HhLs,9
102
- openstef-3.4.62.dist-info/RECORD,,
100
+ openstef-3.4.64.dist-info/LICENSE,sha256=7Pm2fWFFHHUG5lDHed1vl5CjzxObIXQglnYsEdtjo_k,14907
101
+ openstef-3.4.64.dist-info/METADATA,sha256=q6c9ZcvFIz9MWbiczxBe5eXZsmofc0mnySewaKLiuEw,8816
102
+ openstef-3.4.64.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
103
+ openstef-3.4.64.dist-info/top_level.txt,sha256=kD0H4PqrQoncZ957FvqwfBxa89kTrun4Z_RAPs_HhLs,9
104
+ openstef-3.4.64.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.1)
2
+ Generator: setuptools (75.8.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5