Hugo Massonnat commited on
Commit
4b837f2
·
1 Parent(s): b5f210c

add precipitation to historic data

Browse files
data_pipelines/historical_weather_data.py CHANGED
@@ -1,7 +1,8 @@
1
  import openmeteo_requests
2
 
3
- import requests_cache
4
  import pandas as pd
 
5
  from retry_requests import retry
6
 
7
  from compute_et0_adjusted import compute_et0
@@ -77,7 +78,9 @@ def aggregate_hourly_weather_data(
77
  "temperature_2m": ["min", "max"],
78
  "relative_humidity_2m": ["min", "max"],
79
  "wind_speed_10m": "mean",
 
80
  "shortwave_radiation": "mean",
 
81
  })
82
 
83
  monthly_data = pd.DataFrame.from_dict({
@@ -86,8 +89,10 @@ def aggregate_hourly_weather_data(
86
  "air_temperature_max": resampled_data[("temperature_2m", "max")],
87
  "relative_humidity_min": resampled_data[("relative_humidity_2m", "min")],
88
  "relative_humidity_max": resampled_data[("relative_humidity_2m", "max")],
 
89
  "wind_speed": resampled_data[("wind_speed_10m", "mean")],
90
  "irradiance": resampled_data[("shortwave_radiation", "mean")],
 
91
  })
92
 
93
  return monthly_data
@@ -96,10 +101,14 @@ def aggregate_hourly_weather_data(
96
  if __name__ == '__main__':
97
  latitude = 47
98
  longitude = 3
99
- start_year = 2020
100
- end_year = 2021
101
  df = download_historical_weather_data(latitude, longitude, start_year, end_year)
102
  monthly_df = aggregate_hourly_weather_data(df)
103
 
104
  et0 = compute_et0(monthly_df, latitude, longitude)
105
- print(et0)
 
 
 
 
 
1
  import openmeteo_requests
2
 
3
+ import matplotlib.pyplot as plt
4
  import pandas as pd
5
+ import requests_cache
6
  from retry_requests import retry
7
 
8
  from compute_et0_adjusted import compute_et0
 
78
  "temperature_2m": ["min", "max"],
79
  "relative_humidity_2m": ["min", "max"],
80
  "wind_speed_10m": "mean",
81
+ "precipitation": "mean",
82
  "shortwave_radiation": "mean",
83
+ "et0_fao_evapotranspiration": "mean",
84
  })
85
 
86
  monthly_data = pd.DataFrame.from_dict({
 
89
  "air_temperature_max": resampled_data[("temperature_2m", "max")],
90
  "relative_humidity_min": resampled_data[("relative_humidity_2m", "min")],
91
  "relative_humidity_max": resampled_data[("relative_humidity_2m", "max")],
92
+ "precipitation": resampled_data[("precipitation", "mean")],
93
  "wind_speed": resampled_data[("wind_speed_10m", "mean")],
94
  "irradiance": resampled_data[("shortwave_radiation", "mean")],
95
+ "et0_fao_evapotranspiration": resampled_data[("et0_fao_evapotranspiration", "mean")],
96
  })
97
 
98
  return monthly_data
 
101
  if __name__ == '__main__':
102
  latitude = 47
103
  longitude = 3
104
+ start_year = 2000
105
+ end_year = 2024
106
  df = download_historical_weather_data(latitude, longitude, start_year, end_year)
107
  monthly_df = aggregate_hourly_weather_data(df)
108
 
109
  et0 = compute_et0(monthly_df, latitude, longitude)
110
+ monthly_df["et0"] = et0
111
+
112
+ plt.plot(monthly_df["et0_fao_evapotranspiration"] * 100)
113
+ plt.plot(monthly_df["et0"] + 5)
114
+ plt.show()
requirements.txt CHANGED
@@ -17,4 +17,5 @@ requests_cache
17
  retry_requests
18
  fuzzywuzzy
19
  plotly
20
- pvlib
 
 
17
  retry_requests
18
  fuzzywuzzy
19
  plotly
20
+ pvlib
21
+ matplotlib