File size: 2,408 Bytes
55acd92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6394e9c
55acd92
 
6394e9c
55acd92
 
 
 
 
 
 
 
 
6394e9c
55acd92
6394e9c
55acd92
 
 
 
 
 
 
 
 
 
417cac0
 
55acd92
 
 
 
 
 
 
 
 
 
 
 
6394e9c
55acd92
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74

import pandas as pd



def get_coefs_Kc_Ky_and_max_yield(culture: str, region: str = "Bourgogne-Franche-Comté"):
    """
    Get the crop coefficient (Kc) per month, yield response factor (Ky) per month, and maximum yield (Yx) for a specific crop.
    
    Args:
    region (str): Region of the crop (default: "Bourgogne-Franche-Comté")
    culture (str): Crop name ["Colza d'hiver", "Orge d'hiver", "Blé tendre d'hiver"]
    Returns:
    DataFrame: Crop coefficients (Kc) per month, yield response factors (Ky) per month
    Yx : Maximum yield (quintal/ha)
    """

    #CHECK THE REGION AND CROP
    if region not in ["Bourgogne-Franche-Comté"]:
        raise ValueError("The data region is not available.")
    if culture.lower() not in ["colza d'hiver", "orge d'hiver", "blé tendre d'hiver"]:
        raise ValueError("The crop is not available.")

    if culture.lower()=="colza d'hiver":
        culture_yield = "Colza grain d'hiver"
    else:
        culture_yield = culture


    # read the csv file
    df_coef = pd.read_csv("data/data_yield/Coefs_yield_franche_comte.csv", sep =";")
    # filter the region
    df_coef = df_coef[df_coef["Région"]==region]
    df_coef["Culture"] = df_coef["Culture"].str.lower()
    # filter the crop
    df_coef = df_coef[df_coef["Culture"]==culture.lower()]
    # drop the columns "Stade de développement"
    df_coef = df_coef.drop(columns=["Stade de développement","Région","Culture"])
    
    # retrieve the maximum yield
    # read the csv file
    df_yield = pd.read_csv("data/data_yield/data_rendement.csv")
    # filter the region
    df_yield = df_yield[df_yield["LIB_REG2"]==region]
    # filter the crop
    # check if the culture name is part of the string "LIB_SAA"
    df_yield["LIB_SAA"] = df_yield["LIB_SAA"].str.lower()
    isdf_yield = df_yield["LIB_SAA"].str.contains(culture_yield.lower())
    # filter the crop
    df_yield = df_yield[isdf_yield]
    # calculate the max yield from columns REND_2010 to REND_2023
    columns_rend= [f"REND_{i}" for i in range(2010,2024)]
    yield_max = df_yield[columns_rend].max(axis=1) *1.2

    return df_coef, yield_max.iloc[0]

if __name__ == "__main__":

    # Exemple d'utilisation
    region = "Bourgogne-Franche-Comté"
    culture = "blé tendre d'hiver"
    df_coef, yield_max = get_coefs_Kc_Ky_and_max_yield(culture, region)
    
    print(df_coef)
    print(yield_max)