Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 5716cb6
Author: Molier <[email protected]>
Date:   Thu Aug 15 17:48:13 2024 +0200

    chore: Update dependencies: pandera...

commit 75cacb9
Author: Molier <[email protected]>
Date:   Tue Aug 13 16:51:31 2024 +0200

    Refactor capacity input model, add default threshold, update cap analysis logic

    - Refactored the capacity input model in the `models.py` file to include a default value for the `threshold` field. The `threshold` field now has a default value of 2.5 and must be greater than or equal to 0.
    - Updated the `main.py` file to import the `pandera.typing` module for type annotations.
    - Modified the `find_peaks_with_surroundings` method in the `CapacityAnalysis` class to skip peaks that are within a certain time window of previously found peaks.
    - Made other minor code improvements and optimizations.

commit b61c3fb
Author: Molier <[email protected]>
Date:   Tue Aug 13 12:18:04 2024 +0200

    chore: Add basic type checking for Python analysis, small doc refac and removal obs file

commit fe9e685
Author: Molier <[email protected]>
Date:   Tue Aug 13 12:05:01 2024 +0200

    chore: remove pre-commit comment(no strict mypy)

commit a099d9a
Author: Jan Pecinovsky <=>
Date:   Tue Aug 13 10:10:52 2024 +0000

    add threshold to capacity input

commit 8934a0e
Author: Jan Pecinovsky <[email protected]>
Date:   Fri Aug 2 08:22:39 2024 +0000

    version bump

commit 990fef5
Author: Jan Pecinovsky <[email protected]>
Date:   Fri Aug 2 08:19:29 2024 +0000

    Validators on Timeseries data to convert NaN to None for JSON output.

