Advertisement

01 Getting Started with PCSE

阅读量:

该教程介绍了如何使用Python中的PCSE库进行作物生长模拟的基本步骤。首先,在Jupyter Notebook环境中打开虚拟环境并安装PCSE库后(通过pip install pcse命令),可以创建一个Wofost模型实例并初始化它。通过调用run()方法可以执行模拟,并根据需要指定运行天数或直到终止条件为止。此外,还可以使用getoutput()方法获取模拟结果并将其转换为DataFrame显示,并通过getsummary_output()方法快速获得关键摘要信息以方便后续分析和处理。最后,默认情况下会在笔记本中生成相应的图形来展示动态变化趋势或最终结果图景。

参考来源:01 Getting Started with PCSE.ipynb
首先仍然是启动旧的gee虚拟环境。

在这里插入图片描述
复制代码
    pip install pcse -i https://pypi.tuna.tsinghua.edu.cn/simple/

安装好之后,打开jupyter notebook

复制代码
    %matplotlib inline
    import sys
    import pcse
    import pandas
    import matplotlib
    matplotlib.style.use("ggplot")
    import matplotlib.pyplot as plt
    print("This notebook was built with:")
    print(f"python version: {sys.version}")
    print(f"PCSE version: {pcse.__version__}")
复制代码
    wofostPP = pcse.start_wofost(mode="pp")
    wofostPP.run()

也可以指定运行时间,并获取最后一天的参数

复制代码
    wofostPP.run(days=10)
    wofostPP.get_variable("LAI")
在这里插入图片描述

用run_till_terminate()代表终止

复制代码
    wofostPP.run_till_terminate()

用.get_output来获取过程参数,并将这些参数转为dataframe显示

复制代码
    output = wofostPP.get_output()
    dfPP = pandas.DataFrame(output).set_index("day")
    dfPP.tail()
在这里插入图片描述

get_summary_output() 方法常用于完成PCSE模拟过程后提取模拟运行的结果摘要。该方法能够提取如单位时间内的总产量、水资源消耗量等指标的具体数据。它不仅能够提供对模拟结果的关键数据进行集中展示,并且还能够为用户提供便捷的数据整理与分析功能。

复制代码
    summary_output = wofostPP.get_summary_output()
    msg = "Reached maturity at {DOM} with total biomass {TAGP:.1f} kg/ha, " \
      "a yield of {TWSO:.1f} kg/ha with a maximum LAI of {LAIMAX:.2f}."
    for crop_cycle in summary_output:
    print(msg.format(**crop_cycle))
在这里插入图片描述
复制代码
    fig, (axis1, axis2) = plt.subplots(nrows=1, ncols=2, figsize=(16,8), sharex=True)
    dfPP["LAI"].plot(ax=axis1, label="LAI", color='k')
    dfPP["TAGP"].plot(ax=axis2, label="Total biomass")
    dfPP["TWSO"].plot(ax=axis2, label="Yield")
    axis1.set_title("Leaf Area Index")
    axis2.set_title("Crop biomass")
    r = axis2.legend()
    fig.autofmt_xdate()
在这里插入图片描述

全部评论 (0)

还没有任何评论哟~