WOFOST模型的Python代码实现

import pcse
import pandas as pd
import matplotlib.pyplot as plt
import os
from pcse.fileinput import CABOFileReader, ExcelWeatherDataProvider
from pcse.util import WOFOST71SiteDataProvider
from pcse.base import ParameterProvider
from pcse.fileinput import YAMLAgroManagementReader
from pcse.db import NASAPowerWeatherDataProvider
from pcse.models import Wofost71_WLP_FD
#设置文件读取路径
data_dir = r'D:\\wofost\\wofost_learn'

cropfile = os.path.join(data_dir, 'sug0601.crop')
cropdata = CABOFileReader(cropfile)
print(cropdata)

soilfile = os.path.join(data_dir, 'ec3.soil')
soildata = CABOFileReader(soilfile)
sitedata = WOFOST71SiteDataProvider(WAV=100, CO2=360)
print(sitedata)

parameters = ParameterProvider(cropdata=cropdata, soildata=soildata,sitedata=sitedata)

agromanagement_file = os.path.join(data_dir, 'sugarbeet_calendar.agro')
agromanagement = YAMLAgroManagementReader(agromanagement_file)
print(agromanagement)

wdp = ExcelWeatherDataProvider(os.path.join(data_dir,'nl1.xlsx'))
print(wdp)

wofsim = Wofost71_WLP_FD(parameters, wdp, agromanagement)
wofsim.run_till_terminate()

df = pd.DataFrame(wofsim.get_output()).set_index("day")
df.to_excel("wofost_results.xlsx")

output = wofsim.get_output()
print(len(output))

#画图
varnames = ["day", "DVS", "TAGP", "LAI", "SM"]
tmp = {}
for var in varnames:
      tmp[var] = [t[var] for t in output]
day = tmp.pop("day")
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(10,8))
for var, ax in zip(["DVS", "TAGP", "LAI", "SM"], axes.flatten()):
      ax.plot_date(day, tmp[var], 'b-')
      ax.set_title(var)
fig.autofmt_xdate()
fig.savefig('sugarbeet.png')

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
wofost是一种用于农作物生长和发育模拟的模型,在此使用Python语言编写wofost物候模拟的代码示例。 首先,我们需要导入所需的库: ```python import numpy as np import pandas as pd import wofost # 导入wofost模块 from pcse.models import Wofost71_WLP_FD ``` 接下来,我们可以定义一个模拟函数: ```python def wofost_simulation(climate_data, crop_parameters): # 为wofost模型创建一个新的实例 wofost_model = Wofost71_WLP_FD() # 加载气候数据和作物参数 wofost_model.set_weather(climate_data) wofost_model.set_crop(crop_parameters) # 运行wofost模型 wofost_model.run_till_terminate() # 获取模拟结果 output = wofost_model.get_output() return output ``` 在这个函数中,我们首先创建了一个wofost模型的实例,并加载了气候数据和作物参数。然后,我们通过调用`run_till_terminate()`方法来运行模型直到终止。最后,我们使用`get_output()`方法获取模拟结果。 下面是一个使用wofost物候模拟的示例代码: ```python # 加载气候数据 climate_data = pd.read_csv('climate_data.csv') # 加载作物参数 crop_parameters = { "SOIL": { "SMW": 0.4, "SMFCF": 0.8, "CRAIRC": 0.01, "WATER_FC": 0.5 }, "SPECIFICATIOn": { "HarvestIndex": 0.5 }, "WATERMNGMT": { "IrrMethod": 0, "AutomaticIrrigation": 1, "UseIrrDecision": 0, "SMT":0, "MaxIrr": 10, "MaxSurfaceStorage": 10 } } # 进行模拟 simulation_result = wofost_simulation(climate_data, crop_parameters) # 打印模拟结果 print(simulation_result) ``` 在这个示例代码中,我们首先加载了气候数据和作物参数。然后,调用`wofost_simulation()`函数进行模拟,并将模拟结果存储在`simulation_result`变量中。最后,我们打印出模拟结果。 这是一个简化的wofost物候模拟的Python代码示例,仅供参考。具体的实现可能需要根据数据的格式和需求进行适当的调整和扩展。
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值