Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update vignette and analysis #259

Merged
merged 22 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
^benchmarking$
^Rscripts$
^Rold$
^.idea$

# R-markdown files in the root folder.
^.*.ods$
Expand Down
2 changes: 1 addition & 1 deletion COPYING
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright 2023, Geocomputation and Earth Observation, University of Bern
Copyright 2024, Geocomputation and Earth Observation, University of Bern

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Expand Down
18 changes: 15 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Package: rsofun
Title: The P-Model and BiomeE Modelling Framework
Version: 4.4.1
Version: 5.0.0
Authors@R: c(
person(
family = "Benjamin",
given = "Stocker",
family = "Stocker",
given = "Benjamin",
email = "benjamin.stocker@gmail.com",
comment = c(ORCID = "0000-0003-2697-9096"),
role = c("aut", "cre")),
Expand All @@ -26,12 +26,24 @@ Authors@R: c(
email = "lauramarqueslopez@gmail.com",
comment = c(ORCID = "0000-0002-3593-5557"),
role = c("ctb")),
person(
family = "Marcadella",
given = "Mayeul",
email = "mayeul.marcadella@gmail.com",
comment = c(ORCID = "0000-0001-8555-3808"),
role = c("ctb")),
person(
family = "Weng",
given = "Ensheng",
email = "wengensheng@gmail.com",
comment = c(ORCID = "0000-0002-1858-4847"),
role = c("ctb")),
person(
family = "Bernhard",
given = "Fabian",
email = "fabian.bernhard@alumni.epfl.ch",
role = c("aut"),
comment = c(ORCID = "0000-0003-0338-0961")),
person(given = "Geocomputation and Earth Observation, University of Bern",
role = c("cph", "fnd"))
)
Expand Down
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# rsofun v5.0.0

* new BiomeE forcing data matching that of P-model
* `prec` is now called `rain`
* `rh` is now provided as `vpd`
* See `biomee_gs_leuning_drivers` for an example
* fix Fortran modules leading to segmentation faults using BiomeE model
* improved documentation

# rsofun v4.4.1

* bugfix Fortran modules and derived types
Expand Down
9 changes: 1 addition & 8 deletions R/calib_sofun.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ calib_sofun <- function(
...
){
# predefine variables for CRAN check compliance
cost <- lower <- upper <- pars <- out <- out_optim <- priors <- setup <-
bt_par <- bt_settings <- NULL
lower <- upper <- out_optim <- NULL

# check input variables
if(missing(obs) | missing(drivers) | missing(settings)){
Expand Down Expand Up @@ -166,12 +165,6 @@ calib_sofun <- function(
setup <- BayesianTools::createBayesianSetup(
likelihood = function(
random_par) {
# cost(
# par = random_par,
# obs = obs,
# drivers = drivers,
# ...
# )
do.call("cost",
list(
par = random_par,
Expand Down
14 changes: 7 additions & 7 deletions R/cost_likelihood_biomee.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@
#' }

cost_likelihood_biomee <- function(
par,
obs,
drivers,
targets
par,
obs,
drivers,
targets
){

# predefine variables for CRAN check compliance
Expand All @@ -57,7 +57,7 @@ cost_likelihood_biomee <- function(
drivers$params_species[[1]]$LAI_light[] <- par[2]
drivers$params_tile[[1]]$tf_base <- par[3]
drivers$params_tile[[1]]$par_mort <- par[4]

# run model
df <- runread_biomee_f(
drivers,
Expand All @@ -67,7 +67,7 @@ cost_likelihood_biomee <- function(

# did we spin up
spin_up <- drivers$params_siml[[1]]$spinup

# drop spinup years if activated
# see below
if (spin_up){
Expand Down Expand Up @@ -103,7 +103,7 @@ cost_likelihood_biomee <- function(
}) |>
unlist() |>
sum() # sum log-likelihoods

# trap boundary conditions
if(is.nan(ll) || is.na(ll) | ll == 0){
ll <- -Inf
Expand Down
2 changes: 1 addition & 1 deletion R/cost_likelihood_pmodel.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ cost_likelihood_pmodel <- function(
}) |>
unlist() |>
sum()

# trap boundary conditions
if(is.nan(ll) | is.na(ll) | ll == 0){ll <- -Inf}

Expand Down
16 changes: 8 additions & 8 deletions R/cost_rmse_pmodel.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ cost_rmse_pmodel <- function(
targets,
par_fixed = NULL, # non-calibrated model parameters
target_weights = NULL, # if using several targets, how are the individual
# RMSE weighted? named vector
# # RMSE weighted? named vector
parallel = FALSE,
ncores = 2
){
Expand Down Expand Up @@ -144,10 +144,10 @@ cost_rmse_pmodel <- function(
}else{
# Join P-model output and flux observations
df_flux <- df |>
dplyr::filter(sitename %in% flux_sites) |>
dplyr::left_join(
obs_flux,
by = c('sitename', 'date')) # observations with missing date are ignored
dplyr::filter(sitename %in% flux_sites) |>
dplyr::left_join(
obs_flux,
by = c('sitename', 'date')) # observations with missing date are ignored
}
}else{
df_flux <- data.frame()
Expand All @@ -170,7 +170,7 @@ cost_rmse_pmodel <- function(
df_trait <- df |>
dplyr::filter(sitename %in% trait_sites) |>
dplyr::group_by(sitename) |>
# get growing season average traits
# get growing season average traits
dplyr::summarise(across(ends_with("_mod") & !starts_with('gpp'),
~ sum(.x * gpp_mod/sum(gpp_mod)),
.names = "{.col}")) |>
Expand All @@ -192,7 +192,7 @@ cost_rmse_pmodel <- function(
}
if(target %in% colnames(df_trait)){
error <- c(error,
(df_trait[[target]] - df_trait[[paste0(target, '_mod')]])^2)
(df_trait[[target]] - df_trait[[paste0(target, '_mod')]])^2)
}
sqrt(mean(error, na.rm = TRUE))
}) |>
Expand All @@ -204,6 +204,6 @@ cost_rmse_pmodel <- function(
}else{
cost <- mean(rmse, na.rm = TRUE)
}

return(cost)
}
Loading
Loading