pcse输出结果exel源码

# -*- coding: utf-8 -*-


import os, sys
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import pandas as pd
import pcse
from pcse.db import NASAPowerWeatherDataProvider
from pcse.fileinput import CABOFileReader
from pcse.fileinput import PCSEFileReader
from pcse.fileinput import YAMLAgroManagementReader
from pcse.models import Wofost71_WLP_FD
from pcse.base_classes import ParameterProvider
from pcse.fileinput import ExcelWeatherDataProvider

# First set the location where the crop, soil and crop calendar files can be found
data_dir = r"C:\Users\adminstrator\Desktop\maize"#文件路径
if data_dir == "":
    print("Variable 'data_dir' in line 19 must be set to the location of the the data folder")
    sys.exit()
#from  pcse.fileinput  import  ExcelWeatherDataProvider
#wdp  =  ExcelWeatherDataProvider ('nl1.xlsx' )
# Retrieve weather data from the NASA Power database
wdp = NASAPowerWeatherDataProvider(latitude=43, longitude=125,force_update = True,ETmodel ='PM' )#气候数据导入
#print (wdp)
#ppa = range(200710,2007310)
#widp = wdp(ppa)
#wither = pd.DataFrame(widp)
#print (ppa)
#wither.to_excel("wdp.xls")
'''drv =  CGMS8.weatherdataprovider(20070816)#
from datetime import date
day = date(2007,8,16)
wdc = wdp(day)
print(wdc)'''
# Read parameter values from the input files
cropdata = CABOFileReader(os.path.join(data_dir,'maize_new.crop'))#作物数据读入
soildata = CABOFileReader(os.path.join(data_dir,'ec3.soil'))#土壤数据
sitedata = {'SSMAX'  : 0.,
            'IFUNRN' : 0,
            'NOTINF' : 0,
            'SSI'    : 0,
            'WAV'    : 100,
            'SMLIM'  : 0.03,
            'CO2'    : 360}
parameters = ParameterProvider(cropdata=cropdata, soildata=soildata, sitedata=sitedata)

# Read agromanagement
agromanagement = YAMLAgroManagementReader(os.path.join(data_dir,'maize.amgt'))#管理数据读入
#weatherdataprovider = ExcelWeatherDataProvider(os.path.join(data_dir, "nl1.xlsx"))
#agromanagement = YAMLAgroManagementReader(os.path.join(data_dir, "maize.amgt"))

# Start WOFOST 运行wofost模型
wf = Wofost71_WLP_FD(parameters, wdp, agromanagement)
wf.run_till_terminate()

# Get time-series output from WOFOST and take the selected variables
output = wf.get_output()


df = pd.DataFrame(output)
df.to_excel("MAIZE2015_results.xls")#结果导入文件

varnames = ["day", "DVS", "TAGP", "LAI", "TWSO"]
tmp = {}
for var in varnames:
    tmp[var] = [t[var] for t in output]
day = tmp.pop("day")

# make a figure with 2x2 subplots
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(10,8))
# loop over variables and axes in order to plot on each axes
for var, ax in zip(["DVS", "TAGP", "LAI", "TWSO"], axes.flatten()):
    ax.plot_date(day, tmp[var], 'b-')
    ax.set_title(var)
# Autoformat the dates on the x-axis and generate a .PNG file
fig.autofmt_xdate()
fig.savefig('maize2015.png')

猜你喜欢

转载自blog.csdn.net/u011537121/article/details/80500459