Hugo Massonnat commited on
Commit
542edf7
·
1 Parent(s): ac675c8

pipeline to retrieve soil properties

Browse files
Files changed (2) hide show
  1. compute_yield.py +20 -33
  2. utils/soil_utils.py +63 -4
compute_yield.py CHANGED
@@ -1,27 +1,5 @@
1
- import json
2
-
3
-
4
- def calcul_metriques_sol(clay, silt, sand, soc):
5
- """
6
- Calcule le point de flétrissement (WP), l'humidité actuelle du sol (SM) et la capacité au champ (FC).
7
-
8
- :param clay: Pourcentage d'argil dans le sol (%)
9
- :param silt: Pourcentage de silt dans le sol (%)
10
- :param sand: Pourcentage de sand dans le sol (%)
11
- :param soc: Carbone organique du sol (%)
12
- :return: WP, SM et FC (%)
13
- """
14
- # Calcul de la capacité au champ (FC)
15
- FC = 0.2576 * silt + 0.2484 * clay + 0.3664 * soc + 20.83
16
-
17
- # Calcul du point de flétrissement (WP)
18
- WP = 0.026 * clay + 0.5 * soc + 3.0
19
-
20
- # Calcul de l'humidité actuelle du sol (SM) comme 50% de la plage entre FC et WP
21
- SM = WP + 0.5 * (FC - WP)
22
-
23
- # Retourne les résultats sous forme de dictionnaire
24
- return round(SM, 2), round(FC, 2), round(WP, 2)
25
 
26
 
27
  def calculate_ETx(Kc, ETo):
@@ -78,17 +56,26 @@ def calculate_yield_projection(Yx, ETx, ETa, Ky):
78
  return round(Ya, 2)
79
 
80
 
 
 
 
 
 
 
81
 
 
 
 
82
 
83
- if __name__ =="__main__":
84
- # Exemple d'utilisation
85
- Yx = 10000 # Rendement maximum en quintal/ha
86
- Kc = 1.2 # Coefficient de culture
87
- Ky = 1.25 # Facteur de réponse du rendement pour le maïs
88
- soil_moisture, field_capacity, wilting_point = calcul_metriques_sol(clay=20, silt=40, sand=40, soc=1.5)
89
- ETo = 5.0 # Evapotranspiration de référence en mm/jour
90
  ETx = calculate_ETx(Kc, ETo)
91
- ETa = calculate_ETa(ETx, soil_moisture, field_capacity, wilting_point)
 
 
 
 
 
 
92
 
93
  projected_yield = calculate_yield_projection(Yx, ETx, ETa, Ky)
94
- print(f"Le rendement projeté est de {projected_yield} quintal/ha")
 
 
1
+ from forecast import get_forecast_data
2
+ from utils.soil_utils import get_soil_properties
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
 
5
  def calculate_ETx(Kc, ETo):
 
56
  return round(Ya, 2)
57
 
58
 
59
+ def get_yield_forecast(latitude: float, longitude: float, scenario: str = "pessimist", shading_coef: float = 0.):
60
+ monthly_forecast = get_forecast_data(latitude, longitude, scenario=scenario, shading_coef=shading_coef)
61
+
62
+ Kc, Ky = get_cultural_coefficients()
63
+
64
+ Yx = get_maximum_theoretical_yield()
65
 
66
+ soil_properties = get_soil_properties(latitude, longitude)
67
+
68
+ ETo = monthly_forecast["et0"]
69
 
 
 
 
 
 
 
 
70
  ETx = calculate_ETx(Kc, ETo)
71
+
72
+ ETa = calculate_ETa(
73
+ ETx,
74
+ soil_properties["soil_moisture"],
75
+ soil_properties["field_capacity"],
76
+ soil_properties["wilting_point"],
77
+ )
78
 
79
  projected_yield = calculate_yield_projection(Yx, ETx, ETa, Ky)
80
+
81
+ return projected_yield
utils/soil_utils.py CHANGED
@@ -1,4 +1,3 @@
1
- import json
2
  import geopandas as gpd
3
  from dotenv import load_dotenv
4
  from geopy.geocoders import Nominatim
@@ -6,7 +5,7 @@ from shapely.geometry import Point
6
 
7
  load_dotenv()
8
 
9
- file_rmqs ='data/soil_data/raw_data/rmqs.geojson'
10
  df = gpd.read_file(file_rmqs)
