Hugo Massonnat commited on
Commit
b5f210c
·
1 Parent(s): 5f29f14

monthly aggregation of historic weather data

Browse files
compute_et0_adjusted.py CHANGED
@@ -4,7 +4,7 @@ import pandas as pd
4
  import numpy as np
5
 
6
 
7
- def compute_et0_future(
8
  df: pd.DataFrame,
9
  latitude: float,
10
  longitude: float
@@ -35,11 +35,7 @@ def compute_et0_future(
35
  RHmin = df.relative_humidity_min
36
  RHmax = df.relative_humidity_max
37
  WS = df.wind_speed
38
- month = df.month
39
- year = df.year
40
- first_day = datetime.date(year, month, 1)
41
- day_of_year = first_day.timetuple().tm_yday
42
- JJulien = day_of_year
43
 
44
  l = agro_indicators.et0(
45
  irradiance,
@@ -65,12 +61,10 @@ if __name__ == "__main__":
65
  data_test["relative_humidity_min"] = [50, 60, 70]
66
  data_test["relative_humidity_max"] = [50, 60, 70]
67
  data_test["wind_speed"] = [5, 10, 15]
68
- data_test["month"] = [1, 2, 3]
69
- data_test["year"] = [2020, 2020, 2020]
70
 
71
  latitude = 40.7128
72
  longitude = 74.0060
73
 
74
- for i in range(len(data_test)):
75
- et0 = compute_et0_future(data_test.iloc[i], latitude, longitude)
76
- print(et0)
 
4
  import numpy as np
5
 
6
 
7
+ def compute_et0(
8
  df: pd.DataFrame,
9
  latitude: float,
10
  longitude: float
 
35
  RHmin = df.relative_humidity_min
36
  RHmax = df.relative_humidity_max
37
  WS = df.wind_speed
38
+ JJulien = df.day_of_year
 
 
 
 
39
 
40
  l = agro_indicators.et0(
41
  irradiance,
 
61
  data_test["relative_humidity_min"] = [50, 60, 70]
62
  data_test["relative_humidity_max"] = [50, 60, 70]
63
  data_test["wind_speed"] = [5, 10, 15]
64
+ data_test["day_of_year"] = [1, 32, 60]
 
65
 
66
  latitude = 40.7128
67
  longitude = 74.0060
68
 
69
+ et0 = compute_et0(data_test, latitude, longitude)
70
+ print(et0)
 
data_pipelines/historical_weather_data.py CHANGED
@@ -4,7 +4,7 @@ import requests_cache
4
  import pandas as pd
5
  from retry_requests import retry
6
 
7
- from compute_et0_adjusted import compute_et0_future
8
 
9
 
10
  def download_historical_weather_data(
@@ -81,8 +81,7 @@ def aggregate_hourly_weather_data(
81
  })
82
 
83
  monthly_data = pd.DataFrame.from_dict({
84
- "month": resampled_data.index.month,
85
- "year": resampled_data.index.year,
86
  "air_temperature_min": resampled_data[("temperature_2m", "min")],
87
  "air_temperature_max": resampled_data[("temperature_2m", "max")],
88
  "relative_humidity_min": resampled_data[("relative_humidity_2m", "min")],
@@ -102,6 +101,5 @@ if __name__ == '__main__':
102
  df = download_historical_weather_data(latitude, longitude, start_year, end_year)
103
  monthly_df = aggregate_hourly_weather_data(df)
104
 
105
- for i in range(len(monthly_df)):
106
- et0 = compute_et0_future(monthly_df.iloc[i], latitude, longitude)
107
- print(et0)
 
4
  import pandas as pd
5
  from retry_requests import retry
6
 
7
+ from compute_et0_adjusted import compute_et0
8
 
9
 
10
  def download_historical_weather_data(
 
81
  })
82
 
83
  monthly_data = pd.DataFrame.from_dict({
84
+ "day_of_year": resampled_data.index.dayofyear,
 
85
  "air_temperature_min": resampled_data[("temperature_2m", "min")],
86
  "air_temperature_max": resampled_data[("temperature_2m", "max")],
87
  "relative_humidity_min": resampled_data[("relative_humidity_2m", "min")],
 
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)