去B吧,这里没图
我用的Win10啦,Linux、Mac可能得自己再去微调一下。
我用的Pycharm,个人感觉最好使的IDE,没有之一。
Python 解释器随便装个咯,我用的 Python 3.10 版本。
对于 Python,我其实也是个小白,只会写些小脚本,哈哈哈哈哈。
Wofost 模型Python版本
敏感性分析用的包
参数优化包,算法很多,我用的SA
目标变量 地上部生物量:TAGP;最大叶面积指数:LAIMAX;器官重:TWSO;
target_variable = run_details.target_variable
sa_method = run_details.sa_method
run_type = run_details.run_type
params_type = run_details.params_type
problems_parameters = pd.read_excel(params_dir / f"sensitivity_analysis_parameters_{params_type}.xlsx")
problem = {
‘num_vars’: len(problems_parameters),
‘names’: problems_parameters[‘name’].tolist(),
‘bounds’: problems_parameters[[‘low’, ‘up’]].values.tolist()
}
seed = 2000
calc_second_order = True
nsamples = 256
print(“\n================ 参数抽样开始 ================\n”)
st = datetime.datetime.now().timestamp()
paramsets = None
nsamples = 65 * len(problems_parameters)
paramsets = fast_sampler.sample(problem, nsamples, seed=seed)
paramsets_df = pd.DataFrame(paramsets)
paramsets_df.columns = problem[‘names’]
et = datetime.datetime.now().timestamp()
print(f"\n================ 生成参数集结束 {et-st}s ================\n")
target_results = []
with tqdm(total=len(paramsets)) as pbar:
# cpu核数进程池
with mp.Pool(mp.cpu_count()) as pool:
# 并行执行
for result in pool.imap(run_wofost_partial, paramsets):
target_results.append(result)
pbar.update()
et = datetime.datetime.now().timestamp()
print(f"\n================ 执行模拟结束 {et-st}s ================\n")
Si = fast.analyze(problem, target_results, seed=seed)
话不多说,直接模拟退火
初始值用的参数默认值,然后上下波动优化
objfunc_calculator = ObjectiveFunctionCalculator()
lowers, uppers, steps, defaults = [], [], [], []
defaults = [22.8, 0.00406, 525, 962, 24.64, 0.455]
for key, default, fluctuate in tuning_parameters:
lowers.append(default * (1 - fluctuate))
uppers.append(default * (1 + fluctuate))
steps.append(default * 2 * fluctuate / step_times)
firstguess = defaults
sa = SA(func=objfunc_calculator, x0=firstguess, T_max=100, T_min=1e-7, L=1000, max_stay_counter=5, lb=lowers, ub=uppers)
best_x, best_y = sa.run()
这里用的ENKF同化叶面积指数。
observations_for_DA = [(row[‘day’].date(), {‘LAI’: (row[‘LAI’], std_lai[index])}) for index, row in df_observation_LAI.iterrows()]
for i in range(ensemble_size):
for par, distr in override_parameters.items():
p.set_override(par, distr[i])
member = Wofost72_WLP_FD(p, weatherdataprovider, agromanagement)
ensemble.append(member)
for i in range(0, len(observations_for_DA)):
# 模型狂奔
da_enkf_single(i)
for member in ensemble:
member.run_till_terminate()
去B站讨论吧,平常不登录CSDN
挂个小广告不会太过份吧~
需要指导的话,那就得让我挣点零花咯,嘿嘿。PS:不说虚的,程序狂奔才是最重要的。
【闲鱼】https://m.tb.cn/h.5ttgPfa?tk=ue5dW9B3RMm HU9046 「我在闲鱼发布了【wofost python版本 pcse代码 指导】」