mohamed.tsouli commited on
Commit
55acd92
·
1 Parent(s): bf051a0

get yield max and coedf Kc and Ky

Browse files
Files changed (1) hide show
  1. retrieve_coefs_max_yield.py +71 -0
retrieve_coefs_max_yield.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import pandas as pd
3
+
4
+
5
+
6
+ def get_coefs_Kc_Ky_and_max_yield(culture: str, region: str = "Bourgogne-Franche-Comté"):
7
+ """
8
+ Get the crop coefficient (Kc) per month, yield response factor (Ky) per month, and maximum yield (Yx) for a specific crop.
9
+
10
+ Args:
11
+ region (str): Region of the crop (default: "Bourgogne-Franche-Comté")
12
+ culture (str): Crop name ["Colza d'hiver", "Orge d'hiver", "Blé tendre d'hiver"]
13
+ Returns:
14
+ DataFrame: Crop coefficients (Kc) per month, yield response factors (Ky) per month
15
+ Yx : Maximum yield (quintal/ha)
16
+ """
17
+
18
+ #CHECK THE REGION AND CROP
19
+ if region not in ["Bourgogne-Franche-Comté"]:
20
+ raise ValueError("The data region is not available.")
21
+ if culture not in ["Colza d'hiver", "Orge d'hiver", "Blé tendre d'hiver"]:
22
+ raise ValueError("The crop is not available.")
23
+
24
+ if culture=="Colza d'hiver":
25
+ culture_yield = "Colza grain d'hiver"
26
+ else:
27
+ culture_yield = culture
28
+
29
+
30
+ # read the csv file
31
+ df_coef = pd.read_csv("data/data_yield/Coefs_yield_franche_comte.csv", sep =";")
32
+ # filter the region
33
+ df_coef = df_coef[df_coef["Région"]==region]
34
+ # filter the crop
35
+ df_coef = df_coef[df_coef["Culture"]==culture]
36
+ # drop the columns "Stade de développement"
37
+ df_coef = df_coef.drop(columns=["Stade de développement","Région","Culture"])
38
+
39
+ # retrieve the maximum yield
40
+ # read the csv file
41
+ df_yield = pd.read_csv("data/data_yield/data_rendement.csv")
42
+ # filter the region
43
+ df_yield = df_yield[df_yield["LIB_REG2"]==region]
44
+ # filter the crop
45
+ # check if the culture name is part of the string "LIB_SAA"
46
+ isdf_yield = df_yield["LIB_SAA"].str.contains(culture_yield)
47
+ # filter the crop
48
+ df_yield = df_yield[isdf_yield]
49
+ # calculate the max yield from columns REND_2010 to REND_2023
50
+ columns_rend= [f"REND_{i}" for i in range(2010,2024)]
51
+ yield_max = df_yield[columns_rend].max(axis=1) *1.2
52
+
53
+ return df_coef, yield_max.iloc[0]
54
+
55
+ if __name__ == "__main__":
56
+
57
+ # Exemple d'utilisation
58
+ region = "Bourgogne-Franche-Comté"
59
+ culture = "Colza d'hiver"
60
+ df_coef, yield_max = get_coefs_Kc_Ky_and_max_yield(culture, region)
61
+
62
+ print(df_coef)
63
+ print(yield_max)
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+