commit a1fafd7
Author: Jan Pecinovsky <[email protected]>
Date:   Fri Jul 26 19:53:34 2024 +0200

    0.0.14. Capacity Analysis. Refactoring. Poetry Package Manager. (#9)

    * Allow the case where not all participants have offtake, injection or a key

    * readmes updated

    * added capacity analysis with demo nb

    * python compat removal >3.10

    * key validation to 3 decimal values

    * added poetry as package manager and updated the requirements and dev requirements

    * review

    * imports

    * samples

    * add seaborn requirement-dev

    * remove rounding from output

    * Capacity analysis typechanges to make it more pure and only use inout outputmodels in the demo

    * feat: Add PeakDetail model to capacity module

    * chore: Ruff import removal

    * chore: Update pre-commit hooks with pyupgrade v3.16.0 refactoring to upgrade to python311

    * feat: added a test you can run for all the notebooks. (#8)

    * chore: Update pre-commit hooks with pyupgrade v3.16.0 refactoring to upgrade to python311

    * chore: made requirements more human readable

    * feat: Update dependencies for entsoe-py and energyid

    * chore: Add test suite for notebook execution

    ---------

    Co-authored-by: Jan Pecinovsky <[email protected]>

    * Version Bump

    ---------

    Co-authored-by: Molier <[email protected]>
    Co-authored-by: Oscar <[email protected]>
  • Loading branch information
Molier committed Aug 27, 2024
1 parent f1f8857 commit 5b7ce61
Show file tree
Hide file tree
Showing 10 changed files with 1,191 additions and 500 deletions.
10 changes: 8 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.5
rev: v0.6.2
hooks:
# Run the linter.
- id: ruff
Expand All @@ -12,7 +12,13 @@ repos:
types_or: [python, pyi, jupyter]

- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
rev: v3.17.0
hooks:
- id: pyupgrade
args: [--py311-plus]

# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: "" # Use the sha / tag you want to point at
# hooks:
# - id: mypy
# args: [--strict, --ignore-missing-imports]
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.analysis.typeCheckingMode": "basic"
}
2 changes: 1 addition & 1 deletion openenergyid/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Open Energy ID Python SDK."""

__version__ = "0.1.15"
__version__ = "0.1.16"

from .enums import Granularity
from .models import TimeDataFrame, TimeSeries
Expand Down
20 changes: 16 additions & 4 deletions openenergyid/capacity/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Main module for capacity analysis."""

import datetime as dt
import typing
import pandas as pd
import pandera.typing as pdt


class CapacityAnalysis:
Expand All @@ -21,7 +23,7 @@ class CapacityAnalysis:

def __init__(
self,
data: pd.Series,
data: pdt.Series,
threshold: float = 2.5,
window: str = "MS", # Default to month start
x_padding: int = 4,
Expand Down Expand Up @@ -50,11 +52,12 @@ def find_peaks(self) -> pd.Series:
"""
# Group by the specified window (default is month start)
grouped = self.data.groupby(pd.Grouper(freq=self.window))

# Find the index (timestamp) of the maximum value in each group
peak_indices = grouped.idxmax()

# Get the corresponding peak values
peaks = self.data.loc[peak_indices][self.data > self.threshold]

return peaks

def find_peaks_with_surroundings(
Expand All @@ -69,12 +72,20 @@ def find_peaks_with_surroundings(
Returns:
List[tuple[dt.datetime,float,pd.Series]]: A list of tuples containing peak time, peak value, and surrounding data.
"""
peaks = self.data.sort_values(ascending=False).head(num_peaks)
peaks = self.data.nlargest(num_peaks * 2)
peaks = peaks[peaks > self.threshold]
if peaks.empty:
return []

result = []
window_size = dt.timedelta(minutes=15 * (2 * self.x_padding + 1))

for peak_time, peak_value in peaks.items():
peak_time = typing.cast(pd.Timestamp, peak_time)

if any(abs(peak_time - prev_peak[0]) < window_size for prev_peak in result):
continue

start_time = peak_time - dt.timedelta(minutes=15 * self.x_padding)
end_time = peak_time + dt.timedelta(minutes=15 * (self.x_padding + 1))
surrounding_data = self.data[start_time:end_time]
Expand All @@ -86,5 +97,6 @@ def find_peaks_with_surroundings(
surrounding_data,
]
)

if len(result) == num_peaks:
break
return result
1 change: 1 addition & 0 deletions openenergyid/capacity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class CapacityInput(BaseModel):

timezone: str = Field(alias="timeZone")
series: TimeSeries
threshold: float = Field(default=2.5, ge=0)


class PeakDetail(BaseModel):
Expand Down
14 changes: 13 additions & 1 deletion openenergyid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,19 @@ def from_json(cls, string: str | None = None, path: str | None = None, **kwargs)


class TimeSeries(TimeSeriesBase):
"""Time series data with a single column."""
"""
Represents a time series data.
Attributes:
name (str | None): The name of the time series.
data (list[float | None]): The data points of the time series.
Methods:
replace_nan_with_none(cls, data: list[float]) -> list[float | None]:
Replace NaN values with None.
from_pandas(cls, data: pd.Series) -> Self:
Create a TimeSeries object from a Pandas Series.
to_pandas(self, timezone: str = "UTC") -> pd.Series:
Convert the TimeSeries object to a Pandas Series.
"""

name: str | None = None
data: list[float | None]
Expand Down
1,608 changes: 1,130 additions & 478 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ seaborn = "^0.13.2"
pytest = "^8.3.2"
entsoe-py = "^0.6.8"
energyid = "^0.0.17"
snakeviz = "^2.2.0"
27 changes: 14 additions & 13 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ argon2-cffi==23.1.0
arrow==1.3.0
asttokens==2.4.1
async-lru==2.0.4
attrs==23.2.0
babel==2.15.0
attrs==24.2.0
babel==2.16.0
beautifulsoup4==4.12.3
bleach==6.1.0
certifi==2024.7.4
cffi==1.16.0
cffi==1.17.0
charset-normalizer==3.3.2
colorama==0.4.6
comm==0.2.2
contourpy==1.2.1
cycler==0.12.1
debugpy==1.8.2
debugpy==1.8.5
decorator==5.1.1
defusedxml==0.7.1
energyid==0.0.17
Expand Down Expand Up @@ -57,15 +57,15 @@ jupyterlab==4.2.4
kiwisolver==1.4.5
markupsafe==2.1.5
matplotlib-inline==0.1.7
matplotlib==3.9.1
matplotlib==3.9.2
mistune==3.0.2
nbclient==0.10.0
nbconvert==7.16.4
nbformat==5.10.4
nest-asyncio==1.6.0
notebook-shim==0.2.4
notebook==7.2.1
numpy==2.0.0
numpy==2.0.1
overrides==7.7.0
packaging==24.1
pandas==2.2.2
Expand All @@ -79,7 +79,7 @@ prometheus-client==0.20.0
prompt-toolkit==3.0.47
psutil==6.0.0
ptyprocess==0.7.0
pure-eval==0.2.2
pure-eval==0.2.3
pycparser==2.22
pygments==2.18.0
pyparsing==3.1.2
Expand All @@ -89,21 +89,22 @@ python-json-logger==2.0.7
pytz==2024.1
pywin32==306
pywinpty==2.0.13
pyyaml==6.0.1
pyzmq==26.0.3
pyyaml==6.0.2
pyzmq==26.1.0
qtconsole==5.5.2
qtpy==2.4.1
referencing==0.35.1
requests==2.32.3
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rpds-py==0.19.0
rpds-py==0.20.0
seaborn==0.13.2
send2trash==1.8.3
setuptools==71.0.3
setuptools==72.2.0
six==1.16.0
snakeviz==2.2.0
sniffio==1.3.1
soupsieve==2.5
soupsieve==2.6
stack-data==0.6.3
terminado==0.18.1
tinycss2==1.3.0
Expand All @@ -116,7 +117,7 @@ tzdata==2024.1
uri-template==1.3.0
urllib3==2.2.2
wcwidth==0.2.13
webcolors==24.6.0
webcolors==24.8.0
webencodings==0.5.1
websocket-client==1.8.0
widgetsnbextension==4.0.11
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
annotated-types==0.7.0
numpy==2.0.0
multimethod==1.10
mypy-extensions==1.0.0
numpy==2.0.1
packaging==24.1
pandas==2.2.2
pandera==0.20.3
patsy==0.5.6
pydantic-core==2.20.1
pydantic==2.8.2
Expand Down

0 comments on commit 5b7ce61

Please sign in to comment.