Skip to content

Commit 29f901b

Browse files
authored
Merge pull request #9 from cyiallou/task/add-solar-maint-files
Add solar maintenance project files
2 parents 30c3d9f + 5c47b4f commit 29f901b

22 files changed

+8170
-14
lines changed

Diff for: RELEASE_NOTES.md

+10-13
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@
22

33
## Summary
44

5-
<!-- Here goes a general summary of what this release is about -->
6-
7-
## Upgrading
8-
9-
<!-- Here goes notes on how to upgrade from previous versions, including deprecations and what they should be replaced with -->
10-
11-
## New Features
12-
13-
<!-- Here goes the main new features and examples or instructions on how to use them -->
14-
15-
## Bug Fixes
16-
17-
<!-- Here goes notable bug fixes that are worth a special mention or explanation -->
5+
This is the first release of the library with the Solar Maintenance App! 🎉
6+
The repo provides tools to monitor and maintain solar energy systems with the following key features:
7+
- **Data Fetching and Processing:** Retrieve and preprocess weather and solar production data from external APIs (`frequenz-api-weather` and `frequenz-client-reporting`).
8+
- **Prediction Model Preparation:** Prepare basic time series models for solar power predictions.
9+
- **Visualisation Tools:** Generate calendar views, rolling averages, production profiles and daily statistics available via the `*Plotter` classes. Control what/how much data to show and how to display it using the corresponding configuration options. Customise the plots using tools like `PlotStyleStrategy` and `PlotManager`.
10+
- **Translation Support:** Enable English and German translations via the `TranslationManager` class, for controlling all text displayed on the plots and tables.
11+
- **Single Entry Point:** Integrate data fetching, processing and visualisations into a main workflow.
12+
- **Notification Service:** Send alert notifications via email with support for scheduling and retries, including a linear backoff mechanism.
13+
14+
This release provides tools to solar system operators to monitor performance and track trends, and lays the groundwork for identifying potential system issues.

Diff for: pyproject.toml

+12-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ classifiers = [
2727
requires-python = ">= 3.11, < 4"
2828
dependencies = [
2929
"typing-extensions >= 4.12.2, < 5",
30+
"numpy >= 1.26.4, < 1.27.0",
31+
"pandas >= 2.1.4, < 2.3.0",
32+
"matplotlib >= 3.8.4, < 3.11.0",
33+
"ipython == 8.31.0",
34+
"pvlib >= 0.11.0, < 0.12.0",
35+
"python-dotenv >= 0.21.0, < 1.1.0",
36+
"toml >= 0.10.2, < 0.11.0",
37+
"frequenz-client-reporting >= 0.13.0, < 0.14.0",
38+
"frequenz-api-weather >= 0.9.0, < 0.10.0",
3039
]
3140
dynamic = ["version"]
3241

@@ -57,6 +66,8 @@ dev-mkdocs = [
5766
]
5867
dev-mypy = [
5968
"mypy == 1.14.1",
69+
"pandas-stubs == 2.2.3.241126",
70+
"types-toml==0.10.8.20240310",
6071
"types-Markdown == 3.7.0.20241204",
6172
# For checking the noxfile, docs/ script, and tests
6273
"frequenz-lib-notebooks[dev-mkdocs,dev-noxfile,dev-pytest]",
@@ -164,7 +175,7 @@ packages = ["frequenz.lib.notebooks"]
164175
strict = true
165176

166177
[[tool.mypy.overrides]]
167-
module = ["mkdocs_macros.*", "sybil", "sybil.*"]
178+
module = ["mkdocs_macros.*", "sybil", "sybil.*", "pvlib", "pvlib.*"]
168179
ignore_missing_imports = true
169180

170181
[tool.setuptools_scm]

Diff for: src/frequenz/datasci/__init__.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# License: Proprietary
2+
# Copyright © 2024 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Initialise the datasci module."""
5+
6+
from . import weather
7+
8+
__all__ = [weather]

Diff for: src/frequenz/datasci/weather/__init__.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# License: Proprietary
2+
# Copyright © 2024 Frequenz Energy-as-a-Service GmbH
3+
4+
"""Module for interacting with the weather API service."""

Diff for: src/frequenz/datasci/weather/py.typed

Whitespace-only changes.

Diff for: src/frequenz/datasci/weather/weather_api.py

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""
2+
Module for interacting with the weather API service for fetching historical forecast data.
3+
4+
The module provides a client for the weather API service. The client can be used
5+
to retrieve historical weather forecast data for multiple locations and a given
6+
time range.
7+
8+
License: MIT
9+
Copyright © 2024 Frequenz Energy-as-a-Service GmbH
10+
"""
11+
12+
from datetime import datetime
13+
14+
import grpc.aio as grpcaio
15+
import pandas as pd
16+
from frequenz.client.weather._client import Client
17+
from frequenz.client.weather._types import ForecastFeature, Location
18+
19+
20+
async def fetch_historical_weather_forecasts( # pylint: disable=too-many-arguments
21+
*,
22+
service_address: str,
23+
feature_names: list[str],
24+
locations: list[tuple[float, float]],
25+
start_time: datetime,
26+
end_time: datetime,
27+
file_to_store: str = "",
28+
) -> pd.DataFrame:
29+
"""Fetch historical weather forecast data and return a pandas dataframe.
30+
31+
Args:
32+
service_address: The address of the service to connect to given in a
33+
form of a host followed by a colon and a port.
34+
feature_names: The list of forecast feature names. Each feature is a
35+
string representing a ForecastFeature enum value.
36+
locations: The list of locations to retrieve the forecast data for.
37+
Expects location as a tuple of (latitude, longitude) in this order.
38+
start_time: Start of the time range to get weather forecasts for.
39+
end_time: End of the time range to get weather forecasts for.
40+
file_to_store: The filename to optionally store the data. The data
41+
will be stored in the specified file format. Supported formats
42+
are 'csv' and 'parquet'.
43+
44+
Returns:
45+
A pandas dataframe containing the historical weather forecast data.
46+
47+
Raises:
48+
ValueError: If the file format is not supported.
49+
"""
50+
client = Client(service_address)
51+
52+
features = [ForecastFeature[fn] for fn in feature_names]
53+
locations_in = [
54+
Location(latitude=lat, longitude=lon, country_code="")
55+
for (lat, lon) in locations
56+
]
57+
58+
location_forecast_iterator = client.hist_forecast_iterator(
59+
features=features, locations=locations_in, start=start_time, end=end_time
60+
)
61+
62+
# The try and except block was added as a work-around until fixed in the service.
63+
# NOTE: Remove when fixed and uncomment the code block below.
64+
rows = []
65+
try:
66+
async for forecasts in location_forecast_iterator:
67+
rows.extend(forecasts.flatten())
68+
except grpcaio.AioRpcError:
69+
# this error occurs when forecasts for multiple locations are requested
70+
# can be ignored
71+
pass
72+
# rows = [
73+
# item
74+
# async for forecasts in location_forecast_iterator
75+
# for item in forecasts.flatten()
76+
# ]
77+
78+
df = pd.DataFrame(rows)
79+
valid_file_formats = ["csv", "parquet"]
80+
if file_to_store:
81+
file_format = file_to_store.split(".")[-1].lower()
82+
if file_format == "parquet":
83+
df.to_parquet(file_to_store)
84+
elif file_format == "csv":
85+
df.to_csv(file_to_store)
86+
else:
87+
raise ValueError(
88+
f"Unsupported file format: {file_format}. "
89+
f"Supported formats are: {', '.join(valid_file_formats)}."
90+
)
91+
return df

0 commit comments

Comments
 (0)