Exemple #1
0
def set_up_wofost(crop_start_date,
                  crop_end_date,
                  meteo,
                  crop,
                  variety,
                  soil,
                  wav=100,
                  co2=400,
                  rdmsol=100.):
    cropdata = YAMLCropDataProvider(fpath="./WOFOST_crop_parameters")
    cropdata.set_active_crop(crop, variety)
    soildata = CABOFileReader(soil)
    soildata['RDMSOL'] = rdmsol
    sitedata = WOFOST71SiteDataProvider(WAV=wav, CO2=co2)
    parameters = ParameterProvider(cropdata=cropdata,
                                   soildata=soildata,
                                   sitedata=sitedata)
    with open("temporal.amgt", 'w') as fp:
        fp.write(
            agromanagement_contents.format(year=crop_start_date.year,
                                           crop=crop,
                                           variety=variety,
                                           crop_start_date=crop_start_date,
                                           crop_end_date=crop_end_date))
    agromanagement = YAMLAgroManagementReader("temporal.amgt")

    wdp = CABOWeatherDataProvider(meteo, fpath=f"./data/meteo/{meteo}/")
    return parameters, agromanagement, wdp
def set_wofost_up(crop="maize",
                  variety="Maize_VanHeemst_1988",
                  meteo="Upper_East",
                  soil="ec4.new",
                  wav=60,
                  co2=400,
                  rdmsol=100):
    cropdata = YAMLCropDataProvider(fpath="./WOFOST_crop_parameters")
    cropdata.set_active_crop(crop, variety)
    soildata = CABOFileReader(soil)
    soildata["RDMSOL"] = rdmsol
    sitedata = WOFOST71SiteDataProvider(WAV=wav, CO2=co2)
    parameters = ParameterProvider(cropdata=cropdata,
                                   soildata=soildata,
                                   sitedata=sitedata)

    agromanagement = YAMLAgroManagementReader("ghana_maize.amgt")

    wdp = CABOWeatherDataProvider(meteo, fpath=f"./data/meteo/{meteo}/")
    return parameters, agromanagement, wdp
            crop_end_type: harvest
            max_duration: 200
        TimedEvents: null
        StateEvents: null
        """
    agro = yaml.load(agro_yaml)

    #crop parameters have two ways:
    #using YAML cropdataprovider to find the target crop
    #https://github.com/ajwdewit/WOFOST_crop_parameters (introduction of these parameters)
    from pcse.fileinput import YAMLCropDataProvider
    force_reload = True
    cropd = YAMLCropDataProvider()
    #cropd.print_crops_varieties ()
    #read soybena crop
    cropd.set_active_crop('soybean', 'Soybean_902')

    # read soil file
    from pcse.fileinput import CABOFileReader
    soildata = CABOFileReader("soy.soil")

    #site parameters
    from pcse.util import WOFOST71SiteDataProvider
    sitedata = WOFOST71SiteDataProvider(WAV=100, CO2=360)

    #pack the different sets of parameters
    from pcse.base_classes import ParameterProvider
    parameters = ParameterProvider(cropdata=cropd,
                                   soildata=soildata,
                                   sitedata=sitedata)  #cropdata = cropd
Exemple #4
0
def wofost_parameter_sweep_func(crop_start_date=dt.date(2011, 7, 1),
                                crop_end_date=dt.datetime(2011, 11, 1),
                                span=40.0,
                                tdwi=20.,
                                tsum1=750.,
                                tsum2=859.,
                                tsumem=70,
                                rgrlai=0.05,
                                cvo=0.05,
                                cvl=0.05,
                                meteo="Upper_East",
                                crop="maize",
                                variety="Maize_VanHeemst_1988",
                                soil="ec4.new",
                                wav=100,
                                co2=400,
                                rdmsol=100.,
                                potential=False):
    cropdata = YAMLCropDataProvider(fpath="./WOFOST_crop_parameters")
    cropdata.set_active_crop(crop, variety)
    soildata = CABOFileReader(soil)
    soildata["RDMSOL"] = rdmsol
    sitedata = WOFOST71SiteDataProvider(WAV=wav, CO2=co2)
    parameters = ParameterProvider(cropdata=cropdata,
                                   soildata=soildata,
                                   sitedata=sitedata)
    for p, v in zip(
        ["SPAN", "TSUM1", "TSUM2", "TSUMEM", "TDWI", "RGRLAI", "CVO", "CVL"],
        [span, tsum1, tsum2, tsumem, tdwi, rgrlai, cvo, cvl]):
        parameters.set_override(p, v, check=True)
    with open("temporal.amgt", 'w') as fp:
        fp.write(
            agromanagement_contents.format(year=crop_start_date.year,
                                           crop=crop,
                                           variety=variety,
                                           crop_start_date=crop_start_date,
                                           crop_end_date=crop_end_date))
    agromanagement = YAMLAgroManagementReader("temporal.amgt")

    wdp = CABOWeatherDataProvider(meteo, fpath=f"./data/meteo/{meteo}/")
    df_results, simulator = run_wofost(parameters,
                                       agromanagement,
                                       wdp,
                                       potential=potential)
    fig, axs = plt.subplots(nrows=5,
                            ncols=2,
                            sharex=True,
                            squeeze=True,
                            figsize=(16, 16))
    axs = axs.flatten()
    for j, p in enumerate(WOFOST_PARAMETERS):
        axs[j].plot_date(df_results.index, df_results[p], '-')
        axs[j].set_ylabel(WOFOST_LABELS[p], fontsize=8)

    plt.gcf().autofmt_xdate()
    plt.gca().fmt_xdata = matplotlib.dates.DateFormatter('%Y-%m-%d')
    axs[8].set_xlabel("Time [d]")
    axs[9].set_xlabel("Time [d]")

    key = f"span_{span}-tdwi_{tdwi}-tsum1_{tsum1}-tsum2_{tsum2}-tsumem_{tsumem}"
    key += f"-rgrlai_{rgrlai}-wav_{wav}-cvo_{cvo}-cvl_{cvl}"

    if potential:
        key += "-POT.csv"
    else:
        key += "-LIM.csv"

    df_results.to_csv(key, encoding="utf-8", index=False)
Exemple #5
0
# Don't add an extension to 'filename' write_cabo_weather_file will automatically add it.
cabo_weather_file = write_cabo_weather_file(year_of_interest,
                                            lat,
                                            lon,
                                            weather_data_to_write,
                                            filename=filename)

#=======================================
#======= Running the crop model ========

# Set up input paramter files describing soil and crop.
# You will always use the same files here
soil = CABOFileReader('Hengshui.soil')
site = WOFOST71SiteDataProvider(WAV=100, CO2=360)
crop = YAMLCropDataProvider('.')  # directory containing crop file
crop.set_active_crop('maize', 'Grain_maize_204')
parameters = ParameterProvider(crop, soil, site)

# Set up the parameters that describe sowing, harvest and crop management.
agromanagement = YAMLAgroManagementReader('timer_china_maize.amgt')
# Update agromanagement to the year we are interested in. This needs to
# match the year of the weather data you are using
new_agromanagement = change_year(agromanagement, year_of_interest)

# Set up the weather file with the weather data we wrote above
weather = CABOWeatherDataProvider(cabo_weather_file)

# Initialise the model
wofost = Wofost71_PP(parameters, weather, new_agromanagement)
# Run the crop model
wofost.run_till_terminate()