Hugo Massonnat commited on
Commit
399a98a
·
1 Parent(s): 8ff070c

change visualization of yield

Browse files
Files changed (1) hide show
  1. compute_yield.py +19 -3
compute_yield.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import pandas as pd
2
  from matplotlib import pyplot as plt
3
 
@@ -34,7 +35,7 @@ def calculate_ETa(ETx, soil_moisture, field_capacity, wilting_point, water_defic
34
  Returns:
35
  float: Actual evapotranspiration (ETa) in mm
36
  """
37
- Ks = 1 - (water_deficit / (2 * ETo)) # coef de stress hydrique = precipitation / et0
38
  Ks = Ks.clip(lower=0, upper=1)
39
  ETa = ETx * Ks
40
 
@@ -152,7 +153,22 @@ if __name__ == '__main__':
152
  yield_forecast_with_shading = get_annual_yield(monthly_forecast_with_shading)
153
  # print(yield_forecast)
154
 
155
- plt.plot(yield_forecast.rolling(5).mean(), label="No shading")
156
- plt.plot(yield_forecast_with_shading.rolling(5).mean(), label="20% Shading")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  plt.legend()
 
158
  plt.show()
 
1
+ import numpy as np
2
  import pandas as pd
3
  from matplotlib import pyplot as plt
4
 
 
35
  Returns:
36
  float: Actual evapotranspiration (ETa) in mm
37
  """
38
+ Ks = 1 - (water_deficit / ETo) # coef de stress hydrique = precipitation / et0
39
  Ks = Ks.clip(lower=0, upper=1)
40
  ETa = ETx * Ks
41
 
 
153
  yield_forecast_with_shading = get_annual_yield(monthly_forecast_with_shading)
154
  # print(yield_forecast)
155
 
156
+ n_years = 10
157
+ years = 2025 + np.arange(len(yield_forecast_with_shading))
158
+ aggregated_forecasts = yield_forecast.rolling(n_years).sum()[years % n_years == 0]
159
+ aggregated_forecasts_with_shading = yield_forecast_with_shading.rolling(n_years).sum()[years % n_years == 0]
160
+ # plt.plot(yield_forecast.rolling(n_years).sum(), label="No shading")
161
+ # plt.plot(yield_forecast_with_shading.rolling(n_years).sum(), label="20% Shading")
162
+ # plt.bar(years[years % n_years == 0], aggregated_forecasts, label="No shading")
163
+ # plt.bar(years[years % n_years == 0], aggregated_forecasts_with_shading, label="20% Shading")
164
+
165
+ width = 3 # the width of the bars
166
+ fig, ax = plt.subplots(layout='constrained')
167
+
168
+ aggregated_years = years[years % n_years == 0]
169
+ rects = ax.bar(aggregated_years, aggregated_forecasts, width, label="No shading")
170
+ rects2 = ax.bar(aggregated_years + width, aggregated_forecasts_with_shading, width, label="20% shading")
171
+
172
  plt.legend()
173
+ plt.ylim(150)
174
  plt.show()