Skip to content

Commit 943ecdb

Browse files
committed
Updated Streamlit App with new ENR prediction model
1 parent cb6d38f commit 943ecdb

File tree

2 files changed

+17
-55
lines changed

2 files changed

+17
-55
lines changed

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ dependencies = [
3535
"eccodes",
3636
"cfgrib",
3737
"requests",
38-
"statsmodels",
3938
"geojson",
4039
"shapely",
4140
"tqdm",
@@ -80,7 +79,7 @@ build = "sphinx-build -b html doc/ doc/_build"
8079
[tool.hatch.envs.serve]
8180
extra-dependencies = [
8281
"streamlit",
83-
"streamlit-analytics2",
82+
# "streamlit-analytics2",
8483
]
8584

8685
[tool.hatch.envs.serve.scripts]

src/energy_forecast/dashboard/pages/2_Production.py

Lines changed: 16 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,15 @@
55
"""
66
from energy_forecast.energy import ECO2MixDownloader
77
from energy_forecast import ROOT_DIR
8-
from energy_forecast.meteo import get_region_sun, get_region_wind, memory
8+
from energy_forecast.meteo import ArpegeSimpleAPI, memory
9+
from energy_forecast.enr_production_model import ENRProductionModel
910
import pandas as pd
1011
import streamlit as st
1112
import altair as alt
1213
alt.renderers.set_embed_options(time_format_locale="fr-FR", format_locale="fr-FR")
1314

1415
@memory.cache
15-
def compute_data_pv_power(date: str)->pd.DataFrame:
16-
"""Estimate the power generated by solar panels.
17-
18-
Use the data from :func:`get_region_sun` and a linear model to estimate the power generated by solar panels.
19-
20-
Parameters
21-
----------
22-
date : str
23-
The date at which the power is estimated.
24-
25-
Returns
26-
-------
27-
pd.DataFrame
28-
The power generated by solar panels for each hour of the day.
29-
The columns are ["time", "pv_power"]
30-
"""
31-
sun_data = get_region_sun(date)
32-
sun_data.columns = [
33-
c.replace(" ", "_").replace("'", "_").replace("-", "_").lower()
34-
for c in sun_data.columns
35-
]
36-
model_params = pd.read_csv(ROOT_DIR / "data/silver/sun_model_2_params.csv")
37-
model_params.columns = ["region", "coef"]
38-
model_params_ser = model_params.set_index("region").iloc[:, 0]
39-
production = sun_data * model_params_ser
40-
pv_power = production.sum(axis=1).to_frame() / 24
41-
pv_power.reset_index(inplace=True)
42-
pv_power.columns = ["time", "pv_power"]
43-
return pv_power
44-
45-
@memory.cache
46-
def compute_data_eolien(date)->pd.DataFrame:
16+
def compute_my_prodiction(date)->pd.DataFrame:
4717
"""Estimate the power generated by eolien.
4818
4919
Use the data from :func:`get_region_swind` and a linear model to estimate the power generated by wind turbines.
@@ -59,20 +29,12 @@ def compute_data_eolien(date)->pd.DataFrame:
5929
The power generated by solar panels for each hour of the day.
6030
The columns are ["time", "eolien_power"]
6131
"""
62-
wind_data = get_region_wind(date)
63-
wind_data.columns = [
64-
c.replace(" ", "_").replace("'", "_").replace("-", "_").lower()
65-
for c in wind_data.columns
66-
]
67-
model_params = pd.read_csv(ROOT_DIR / "data/silver/wind_model_2_params.csv")
68-
model_params.columns = ["region", "coef"]
69-
model_params_ser = model_params.set_index("region").iloc[:, 0]
70-
production = wind_data * model_params_ser
71-
eolien_power = production.sum(axis=1).to_frame() / 24
72-
eolien_power.reset_index(inplace=True)
73-
eolien_power.columns = ["time", "eolien_power"]
74-
return eolien_power
75-
32+
wind_data = ArpegeSimpleAPI(date).departement_wind()
33+
sun_data = ArpegeSimpleAPI(date).departement_sun()
34+
my_model = ENRProductionModel.load(filename="model_departements.pkl")
35+
36+
predictions = my_model.predict(sun_data, wind_data)
37+
return predictions
7638

7739
@memory.cache
7840
def compute_energy(date:str):
@@ -101,8 +63,8 @@ def compute_energy(date:str):
10163
- ``"Eolien Prediction"``: the wind power production prediction (from linear model using weather date)
10264
10365
"""
104-
pv_power = compute_data_pv_power(date)
105-
eolien_power = compute_data_eolien(date)
66+
predictions = compute_my_prodiction(date)
67+
10668
current_year = pd.Timestamp(date).year
10769
r = ECO2MixDownloader(year=current_year)
10870
r.download()
@@ -116,9 +78,9 @@ def compute_energy(date:str):
11678
energy.index = energy.index.tz_localize("Europe/Paris").tz_convert("UTC").tz_localize(None)
11779
energy = pd.concat([
11880
energy,
119-
pv_power.set_index("time").rename(columns={"pv_power": "PV Prediction"}),
120-
eolien_power.set_index("time").rename(columns={"eolien_power": "Eolien Prediction"})
121-
], axis=1).reset_index()
81+
predictions.rename(columns={"sun": "PV Prediction",
82+
"wind": "Eolien Prediction"})
83+
], axis=1).reset_index(names="time")
12284

12385
return energy
12486

@@ -129,6 +91,7 @@ def compute_energy(date:str):
12991
# date = pd.Timestamp.now().strftime("%Y-%m-%d")
13092
energy = compute_energy(date_input)
13193
# keep only full hours, needed to plot the data without empty spaces
94+
print(energy)
13295
energy = energy[energy["time"].dt.minute == 0]
13396

13497
st.title("Prévision de production ENR")
@@ -162,4 +125,4 @@ def compute_energy(date:str):
162125
)
163126
st.altair_chart(sun_chart,
164127
use_container_width=True
165-
)
128+
)

0 commit comments

Comments
 (0)