Yasso20模型R语言实现运行报错及修改合理性确认求助
关于Yasso20模型R实现的运行问题及修改尝试
我在运行Yasso20模型的R语言实现时,使用对应测试数据调用函数:
Yasso20(YParameters = sample_parameters, SimulationTime = sample_data_run$time, MonthlyTemperature = sample_data_run$temp, Precipitation = sample_data_run$prec, InitialCPool = sample_data_run$init, LitterInput = sample_data_run$litter, WoodySize = sample_data_run$wsize, leac = sample_data_run$leac, SS_pred = TRUE)
出现报错:
Error in if (tem <= 1e-16) { : the condition has length > 1
猜测函数需要按时间步循环调用,于是尝试单步测试:
Yasso20(YParameters = sample_parameters, SimulationTime = sample_data_run$time[1], MonthlyTemperature = sample_data_run$temp[1], Precipitation = sample_data_run$prec[1], InitialCPool = sample_data_run$init[1], LitterInput = sample_data_run$litter[1], WoodySize = sample_data_run$wsize[1], leac = sample_data_run$leac[1], SS_pred = TRUE)
仍报错:
Error in h(simpleError(msg, call)) : error in evaluating the argument 'x' in selecting a method for function 'as.array': replacement has length zero
我怀疑是输入数据格式问题,但不确定正确格式和可用测试数据。
2024年2月1日更新
对比原Fortran90代码中温度依赖的实现:
tem = 0.0 temN = 0.0 temH = 0.0 DO i = 1,12 ! Average temperature and precipitation dependence tem = tem+EXP(theta(22)*temp(i)+theta(23)*temp(i)**2.0) temN = temN+EXP(theta(24)*temp(i)+theta(25)*temp(i)**2.0) temH = temH+EXP(theta(26)*temp(i)+theta(27)*temp(i)**2.0) END DO
我修改了R语言的Yasso20函数中对应的温度计算部分:
tem <- 0 temN <- 0 temH <- 0 for (i in 1:12) { tem <- tem + exp(theta[22] * T[,i] + theta[23] * T[i]^2) temN <- temN + exp(theta[24] * T[,i] + theta[25] * T[i]^2) temH <- temH + exp(theta[26] * T[,i] + theta[27] * T[i]^2) }
修改后用以下参数调用函数可正常运行,但不确定这个修改方法是否正确:
Yasso20(YParameters = sample_parameters, SimulationTime = sample_data_run$time[1], MonthlyTemperature = sample_data_run$temp[1,], Precipitation = sample_data_run$prec[1], InitialCPool = sample_data_run$init, LitterInput = sample_data_run$litter[1,], WoodySize = sample_data_run$wsize[1], leac = sample_data_run$leac[1], SS_pred = TRUE)
内容的提问来源于stack exchange,提问作者jordi
相关产品推荐
相关产品推荐

