-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from lauramarques/master
Corrected forcing data script and added function to run biomee multiple times
- Loading branch information
Showing
28 changed files
with
953 additions
and
571 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
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,65 @@ | ||
|
||
library(rsofun) | ||
library(dplyr) | ||
library(ggplot2) | ||
library(tibble) | ||
library(patchwork) | ||
library(devtools) | ||
|
||
load("data/biomee_gs_leuning_drivers.rda") | ||
biomee_gs_leuning_drivers$params_siml | ||
head(biomee_gs_leuning_drivers$forcing) | ||
|
||
load("data/biomee_p_model_drivers.rda") | ||
biomee_p_model_drivers$params_siml | ||
head(biomee_p_model_drivers$forcing) | ||
|
||
set.seed(2023) | ||
|
||
# run the model | ||
# build() | ||
# install() | ||
out <- runread_biomee_f( | ||
biomee_p_model_drivers, | ||
makecheck = TRUE, | ||
parallel = FALSE | ||
) | ||
|
||
# split out the annual data | ||
biomee_pmodel_output <- out$data[[1]]$output_annual_tile | ||
|
||
# plot | ||
cowplot::plot_grid( | ||
biomee_pmodel_output |> | ||
ggplot() + | ||
geom_line(aes(x = year, y = GPP)) + | ||
theme_classic()+labs(x = "Year", y = "GPP"), | ||
biomee_pmodel_output |> | ||
ggplot() + | ||
geom_line(aes(x = year, y = plantC)) + | ||
theme_classic()+labs(x = "Year", y = "plantC") | ||
) | ||
|
||
# function to run biomee multiple times and detect the segmentation fault error | ||
biomeextimes <- function(drivers,n){ | ||
results <- list() | ||
for(i in 1:n) { | ||
set.seed(2023) | ||
out <- runread_biomee_f( | ||
drivers, | ||
makecheck = TRUE, | ||
parallel = FALSE | ||
)$data[[1]]$output_annual_tile['plantC'] %>% | ||
slice(tail(row_number(), 1)) | ||
if(is.na(out)|out==0) message("Error: Simulation failed") | ||
results <- append(results, out) | ||
} | ||
save(results, file= "data/results.rda") | ||
return(results) | ||
} | ||
|
||
# run the model n times | ||
n = 500 | ||
biomeextimes(biomee_p_model_drivers,n) | ||
load("data/results.rda") | ||
results |
Oops, something went wrong.