--- title: "Model customization" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Model customization} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- `barrks` offers multiple ways of model customization. The parameters of a model can be modified and individual submodels can be combined to create a new model. Furthermore, it is possible to create phenological events (such as onset, diapause and mortality) manually to apply a model with observed or arbitrary data. This vignette illustrates the corresponding procedures and compares the respective outputs with an unmodified model. ``` r library(barrks) library(tidyverse) library(terra) # function to unify the appearance of raster plots my_rst_plot <- function(rst) { plot(rst, mar = c(0.2, 0.1, 2, 5), axes = FALSE, box = TRUE, nr = 1, cex.main = 1.9, plg = list(cex = 1.8)) } data <- barrks_data() # calculate phenology without modification for comparison pheno_std <- phenology('phenips', data) ``` # Modify and combine models To modify parameters of individual models the new values should be passed to `model()`. In this example PHENIPS is customized by setting the daylength threshold for the diapause submodel to 14 hours (default are 14.5 hours). The parameters available for customization are found on the model customization manuals which are listed at the `model()` manual. To combine individual submodels, `model_combine()` is used. As parameters, the individual models are listed. To combine a model with a specific submodel, pass a list with the keys `model` and `submodels`. In the example PHENIPS is combined with the diapause submodel of PHENIPS-Clim. To compare the model outputs, the prevailing generations for all calculated models are plotted on four different dates. ``` r # calculate phenology with a customized model model_custom <- model('phenips', daylength_dia = 14) # `daylength_dia` is 14.5 by default pheno_custom <- phenology(model_custom, data) # calculate phenology with a combined model model_combined <- model_combine('phenips', list(model = 'phenips-clim', submodels = 'diapause')) pheno_combined <- phenology(model_combined, data) # plot generations dates <- c('2015-04-15', '2015-06-15', '2015-08-15', '2015-10-15') get_generations_rst(pheno_std, dates) %>% my_rst_plot() get_generations_rst(pheno_custom, dates) %>% my_rst_plot() get_generations_rst(pheno_combined, dates) %>% my_rst_plot() ```