11
 
12
  def get_city_coordinates(city_name):
@@ -17,7 +16,7 @@ def get_city_coordinates(city_name):
17
  return (location.longitude, location.latitude)
18
  return None
19
 
20
- def find_nearest_point(city_name):
21
  """Find the closest GPS point in the dataset to the given city."""
22
  city_coords = get_city_coordinates(city_name)
23
  print("city coords", city_coords)
@@ -32,8 +31,68 @@ def find_nearest_point(city_name):
32
  return closest_point # Returns the closest feature
33
 
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  if __name__ == "__main__":
36
  # Example usage
37
  city = "Paris"
38
- closest_feature = find_nearest_point(city)
 
 
 
 
39
  print(closest_feature)
 
 
 
 
 
1
  import geopandas as gpd
2
  from dotenv import load_dotenv
3
  from geopy.geocoders import Nominatim
 
5
 
6
  load_dotenv()
7
 
8
+ file_rmqs ='../data/soil_data/raw_data/rmqs.geojson'
9
  df = gpd.read_file(file_rmqs)
10
 
11
  def get_city_coordinates(city_name):
 
16
  return (location.longitude, location.latitude)
17
  return None
18
 
19
+ def find_nearest_point_to_city(city_name):
20
  """Find the closest GPS point in the dataset to the given city."""
21
  city_coords = get_city_coordinates(city_name)
22
  print("city coords", city_coords)
 
31
  return closest_point # Returns the closest feature
32
 
33
 
34
+ def find_nearest_point_to_coordinates(latitude, longitude):
35
+ """Find the closest GPS point in the dataset to the given GPS coordinates."""
36
+ # Iterate through GeoJSON features
37
+ df["distance"] = df["geometry"].distance(Point(latitude, longitude))
38
+ closest_point = df.loc[df["distance"].idxmin()]
39
+
40
+ return closest_point # Returns the closest feature
41
+
42
+
43
+ def get_soil_properties(latitude, longitude):
44
+ closest_feature = find_nearest_point_to_coordinates(latitude, longitude)
45
+ clay = closest_feature.clay
46
+ silt = closest_feature.silt
47
+ sand = closest_feature.sand
48
+ soc = closest_feature.soc
49
+ soil_mosture, field_capacity, wilting_point = calcul_metriques_sol(clay, silt, sand, soc)
50
+
51
+ soil_properties = {
52
+ "clay": clay,
53
+ "silt": silt,
54
+ "sand": sand,
55
+ "soc": soc,
56
+ "soil_mosture": soil_mosture,
57
+ "field_capacity": field_capacity,
58
+ "wilting_point": wilting_point,
59
+ }
60
+
61
+ return soil_properties
62
+
63
+
64
+ def calcul_metriques_sol(clay, silt, sand, soc):
65
+ """
66
+ Calcule le point de flétrissement (WP), l'humidité actuelle du sol (SM) et la capacité au champ (FC).
67
+
68
+ :param clay: Pourcentage d'argil dans le sol (%)
69
+ :param silt: Pourcentage de silt dans le sol (%)
70
+ :param sand: Pourcentage de sand dans le sol (%)
71
+ :param soc: Carbone organique du sol (%)
72
+ :return: WP, SM et FC (%)
73
+ """
74
+ # Calcul de la capacité au champ (FC)
75
+ FC = 0.2576 * silt + 0.2484 * clay + 0.3664 * soc + 20.83
76
+
77
+ # Calcul du point de flétrissement (WP)
78
+ WP = 0.026 * clay + 0.5 * soc + 3.0
79
+
80
+ # Calcul de l'humidité actuelle du sol (SM) comme 50% de la plage entre FC et WP
81
+ SM = WP + 0.5 * (FC - WP)
82
+
83
+ # Retourne les résultats sous forme de dictionnaire
84
+ return round(SM, 2), round(FC, 2), round(WP, 2)
85
+
86
+
87
  if __name__ == "__main__":
88
  # Example usage
89
  city = "Paris"
90
+ closest_feature = find_nearest_point_to_city(city)
91
+ print(closest_feature)
92
+
93
+ latitude, longitude = 47, 5
94
+ closest_feature = find_nearest_point_to_coordinates(latitude, longitude)
95
  print(closest_feature)
96
+
97
+ soil_properties = get_soil_properties(latitude, longitude)
98
+ print(soil_properties)