Spaces:
Runtime error
Runtime error
Hugo Massonnat
commited on
Commit
·
25d0ed1
1
Parent(s):
399a98a
add function to create bar plot for yield
Browse files- compute_yield.py +42 -0
compute_yield.py
CHANGED
@@ -125,6 +125,48 @@ def get_annual_yield(monthly_forecast: pd.DataFrame) -> pd.Series:
|
|
125 |
return yield_forecast
|
126 |
|
127 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
if __name__ == '__main__':
|
129 |
culture = "Colza d'hiver"
|
130 |
scenario = "pessimist"
|
|
|
125 |
return yield_forecast
|
126 |
|
127 |
|
128 |
+
def plot_yield(
|
129 |
+
latitude: float,
|
130 |
+
longitude: float,
|
131 |
+
culture: str = "Colza d'hiver",
|
132 |
+
region: str = "Bourgogne-Franche-Comté",
|
133 |
+
scenario: str = "pessimist",
|
134 |
+
shading_coef: float = 0.,
|
135 |
+
) -> plt.Figure:
|
136 |
+
monthly_forecast = compute_yield_forecast(
|
137 |
+
latitude=latitude,
|
138 |
+
longitude=longitude,
|
139 |
+
culture=culture,
|
140 |
+
scenario=scenario,
|
141 |
+
shading_coef=0.,
|
142 |
+
)
|
143 |
+
|
144 |
+
monthly_forecast_with_shading = compute_yield_forecast(
|
145 |
+
latitude=latitude,
|
146 |
+
longitude=longitude,
|
147 |
+
culture=culture,
|
148 |
+
scenario=scenario,
|
149 |
+
shading_coef=shading_coef,
|
150 |
+
)
|
151 |
+
|
152 |
+
yield_forecast = get_annual_yield(monthly_forecast)
|
153 |
+
yield_forecast_with_shading = get_annual_yield(monthly_forecast_with_shading)
|
154 |
+
|
155 |
+
n_years = 10
|
156 |
+
years = 2025 + np.arange(len(yield_forecast_with_shading))
|
157 |
+
aggregated_forecasts = yield_forecast.rolling(n_years).sum()[years % n_years == 0]
|
158 |
+
aggregated_forecasts_with_shading = yield_forecast_with_shading.rolling(n_years).sum()[years % n_years == 0]
|
159 |
+
|
160 |
+
width = 3 # the width of the bars
|
161 |
+
fig, ax = plt.subplots(layout='constrained')
|
162 |
+
aggregated_years = years[years % n_years == 0]
|
163 |
+
_ = ax.bar(aggregated_years, aggregated_forecasts, width, label="No shading")
|
164 |
+
_ = ax.bar(aggregated_years + width, aggregated_forecasts_with_shading, width, label="20% shading")
|
165 |
+
ax.legend()
|
166 |
+
ax.set_ylim(150)
|
167 |
+
|
168 |
+
return fig
|
169 |
+
|
170 |
if __name__ == '__main__':
|
171 |
culture = "Colza d'hiver"
|
172 |
scenario = "pessimist"
|