knitr::opts_chunk$set(echo = FALSE) knitr::opts_chunk$set(error = TRUE) knitr::opts_chunk$set(message = FALSE) knitr::opts_chunk$set(warning = FALSE) knitr::opts_knit$set(root.dir = params$wd) library(medfate) library(MedfateValidation) library(dplyr)
# site/plot code code <- params$code # raw data treeData <- load_treeData(code) shrubData <- load_shrubData(code) seedData <- load_seedData(code) customParams <- load_customParams(code) measuredData <- load_measuredData(code) meteoData <- load_meteoData(code) miscData <- load_miscData(code) soilData <- load_soilDataUnilayer(code) # soil data for only one layer terrainData <- load_terrainData(code) # model objects forest_object <- buildForest(treeData, shrubData, seedData, miscData) # SpParams # check if new or old will be used if (params$SPParams == 'old') { # load data('SpParamsMED', package = 'medfate') # modify sp_params <- SpParams_mod(SpParamsMED, customParams) } if (params$SPParams == 'new') { # load data('newParams', package = 'MedfateValidation') # modify sp_params <- SpParams_mod(newParams, customParams) } # Warning for custom FC if (!all(is.na((soilData[['FC']])))) { warning('Custom FC values has been provided: ', soilData[['FC']][1], ' ...') }
knitr::kable( data.frame( Pkg_version = as.character(packageVersion('medfate')), Site = params$code, Date = format(Sys.Date()) ) )
# check if simple mode has to be performed if (params$transpMode %in% c('simple', 'both')) { # control object control_obj <- medfate::defaultControl() control_obj$verbose <- FALSE control_obj$transpirationMode <- 'Simple' # input object simple_input <- medfate::forest2swbInput(forest_object, buildSoil(soilData), sp_params, control_obj) # input modifications (if any) simple_input <- inputMod(simple_input, customParams) # model run day by day res_simple <- transp_day_by_day(simple_input, meteoData, soilData, terrainData, measuredData) } else { # if simple mode is not performed, report about it res_simple <- NULL cat('Simple model has not been selected to be performed') }
# check if complex mode has to be performed if (params$transpMode %in% c('complex', 'both')) { # control object control_obj <- medfate::defaultControl() control_obj$verbose <- FALSE control_obj$transpirationMode <- 'Complex' # input object # we also rebuild the soil_object to avoid using W data from the previous # runs complex_input <- medfate::forest2swbInput(forest_object, buildSoil(soilData), sp_params, control_obj) # input modifications (if any) complex_input <- inputMod(complex_input, customParams) # model run day by day res_complex <- transp_day_by_day(complex_input, meteoData, soilData, terrainData, measuredData) } else { # if simple mode is not performed, report about it res_complex <- NULL cat('Complex model has not been selected to be performed') }
models_dfs <- list( simple = res_simple, complex = res_complex )
Eplanttot_stats <- statistics_summary('Eplanttot', models_dfs, measuredData, soil = buildSoil(soilData))
Comparision | MAE | r² | Bias
------------|-----|----|-------
Simple vs. Measured | r Eplanttot_stats$Eplanttot_MAE_simple
| r Eplanttot_stats$Eplanttot_r_sq_simple
| r Eplanttot_stats$Eplanttot_bias_simple
Complex vs. Measured | r Eplanttot_stats$Eplanttot_MAE_complex
| r Eplanttot_stats$Eplanttot_r_sq_complex
| r Eplanttot_stats$Eplanttot_bias_complex
Simple vs. Complex | r Eplanttot_stats$Eplanttot_MAE_both
| r Eplanttot_stats$Eplanttot_r_sq_both
| r Eplanttot_stats$Eplanttot_bias_both
print(plot_res_gg('Eplanttot', models_dfs, buildSoil(soilData), measuredData, params$transpMode))
Ecohorts_stats <- statistics_summary('E_by_Cohort', models_dfs, measuredData, buildSoil(soilData)) rbind( round(Ecohorts_stats[["Esp_MAE_simple"]], 5), round(Ecohorts_stats[["Esp_r_sq_simple"]], 5), round(Ecohorts_stats[["Esp_bias_simple"]], 5), round(Ecohorts_stats[["Esp_MAE_complex"]], 5), round(Ecohorts_stats[["Esp_r_sq_complex"]], 5), round(Ecohorts_stats[["Esp_bias_complex"]], 5), round(Ecohorts_stats[["Esp_MAE_both"]], 5), round(Ecohorts_stats[["Esp_r_sq_both"]], 5), round(Ecohorts_stats[["Esp_bias_both"]], 5) ) %>% cbind( c('MAE Simple vs. Measured', 'rsq Simple vs. Measured', 'Bias Simple vs. Measured', 'MAE Complex vs. Measured', 'rsq Complex vs. Measured', 'Bias Complex vs. Measured', 'MAE Simple vs. Complex', 'rsq Simple vs. Complex', 'Bias Simple vs. Complex'), . ) %>% as.data.frame() %>% knitr::kable(col.names = c('Statistics', Ecohorts_stats[['Cohort_name']]))
plots_cohorts <- plot_res_gg('E_by_Cohort', models_dfs, buildSoil(soilData), measuredData, params$transpMode) purrr::walk( plots_cohorts, ~ print(.x) )
if (params$transpMode %in% c('simple', 'both')) { print(buildSoil(soilData)) simple_input[['below']] } else { print(buildSoil(soilData)) complex_input[['below']] }
if (params$transpMode == 'simple') { print(simple_input) } else { if (params$transpMode == 'complex') { print(complex_input) } else { print(simple_input) print(complex_input) } }
# saving objects file_name <- file.path('Output', packageVersion('medfate')[[1]], params$code, paste0(format(Sys.time(), "%Y%m%d_%H%M"), '_', params$code, '_', 'transp_report_objects.RData')) save(list = ls(all.names = TRUE), file = file_name) # printing session info devtools::session_info()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.