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')
WOFOST模型的Python代码实现
最新推荐文章于 2024-08-08 17:40:53 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)