-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed #70, added tests to propery recognize list-parameters in multir…
…un-simulations
- Loading branch information
--replace-all
committed
Dec 8, 2023
1 parent
acb9e7d
commit afc5fdc
Showing
4 changed files
with
67 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
library(LWFBrook90R) | ||
library(data.table) | ||
data("slb1_soil") | ||
data("slb1_meteo") | ||
|
||
if (parallelly::availableCores() > 1) { | ||
cores <- 2 | ||
} else { | ||
cores <- 1 | ||
} | ||
|
||
soil <- cbind(slb1_soil, hydpar_wessolek_tab(texture = slb1_soil$texture)) | ||
soil_lay_mat <- soil_to_param(soil) | ||
|
||
opts <- set_optionsLWFB90(startdate = as.Date("2002-12-15"), enddate = as.Date("2003-01-15")) | ||
parms <- set_paramLWFB90(sai = c(0.5,1.2),maxlai = c(2,5), | ||
soil_nodes = soil_lay_mat$soil_nodes, | ||
soil_materials = soil_lay_mat$soil_materials) | ||
|
||
|
||
vary_parms <- data.frame(maxlai = c(0.941, 0.952), | ||
sai2 = c(0.951, 0.952), | ||
fsintlai = c(0.961,0.962), | ||
frintsai = c(0.971, 0.972), | ||
fsintsai = c(0.981, 0.982), | ||
soil_materials.ths2 = c(0.991,0.992)) | ||
|
||
res_multi <- run_multi_LWFB90(paramvar = vary_parms[1:N,], | ||
param_b90 = parms, | ||
options_b90 = opts, | ||
climate = slb1_meteo) | ||
|
||
|
||
used_singleparms = rbindlist( | ||
lapply(res_multi, function(x) { | ||
x$model_input$param_b90[c("fsintlai","frintsai", "fsintsai" )] | ||
})) | ||
|
||
used_annual_vegparms = rbindlist(lapply(res_multi, function(x) { | ||
x$model_input$param_b90[c("maxlai", "sai")] | ||
}), idcol="No.") | ||
|
||
used_listparms = unlist(lapply(res_multi, function(x) { | ||
x$model_input$param_b90$soil_materials$ths[2] | ||
}), use.names = FALSE) | ||
|
||
setDT(vary_parms) | ||
test_that("multi-run: all vary_parms at the right place",{ | ||
expect_equal(used_singleparms,vary_parms[,names(used_singleparms), with = F]) | ||
expect_equal(used_annual_vegparms$maxlai, rep(vary_parms$maxlai, each = 2)) | ||
expect_equal(used_annual_vegparms$sai[c(2,4)], vary_parms$sai2) | ||
expect_equal(used_listparms, vary_parms$soil_materials.ths2) | ||
}) |