# \donttest{
# use of \donttest{} because execution time exceeds 5 seconds
# estimate parameters of 4 samples of the Swiss forest soil dataset
# that have water retention (theta, all samples), saturated hydraulic conductivity
# (ksat) and optionally unsaturated hydraulic conductivity data
# (ku, samples "CH2_4" and "CH3_1")
data(swissforestsoils)
# select subset of data
sfs_subset <- droplevels(
subset(
swissforestsoils,
layer_id %in% c("CH2_3", "CH2_4", "CH2_6", "CH3_1")
))
# extract ksat measurements
ksat <- sfs_subset[!duplicated(sfs_subset$layer_id), "ksat", drop = FALSE]
rownames(ksat) <- levels(sfs_subset$layer_id)
colnames(ksat) <- "k0"
# define number of cores for parallel computations
if(interactive()) ncpu <- parallel::detectCores() - 1L else ncpu <- 1L
# unconstrained estimation (global optimisation algorithm NLOPT_GN_MLSL)
# k0 fixed at measured ksat values
rsfs_uglob <- fit_wrc_hcc(
wrc_formula = theta ~ head | layer_id,
hcc_formula = ku ~ head | layer_id,
data = sfs_subset,
param = ksat,
fit_param = default_fit_param(k0 = FALSE),
control = control_fit_wrc_hcc(
settings = "uglobal", pcmp = control_pcmp(ncores = ncpu)))
summary(rsfs_uglob)
coef(rsfs_uglob, lc = TRUE, gof = TRUE)
# constrained estimation by restricting ratio Lc/Lt to [0.5, 2]
# (global constrained optimisation algorithm NLOPT_GN_MLSL)
# k0 fixed at measured ksat values
rsfs_cglob <- update(
rsfs_uglob,
control = control_fit_wrc_hcc(
settings = "cglobal", nloptr = control_nloptr(ranseed = 1),
pcmp = control_pcmp(ncores = ncpu)))
summary(rsfs_cglob)
coef(rsfs_cglob, lc = TRUE, gof = TRUE)
# get initial parameter values from rsfs_cglob
ini_param <- cbind(
coef(rsfs_cglob)[, c("alpha", "n")],
ksat
)
# constrained estimation by restricting ratio Lc/Lt to [0.5, 2]
# (local constrained optimisation algorithm NLOPT_LD_CCSAQ)
# k0 fixed at measured ksat values
rsfs_cloc <- update(
rsfs_uglob,
param = ini_param,
control = control_fit_wrc_hcc(
settings = "clocal", nloptr = control_nloptr(ranseed = 1),
pcmp = control_pcmp(ncores = ncpu)))
summary(rsfs_cloc)
coef(rsfs_cloc, lc = TRUE, gof = TRUE)
op <- par(mfrow = c(4, 2))
plot(rsfs_uglob, y = rsfs_cglob)
on.exit(par(op))
op <- par(mfrow = c(4, 2))
plot(rsfs_uglob, y = rsfs_cloc)
on.exit(par(op))
# }Run the code above in your browser using DataLab