openenergyid 0.1.20__tar.gz → 0.1.28__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.
Potentially problematic release.
This version of openenergyid might be problematic. Click here for more details.
- openenergyid-0.1.28/PKG-INFO +41 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/README.md +1 -1
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/__init__.py +1 -1
- openenergyid-0.1.28/openenergyid/baseload/__init__.py +15 -0
- openenergyid-0.1.28/openenergyid/baseload/analysis.py +173 -0
- openenergyid-0.1.28/openenergyid/baseload/exceptions.py +9 -0
- openenergyid-0.1.28/openenergyid/baseload/models.py +31 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/models.py +46 -10
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/mvlr/main.py +6 -2
- {openenergyid-0.1.20 → openenergyid-0.1.28}/pyproject.toml +33 -38
- openenergyid-0.1.20/.devcontainer/devcontainer.json +0 -39
- openenergyid-0.1.20/.devcontainer/post-install.sh +0 -24
- openenergyid-0.1.20/.github/workflows/python-publish.yml +0 -39
- openenergyid-0.1.20/.github/workflows/ruff.yml +0 -8
- openenergyid-0.1.20/.gitignore +0 -167
- openenergyid-0.1.20/.pre-commit-config.yaml +0 -24
- openenergyid-0.1.20/.vscode/settings.json +0 -3
- openenergyid-0.1.20/DEVELOPERS.md +0 -63
- openenergyid-0.1.20/PKG-INFO +0 -50
- openenergyid-0.1.20/data/capacity/capacity_output.json +0 -327
- openenergyid-0.1.20/data/capacity/power_sample.json +0 -3473
- openenergyid-0.1.20/data/da_prices_be.json +0 -291657
- openenergyid-0.1.20/data/dyntar/demo_dyntar_analysis.html +0 -8725
- openenergyid-0.1.20/data/dyntar/sample.json +0 -1
- openenergyid-0.1.20/data/dyntar/sample_output.json +0 -240540
- openenergyid-0.1.20/data/energiedelen/Optimaal_1.png +0 -0
- openenergyid-0.1.20/data/energiedelen/Optimaal_2.png +0 -0
- openenergyid-0.1.20/data/energiedelen/Relatief.png +0 -0
- openenergyid-0.1.20/data/energiedelen/Vast.png +0 -0
- openenergyid-0.1.20/data/energiedelen/sample_input.json +0 -1
- openenergyid-0.1.20/data/mvlr/sample_gas.json +0 -1869
- openenergyid-0.1.20/data/mvlr/sample_solar.json +0 -2586
- openenergyid-0.1.20/demo_capacity_analysis.ipynb +0 -472
- openenergyid-0.1.20/demo_dyntar_analysis.ipynb +0 -1243
- openenergyid-0.1.20/demo_energiedelen.ipynb +0 -1184
- openenergyid-0.1.20/demo_energyid_download.ipynb +0 -152
- openenergyid-0.1.20/demo_mvlr.ipynb +0 -118
- openenergyid-0.1.20/download_prices.ipynb +0 -110
- openenergyid-0.1.20/poetry.lock +0 -3508
- openenergyid-0.1.20/requirements-dev.txt +0 -123
- openenergyid-0.1.20/requirements.txt +0 -20
- openenergyid-0.1.20/tests/__init__.py +0 -0
- openenergyid-0.1.20/tests/data/mvlr/sample.dat +0 -2585
- openenergyid-0.1.20/tests/nb.py +0 -38
- {openenergyid-0.1.20 → openenergyid-0.1.28}/LICENSE +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/capacity/__init__.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/capacity/main.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/capacity/models.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/const.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/dyntar/__init__.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/dyntar/const.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/dyntar/main.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/dyntar/models.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/energysharing/__init__.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/energysharing/const.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/energysharing/data_formatting.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/energysharing/main.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/energysharing/models.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/enums.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/mvlr/__init__.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/mvlr/helpers.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/mvlr/models.py +0 -0
- {openenergyid-0.1.20 → openenergyid-0.1.28}/openenergyid/mvlr/mvlr.py +0 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: openenergyid
|
|
3
|
+
Version: 0.1.28
|
|
4
|
+
Summary: Open Source Python library for energy analytics and simulations
|
|
5
|
+
License: MIT
|
|
6
|
+
Keywords: energy,analytics,simulation
|
|
7
|
+
Author: Jan Pecinovsky
|
|
8
|
+
Author-email: jan@energieid.be
|
|
9
|
+
Requires-Python: >=3.11,<4.0
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
22
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Dist: numpy (>=2.0.0,<3.0.0)
|
|
25
|
+
Requires-Dist: pandas (>=2.2.2,<3.0.0)
|
|
26
|
+
Requires-Dist: pandera[polars] (>=0.22.1,<0.23.0)
|
|
27
|
+
Requires-Dist: patsy (>=0.5.6,<0.6.0)
|
|
28
|
+
Requires-Dist: polars (>=1.9.0,<2.0.0)
|
|
29
|
+
Requires-Dist: pydantic (>=2.8.2,<3.0.0)
|
|
30
|
+
Requires-Dist: statsmodels (>=0.14.2,<0.15.0)
|
|
31
|
+
Project-URL: Documentation, https://github.com/EnergieID/OpenEnergyID
|
|
32
|
+
Project-URL: Homepage, https://energyid.eu
|
|
33
|
+
Project-URL: Repository, https://github.com/EnergieID/OpenEnergyID
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# OpenEnergyID
|
|
37
|
+
|
|
38
|
+
Open Source Python library for energy data analytics and simulations
|
|
39
|
+
|
|
40
|
+
[*more info for developers*](DEVELOPERS.md)
|
|
41
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Baseload analysis package for power consumption data."""
|
|
2
|
+
|
|
3
|
+
from .models import PowerReadingSchema, PowerSeriesSchema, BaseloadResultSchema
|
|
4
|
+
from .analysis import BaseloadAnalyzer
|
|
5
|
+
from .exceptions import InsufficientDataError, InvalidDataError
|
|
6
|
+
|
|
7
|
+
__version__ = "0.1.0"
|
|
8
|
+
__all__ = [
|
|
9
|
+
"BaseloadAnalyzer",
|
|
10
|
+
"InsufficientDataError",
|
|
11
|
+
"InvalidDataError",
|
|
12
|
+
"PowerReadingSchema",
|
|
13
|
+
"PowerSeriesSchema",
|
|
14
|
+
"BaseloadResultSchema",
|
|
15
|
+
]
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"""Baseload Power Consumption Analysis Module
|
|
2
|
+
|
|
3
|
+
This module provides tools for analyzing electrical power consumption patterns to identify
|
|
4
|
+
and quantify baseload - the continuous background power usage in electrical systems.
|
|
5
|
+
It uses sophisticated time-series analysis to detect consistent minimum power draws
|
|
6
|
+
that represent always-on devices and systems.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import polars as pl
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class BaseloadAnalyzer:
|
|
13
|
+
"""Analyzes power consumption data to determine baseload characteristics.
|
|
14
|
+
|
|
15
|
+
The BaseloadAnalyzer helps identify the minimum continuous power consumption in
|
|
16
|
+
an electrical system by analyzing regular energy readings. It uses a statistical
|
|
17
|
+
approach to determine baseload, which represents power used by devices that run
|
|
18
|
+
continuously (like refrigerators, standby electronics, or network equipment).
|
|
19
|
+
|
|
20
|
+
The analyzer works by:
|
|
21
|
+
1. Converting 15-minute energy readings to instantaneous power values
|
|
22
|
+
2. Analyzing daily patterns to identify consistent minimum usage
|
|
23
|
+
3. Aggregating results into configurable time periods
|
|
24
|
+
|
|
25
|
+
Parameters
|
|
26
|
+
----------
|
|
27
|
+
quantile : float, default=0.05
|
|
28
|
+
Defines what portion of lowest daily readings to consider as baseload.
|
|
29
|
+
The default 0.05 (5%) corresponds to roughly 72 minutes of lowest
|
|
30
|
+
consumption per day, which helps filter out brief power dips while
|
|
31
|
+
capturing true baseload patterns.
|
|
32
|
+
|
|
33
|
+
timezone : str
|
|
34
|
+
Timezone for analysis. All timestamps will be converted to this timezone
|
|
35
|
+
to ensure correct daily boundaries and consistent reporting periods.
|
|
36
|
+
|
|
37
|
+
Example Usage
|
|
38
|
+
------------
|
|
39
|
+
>>> analyzer = BaseloadAnalyzer(quantile=0.05)
|
|
40
|
+
>>> power_data = analyzer.prepare_power_seriespolars(energy_readings)
|
|
41
|
+
>>> hourly_analysis = analyzer.analyze(power_data, "1h")
|
|
42
|
+
>>> monthly_analysis = analyzer.analyze(power_data, "1mo")
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
def __init__(self, timezone: str, quantile: float = 0.05):
|
|
46
|
+
self.quantile = quantile
|
|
47
|
+
self.timezone = timezone
|
|
48
|
+
|
|
49
|
+
def prepare_power_seriespolars(self, energy_lf: pl.LazyFrame) -> pl.LazyFrame:
|
|
50
|
+
"""Converts energy readings into a power consumption time series.
|
|
51
|
+
|
|
52
|
+
Transforms 15-minute energy readings (kilowatt-hours) into instantaneous
|
|
53
|
+
power readings (watts) while handling timezone conversion.
|
|
54
|
+
|
|
55
|
+
Parameters
|
|
56
|
+
----------
|
|
57
|
+
energy_lf : pl.LazyFrame
|
|
58
|
+
Input energy data with columns:
|
|
59
|
+
- timestamp: Datetime with timezone (e.g. "2023-01-01T00:00:00+01:00")
|
|
60
|
+
- total: Energy readings in kilowatt-hours (kWh)
|
|
61
|
+
|
|
62
|
+
Returns
|
|
63
|
+
-------
|
|
64
|
+
pl.LazyFrame
|
|
65
|
+
Power series with columns:
|
|
66
|
+
- timestamp: Timezone-adjusted timestamps
|
|
67
|
+
- power: Power readings in watts
|
|
68
|
+
|
|
69
|
+
Notes
|
|
70
|
+
-----
|
|
71
|
+
The conversion from kWh/15min to watts uses the formula:
|
|
72
|
+
watts = kWh * 4000
|
|
73
|
+
where:
|
|
74
|
+
- Multiply by 4 to convert from 15-minute to hourly rate
|
|
75
|
+
- Multiply by 1000 to convert from kilowatts to watts
|
|
76
|
+
"""
|
|
77
|
+
return (
|
|
78
|
+
energy_lf.with_columns(
|
|
79
|
+
[
|
|
80
|
+
# Convert timezone
|
|
81
|
+
pl.col("timestamp")
|
|
82
|
+
.dt.replace_time_zone("UTC")
|
|
83
|
+
.dt.convert_time_zone(self.timezone)
|
|
84
|
+
.alias("timestamp"),
|
|
85
|
+
# Convert to watts and clip negative values
|
|
86
|
+
(pl.col("total") * 4000).clip(0).alias("power"),
|
|
87
|
+
]
|
|
88
|
+
)
|
|
89
|
+
.drop("total")
|
|
90
|
+
.sort("timestamp")
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
def analyze(self, power_lf: pl.LazyFrame, reporting_granularity: str = "1h") -> pl.LazyFrame:
|
|
94
|
+
"""Analyze power consumption data to calculate baseload and total energy metrics.
|
|
95
|
+
|
|
96
|
+
Takes power readings (in watts) with 15-minute intervals and calculates:
|
|
97
|
+
- Daily baseload power using a percentile threshold
|
|
98
|
+
- Energy consumption from baseload vs total consumption
|
|
99
|
+
- Average power metrics
|
|
100
|
+
|
|
101
|
+
The analysis happens in three steps:
|
|
102
|
+
1. Calculate the daily baseload power level using the configured percentile
|
|
103
|
+
2. Join this daily baseload with the original power readings
|
|
104
|
+
3. Aggregate the combined data into the requested reporting periods
|
|
105
|
+
|
|
106
|
+
Parameters
|
|
107
|
+
----------
|
|
108
|
+
power_lf : pl.LazyFrame
|
|
109
|
+
Power consumption data with columns:
|
|
110
|
+
- timestamp: Datetime in configured timezone
|
|
111
|
+
- power: Power readings in watts
|
|
112
|
+
|
|
113
|
+
reporting_granularity : str, default="1h"
|
|
114
|
+
Time period for aggregating results. Must be a valid Polars interval string
|
|
115
|
+
like "1h", "1d", "1mo" etc.
|
|
116
|
+
|
|
117
|
+
Returns
|
|
118
|
+
-------
|
|
119
|
+
pl.LazyFrame
|
|
120
|
+
Analysis results with metrics per reporting period:
|
|
121
|
+
- timestamp: Start of reporting period
|
|
122
|
+
- consumption_due_to_baseload_in_kilowatthour: Baseload energy
|
|
123
|
+
- total_consumption_in_kilowatthour: Total energy
|
|
124
|
+
- consumption_not_due_to_baseload_in_kilowatthour: Non-baseload energy
|
|
125
|
+
- average_daily_baseload_in_watt: Average baseload power level
|
|
126
|
+
- average_power_in_watt: Average total power
|
|
127
|
+
- baseload_ratio: Fraction of energy from baseload
|
|
128
|
+
"""
|
|
129
|
+
# Step 1: Calculate the daily baseload level
|
|
130
|
+
# Group power readings by day and find the threshold power level that represents baseload
|
|
131
|
+
daily_baseload = power_lf.group_by_dynamic("timestamp", every="1d").agg(
|
|
132
|
+
pl.col("power").quantile(self.quantile).alias("daily_baseload")
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
# Step 2 & 3: Join baseload data and aggregate metrics
|
|
136
|
+
return (
|
|
137
|
+
# Join the daily baseload level with original power readings
|
|
138
|
+
# Using asof join since baseload changes daily but readings are every 15min
|
|
139
|
+
power_lf.join_asof(daily_baseload, on="timestamp")
|
|
140
|
+
# Group into requested reporting periods
|
|
141
|
+
.group_by_dynamic("timestamp", every=reporting_granularity)
|
|
142
|
+
.agg(
|
|
143
|
+
[
|
|
144
|
+
# Energy calculations:
|
|
145
|
+
# Each 15min power reading (watts) represents 0.25 hours
|
|
146
|
+
# Convert to kWh: watts * 0.25h * (1kW/1000W)
|
|
147
|
+
(pl.col("daily_baseload").sum() * 0.25 / 1000).alias(
|
|
148
|
+
"consumption_due_to_baseload_in_kilowatthour"
|
|
149
|
+
),
|
|
150
|
+
(pl.col("power").sum() * 0.25 / 1000).alias(
|
|
151
|
+
"total_consumption_in_kilowatthour"
|
|
152
|
+
),
|
|
153
|
+
# Average power levels during the period
|
|
154
|
+
pl.col("daily_baseload").mean().alias("average_daily_baseload_in_watt"),
|
|
155
|
+
pl.col("power").mean().alias("average_power_in_watt"),
|
|
156
|
+
]
|
|
157
|
+
)
|
|
158
|
+
# Calculate derived metrics
|
|
159
|
+
.with_columns(
|
|
160
|
+
[
|
|
161
|
+
# Energy consumed above baseload level
|
|
162
|
+
(
|
|
163
|
+
pl.col("total_consumption_in_kilowatthour")
|
|
164
|
+
- pl.col("consumption_due_to_baseload_in_kilowatthour")
|
|
165
|
+
).alias("consumption_not_due_to_baseload_in_kilowatthour"),
|
|
166
|
+
# What fraction of total energy was from baseload
|
|
167
|
+
(
|
|
168
|
+
pl.col("consumption_due_to_baseload_in_kilowatthour")
|
|
169
|
+
/ pl.col("total_consumption_in_kilowatthour")
|
|
170
|
+
).alias("baseload_ratio"),
|
|
171
|
+
]
|
|
172
|
+
)
|
|
173
|
+
)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import pandera.polars as pa
|
|
2
|
+
from pandera.engines.polars_engine import DateTime
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class PowerReadingSchema(pa.DataFrameModel):
|
|
6
|
+
"""Validates input energy readings"""
|
|
7
|
+
|
|
8
|
+
timestamp: DateTime = pa.Field()
|
|
9
|
+
total: float = pa.Field(ge=0)
|
|
10
|
+
|
|
11
|
+
class Config:
|
|
12
|
+
coerce = True
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class PowerSeriesSchema(pa.DataFrameModel):
|
|
16
|
+
"""Validates converted power series"""
|
|
17
|
+
|
|
18
|
+
timestamp: DateTime = pa.Field()
|
|
19
|
+
power: float = pa.Field(ge=0)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class BaseloadResultSchema(pa.DataFrameModel):
|
|
23
|
+
"""Validates analysis results"""
|
|
24
|
+
|
|
25
|
+
timestamp: DateTime = pa.Field()
|
|
26
|
+
consumption_due_to_baseload_in_kilowatthour: float = pa.Field(ge=0)
|
|
27
|
+
total_consumption_in_kilowatthour: float = pa.Field(ge=0)
|
|
28
|
+
average_daily_baseload_in_watt: float = pa.Field(ge=0)
|
|
29
|
+
average_power_in_watt: float = pa.Field(ge=0)
|
|
30
|
+
consumption_not_due_to_baseload_in_kilowatthour: float
|
|
31
|
+
baseload_ratio: float = pa.Field(ge=0, le=2)
|
|
@@ -7,6 +7,7 @@ from typing import Self
|
|
|
7
7
|
|
|
8
8
|
import pandas as pd
|
|
9
9
|
from pydantic import BaseModel
|
|
10
|
+
import polars as pl
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class TimeSeriesBase(BaseModel):
|
|
@@ -75,10 +76,14 @@ class TimeSeries(TimeSeriesBase):
|
|
|
75
76
|
Create a TimeSeries object from a Pandas Series.
|
|
76
77
|
to_pandas(self, timezone: str = "UTC") -> pd.Series:
|
|
77
78
|
Convert the TimeSeries object to a Pandas Series.
|
|
79
|
+
from_polars(cls, data: pl.DataFrame | pl.LazyFrame) -> Self:
|
|
80
|
+
Create a TimeSeries object from Polars data.
|
|
81
|
+
to_polars(self, timezone: str = "UTC") -> pl.LazyFrame:
|
|
82
|
+
Convert the TimeSeries object to a Polars LazyFrame.
|
|
78
83
|
"""
|
|
79
84
|
|
|
80
85
|
name: str | None = None
|
|
81
|
-
data: list[float]
|
|
86
|
+
data: list[float | None]
|
|
82
87
|
|
|
83
88
|
@classmethod
|
|
84
89
|
def from_pandas(cls, data: pd.Series) -> Self:
|
|
@@ -91,19 +96,50 @@ class TimeSeries(TimeSeriesBase):
|
|
|
91
96
|
series.index = pd.to_datetime(series.index, utc=True)
|
|
92
97
|
return series.tz_convert(timezone)
|
|
93
98
|
|
|
99
|
+
@classmethod
|
|
100
|
+
def from_polars(cls, data: pl.DataFrame | pl.LazyFrame) -> Self:
|
|
101
|
+
"""Create from Polars data."""
|
|
102
|
+
# Always work with DataFrame
|
|
103
|
+
df = data.collect() if isinstance(data, pl.LazyFrame) else data
|
|
104
|
+
|
|
105
|
+
if len(df.columns) != 2:
|
|
106
|
+
raise ValueError("Must contain exactly two columns: timestamp and value")
|
|
107
|
+
|
|
108
|
+
value_col = [col for col in df.columns if col != "timestamp"][0]
|
|
109
|
+
return cls(
|
|
110
|
+
name=value_col,
|
|
111
|
+
data=df[value_col].cast(pl.Float64).to_list(), # Ensure float type
|
|
112
|
+
index=df["timestamp"].cast(pl.Datetime).dt.convert_time_zone("UTC").to_list(),
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
def to_polars(self, timezone: str = "UTC") -> pl.LazyFrame:
|
|
116
|
+
"""Convert to Polars LazyFrame."""
|
|
117
|
+
# Always return LazyFrame as specified in return type
|
|
118
|
+
df = pl.DataFrame(
|
|
119
|
+
{
|
|
120
|
+
"timestamp": pl.Series(self.index, dtype=pl.Datetime).dt.convert_time_zone(
|
|
121
|
+
timezone
|
|
122
|
+
),
|
|
123
|
+
"total" if self.name is None else self.name: pl.Series(self.data, dtype=pl.Float64),
|
|
124
|
+
}
|
|
125
|
+
)
|
|
126
|
+
return df.lazy()
|
|
127
|
+
|
|
94
128
|
|
|
95
129
|
class TimeDataFrame(TimeSeriesBase):
|
|
96
130
|
"""Time series data with multiple columns."""
|
|
97
131
|
|
|
98
132
|
columns: list[str]
|
|
99
|
-
data: list[list[float]]
|
|
133
|
+
data: list[list[float | None]]
|
|
100
134
|
|
|
101
135
|
@classmethod
|
|
102
136
|
def from_pandas(cls, data: pd.DataFrame) -> Self:
|
|
103
137
|
"""Create from a Pandas DataFrame."""
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
138
|
+
# Cast values to float | None
|
|
139
|
+
values = [
|
|
140
|
+
[float(x) if pd.notnull(x) else None for x in row] for row in data.values.tolist()
|
|
141
|
+
]
|
|
142
|
+
return cls(columns=data.columns.tolist(), data=values, index=data.index.tolist())
|
|
107
143
|
|
|
108
144
|
def to_pandas(self, timezone: str = "UTC") -> pd.DataFrame:
|
|
109
145
|
"""Convert to a Pandas DataFrame."""
|
|
@@ -114,15 +150,15 @@ class TimeDataFrame(TimeSeriesBase):
|
|
|
114
150
|
@classmethod
|
|
115
151
|
def from_timeseries(cls, data: list[TimeSeries]) -> Self:
|
|
116
152
|
"""Create from a list of TimeSeries objects."""
|
|
117
|
-
return cls
|
|
118
|
-
columns=[series.name for series in data],
|
|
119
|
-
data=[series.data for series in data],
|
|
153
|
+
return cls(
|
|
154
|
+
columns=[series.name or "" for series in data], # Handle None names
|
|
155
|
+
data=[series.data for series in data], # Pass list of value lists
|
|
120
156
|
index=data[0].index,
|
|
121
157
|
)
|
|
122
158
|
|
|
123
159
|
def to_timeseries(self) -> list[TimeSeries]:
|
|
124
160
|
"""Convert to a list of TimeSeries objects."""
|
|
125
161
|
return [
|
|
126
|
-
TimeSeries(name=
|
|
127
|
-
for
|
|
162
|
+
TimeSeries(name=col, data=[row[i] for row in self.data], index=self.index)
|
|
163
|
+
for i, col in enumerate(self.columns)
|
|
128
164
|
]
|
|
@@ -9,6 +9,7 @@ def find_best_mvlr(
|
|
|
9
9
|
data: MultiVariableRegressionInput,
|
|
10
10
|
) -> MultiVariableRegressionResult:
|
|
11
11
|
"""Cycle through multiple granularities and return the best model."""
|
|
12
|
+
best_rsquared = 0
|
|
12
13
|
for granularity in data.granularities:
|
|
13
14
|
frame = data.data_frame()
|
|
14
15
|
frame = resample_input_data(data=frame, granularity=granularity)
|
|
@@ -17,7 +18,7 @@ def find_best_mvlr(
|
|
|
17
18
|
y=data.dependent_variable,
|
|
18
19
|
granularity=granularity,
|
|
19
20
|
allow_negative_predictions=data.allow_negative_predictions,
|
|
20
|
-
single_use_exog_prefixes=data.single_use_exog_prefixes,
|
|
21
|
+
single_use_exog_prefixes=data.single_use_exog_prefixes or [],
|
|
21
22
|
exogs__disallow_negative_coefficient=data.get_disallowed_negative_coefficients(),
|
|
22
23
|
)
|
|
23
24
|
mvlr.do_analysis()
|
|
@@ -27,4 +28,7 @@ def find_best_mvlr(
|
|
|
27
28
|
max_pvalues=data.validation_parameters.pvalues,
|
|
28
29
|
):
|
|
29
30
|
return MultiVariableRegressionResult.from_mvlr(mvlr)
|
|
30
|
-
|
|
31
|
+
best_rsquared = max(best_rsquared, mvlr.fit.rsquared_adj)
|
|
32
|
+
raise ValueError(
|
|
33
|
+
f"No valid model found. Best R²: {best_rsquared:.3f} (need ≥{data.validation_parameters.rsquared})"
|
|
34
|
+
)
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["
|
|
3
|
-
build-backend = "
|
|
2
|
+
requires = ["poetry-core>=1.0.0"]
|
|
3
|
+
build-backend = "poetry.core.masonry.api"
|
|
4
4
|
|
|
5
|
-
[
|
|
6
|
-
dynamic = ["version"]
|
|
5
|
+
[tool.poetry]
|
|
7
6
|
name = "openenergyid"
|
|
7
|
+
version = "0.1.28"
|
|
8
|
+
description = "Open Source Python library for energy analytics and simulations"
|
|
8
9
|
authors = [
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
"Jan Pecinovsky <jan@energieid.be>",
|
|
11
|
+
"Max Helskens <max@energieid.be>",
|
|
12
|
+
"Oscar Swyns <oscar@energieid.be>"
|
|
11
13
|
]
|
|
12
|
-
maintainers = [{ name = "Jan Pecinovsky", email = "jan@energieid.be" }]
|
|
13
|
-
description = "Open Source Python library for energy analytics and simulations"
|
|
14
14
|
readme = "README.md"
|
|
15
|
-
license =
|
|
15
|
+
license = "MIT"
|
|
16
|
+
homepage = "https://energyid.eu"
|
|
17
|
+
repository = "https://github.com/EnergieID/OpenEnergyID"
|
|
18
|
+
documentation = "https://github.com/EnergieID/OpenEnergyID"
|
|
16
19
|
keywords = ["energy", "analytics", "simulation"]
|
|
17
20
|
classifiers = [
|
|
18
21
|
"Development Status :: 3 - Alpha",
|
|
@@ -25,37 +28,18 @@ classifiers = [
|
|
|
25
28
|
"Topic :: Scientific/Engineering",
|
|
26
29
|
"Topic :: Scientific/Engineering :: Mathematics",
|
|
27
30
|
"Topic :: Scientific/Engineering :: Physics",
|
|
28
|
-
"Topic :: Software Development :: Libraries :: Python Modules"
|
|
31
|
+
"Topic :: Software Development :: Libraries :: Python Modules"
|
|
29
32
|
]
|
|
30
33
|
|
|
31
|
-
[
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
[
|
|
40
|
-
line-length = 100
|
|
41
|
-
|
|
42
|
-
[tool.poetry]
|
|
43
|
-
name = "openenergyid"
|
|
44
|
-
version = "0.1.20" # You'll need to set this manually or use a different method for dynamic versioning
|
|
45
|
-
description = "Open Source Python library for energy analytics and simulations"
|
|
46
|
-
authors = [
|
|
47
|
-
"Jan Pecinovsky <jan@energieid.be>",
|
|
48
|
-
"Max Helskens <max@energieid.be>",
|
|
49
|
-
"Oscar Swyns <oscar@energieid.be>",
|
|
50
|
-
]
|
|
51
|
-
dependencies.python = "^3.10"
|
|
52
|
-
dependencies.polars = "^1.9.0"
|
|
53
|
-
dependencies.pandera = "^0.20.3"
|
|
54
|
-
dependencies.numpy = "^2.0.0"
|
|
55
|
-
dependencies.patsy = "^0.5.6"
|
|
56
|
-
dependencies.statsmodels = "^0.14.2"
|
|
57
|
-
dependencies.pydantic = "^2.8.2"
|
|
58
|
-
dependencies.pandas = "^2.2.2"
|
|
34
|
+
[tool.poetry.dependencies]
|
|
35
|
+
python = "^3.11"
|
|
36
|
+
polars = "^1.9.0"
|
|
37
|
+
numpy = "^2.0.0"
|
|
38
|
+
patsy = "^0.5.6"
|
|
39
|
+
statsmodels = "^0.14.2"
|
|
40
|
+
pydantic = "^2.8.2"
|
|
41
|
+
pandas = "^2.2.2"
|
|
42
|
+
pandera = {extras = ["polars"], version = "^0.22.1"}
|
|
59
43
|
|
|
60
44
|
[tool.poetry.group.dev.dependencies]
|
|
61
45
|
altair = "^5.4.1"
|
|
@@ -68,3 +52,14 @@ entsoe-py = "^0.6.8"
|
|
|
68
52
|
energyid = "^0.0.17"
|
|
69
53
|
snakeviz = "^2.2.0"
|
|
70
54
|
plotly = "^5.24.1"
|
|
55
|
+
vegafusion = {version = ">=1.5.0", extras = ["embed"]}
|
|
56
|
+
vl-convert-python = "^1.7.0"
|
|
57
|
+
pyarrow = "^19.0.0"
|
|
58
|
+
pyinstrument = "^5.0.0"
|
|
59
|
+
deptry = "^0.23.0"
|
|
60
|
+
|
|
61
|
+
[tool.poetry.requires-plugins]
|
|
62
|
+
poetry-plugin-export = ">=1.8"
|
|
63
|
+
|
|
64
|
+
[tool.ruff]
|
|
65
|
+
line-length = 100
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "Python 3",
|
|
3
|
-
"image": "mcr.microsoft.com/devcontainers/python:1.1.9-3.11-bookworm",
|
|
4
|
-
"features": {},
|
|
5
|
-
"postCreateCommand": "zsh -l .devcontainer/post-install.sh",
|
|
6
|
-
// "postStartCommand": "",
|
|
7
|
-
"remoteUser": "root",
|
|
8
|
-
"customizations": {
|
|
9
|
-
"vscode": {
|
|
10
|
-
"extensions": [
|
|
11
|
-
"ms-toolsai.jupyter",
|
|
12
|
-
"charliermarsh.ruff",
|
|
13
|
-
"ms-python.pylint",
|
|
14
|
-
"ms-python.vscode-pylance",
|
|
15
|
-
"visualstudioexptteam.vscodeintellicode",
|
|
16
|
-
"esbenp.prettier-vscode",
|
|
17
|
-
"GitHub.vscode-pull-request-github",
|
|
18
|
-
"mhutchie.git-graph"
|
|
19
|
-
],
|
|
20
|
-
"settings": {
|
|
21
|
-
"python.pythonPath": "/usr/local/bin/python",
|
|
22
|
-
"python.testing.pytestArgs": ["--no-cov"],
|
|
23
|
-
"editor.formatOnPaste": false,
|
|
24
|
-
"editor.formatOnSave": true,
|
|
25
|
-
"editor.formatOnType": true,
|
|
26
|
-
"files.trimTrailingWhitespace": true,
|
|
27
|
-
"terminal.integrated.profiles.linux": {
|
|
28
|
-
"zsh": {
|
|
29
|
-
"path": "/usr/bin/zsh"
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
"terminal.integrated.defaultProfile.linux": "zsh",
|
|
33
|
-
"[python]": {
|
|
34
|
-
"editor.defaultFormatter": "charliermarsh.ruff"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
#!/bin/zsh -l
|
|
2
|
-
# Add the current directory to Git's safe directory list
|
|
3
|
-
git config --global --add safe.directory /workspaces/OpenEnergyID
|
|
4
|
-
|
|
5
|
-
# Install Python tools
|
|
6
|
-
pipx install ruff poetry pre-commit
|
|
7
|
-
|
|
8
|
-
# Install project dependencies using Poetry
|
|
9
|
-
poetry install
|
|
10
|
-
|
|
11
|
-
# Install pre-commit hooks
|
|
12
|
-
pre-commit install
|
|
13
|
-
|
|
14
|
-
# Install Node.js and Pure prompt
|
|
15
|
-
# nvm install node
|
|
16
|
-
# npm install --global pure-prompt
|
|
17
|
-
|
|
18
|
-
# # Configure Zsh to use Pure prompt
|
|
19
|
-
# "autoload -U promptinit; promptinit; prompt pure"
|
|
20
|
-
# "echo "autoload -U promptinit; promptinit; prompt pure" >> ~/.zshrc"
|
|
21
|
-
|
|
22
|
-
# # Uncomment the following line to install zsh-syntax-highlighting
|
|
23
|
-
# # sudo apt-get install zsh-syntax-highlighting
|
|
24
|
-
# # echo "source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> ${ZDOTDIR:-$HOME}/.zshrc
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
# This workflow will upload a Python Package using Twine when a release is created
|
|
2
|
-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
|
|
3
|
-
|
|
4
|
-
# This workflow uses actions that are not certified by GitHub.
|
|
5
|
-
# They are provided by a third-party and are governed by
|
|
6
|
-
# separate terms of service, privacy policy, and support
|
|
7
|
-
# documentation.
|
|
8
|
-
|
|
9
|
-
name: Upload Python Package
|
|
10
|
-
|
|
11
|
-
on:
|
|
12
|
-
release:
|
|
13
|
-
types: [published]
|
|
14
|
-
|
|
15
|
-
permissions:
|
|
16
|
-
contents: read
|
|
17
|
-
|
|
18
|
-
jobs:
|
|
19
|
-
deploy:
|
|
20
|
-
runs-on: ubuntu-latest
|
|
21
|
-
permissions:
|
|
22
|
-
id-token: write
|
|
23
|
-
environment: release
|
|
24
|
-
|
|
25
|
-
steps:
|
|
26
|
-
- uses: actions/checkout@v3
|
|
27
|
-
- name: Set up Python
|
|
28
|
-
uses: actions/setup-python@v3
|
|
29
|
-
with:
|
|
30
|
-
python-version: '3.x'
|
|
31
|
-
- name: Install dependencies
|
|
32
|
-
run: |
|
|
33
|
-
python -m pip install --upgrade pip
|
|
34
|
-
pip install build
|
|
35
|
-
- name: Build package
|
|
36
|
-
run: python -m build
|
|
37
|
-
- name: Publish package
|
|
38
|
-
uses: pypa/gh-action-pypi-publish@release/v1
|
|
39
|
-
|