Spaces:
Runtime error
Runtime error
added separation between infos and results in two pages
Browse files- .gitignore +1 -0
- app.py +143 -64
- func_utils.py +22 -3
- poetry.lock +0 -0
- requirements.txt +1 -1
- summary_test.py +76 -39
.gitignore
CHANGED
@@ -1,2 +1,3 @@
|
|
1 |
.env
|
2 |
__pycache__/
|
|
|
|
1 |
.env
|
2 |
__pycache__/
|
3 |
+
.venv/
|
app.py
CHANGED
@@ -46,78 +46,157 @@ description = "Example of simple chatbot with Gradio and Mistral AI via its API"
|
|
46 |
|
47 |
# import gradio as gr
|
48 |
from func_utils import *
|
|
|
49 |
|
50 |
-
|
51 |
-
gr.
|
52 |
-
"""
|
53 |
-
<style>
|
54 |
-
/* Custom style for a specific row */
|
55 |
-
.box {
|
56 |
-
background-color: #90909b;
|
57 |
-
# padding: 20px;
|
58 |
-
border-radius: 10px;
|
59 |
-
# border: solid 2px #4CAF50;
|
60 |
-
display: flex;
|
61 |
-
align-content: center;
|
62 |
-
padding: 20px;
|
63 |
-
}
|
64 |
-
.culture_box {
|
65 |
-
background-color: #52525b;
|
66 |
-
border-radius: 10px;
|
67 |
-
display: flex;
|
68 |
-
align-content: center;
|
69 |
-
}
|
70 |
-
</style>
|
71 |
-
"""
|
72 |
-
)
|
73 |
-
demo.title = "Démo GAIA - Les bénéfices de l'ombrage"
|
74 |
-
gr.HTML("<h1 style='text-align: center;'>Les bénéfices de l'ombrage</h1>")
|
75 |
-
gr.HTML(
|
76 |
-
"<p style='border: solid white 1px; border-radius: 10px; padding:20px'>L'outil vous permet de voir les avantages potentiels de l'ombrage sur votre exploitation. </p>"
|
77 |
-
)
|
78 |
-
|
79 |
-
with gr.Blocks() as infos:
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
with gr.Row(equal_height=True, elem_classes="box"):
|
86 |
-
with gr.Tab(label="
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
demo.load(on_init, [lat, lon, address], [lat, lon, map])
|
116 |
place_btn.click(on_init, [lat, lon, address], [lat, lon, map])
|
117 |
place_cancel_btn.click(on_delete, [lat, lon, map], [lat, lon, address, map])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
simulation_btn.click(
|
119 |
-
launch_simulation,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
)
|
121 |
demo.title = "Démo GAIA - Les bénéfices de l'ombrage"
|
122 |
-
# demo.description = "Example of simple chatbot with Gradio and Mistral AI via its API"
|
123 |
demo.launch()
|
|
|
46 |
|
47 |
# import gradio as gr
|
48 |
from func_utils import *
|
49 |
+
from summary_test import generate_irradiance_trend, get_mocked_summary
|
50 |
|
51 |
+
def go_to_page_1():
|
52 |
+
return gr.Column(visible=True), gr.Column(visible=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
|
54 |
+
with gr.Blocks() as demo:
|
55 |
+
with gr.Row():
|
56 |
+
page_1 = gr.Column(visible=True)
|
57 |
+
with page_1:
|
58 |
+
gr.HTML(
|
59 |
+
"""
|
60 |
+
<style>
|
61 |
+
/* Custom style for a specific row */
|
62 |
+
.box {
|
63 |
+
background-color: #90909b;
|
64 |
+
border-radius: 10px;
|
65 |
+
display: flex;
|
66 |
+
align-content: center;
|
67 |
+
padding: 20px;
|
68 |
+
}
|
69 |
+
.culture_box {
|
70 |
+
background-color: #52525b;
|
71 |
+
border-radius: 10px;
|
72 |
+
display: flex;
|
73 |
+
align-content: center;
|
74 |
+
}
|
75 |
+
.title-box{
|
76 |
+
background-color: #90909b;
|
77 |
+
}
|
78 |
+
</style>
|
79 |
+
"""
|
80 |
+
)
|
81 |
+
demo.title = "Démo GAIA - Les bénéfices de l'ombrage"
|
82 |
+
gr.HTML("<h1 style='text-align: center;'>Les bénéfices de l'ombrage</h1>")
|
83 |
+
gr.HTML(
|
84 |
+
"<p style='border: solid white 1px; border-radius: 10px; padding:20px'>L'outil vous permet de voir les avantages potentiels de l'ombrage sur votre exploitation. </p>"
|
85 |
+
)
|
86 |
+
|
87 |
+
with gr.Blocks() as infos:
|
88 |
+
|
89 |
+
infos.title = "Informations sur votre exploitation"
|
90 |
+
gr.HTML("<h2>Renseignez les informations relatives à votre projet</h2>")
|
91 |
+
with gr.Row(equal_height=True):
|
92 |
+
with gr.Column(variant="panel", scale=1):
|
93 |
+
with gr.Row(equal_height=True, elem_classes="box"):
|
94 |
+
with gr.Tab(label="Adresse", scale=1):
|
95 |
+
address = gr.Textbox(
|
96 |
+
label="Addresse",
|
97 |
+
info="Adresse de votre projet",
|
98 |
+
)
|
99 |
+
with gr.Tab(label="Coordonnées GPS", scale=1):
|
100 |
+
lat = gr.Number(
|
101 |
+
label="Latitude",
|
102 |
+
info="Latitude de votre projet",
|
103 |
+
)
|
104 |
+
lon = gr.Number(
|
105 |
+
label="Longitude",
|
106 |
+
info="Longitude de votre projet",
|
107 |
+
)
|
108 |
+
place_btn = gr.Button(
|
109 |
+
value="Valider la localisation", size="sm"
|
110 |
+
)
|
111 |
+
place_cancel_btn = gr.Button(
|
112 |
+
value="Réinitialiser la localisation", size="sm"
|
113 |
+
)
|
114 |
+
|
115 |
+
with gr.Row(elem_classes="box"):
|
116 |
+
culture = gr.Textbox(
|
117 |
+
label="Culture", scale=1, elem_classes="culture_box"
|
118 |
+
)
|
119 |
+
|
120 |
+
with gr.Column(variant="panel", scale=3):
|
121 |
+
map = gr.HTML()
|
122 |
+
|
123 |
+
simulation_btn = gr.Button(value="Lancer la simulation", size="lg")
|
124 |
+
|
125 |
+
go_to_page_2_btn = gr.Button("Aller aux résultats", visible=False)
|
126 |
+
|
127 |
+
page_2 = gr.Column(visible=False)
|
128 |
+
with page_2:
|
129 |
+
with gr.Blocks() as results:
|
130 |
+
results.title = "Résultats"
|
131 |
+
gr.HTML("<h2 style='padding: 20px'>Résultats de la simulation</h2>")
|
132 |
with gr.Row(equal_height=True, elem_classes="box"):
|
133 |
+
with gr.Tab(label="Analyse générale", scale=1):
|
134 |
+
with gr.Row(elem_classes="box"):
|
135 |
+
with gr.Column():
|
136 |
+
gr.HTML("<h2>Synthèse</h2>")
|
137 |
+
current_situation_summary = gr.TextArea(
|
138 |
+
placeholder="Synthèse de la simulation", label="", show_label=None
|
139 |
+
)
|
140 |
+
with gr.Row(elem_classes="box"):
|
141 |
+
with gr.Column():
|
142 |
+
gr.HTML("<h2>Déficit hydrique</h2>")
|
143 |
+
gr.Plot()
|
144 |
+
with gr.Column():
|
145 |
+
gr.HTML("<h2>Rendements</h2>")
|
146 |
+
gr.Plot()
|
147 |
+
with gr.Column(elem_classes="box"):
|
148 |
+
with gr.Row():
|
149 |
+
gr.HTML("<h2>Bilan climatique</h2>")
|
150 |
+
with gr.Row():
|
151 |
+
with gr.Column():
|
152 |
+
gr.HTML("<h3>Précipitations</h2>")
|
153 |
+
gr.Plot()
|
154 |
+
with gr.Column():
|
155 |
+
gr.HTML("<h3>Evapotranspiration</h2>")
|
156 |
+
gr.Plot()
|
157 |
+
with gr.Column():
|
158 |
+
gr.HTML("<h3>Irradiance</h2>")
|
159 |
+
gr.Plot()
|
160 |
+
with gr.Tab(label="Analyse avec AgriPv", scale=1):
|
161 |
+
with gr.Row(elem_classes="box"):
|
162 |
+
with gr.Column():
|
163 |
+
gr.HTML("<h2>Synthèse</h2>")
|
164 |
+
agripv_summary = gr.TextArea(
|
165 |
+
placeholder="Synthèse de la simulation", label="", show_label=None
|
166 |
+
)
|
167 |
+
with gr.Row(elem_classes="box"):
|
168 |
+
with gr.Column():
|
169 |
+
gr.HTML("<h2>Déficit hydrique</h2>")
|
170 |
+
gr.Plot()
|
171 |
+
with gr.Column():
|
172 |
+
gr.HTML("<h2>Rendements</h2>")
|
173 |
+
gr.Plot()
|
174 |
+
go_to_page_1_btn = gr.Button(value="Revenir aux informations du projet", size="lg")
|
175 |
|
176 |
demo.load(on_init, [lat, lon, address], [lat, lon, map])
|
177 |
place_btn.click(on_init, [lat, lon, address], [lat, lon, map])
|
178 |
place_cancel_btn.click(on_delete, [lat, lon, map], [lat, lon, address, map])
|
179 |
+
go_to_page_2_btn.click(
|
180 |
+
fn=go_to_page_2,
|
181 |
+
inputs="",
|
182 |
+
outputs=[page_1, page_2],
|
183 |
+
)
|
184 |
+
go_to_page_1_btn.click(
|
185 |
+
fn=go_to_page_1,
|
186 |
+
inputs="",
|
187 |
+
outputs=[page_1, page_2],
|
188 |
+
)
|
189 |
+
|
190 |
simulation_btn.click(
|
191 |
+
launch_simulation,
|
192 |
+
[lat, lon, address, culture],
|
193 |
+
[
|
194 |
+
current_situation_summary,
|
195 |
+
agripv_summary,
|
196 |
+
page_1,
|
197 |
+
page_2,
|
198 |
+
go_to_page_2_btn
|
199 |
+
],
|
200 |
)
|
201 |
demo.title = "Démo GAIA - Les bénéfices de l'ombrage"
|
|
|
202 |
demo.launch()
|
func_utils.py
CHANGED
@@ -1,8 +1,11 @@
|
|
1 |
import folium
|
2 |
import requests
|
|
|
3 |
|
|
|
4 |
|
5 |
-
|
|
|
6 |
def get_geolocation(adresse, latitude, longitude):
|
7 |
"""Return latitude, longitude & code INSEE from an adress. Latitude & longitude only if they are not specified in the function.
|
8 |
Args:
|
@@ -29,6 +32,7 @@ def get_geolocation(adresse, latitude, longitude):
|
|
29 |
return None, None, None
|
30 |
|
31 |
|
|
|
32 |
def on_init(lat, lon, address):
|
33 |
map_html, lat, lon = show_map(lat, lon, address)
|
34 |
return lat, lon, map_html
|
@@ -40,6 +44,7 @@ def on_delete(lat, lon, address):
|
|
40 |
return lat, lon, address, map_html
|
41 |
|
42 |
|
|
|
43 |
def show_map(lat, lon, address):
|
44 |
if address:
|
45 |
lat_tmp, lon_tmp, code_insee = get_geolocation(address, None, None)
|
@@ -57,6 +62,20 @@ def show_map(lat, lon, address):
|
|
57 |
return map_html, lat, lon
|
58 |
|
59 |
|
|
|
|
|
|
|
|
|
60 |
def launch_simulation(lat, lon, address, culture):
|
61 |
-
#
|
62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import folium
|
2 |
import requests
|
3 |
+
import gradio as gr
|
4 |
|
5 |
+
from summary_test import generate_irradiance_trend, get_mocked_summary
|
6 |
|
7 |
+
|
8 |
+
# code from https://huggingface.co/spaces/gaia-mistral/pest-livestock-information
|
9 |
def get_geolocation(adresse, latitude, longitude):
|
10 |
"""Return latitude, longitude & code INSEE from an adress. Latitude & longitude only if they are not specified in the function.
|
11 |
Args:
|
|
|
32 |
return None, None, None
|
33 |
|
34 |
|
35 |
+
# code from https://huggingface.co/spaces/gaia-mistral/pest-livestock-information
|
36 |
def on_init(lat, lon, address):
|
37 |
map_html, lat, lon = show_map(lat, lon, address)
|
38 |
return lat, lon, map_html
|
|
|
44 |
return lat, lon, address, map_html
|
45 |
|
46 |
|
47 |
+
# code from https://huggingface.co/spaces/gaia-mistral/pest-livestock-information
|
48 |
def show_map(lat, lon, address):
|
49 |
if address:
|
50 |
lat_tmp, lon_tmp, code_insee = get_geolocation(address, None, None)
|
|
|
62 |
return map_html, lat, lon
|
63 |
|
64 |
|
65 |
+
def go_to_page_2():
|
66 |
+
return gr.Column(visible=False), gr.Column(visible=True)
|
67 |
+
|
68 |
+
|
69 |
def launch_simulation(lat, lon, address, culture):
|
70 |
+
# current_situation_summary = get_mocked_summary("pessimiste")
|
71 |
+
# agripv_summary = get_mocked_summary("modéré")
|
72 |
+
current_situation_summary = "truc"
|
73 |
+
agripv_summary = "bicule"
|
74 |
+
page1, page_2 = go_to_page_2()
|
75 |
+
return (
|
76 |
+
current_situation_summary,
|
77 |
+
agripv_summary,
|
78 |
+
page1,
|
79 |
+
page_2,
|
80 |
+
gr.Button(visible=True),
|
81 |
+
)
|
poetry.lock
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
CHANGED
@@ -21,4 +21,4 @@ pvlib
|
|
21 |
matplotlib
|
22 |
xarray
|
23 |
folium
|
24 |
-
netcdf4
|
|
|
21 |
matplotlib
|
22 |
xarray
|
23 |
folium
|
24 |
+
netcdf4
|
summary_test.py
CHANGED
@@ -3,13 +3,21 @@ import pandas as pd
|
|
3 |
import numpy as np
|
4 |
|
5 |
from utils.summary import get_meterological_summary, get_agricultural_yield_comparison
|
|
|
6 |
# Générer des dates sur 5 ans (historique) + 5 ans (prévision)
|
7 |
-
dates_past = pd.date_range(
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
# Température: Tendance à la hausse selon le scénario
|
11 |
def generate_temperature_trend(scenario):
|
12 |
-
base_temp = 10 + 10 * np.sin(
|
|
|
|
|
13 |
if scenario == "optimiste":
|
14 |
trend = base_temp + np.linspace(0, 1, len(base_temp)) # Faible réchauffement
|
15 |
elif scenario == "modéré":
|
@@ -18,9 +26,12 @@ def generate_temperature_trend(scenario):
|
|
18 |
trend = base_temp + np.linspace(0, 3, len(base_temp)) # Fort réchauffement
|
19 |
return trend
|
20 |
|
|
|
21 |
# Précipitations: Variation selon le scénario
|
22 |
def generate_precipitation_trend(scenario):
|
23 |
-
base_rain = 50 + 20 * np.cos(
|
|
|
|
|
24 |
if scenario == "optimiste":
|
25 |
trend = base_rain - np.linspace(0, 5, len(base_rain)) # Légère baisse
|
26 |
elif scenario == "modéré":
|
@@ -29,37 +40,53 @@ def generate_precipitation_trend(scenario):
|
|
29 |
trend = base_rain - np.linspace(0, 15, len(base_rain)) # Forte baisse
|
30 |
return trend
|
31 |
|
|
|
32 |
# Irradiance: Augmentation progressive
|
33 |
def generate_irradiance_trend(scenario):
|
34 |
-
base_irradiance = 200 + 50 * np.sin(
|
|
|
|
|
35 |
if scenario == "optimiste":
|
36 |
-
trend = base_irradiance + np.linspace(
|
|
|
|
|
37 |
elif scenario == "modéré":
|
38 |
-
trend = base_irradiance + np.linspace(
|
|
|
|
|
39 |
else: # pessimiste
|
40 |
-
trend = base_irradiance + np.linspace(
|
|
|
|
|
41 |
return trend
|
42 |
|
43 |
-
# Choix du scénario
|
44 |
-
scenario = "modéré" # Changer entre "optimiste", "modéré" et "pessimiste"
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
-
# Afficher un extrait
|
57 |
-
print("Température (extrait) :")
|
58 |
-
print(temperature_df.head(3))
|
59 |
-
print("\nPrécipitations (extrait) :")
|
60 |
-
print(rain_df.head(3))
|
61 |
-
print("\nIrradiance (extrait) :")
|
62 |
-
print(irradiation_df.head(3))
|
63 |
|
64 |
if __name__ == "__main__":
|
65 |
# summary = get_meterological_summary(scenario, temperature_df, rain_df, irradiation_df)
|
@@ -70,6 +97,7 @@ if __name__ == "__main__":
|
|
70 |
import numpy as np
|
71 |
|
72 |
from utils.soil_utils import find_nearest_point
|
|
|
73 |
city = "Bourgogne Franche Comté"
|
74 |
closest_soil_features = find_nearest_point(city)
|
75 |
print(closest_soil_features)
|
@@ -79,7 +107,7 @@ if __name__ == "__main__":
|
|
79 |
end_date = "2029-12"
|
80 |
|
81 |
# Générer une série de dates mensuelles
|
82 |
-
dates = pd.date_range(start=start_date, end=end_date, freq=
|
83 |
|
84 |
# Générer des données fictives de rendement (en tonnes par hectare)
|
85 |
np.random.seed(42) # Pour reproductibilité
|
@@ -88,28 +116,37 @@ if __name__ == "__main__":
|
|
88 |
trend = np.linspace(2.5, 3.2, len(dates)) # Augmente légèrement sur les années
|
89 |
|
90 |
# Ajout de variations saisonnières et aléatoires
|
91 |
-
seasonality = 0.3 * np.sin(
|
|
|
|
|
92 |
random_variation = np.random.normal(0, 0.1, len(dates)) # Bruit aléatoire
|
93 |
|
94 |
# Calcul du rendement sans ombrage
|
95 |
yield_no_shade = trend + seasonality + random_variation
|
96 |
|
97 |
# Appliquer un effet d'ombrage (réduction de 10-20% du rendement)
|
98 |
-
shade_factor = np.random.uniform(
|
|
|
|
|
99 |
yield_with_shade = yield_no_shade * (1 - shade_factor)
|
100 |
|
101 |
# Créer le DataFrame
|
102 |
-
df = pd.DataFrame(
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
107 |
water_deficit_data = pd.DataFrame()
|
108 |
climate_data = pd.DataFrame()
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
|
|
|
|
|
|
|
3 |
import numpy as np
|
4 |
|
5 |
from utils.summary import get_meterological_summary, get_agricultural_yield_comparison
|
6 |
+
|
7 |
# Générer des dates sur 5 ans (historique) + 5 ans (prévision)
|
8 |
+
dates_past = pd.date_range(
|
9 |
+
start="2023-01-01", periods=36, freq="ME"
|
10 |
+
) # 3 ans d'historique
|
11 |
+
dates_future = pd.date_range(
|
12 |
+
start="2023-01-01", periods=60, freq="ME"
|
13 |
+
) # 5 ans de prévisions
|
14 |
+
|
15 |
|
16 |
# Température: Tendance à la hausse selon le scénario
|
17 |
def generate_temperature_trend(scenario):
|
18 |
+
base_temp = 10 + 10 * np.sin(
|
19 |
+
np.linspace(0, 2 * np.pi, len(dates_past) + len(dates_future))
|
20 |
+
)
|
21 |
if scenario == "optimiste":
|
22 |
trend = base_temp + np.linspace(0, 1, len(base_temp)) # Faible réchauffement
|
23 |
elif scenario == "modéré":
|
|
|
26 |
trend = base_temp + np.linspace(0, 3, len(base_temp)) # Fort réchauffement
|
27 |
return trend
|
28 |
|
29 |
+
|
30 |
# Précipitations: Variation selon le scénario
|
31 |
def generate_precipitation_trend(scenario):
|
32 |
+
base_rain = 50 + 20 * np.cos(
|
33 |
+
np.linspace(0, 2 * np.pi, len(dates_past) + len(dates_future))
|
34 |
+
)
|
35 |
if scenario == "optimiste":
|
36 |
trend = base_rain - np.linspace(0, 5, len(base_rain)) # Légère baisse
|
37 |
elif scenario == "modéré":
|
|
|
40 |
trend = base_rain - np.linspace(0, 15, len(base_rain)) # Forte baisse
|
41 |
return trend
|
42 |
|
43 |
+
|
44 |
# Irradiance: Augmentation progressive
|
45 |
def generate_irradiance_trend(scenario):
|
46 |
+
base_irradiance = 200 + 50 * np.sin(
|
47 |
+
np.linspace(0, 2 * np.pi, len(dates_past) + len(dates_future))
|
48 |
+
)
|
49 |
if scenario == "optimiste":
|
50 |
+
trend = base_irradiance + np.linspace(
|
51 |
+
0, 5, len(base_irradiance)
|
52 |
+
) # Faible augmentation
|
53 |
elif scenario == "modéré":
|
54 |
+
trend = base_irradiance + np.linspace(
|
55 |
+
0, 10, len(base_irradiance)
|
56 |
+
) # Augmentation modérée
|
57 |
else: # pessimiste
|
58 |
+
trend = base_irradiance + np.linspace(
|
59 |
+
0, 20, len(base_irradiance)
|
60 |
+
) # Forte augmentation
|
61 |
return trend
|
62 |
|
|
|
|
|
63 |
|
64 |
+
def get_mocked_summary(scenario):
|
65 |
+
# Choix du scénario
|
66 |
+
# scenario = "modéré" # Changer entre "optimiste", "modéré" et "pessimiste"
|
67 |
|
68 |
+
# Créer les DataFrames
|
69 |
+
temperature_df = pd.DataFrame(
|
70 |
+
{
|
71 |
+
"Date": dates_past.tolist() + dates_future.tolist(),
|
72 |
+
"Température (°C)": generate_temperature_trend(scenario),
|
73 |
+
}
|
74 |
+
)
|
75 |
|
76 |
+
rain_df = pd.DataFrame(
|
77 |
+
{
|
78 |
+
"Date": dates_past.tolist() + dates_future.tolist(),
|
79 |
+
"Précipitations (mm)": generate_precipitation_trend(scenario),
|
80 |
+
}
|
81 |
+
)
|
82 |
+
|
83 |
+
irradiation_df = pd.DataFrame(
|
84 |
+
{
|
85 |
+
"Date": dates_past.tolist() + dates_future.tolist(),
|
86 |
+
"Irradiance (W/m²)": generate_irradiance_trend(scenario),
|
87 |
+
}
|
88 |
+
)
|
89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
if __name__ == "__main__":
|
92 |
# summary = get_meterological_summary(scenario, temperature_df, rain_df, irradiation_df)
|
|
|
97 |
import numpy as np
|
98 |
|
99 |
from utils.soil_utils import find_nearest_point
|
100 |
+
|
101 |
city = "Bourgogne Franche Comté"
|
102 |
closest_soil_features = find_nearest_point(city)
|
103 |
print(closest_soil_features)
|
|
|
107 |
end_date = "2029-12"
|
108 |
|
109 |
# Générer une série de dates mensuelles
|
110 |
+
dates = pd.date_range(start=start_date, end=end_date, freq="M")
|
111 |
|
112 |
# Générer des données fictives de rendement (en tonnes par hectare)
|
113 |
np.random.seed(42) # Pour reproductibilité
|
|
|
116 |
trend = np.linspace(2.5, 3.2, len(dates)) # Augmente légèrement sur les années
|
117 |
|
118 |
# Ajout de variations saisonnières et aléatoires
|
119 |
+
seasonality = 0.3 * np.sin(
|
120 |
+
np.linspace(0, 12 * np.pi, len(dates))
|
121 |
+
) # Effet saisonnier
|
122 |
random_variation = np.random.normal(0, 0.1, len(dates)) # Bruit aléatoire
|
123 |
|
124 |
# Calcul du rendement sans ombrage
|
125 |
yield_no_shade = trend + seasonality + random_variation
|
126 |
|
127 |
# Appliquer un effet d'ombrage (réduction de 10-20% du rendement)
|
128 |
+
shade_factor = np.random.uniform(
|
129 |
+
0.1, 0.2, len(dates)
|
130 |
+
) # Entre 10% et 20% de réduction
|
131 |
yield_with_shade = yield_no_shade * (1 - shade_factor)
|
132 |
|
133 |
# Créer le DataFrame
|
134 |
+
df = pd.DataFrame(
|
135 |
+
{
|
136 |
+
"date": dates,
|
137 |
+
"yield_no_shade": yield_no_shade,
|
138 |
+
"yield_with_shade": yield_with_shade,
|
139 |
+
}
|
140 |
+
)
|
141 |
water_deficit_data = pd.DataFrame()
|
142 |
climate_data = pd.DataFrame()
|
143 |
+
|
144 |
+
summary = get_agricultural_yield_comparison(
|
145 |
+
culture="orge",
|
146 |
+
region="bourgogne franche comté",
|
147 |
+
water_df=water_deficit_data,
|
148 |
+
climate_df=climate_data,
|
149 |
+
soil_df=closest_soil_features,
|
150 |
+
agri_yield_df=df,
|
151 |
+
)
|
152 |
+
print(summary)
|