| Title: | Multi-Barrier Approach for Water Reuse Risk Assessment |
|---|---|
| Description: | Provides a Quantitative Microbial Risk Assessment (QMRA) framework for the reuse of treated wastewater in agricultural irrigation. Following a multi-barrier approach, the package simulates pathogen inflow and removal along a treatment train, estimates human exposure, and computes health risk indicators such as infection probability, illness probability, and Disability-Adjusted Life Years (DALYs). It also supports an economic analysis of the treatment scenarios considered. For more details see <doi:10.36904/20240595>. |
| Authors: | Flora Girard [aut, cre] (ORCID: <https://orcid.org/0000-0003-0537-4530>), Nicolas Forquet [ctb] (ORCID: <https://orcid.org/0000-0003-1154-5498>), Arthur Bréant [ctb], Colin Fay [ctb] (ORCID: <https://orcid.org/0000-0001-7343-1846>) |
| Maintainer: | Flora Girard <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 2.1.2 |
| Built: | 2026-10-05 11:02:11 UTC |
| Source: | https://github.com/cran/ambre |
Calculate annual cost of the scenario simulated
annual_cost( scenario, price_per_m3, membership_fee, grant, initialSituation, allocation_key = NULL )annual_cost( scenario, price_per_m3, membership_fee, grant, initialSituation, allocation_key = NULL )
scenario |
data.frame scenario obtained with create_scenario function |
price_per_m3 |
numeric, water price in euro per cubic meter |
membership_fee |
numeric annual membership fee in euro per hectare |
grant |
numeric amount of the grant in percentage |
initialSituation |
boolean TRUE to simulate initial situation cost, FALSE to simulation supplementary process cost |
allocation_key |
numeric allocation key, NULL by default |
result list
scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) annual_cost(scenario = scenario_apprentissage, price_per_m3 = 0.1, membership_fee = 200, grant = 0.5, initialSituation = TRUE) annual_cost(scenario = scenario_apprentissage, price_per_m3 = 0.1, membership_fee = 200, grant = 0.5, initialSituation = FALSE) crop <- scenario_apprentissage$CropName allocation_custom <- data.frame(CropName = crop, allocation = c(0.5, 0.5)) annual_cost(scenario = scenario_apprentissage, price_per_m3 = 0.1, membership_fee = 200, grant = 0, initialSituation = TRUE, allocation_key = allocation_custom) annual_cost(scenario = scenario_apprentissage, price_per_m3 = 0.1, membership_fee = 200, grant = 0, initialSituation = FALSE, allocation_key = allocation_custom)scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) annual_cost(scenario = scenario_apprentissage, price_per_m3 = 0.1, membership_fee = 200, grant = 0.5, initialSituation = TRUE) annual_cost(scenario = scenario_apprentissage, price_per_m3 = 0.1, membership_fee = 200, grant = 0.5, initialSituation = FALSE) crop <- scenario_apprentissage$CropName allocation_custom <- data.frame(CropName = crop, allocation = c(0.5, 0.5)) annual_cost(scenario = scenario_apprentissage, price_per_m3 = 0.1, membership_fee = 200, grant = 0, initialSituation = TRUE, allocation_key = allocation_custom) annual_cost(scenario = scenario_apprentissage, price_per_m3 = 0.1, membership_fee = 200, grant = 0, initialSituation = FALSE, allocation_key = allocation_custom)
Calculate cost of the simulated collective treatment train
collective_treatment_cost_calculation(scenario, grant, allocation_key = NULL)collective_treatment_cost_calculation(scenario, grant, allocation_key = NULL)
scenario |
data.frame scenario with irrigation_need_m3an column obtained with irrigation_need_calculation |
grant |
numeric amount of the grant in percentage |
allocation_key |
data.frame allocation key, NULL by default |
cost
scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) irrigation_need <- irrigation_need_calculation(scenario_apprentissage) collective_treatment_cost_calculation(scenario = irrigation_need, grant = 0.5) crop <- scenario_apprentissage$CropName |> unique() allocation_custom <- data.frame(CropName = crop, allocation = c(0.5, 0.1, 0.1, 0.1, 0.1, 0.1)) collective_treatment_cost_calculation(scenario = irrigation_need, grant = 0, allocation_key = allocation_custom)scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) irrigation_need <- irrigation_need_calculation(scenario_apprentissage) collective_treatment_cost_calculation(scenario = irrigation_need, grant = 0.5) crop <- scenario_apprentissage$CropName |> unique() allocation_custom <- data.frame(CropName = crop, allocation = c(0.5, 0.1, 0.1, 0.1, 0.1, 0.1)) collective_treatment_cost_calculation(scenario = irrigation_need, grant = 0, allocation_key = allocation_custom)
A structured database containing the parameters and values needed to perform Quantitative Microbial Risk Assessment (QMRA) and cost calculations.
config_ambreconfig_ambre
A list of 3 lists and 5 tibbles :
Exposure condition : number of repeatings for Monte Carlo simulation, number of exposures per year, volume (L) per exposure event
Pathogen concentration (number of pathogen per L)
Database of log reductions for risk management measures
General values for the log reductions
Risk management process (sequence of measures) assessed
Specific values for log reductions based on the assessed route of exposure
Specific values for log reductions based on the assessed measure
Specific values for log reductions for the natural die off measure
Parameters for dose response model (https://qmrawiki.org/framework/dose-response/highest-quality-models-and-parameters)
Details on pathways of exposure
Description of pathways of exposure
Frequency values of pathways of exposure
Volume values of pathways of exposure
Description of crop
Parameters for risk characterization
Parameters for economic analysis
Value of irrigation need according to crop type
Description of population exposed
Database of opex and capex cost of risk management measures (https://theses.hal.science/tel-05009670)
Database of required microorganism removal performance (in terms of concentration or removal rate) by regulatory class and pathogen group
Database of required water class acording to crop
names(config_ambre)names(config_ambre)
This function does the same thing as kwb.utils::create_random_distribution(), but it is bundled with ambre to avoid a hard dependency on the unmaintained package.
create_random_distribution( type = "uniform", number_of_repeatings = 1, number_of_events = 365, value = 10, min = 10, max = 1000, percent_within_minmax = 0.9, min_zero = 0.01, log10_min = default_min(min, max, min_zero, f = log10), log10_max = default_max(max, min_zero * 10, f = log10), log10_mean = (log10_min + log10_max)/2, log10_sdev = abs((log10_max - log10_mean)/get_percentile(percent_within_minmax)), mean = (default_min(min, max, min_zero) + default_max(max, 10 * min_zero))/2, sdev = abs((default_max(max, 10 * min_zero) - mean)/get_percentile(percent_within_minmax)), meanlog = mean(log(default_min(min, max, min_zero) + default_max(max, 10 * min_zero))/2), sdlog = abs(sd(c(default_min(min, max, min_zero, f = log), default_max(max, 10 * min_zero, f = log)))), mode = (default_min(min, max, min_zero) + default_max(max, 10 * min_zero))/2, debug = TRUE )create_random_distribution( type = "uniform", number_of_repeatings = 1, number_of_events = 365, value = 10, min = 10, max = 1000, percent_within_minmax = 0.9, min_zero = 0.01, log10_min = default_min(min, max, min_zero, f = log10), log10_max = default_max(max, min_zero * 10, f = log10), log10_mean = (log10_min + log10_max)/2, log10_sdev = abs((log10_max - log10_mean)/get_percentile(percent_within_minmax)), mean = (default_min(min, max, min_zero) + default_max(max, 10 * min_zero))/2, sdev = abs((default_max(max, 10 * min_zero) - mean)/get_percentile(percent_within_minmax)), meanlog = mean(log(default_min(min, max, min_zero) + default_max(max, 10 * min_zero))/2), sdlog = abs(sd(c(default_min(min, max, min_zero, f = log), default_max(max, 10 * min_zero, f = log)))), mode = (default_min(min, max, min_zero) + default_max(max, 10 * min_zero))/2, debug = TRUE )
type |
"uniform" calls runif(), "log10_uniform" calls 10^runif(number_of_events, log10_min, log10_max), "triangle" calls EnvStats::rtri(), "lognorm" calls rlnorm(), "norm" calls rnorm() and "log10_norm" calls 10^rnorm(number_of_events, mean = log10_mean, sdev = log10_sdev), (default: "uniform") |
number_of_repeatings |
how often should the random distribution with the same parameters be generated (default: 1) |
number_of_events |
number of events |
value |
constant value (no random number), gets repeated number_of_events times (if 'type' = 'value') |
min |
minimum value (default: 10), only used if 'type' is "runif" or "triangle" |
max |
maximum value (default: 1000), only used if 'type' is "runif" or "triangle" |
percent_within_minmax |
percent of data point within min/max (default: 0.9 i.e. 90 percent |
min_zero |
only used if 'type' is "log10_uniform" or
"log10_norm", "norm" or "lognorm" and "min" value equal zero.
In this case the zero is replaced by this value (default: 0.01), see also
|
log10_min |
minimum value (default: default_min(min, max, min_zero, f = log10)), only used if 'type' is "log10_uniform" or "log10_norm" |
log10_max |
maximum value (default: ifelse(max > 0, log10(max), log10_zero_threshold), only used if 'type' is "log10_uniform" or "log10_norm" |
log10_mean |
mean value (default: (log10_min + log10_max)/2), only used if 'type' is "log10_norm" |
log10_sdev |
standard deviation (default: abs((log10_max- log10_mean) / get_percentile(0.95)), only used if 'type' is "log10_norm" |
mean |
mean value (default: (default_min(min, max, min_zero) / default_max(max, 10*min_zero)) / 2), only used if 'type' is "norm" |
sdev |
standard deviation (default: abs((default_max(max, 10*min_zero) - mean) / get_percentile(0.95))), only used if 'type' is "norm" |
meanlog |
log mean value (default: mean(log((min + max) / 2))), only used if 'type' is "lognorm" |
sdlog |
standard deviation (default: abs(sd(c(default_min(min, max, min_zero, f = log)))) ), only used if 'type' is "lognorm" |
mode |
(default: default_min(min, max, min_zero) + default_max(max, 10 * min_zero) / 2), only used if 'type' is "triangle" |
debug |
print debug information (default: TRUE) |
list with parameters of user defined random distribution and corresponding values
Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0 URL: https://github.com/kwb-r/kwb.utils (MIT Licence)
# Example usage of create_random_distribution # Uniform distribution uniform_dist <- create_random_distribution( type = "uniform", number_of_repeatings = 2, number_of_events = 10, min = 0, max = 100 ) # Log10 uniform distribution log10_uniform_dist <- create_random_distribution( type = "log10_uniform", number_of_events = 10, min = 1, max = 1000 ) # Triangle distribution triangle_dist <- create_random_distribution( type = "triangle", number_of_events = 10, min = 0, max = 100, mode = 50 ) # Normal distribution norm_dist <- create_random_distribution( type = "norm", number_of_events = 10, mean = 50, sdev = 10 ) # Log10 normal distribution log10_norm_dist <- create_random_distribution( type = "log10_norm", number_of_events = 10, log10_mean = 2, log10_sdev = 0.5 ) # Lognormal distribution lognorm_dist <- create_random_distribution( type = "lognorm", number_of_events = 10, meanlog = 2, sdlog = 0.5 ) # Constant value value_dist <- create_random_distribution( type = "value", number_of_events = 10, value = 42 )# Example usage of create_random_distribution # Uniform distribution uniform_dist <- create_random_distribution( type = "uniform", number_of_repeatings = 2, number_of_events = 10, min = 0, max = 100 ) # Log10 uniform distribution log10_uniform_dist <- create_random_distribution( type = "log10_uniform", number_of_events = 10, min = 1, max = 1000 ) # Triangle distribution triangle_dist <- create_random_distribution( type = "triangle", number_of_events = 10, min = 0, max = 100, mode = 50 ) # Normal distribution norm_dist <- create_random_distribution( type = "norm", number_of_events = 10, mean = 50, sdev = 10 ) # Log10 normal distribution log10_norm_dist <- create_random_distribution( type = "log10_norm", number_of_events = 10, log10_mean = 2, log10_sdev = 0.5 ) # Lognormal distribution lognorm_dist <- create_random_distribution( type = "lognorm", number_of_events = 10, meanlog = 2, sdlog = 0.5 ) # Constant value value_dist <- create_random_distribution( type = "value", number_of_events = 10, value = 42 )
This function creates exposure scenarios during the two game turns.
create_scenario(filepath, config = config_ambre)create_scenario(filepath, config = config_ambre)
filepath |
Path to the Excel file containing input data |
config |
list config file default value config_ambre |
A list containing the scenario data and a placeholder for future data
scenario <- create_scenario(system.file("input_cas_apprentissage_complet.xlsx", package = "ambre"))scenario <- create_scenario(system.file("input_cas_apprentissage_complet.xlsx", package = "ambre"))
Like create_scenario() but takes an in-memory data.frame instead of an
Excel file, and each of the four treatment roles
(STEP / Collective / Initial / Supplementary) may hold a vector of process
names (a list-column), so a train can contain more than one process per role.
create_scenario_from_df(user_input, config = config_ambre)create_scenario_from_df(user_input, config = config_ambre)
user_input |
A data.frame / tibble with columns |
config |
list config file, default value |
Single-value role columns are also accepted (they behave like
create_scenario()); NA / empty roles are dropped from the train.
A scenario tibble, same structure as create_scenario().
df <- data.frame( CropName = "Tomato", Area = 35, PopulationName = "Maintenance staff", nb_population = 1, PathName = "Consumption of the final product tomato", nb_day_decay = NA_real_ ) df$STEPtreatmentName <- list(c("Q.1 - Activated Sludge", "Q.2 - Maturation Pond")) df$CollectiveTreatmentName <- list(NA_character_) df$InitialProcessName <- list("Q.6 - Chlorination") df$SupplementaryProcessName <- list(NA_character_) create_scenario_from_df(df)df <- data.frame( CropName = "Tomato", Area = 35, PopulationName = "Maintenance staff", nb_population = 1, PathName = "Consumption of the final product tomato", nb_day_decay = NA_real_ ) df$STEPtreatmentName <- list(c("Q.1 - Activated Sludge", "Q.2 - Maturation Pond")) df$CollectiveTreatmentName <- list(NA_character_) df$InitialProcessName <- list("Q.6 - Chlorination") df$SupplementaryProcessName <- list(NA_character_) create_scenario_from_df(df)
Calculate dalys lose per event according to illness probability
dalys_calculation(scenario)dalys_calculation(scenario)
scenario |
data.frame scenario with risk column |
scenario_updated
library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co) scenario_inf_proba_and_co <- infection_probability_calculation(scenario_final_dose_and_co_test) scenario_illness_proba_and_co <- illness_probability_calculation(scenario_inf_proba_and_co) dalys_calculation(scenario_illness_proba_and_co)library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co) scenario_inf_proba_and_co <- infection_probability_calculation(scenario_final_dose_and_co_test) scenario_illness_proba_and_co <- illness_probability_calculation(scenario_inf_proba_and_co) dalys_calculation(scenario_illness_proba_and_co)
This function does the same thing as kwb.utils::distribution_repeater(), but it is bundled with ambre to avoid a hard dependency on the unmaintained package.
distribution_repeater( number_of_repeatings = 10, number_of_events = 365, func, ... )distribution_repeater( number_of_repeatings = 10, number_of_events = 365, func, ... )
number_of_repeatings |
how often should the random distribution with the same parameters be generated (default: 1) |
number_of_events |
number of events (a single positive integer, >= 1) |
func |
distribution function to be repeated (e.g. runif, rlnorm, rnorm) |
... |
further parameters passed to func |
data.frame with columns repeatID, eventID and values
Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0 URL: https://github.com/kwb-r/kwb.utils (MIT Licence)
distribution_repeater( number_of_repeatings = 2, number_of_events = 10, func = runif, min = 1, max = 10 )distribution_repeater( number_of_repeatings = 2, number_of_events = 10, func = runif, min = 1, max = 10 )
Dose-response model: beta-poisson
dr.betapoisson( dose = sfsmisc::lseq(from = 1, to = 10^10, length = 1000), alpha = 0.328, N50 = 5430 )dr.betapoisson( dose = sfsmisc::lseq(from = 1, to = 10^10, length = 1000), alpha = 0.328, N50 = 5430 )
dose |
vector of dose data (default:
|
alpha |
alpha (default: 3.28E-01) |
N50 |
N50 (default: 5.43E+03) |
tibble
Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0 URL: https://github.com/kwb-r/kwb.utils (MIT Licence)
Dose-response model: exponential
dr.expo(dose = sfsmisc::lseq(from = 1, to = 10^10, length = 1000), k = 0.572)dr.expo(dose = sfsmisc::lseq(from = 1, to = 10^10, length = 1000), k = 0.572)
dose |
vector of dose data (default:
|
k |
k-value (default: 5.72E-01) |
tibble
Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0 URL: https://github.com/kwb-r/kwb.utils (MIT Licence)
This function does the same thing as kwb.utils::enumeration(), but it is bundled with ambre to avoid a hard dependency on the unmaintained package.
enumeration(x, type = "element", sorted = FALSE, suffix = "")enumeration(x, type = "element", sorted = FALSE, suffix = "")
x |
vector of elements to be enumerated |
type |
type of element to appear in the message. Default: "element" |
sorted |
logical. Whether or not to print the available elements in
lexical order. Default: |
suffix |
suffix to be appended to |
character string containing the enumeration
Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0 URL: https://github.com/kwb-r/kwb.utils (MIT Licence)
# Example usage of enumeration cat(enumeration(c("a", "b", "c"), type = "element")) cat(enumeration(c("x", "y"), type = "element", suffix = "s"))# Example usage of enumeration cat(enumeration(c("a", "b", "c"), type = "element")) cat(enumeration(c("x", "y"), type = "element", suffix = "s"))
Calculation of the final dose according to initial dose and log reduction of the treatments simulated
final_dose_calculation(scenario)final_dose_calculation(scenario)
scenario |
dataFrame scenario with initial_dose and log_reduction columns |
scenario_with_final_dose
library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Escherichia coli")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) final_dose_calculation(scenario_with_logreduc_and_co)library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Escherichia coli")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) final_dose_calculation(scenario_with_logreduc_and_co)
This function does the same thing as kwb.utils::generate_random_values(), but it is bundled with ambre to avoid a hard dependency on the unmaintained package.
generate_random_values( config, number_of_repeatings = 1, number_of_events, debug = TRUE )generate_random_values( config, number_of_repeatings = 1, number_of_events, debug = TRUE )
config |
as retrieved by config_read() |
number_of_repeatings |
how often should the random distribution with the same parameters be generated (default: 1) |
number_of_events |
number of events |
debug |
print debug information (default: TRUE) |
list random distributions based on configuration file
Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0 URL: https://github.com/kwb-r/kwb.utils (MIT Licence)
# Example usage of generate_random_values # Create a sample config object config <- list( type = "norm", value = 10, min = 5, max = 15, mean = 10, sd = 2, meanlog = log(10), sdlog = 0.5, mode = 10 ) # Call generate_random_values with the sample config result <- generate_random_values( config = config, number_of_repeatings = 2, number_of_events = 10, debug = FALSE ) # Print the results cat("Simulated events:") print(result$events) cat("Parameters used for simulation:") print(result$paras)# Example usage of generate_random_values # Create a sample config object config <- list( type = "norm", value = 10, min = 5, max = 15, mean = 10, sd = 2, meanlog = log(10), sdlog = 0.5, mode = 10 ) # Call generate_random_values with the sample config result <- generate_random_values( config = config, number_of_repeatings = 2, number_of_events = 10, debug = FALSE ) # Print the results cat("Simulated events:") print(result$events) cat("Parameters used for simulation:") print(result$paras)
This function does the same thing as kwb.utils::exposure_value_or_stop(), but it is bundled with ambre to avoid a hard dependency on the unmaintained package.
get_exposure_value_or_stop(config, name)get_exposure_value_or_stop(config, name)
config |
list config |
name |
character name of the column |
Description
value
Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0 URL: https://github.com/kwb-r/kwb.utils (MIT Licence)
get_exposure_value_or_stop(config_ambre, "number_of_exposures")get_exposure_value_or_stop(config_ambre, "number_of_exposures")
Simulate infection probability according to pathogen consider
get_infection_prob(tbl_risk, dose_response, health)get_infection_prob(tbl_risk, dose_response, health)
tbl_risk |
data.frame containing PathogenID and dose_perEvent columns |
dose_response |
data.frame database of dose_response factors presents in config_ambre |
health |
data.frame database of health factors presents in config_ambre |
result_vector
Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0 URL: https://github.com/kwb-r/kwb.utils (MIT Licence)
Calcul the total illness probability and total dalys that are the sum of every exposure event
get_risk_total(scenario)get_risk_total(scenario)
scenario |
data.frame with risk column |
scenario_updated
library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co) scenario_inf_proba_and_co <- infection_probability_calculation(scenario_final_dose_and_co_test) scenario_illness_proba_and_co <- illness_probability_calculation(scenario_inf_proba_and_co) scenario_dalys_and_co <- dalys_calculation(scenario_illness_proba_and_co) get_risk_total(scenario_dalys_and_co)library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co) scenario_inf_proba_and_co <- infection_probability_calculation(scenario_final_dose_and_co_test) scenario_illness_proba_and_co <- illness_probability_calculation(scenario_inf_proba_and_co) scenario_dalys_and_co <- dalys_calculation(scenario_illness_proba_and_co) get_risk_total(scenario_dalys_and_co)
This function and returns the results in a wide-format data frame.
get_scheme_events_wide(config, treatment_events_wide)get_scheme_events_wide(config, treatment_events_wide)
config |
A configuration object containing treatment scheme information. |
treatment_events_wide |
A data frame in wide format containing treatment events with columns for each treatment ID and log-reduction values. |
This function does the same thing as kwb.qmra::get_scheme_events_wide(), but it is bundled with ambre to avoid a hard dependency on the unmaintained package.
A data frame with columns for event ID, pathogen group, and one column for each treatment scheme containing the sum of log-reduction values for that scheme.
Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0 URL: https://github.com/kwb-r/kwb.utils (MIT Licence)
# Example usage of get_scheme_events_wide scenario_test <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_updated <- update_pathogen(scenario = scenario_test, pathoName = c("Campylobacter jejuni", "Rotavirus")) config <- scenario_updated$config[[1]] # Simulate treatment data treatment_data <- get_treatment_data(config$treatment$processes, n_repeatings = 5, n_events = 3) treatment_events_wide <- treatment_data$events |> tidyr::spread( key = TreatmentID, value = logreduction ) # Apply get_scheme_events_wide scheme_events_wide <- get_scheme_events_wide(config, treatment_events_wide) # Print results print(scheme_events_wide)# Example usage of get_scheme_events_wide scenario_test <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_updated <- update_pathogen(scenario = scenario_test, pathoName = c("Campylobacter jejuni", "Rotavirus")) config <- scenario_updated$config[[1]] # Simulate treatment data treatment_data <- get_treatment_data(config$treatment$processes, n_repeatings = 5, n_events = 3) treatment_events_wide <- treatment_data$events |> tidyr::spread( key = TreatmentID, value = logreduction ) # Apply get_scheme_events_wide scheme_events_wide <- get_scheme_events_wide(config, treatment_events_wide) # Print results print(scheme_events_wide)
Get table risk to calculate infection probability
get_tbl_risk(scenario)get_tbl_risk(scenario)
scenario |
data.frame with columns inflow concentration, final dose and volume |
tbl_risk
library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Escherichia coli")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co) tbl_risk_test <- get_tbl_risk(scenario_final_dose_and_co_test)library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Escherichia coli")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co) tbl_risk_test <- get_tbl_risk(scenario_final_dose_and_co_test)
This function simulates treatment data for a set of pathogen processes, including random values for each process and optional parameters. It can be used to generate synthetic data for analysis or testing.
get_treatment_data( processes, n_repeatings, n_events, debug = TRUE, include_paras = TRUE )get_treatment_data( processes, n_repeatings, n_events, debug = TRUE, include_paras = TRUE )
processes |
A data frame containing information about pathogen processes, including treatment names and pathogen groups. |
n_repeatings |
The number of times each process should be repeated. |
n_events |
The number of events to simulate for each process. |
debug |
Logical indicating whether to print debug information. |
include_paras |
Logical indicating whether to include parameter data. |
This function does the same thing as kwb.qmra::get_treatment_data(), but it is bundled with ambre to avoid a hard dependency on the unmaintained package.
If include_paras is FALSE, returns a data frame of simulated events.
If include_paras is TRUE, returns a list containing both the events data frame
and a data frame of parameters.
Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0 URL: https://github.com/kwb-r/kwb.utils (MIT Licence)
# Example usage (assuming 'processes' is defined) scenario_test <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_updated <- update_pathogen(scenario = scenario_test, pathoName = c("Campylobacter jejuni", "Rotavirus")) config = scenario_updated$config[[1]] processes_simulated <- config$treatment$processes result <- get_treatment_data(processes_simulated, n_repeatings = 10, n_events = 5) print(result)# Example usage (assuming 'processes' is defined) scenario_test <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_updated <- update_pathogen(scenario = scenario_test, pathoName = c("Campylobacter jejuni", "Rotavirus")) config = scenario_updated$config[[1]] processes_simulated <- config$treatment$processes result <- get_treatment_data(processes_simulated, n_repeatings = 10, n_events = 5) print(result)
Calculate illness probability according to infection probability and pathogen simulated
illness_probability_calculation(scenario)illness_probability_calculation(scenario)
scenario |
data.frame with risk column |
scenario_updated
library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co) scenario_inf_proba_and_co <- infection_probability_calculation(scenario_final_dose_and_co_test) illness_probability_calculation(scenario_inf_proba_and_co)library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co) scenario_inf_proba_and_co <- infection_probability_calculation(scenario_final_dose_and_co_test) illness_probability_calculation(scenario_inf_proba_and_co)
Simulate infection probability for each events
infection_probability_calculation(scenario)infection_probability_calculation(scenario)
scenario |
data.frame with columns inflow concentration, final dose and volume |
scenario_updated
library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Escherichia coli")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co) infection_probability_calculation(scenario_final_dose_and_co_test)library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Escherichia coli")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co) infection_probability_calculation(scenario_final_dose_and_co_test)
To calculate inflow concentration for specified pathogen
inflow_concentration(scenario, pathogenName, monteCarlo = 1000)inflow_concentration(scenario, pathogenName, monteCarlo = 1000)
scenario |
list scenario created with create_scenario |
pathogenName |
character names of the pathogens to be simulated |
monteCarlo |
integer number of simulation iterations for Monte Carlo |
scenario_with_concentration
scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) result <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Norovirus"), monteCarlo = 2000)scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) result <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Norovirus"), monteCarlo = 2000)
To calculate inflow concentration for specified pathogen
inflow_concentration_custom(scenario, concentration, monteCarlo = 1000)inflow_concentration_custom(scenario, concentration, monteCarlo = 1000)
scenario |
list scenario created with create_scenario |
concentration |
data.frame min, max and distribution law of pathogen concentration |
monteCarlo |
integer number of simulation iterations for Monte Carlo |
scenario_with_concentration
sc <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) sc <- update_volume_with_desired_value(sc, volume = data.frame(min = c(0.5,1), max = c(1,2), type = c("triangle", "triangle"))) sc <- update_frequency_with_desired_value(scenario = sc, frequency = c(200L, 300L)) concentration_custom <- data.frame(PathogenName = c("Campylobacter jejuni", "Norovirus"), min = c(1, 10), max = c(2,20), type = c("uniform", "uniform")) inflow_concentration_custom(scenario = sc, concentration = concentration_custom)sc <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) sc <- update_volume_with_desired_value(sc, volume = data.frame(min = c(0.5,1), max = c(1,2), type = c("triangle", "triangle"))) sc <- update_frequency_with_desired_value(scenario = sc, frequency = c(200L, 300L)) concentration_custom <- data.frame(PathogenName = c("Campylobacter jejuni", "Norovirus"), min = c(1, 10), max = c(2,20), type = c("uniform", "uniform")) inflow_concentration_custom(scenario = sc, concentration = concentration_custom)
This function calculates the initial dose that is a product of inflow concentration and volume for each exposure events.
initial_dose_calculation(scenario)initial_dose_calculation(scenario)
scenario |
dataFrame scenario with volume and inflow_concentration columns |
scenario_with_initial_dose
library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) initial_dose_calculation(scenario_volume)library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) initial_dose_calculation(scenario_volume)
Calculate irrigation need according to irrigation need of the culture simulated and its surface
irrigation_need_calculation(scenario)irrigation_need_calculation(scenario)
scenario |
data.frame scenario obtained with create_scenario function |
scenario_updated
scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) irrigation_need <- irrigation_need_calculation(scenario_apprentissage) print(irrigation_need$irrigation_need_m3an)scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) irrigation_need <- irrigation_need_calculation(scenario_apprentissage) print(irrigation_need$irrigation_need_m3an)
Calculate percentage irrigation need for each culture according to total irrigation need
percentage_irrigation_need(scenario)percentage_irrigation_need(scenario)
scenario |
data.frame with irrigation_need_m3an column obtained with irrigation_need_calculation function |
(scenario_updated)
scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) irrigation_need <- irrigation_need_calculation(scenario_apprentissage) irrigation_pct <- percentage_irrigation_need(irrigation_need) print(irrigation_pct$irrigation_need_percentage)scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) irrigation_need <- irrigation_need_calculation(scenario_apprentissage) irrigation_pct <- percentage_irrigation_need(irrigation_need) print(irrigation_pct$irrigation_need_percentage)
Calculate perimeter (linear meter) according to surface, and add the value to the scenario dataframe
perimeter_calculation(scenario)perimeter_calculation(scenario)
scenario |
data.frame scenario obtained with create_scenario function |
scenario_updated
scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_apprentissage_updated <- perimeter_calculation(scenario_apprentissage) print(scenario_apprentissage_updated$perimeter)scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_apprentissage_updated <- perimeter_calculation(scenario_apprentissage) print(scenario_apprentissage_updated$perimeter)
Compare the result of the QMRA simulation with reduction_log from initial vs supplementary processes
plot_comparison_qmra_initial_vs_supplementary_processes( scenario, pathogen, regulationLog, regulationConcentration )plot_comparison_qmra_initial_vs_supplementary_processes( scenario, pathogen, regulationLog, regulationConcentration )
scenario |
data.frame, scenario obtained with create_scenario function |
pathogen |
character, Name of the pathogen to simulate |
regulationLog |
data.frame regulation value of the log reduction to compare with simulation result |
regulationConcentration |
data.frame regulation value of the log reduction to compare with simulation result |
combine_plots
library(dplyr) scenario_example <- create_scenario( filepath = system.file("input_1culture_2pop.xlsx", package = "ambre") ) regulation_reduction <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Concentration, Country, RegulationID)) regulation_concentration <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Country, RegulationID, Reduction)) plot_comparison_qmra_initial_vs_supplementary_processes( scenario = scenario_example, pathogen = c("Campylobacter jejuni", "Norovirus"), regulationLog = regulation_reduction, regulationConcentration = regulation_concentration )library(dplyr) scenario_example <- create_scenario( filepath = system.file("input_1culture_2pop.xlsx", package = "ambre") ) regulation_reduction <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Concentration, Country, RegulationID)) regulation_concentration <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Country, RegulationID, Reduction)) plot_comparison_qmra_initial_vs_supplementary_processes( scenario = scenario_example, pathogen = c("Campylobacter jejuni", "Norovirus"), regulationLog = regulation_reduction, regulationConcentration = regulation_concentration )
Boxplot of total dalys lost per year according to population exposed and pathogen simulated
plot_dalys(scenario, objective = 1e-06)plot_dalys(scenario, objective = 1e-06)
scenario |
data.frame with risk_total column obtained with get_risk_total |
objective |
numeric OMS default value 1e-6 |
plots
library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Escherichia coli", "Norovirus", "Rotavirus")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co) scenario_inf_proba_and_co <- infection_probability_calculation(scenario_final_dose_and_co_test) scenario_illness_proba_and_co <- illness_probability_calculation(scenario_inf_proba_and_co) scenario_dalys_and_co <- dalys_calculation(scenario_illness_proba_and_co) scenario_risk_total_and_co <-get_risk_total(scenario_dalys_and_co) plot_dalys(scenario_risk_total_and_co)library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Escherichia coli", "Norovirus", "Rotavirus")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co) scenario_inf_proba_and_co <- infection_probability_calculation(scenario_final_dose_and_co_test) scenario_illness_proba_and_co <- illness_probability_calculation(scenario_inf_proba_and_co) scenario_dalys_and_co <- dalys_calculation(scenario_illness_proba_and_co) scenario_risk_total_and_co <-get_risk_total(scenario_dalys_and_co) plot_dalys(scenario_risk_total_and_co)
Boxplot of infection probability per year according to population exposed and pathogen simulated
plot_infection_probability(scenario)plot_infection_probability(scenario)
scenario |
with risk_total column obtained with get_risk_total |
plots
library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Escherichia coli", "Norovirus", "Rotavirus")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co) scenario_inf_proba_and_co <- infection_probability_calculation(scenario_final_dose_and_co_test) scenario_illness_proba_and_co <- illness_probability_calculation(scenario_inf_proba_and_co) scenario_dalys_and_co <- dalys_calculation(scenario_illness_proba_and_co) scenario_risk_total_and_co <-get_risk_total(scenario_dalys_and_co) plot_infection_probability(scenario_risk_total_and_co)library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Escherichia coli", "Norovirus", "Rotavirus")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co) scenario_inf_proba_and_co <- infection_probability_calculation(scenario_final_dose_and_co_test) scenario_illness_proba_and_co <- illness_probability_calculation(scenario_inf_proba_and_co) scenario_dalys_and_co <- dalys_calculation(scenario_illness_proba_and_co) scenario_risk_total_and_co <-get_risk_total(scenario_dalys_and_co) plot_infection_probability(scenario_risk_total_and_co)
Violin plot of inflow concentration according to pathogen simulated
plot_inflow(scenario)plot_inflow(scenario)
scenario |
data.frame with inflow_concentration column obtained from inflow_concentration function |
plot
scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_with_inflow <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Norovirus")) plot_inflow(scenario_with_inflow)scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_with_inflow <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Norovirus")) plot_inflow(scenario_with_inflow)
Boxplot of log reduction for each barrier according to population exposed and pathogen Name
plot_logreduction(scenario)plot_logreduction(scenario)
scenario |
with log reduction column obtained with simulate_treatment function |
plots
library(purrr) library(tidyr) library(dplyr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Norovirus")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) plot_logreduction(scenario_with_logreduc_and_co)library(purrr) library(tidyr) library(dplyr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni", "Norovirus")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) scenario_dose_ini <- initial_dose_calculation(scenario_volume) scenario_scheme <- update_treatment_scheme(scenario_dose_ini) scenario_with_logreduc_and_co <- scenario_scheme |> mutate( log_reduction = map(config, simulate_treatment)) plot_logreduction(scenario_with_logreduc_and_co)
Boxplot of the volume of exposition for each population exposed
plot_volumes(scenario)plot_volumes(scenario)
scenario |
data.frame with volume column obtained with simulate_exposure function |
plot
library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) plot_volumes(scenario_volume)library(dplyr) library(purrr) scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_conc <- inflow_concentration(scenario = scenario_test, pathogenName = c("Campylobacter jejuni")) scenario_volume <- scenario_conc |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x) ) ) plot_volumes(scenario_volume)
Calculate cost of supplementary barriers
process_cost_calculation(scenario, membership_fee, charge, initialSituation)process_cost_calculation(scenario, membership_fee, charge, initialSituation)
scenario |
data.frame scenario with irrigation_need_m3an column obtained from irrigation_need_calculation function |
membership_fee |
numeric annual membership fee |
charge |
numeric water charge |
initialSituation |
boolean TRUE to simulate initial simulation cost, FALSE to simulate supplementary process cost |
scenario_updated
scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre")) irrigation_need <- irrigation_need_calculation(scenario_apprentissage) process_cost_calculation(scenario = irrigation_need, membership_fee = 200, charge = 0.1, initialSituation = TRUE) process_cost_calculation(scenario = irrigation_need, membership_fee = 200, charge = 0.1, initialSituation = FALSE)scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre")) irrigation_need <- irrigation_need_calculation(scenario_apprentissage) process_cost_calculation(scenario = irrigation_need, membership_fee = 200, charge = 0.1, initialSituation = TRUE) process_cost_calculation(scenario = irrigation_need, membership_fee = 200, charge = 0.1, initialSituation = FALSE)
retrieve Barrier ID according to its name in the barrier database
query_barrier(config = config_ambre, barrierName, na.rm = FALSE)query_barrier(config = config_ambre, barrierName, na.rm = FALSE)
config |
list configuration file default value is config_ambre dataset |
barrierName |
character Name of the barrier you want to find the ID |
na.rm |
boolean FALSE by default |
barrierID
query_barrier(barrierName = "Q.1 - Activated Sludge") query_barrier(barrierName = c("Q.1 - Activated Sludge", "Q.2 - Maturation Pond")) query_barrier(barrierName = "P.9 - Peeling, P.7 - Cooking")query_barrier(barrierName = "Q.1 - Activated Sludge") query_barrier(barrierName = c("Q.1 - Activated Sludge", "Q.2 - Maturation Pond")) query_barrier(barrierName = "P.9 - Peeling, P.7 - Cooking")
Query to return crop ID from crop Name in crop database
query_crop(config = config_ambre, cropName)query_crop(config = config_ambre, cropName)
config |
list configuration file default value is config_ambre dataset |
cropName |
character Name of crop for which you want to find the identifier |
cropID integer
query_crop(cropName = "Corn seed")query_crop(cropName = "Corn seed")
Retrieve height of the crop simulated
query_crop_height(cropName)query_crop_height(cropName)
cropName |
integer, identifier of the crop simulated |
height
query_crop_height("Tomato")query_crop_height("Tomato")
Query to return path ID from path Name using the database
query_exp_path(config = config_ambre, pathName)query_exp_path(config = config_ambre, pathName)
config |
list configuration file default value is config_ambre dataset |
pathName |
character Name of the path for which you want to find the ID |
pathID integer ID of the population define
query_exp_path(pathName = "Consumption of the final product potatoes")query_exp_path(pathName = "Consumption of the final product potatoes")
Retrieve min and max frequency values according to path defined in the scenario (database ambre_frequence)
query_frequency(pathID)query_frequency(pathID)
pathID |
integer ID of the path for which we want to retrieve the frequency values |
frequency
scenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) query_frequency(pathID = scenario_example$PathID)scenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) query_frequency(pathID = scenario_example$PathID)
Retrieve irrigation need according to crop ID
query_irrigation_need(scenario)query_irrigation_need(scenario)
scenario |
data.frame scenario obtained with create_scenario function |
scenario_updated
scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) irrigation_need <- query_irrigation_need(scenario_apprentissage) print(irrigation_need$IrrigationNeed)scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) irrigation_need <- query_irrigation_need(scenario_apprentissage) print(irrigation_need$IrrigationNeed)
Retrieve Matrix ID according to path
query_matrix(config = config_ambre, pathName)query_matrix(config = config_ambre, pathName)
config |
list configuration file default value is config_ambre dataset |
pathName |
character Name of the path for which you want to find the ID |
matrixID integer
query_matrix(pathName = "Consumption of the final product potatoes")query_matrix(pathName = "Consumption of the final product potatoes")
Query to return pathogen ID from pathogen Name using the database
query_pathogen(config = config_ambre, pathogenName)query_pathogen(config = config_ambre, pathogenName)
config |
list configuration file default value is config_ambre dataset |
pathogenName |
character Name of the pathogen for which you want to find the ID |
pathogenID integer ID of the pathogen define
query_pathogen(pathogenName = "Campylobacter jejuni") query_pathogen(pathogenName = c("Campylobacter jejuni", "Rotavirus"))query_pathogen(pathogenName = "Campylobacter jejuni") query_pathogen(pathogenName = c("Campylobacter jejuni", "Rotavirus"))
Query to return population ID from population Name using the database
query_pop(config = config_ambre, popName)query_pop(config = config_ambre, popName)
config |
list configuration file default value is config_ambre dataset |
popName |
character Name of the population for which you want to find the ID |
popID integer ID of the population define
query_pop(popName = "Irrigation staff")query_pop(popName = "Irrigation staff")
Retrieve min and max volume values according to path defined in the scenario (database ambre_volume)
query_volume(pathID)query_volume(pathID)
pathID |
integer ID of the path for which we want to retrieve the volume min and max values |
volume
query_volume(pathID = 1)query_volume(pathID = 1)
Calculate the difference of achieve concentration in effluent according to regulation
regulation_matrix_concentration(scenario, regulation)regulation_matrix_concentration(scenario, regulation)
scenario |
data.frame with log_reduction column obtained with simulate_treatment function |
regulation |
data.frame regulation table to compare to simulation results |
formattable
library(dplyr) library(purrr) scenario_example <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_exposure <- scenario_example |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x))) scenario_patho <- update_pathogen(scenario = scenario_exposure, pathoName = c("Rotavirus", "Campylobacter jejuni", "Norovirus")) concentration = map(.x = scenario_patho$config, .f= ~ simulate_inflow(.x)) scenario_concentration <- scenario_patho |> mutate(inflow_concentration = concentration) scenario_ini_dose <- initial_dose_calculation(scenario = scenario_concentration) scenario_barrier <- update_treatment_scheme(scenario = scenario_ini_dose, initial_situation = TRUE) scenario_barrier$config <- purrr::pmap( list( config = scenario_barrier$config, barrierID = scenario_barrier$SupplementaryProcessID, cropHeight = scenario_barrier$CropHeight, matrixID = scenario_barrier$MatrixID, popID = scenario_barrier$PopulationID, decay = scenario_barrier$nb_day_decay ), function(config, barrierID, cropHeight, matrixID, popID, decay) { if (barrierID %in% c(24, 26, 27, 28) && matrixID %in% c(3, 5)) { update_logreduction_specific_barrier( config = config, cropHeight = cropHeight, barrierID = barrierID ) } else if (barrierID %in% c(12)) { update_logreduction_decay( config = config, cropHeight = cropHeight, barrierID = barrierID, popID = popID, nb_day_decay = decay ) } else if (barrierID %in% c(9,13,14,15,16,17,18,24,26,27,28)) { update_logreduction_path( config = config, matrixID = matrixID, barrierID = barrierID, popID = popID ) } else { config } } ) scenario_logreduction <- scenario_barrier |> mutate(log_reduction = map(config, simulate_treatment)) regulation_concentration <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Country, RegulationID, Reduction)) regulation_matrix_concentration(scenario = scenario_logreduction, regulation = regulation_concentration)library(dplyr) library(purrr) scenario_example <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_exposure <- scenario_example |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x))) scenario_patho <- update_pathogen(scenario = scenario_exposure, pathoName = c("Rotavirus", "Campylobacter jejuni", "Norovirus")) concentration = map(.x = scenario_patho$config, .f= ~ simulate_inflow(.x)) scenario_concentration <- scenario_patho |> mutate(inflow_concentration = concentration) scenario_ini_dose <- initial_dose_calculation(scenario = scenario_concentration) scenario_barrier <- update_treatment_scheme(scenario = scenario_ini_dose, initial_situation = TRUE) scenario_barrier$config <- purrr::pmap( list( config = scenario_barrier$config, barrierID = scenario_barrier$SupplementaryProcessID, cropHeight = scenario_barrier$CropHeight, matrixID = scenario_barrier$MatrixID, popID = scenario_barrier$PopulationID, decay = scenario_barrier$nb_day_decay ), function(config, barrierID, cropHeight, matrixID, popID, decay) { if (barrierID %in% c(24, 26, 27, 28) && matrixID %in% c(3, 5)) { update_logreduction_specific_barrier( config = config, cropHeight = cropHeight, barrierID = barrierID ) } else if (barrierID %in% c(12)) { update_logreduction_decay( config = config, cropHeight = cropHeight, barrierID = barrierID, popID = popID, nb_day_decay = decay ) } else if (barrierID %in% c(9,13,14,15,16,17,18,24,26,27,28)) { update_logreduction_path( config = config, matrixID = matrixID, barrierID = barrierID, popID = popID ) } else { config } } ) scenario_logreduction <- scenario_barrier |> mutate(log_reduction = map(config, simulate_treatment)) regulation_concentration <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Country, RegulationID, Reduction)) regulation_matrix_concentration(scenario = scenario_logreduction, regulation = regulation_concentration)
Calculate the difference of maximal log reduction achieve according to regulation
regulation_matrix_log(scenario, regulation)regulation_matrix_log(scenario, regulation)
scenario |
data.frame with log_reduction column obtained with simulate_treatment function |
regulation |
data.frame regulation value to compare to simulation results |
formattable
library(dplyr) library(purrr) scenario_example <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_exposure <- scenario_example |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x))) scenario_patho <- update_pathogen(scenario = scenario_exposure, pathoName = c("Rotavirus", "Campylobacter jejuni")) concentration = map(.x = scenario_patho$config, .f= ~ simulate_inflow(.x)) scenario_concentration <- scenario_patho |> mutate(inflow_concentration = concentration) scenario_ini_dose <- initial_dose_calculation(scenario = scenario_concentration) scenario_barrier <- update_treatment_scheme(scenario = scenario_ini_dose, initial_situation = TRUE) scenario_barrier$config <- purrr::pmap( list( config = scenario_barrier$config, barrierID = scenario_barrier$SupplementaryProcessID, cropHeight = scenario_barrier$CropHeight, matrixID = scenario_barrier$MatrixID, popID = scenario_barrier$PopulationID, decay = scenario_barrier$nb_day_decay ), function(config, barrierID, cropHeight, matrixID, popID, decay) { if (barrierID %in% c(24, 26, 27, 28) && matrixID %in% c(3, 5)) { update_logreduction_specific_barrier( config = config, cropHeight = cropHeight, barrierID = barrierID ) } else if (barrierID %in% c(12)) { update_logreduction_decay( config = config, cropHeight = cropHeight, barrierID = barrierID, popID = popID, nb_day_decay = decay ) } else if (barrierID %in% c(9,13,14,15,16,17,18,24,26,27,28)) { update_logreduction_path( config = config, matrixID = matrixID, barrierID = barrierID, popID = popID ) } else { config } } ) scenario_logreduction <- scenario_barrier |> mutate(log_reduction = map(config, simulate_treatment)) regulation_reduction <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Concentration, Country, RegulationID)) regulation_matrix_log(scenario = scenario_logreduction, regulation = regulation_reduction)library(dplyr) library(purrr) scenario_example <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_exposure <- scenario_example |> mutate( volume = map( .x = config, .f = ~ simulate_exposure(config = .x))) scenario_patho <- update_pathogen(scenario = scenario_exposure, pathoName = c("Rotavirus", "Campylobacter jejuni")) concentration = map(.x = scenario_patho$config, .f= ~ simulate_inflow(.x)) scenario_concentration <- scenario_patho |> mutate(inflow_concentration = concentration) scenario_ini_dose <- initial_dose_calculation(scenario = scenario_concentration) scenario_barrier <- update_treatment_scheme(scenario = scenario_ini_dose, initial_situation = TRUE) scenario_barrier$config <- purrr::pmap( list( config = scenario_barrier$config, barrierID = scenario_barrier$SupplementaryProcessID, cropHeight = scenario_barrier$CropHeight, matrixID = scenario_barrier$MatrixID, popID = scenario_barrier$PopulationID, decay = scenario_barrier$nb_day_decay ), function(config, barrierID, cropHeight, matrixID, popID, decay) { if (barrierID %in% c(24, 26, 27, 28) && matrixID %in% c(3, 5)) { update_logreduction_specific_barrier( config = config, cropHeight = cropHeight, barrierID = barrierID ) } else if (barrierID %in% c(12)) { update_logreduction_decay( config = config, cropHeight = cropHeight, barrierID = barrierID, popID = popID, nb_day_decay = decay ) } else if (barrierID %in% c(9,13,14,15,16,17,18,24,26,27,28)) { update_logreduction_path( config = config, matrixID = matrixID, barrierID = barrierID, popID = popID ) } else { config } } ) scenario_logreduction <- scenario_barrier |> mutate(log_reduction = map(config, simulate_treatment)) regulation_reduction <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Concentration, Country, RegulationID)) regulation_matrix_log(scenario = scenario_logreduction, regulation = regulation_reduction)
For one or more supplementary barriers, updates the per-config log-reduction
according to each barrier's type: pathway-specific barriers use
update_logreduction_path(), natural die-off uses
update_logreduction_decay(), and product/soil-specific barriers use
update_logreduction_specific_barrier(). Barriers are applied in turn so
their reductions accumulate; any other barrier leaves the config unchanged.
Extracted from run_qmra_initial_situation() /
run_qmra_supplementary_process() (was an inline anonymous function).
retrieve_specific_barrier( config, barrierID, cropHeight, matrixID, popID, decay )retrieve_specific_barrier( config, barrierID, cropHeight, matrixID, popID, decay )
config |
A per-row config (list) from the scenario. |
barrierID |
One or more supplementary barrier ids (a scalar or a vector);
each is applied in turn. |
cropHeight |
The crop height. |
matrixID |
The exposure-matrix id. |
popID |
The exposed-population id. |
decay |
The number of decay days (for natural die-off barriers). |
The updated config.
Calculate annual cost and total investment fees for simulated management risk scenario
run_economic_analysis( scenario, price_per_m3, membership_fee, grant, initialSituation, allocation_key = NULL )run_economic_analysis( scenario, price_per_m3, membership_fee, grant, initialSituation, allocation_key = NULL )
scenario |
data.frame scenario obtained with create_scenario function |
price_per_m3 |
numeric, water price in euro per cubic meter |
membership_fee |
numeric annual membership fee in euro per hectare |
grant |
numeric amount of the grant in percentage |
initialSituation |
boolean, TRUE to simulate initial situation cost, FALSE to simulate supplementary process cost |
allocation_key |
numeric allocation key, NULL by default |
all_plots
scenario <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) run_economic_analysis(scenario = scenario, price_per_m3 = 0.1, membership_fee = 200, grant = 0.5, initialSituation = TRUE) run_economic_analysis(scenario = scenario, price_per_m3 = 0.1, membership_fee = 200, grant = 0.5, initialSituation = FALSE) crop <- scenario$CropName allocation_custom <- data.frame(CropName = crop, allocation = c(0.5, 0.5)) run_economic_analysis(scenario = scenario, price_per_m3 = 0.1, membership_fee = 200, grant = 0, initialSituation = TRUE, allocation_key = allocation_custom)scenario <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) run_economic_analysis(scenario = scenario, price_per_m3 = 0.1, membership_fee = 200, grant = 0.5, initialSituation = TRUE) run_economic_analysis(scenario = scenario, price_per_m3 = 0.1, membership_fee = 200, grant = 0.5, initialSituation = FALSE) crop <- scenario$CropName allocation_custom <- data.frame(CropName = crop, allocation = c(0.5, 0.5)) run_economic_analysis(scenario = scenario, price_per_m3 = 0.1, membership_fee = 200, grant = 0, initialSituation = TRUE, allocation_key = allocation_custom)
Run the full QMRA workflow using custom data for volume and frequency of exposure (not the default databases)
simulate inflow concentration, volume of exposure
calculate initial dose
simulate log reduction for treatment processes
calculate final dose
calculate infection probability, illness probability and dalys reduction
calculate annual total risk
run_qmra_custom( scenario, volume, frequency, concentration, objective = 1e-06, regulationLog, regulationConcentration, initialSituation )run_qmra_custom( scenario, volume, frequency, concentration, objective = 1e-06, regulationLog, regulationConcentration, initialSituation )
scenario |
data.frame obtain with create_scenario function |
volume |
data.frame of min and max value, same size as scenario |
frequency |
array of integer same size as scenario |
concentration |
data.frame of pathogenName, min, max and distribution law to simulate |
objective |
numeric reference dalys threshold to compare simulation result on dalys plot. default value is OMS threshold 1e-6 dalys |
regulationLog |
data.frame regulation value of the log reduction to compare with simulation result |
regulationConcentration |
data.frame regulation value of the log reduction to compare with simulation result |
initialSituation |
boolean, TRUE to consider InitialTrainID for simulation, FALSE to consider SupplementaryTrainID for simulation |
all_plots list
sc <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) regulation_reduction <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Concentration, Country, RegulationID)) regulation_concentration <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Country, RegulationID, Reduction)) concentration_custom <- data.frame(PathogenName = c("Rotavirus"), min = c(1), max = c(2), type = c("uniform")) run_qmra_custom(scenario = sc, concentration = concentration_custom, volume = data.frame(min=c(0.5,1), max = c(1,2), type= c("triangle", "triangle")), frequency = c(200L, 300L), regulationLog = regulation_reduction, regulationConcentration = regulation_concentration, initialSituation = TRUE) run_qmra_custom(scenario = sc, concentration = concentration_custom, volume = data.frame(min=c(0.5,1), max = c(1,2), type= c("triangle", "triangle")), frequency = c(200L, 300L), regulationLog = regulation_reduction, regulationConcentration = regulation_concentration, initialSituation = FALSE)sc <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) regulation_reduction <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Concentration, Country, RegulationID)) regulation_concentration <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Country, RegulationID, Reduction)) concentration_custom <- data.frame(PathogenName = c("Rotavirus"), min = c(1), max = c(2), type = c("uniform")) run_qmra_custom(scenario = sc, concentration = concentration_custom, volume = data.frame(min=c(0.5,1), max = c(1,2), type= c("triangle", "triangle")), frequency = c(200L, 300L), regulationLog = regulation_reduction, regulationConcentration = regulation_concentration, initialSituation = TRUE) run_qmra_custom(scenario = sc, concentration = concentration_custom, volume = data.frame(min=c(0.5,1), max = c(1,2), type= c("triangle", "triangle")), frequency = c(200L, 300L), regulationLog = regulation_reduction, regulationConcentration = regulation_concentration, initialSituation = FALSE)
Run the full QMRA workflow
simulate inflow concentration, volume of exposure
calculate initial dose
simulate log reduction for treatment processes
calculate final dose
calculate infection probability, illness probability and dalys reduction
calculate annual total risk
run_qmra_initial_situation( scenario, pathogen, regulationLog, regulationConcentration )run_qmra_initial_situation( scenario, pathogen, regulationLog, regulationConcentration )
scenario |
data.frame scenario obtained with create_scenario function path of the scenario file |
pathogen |
character Name of the pathogen to simulate |
regulationLog |
data.frame regulation value of the log reduction to compare with simulation result |
regulationConcentration |
data.frame regulation value of the log reduction to compare with simulation result |
all_plots list of ggplot
library(dplyr) scenario <- create_scenario(system.file("input_cas_apprentissage_complet.xlsx", package = "ambre")) regulation_reduction <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Concentration, Country, RegulationID)) regulation_concentration <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Country, RegulationID, Reduction)) run_qmra_initial_situation(scenario = scenario, pathogen = c("Campylobacter jejuni", "Escherichia coli"), regulationLog = regulation_reduction, regulationConcentration = regulation_concentration)library(dplyr) scenario <- create_scenario(system.file("input_cas_apprentissage_complet.xlsx", package = "ambre")) regulation_reduction <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Concentration, Country, RegulationID)) regulation_concentration <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Country, RegulationID, Reduction)) run_qmra_initial_situation(scenario = scenario, pathogen = c("Campylobacter jejuni", "Escherichia coli"), regulationLog = regulation_reduction, regulationConcentration = regulation_concentration)
Run a learning case to evaluate risk on scenario with 6 crops (Corn Seed, Tomato, Potato, Salad, Onion) and 6 populations (maintainer, harverster, irrigation, consumer, local resident, passerby). Run QMRA calculation with barrier measures
run_qmra_learning_case()run_qmra_learning_case()
all_plots list
run_qmra_learning_case()run_qmra_learning_case()
Run the full QMRA workflow on additional processes
simulate inflow concentration, volume of exposure
calculate initial dose
simulate log reduction for barrier processes
calculate final dose
calculate infection probability, illness probability and dalys reduction
calculate annual total risk
run_qmra_supplementary_process( scenario, pathogen, regulationLog, regulationConcentration )run_qmra_supplementary_process( scenario, pathogen, regulationLog, regulationConcentration )
scenario |
data.frame scenario obtained with create_scenario function |
pathogen |
character Name of the pathogen to simulate |
regulationLog |
data.frame regulation value of the log reduction to compare with simulation result |
regulationConcentration |
data.frame regulation value of the log reduction to compare with simulation result |
all_plots list of ggplot
library(dplyr) scenario <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) regulation_reduction <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Concentration, Country, RegulationID)) regulation_concentration <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Country, RegulationID, Reduction)) run_qmra_supplementary_process(scenario = scenario, pathogen = c("Campylobacter jejuni", "Escherichia coli"), regulationLog = regulation_reduction, regulationConcentration = regulation_concentration)library(dplyr) scenario <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) regulation_reduction <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Concentration, Country, RegulationID)) regulation_concentration <- config_ambre$regulation$regulation_value |> dplyr::filter(Country == "France") |> dplyr::select(-c(Country, RegulationID, Reduction)) run_qmra_supplementary_process(scenario = scenario, pathogen = c("Campylobacter jejuni", "Escherichia coli"), regulationLog = regulation_reduction, regulationConcentration = regulation_concentration)
This function does the same thing as kwb.qmra::get_treatment_data(), but it is bundled with ambre to avoid a hard dependency on the unmaintained package.
simulate_exposure(config, debug = TRUE)simulate_exposure(config, debug = TRUE)
config |
as retrieved by config_read() |
debug |
print debug information (default: TRUE) |
list with parameters of user defined exposure scenario (number of events and volumes per Event)
Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0 URL: https://github.com/kwb-r/kwb.utils (MIT Licence)
scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_updated <- update_pathogen(scenario = scenario_test, pathoName = c("Campylobacter jejuni", "Rotavirus")) simulate_exposure(config = scenario_updated$config[[1]])scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_updated <- update_pathogen(scenario = scenario_test, pathoName = c("Campylobacter jejuni", "Rotavirus")) simulate_exposure(config = scenario_updated$config[[1]])
This function does the same thing as kwb.utils::simulate_inflow(), but it is bundled with ambre to avoid a hard dependency on the unmaintained package.
simulate_inflow(config, debug = TRUE, lean = FALSE)simulate_inflow(config, debug = TRUE, lean = FALSE)
config |
list contained in the scenario object |
debug |
print debug information (default: TRUE) |
lean |
if |
Simulate pathogen concentrations
list with parameters of user defined random distribution and corresponding values
Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0 URL: https://github.com/kwb-r/kwb.utils (MIT Licence)
# Example usage of simulate_inflow scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_updated <- update_pathogen(scenario = scenario_test, pathoName = c("Campylobacter jejuni", "Rotavirus")) # Call simulate_inflow with the sample config result_1 <- simulate_inflow(config = scenario_updated$config[[1]], debug = FALSE) # Print the results cat("Parameters used for simulation:") print(result_1$paras) # Example with lean = TRUE lean_result_1 <- simulate_inflow(config = scenario_updated$config[[1]], debug = FALSE, lean = TRUE) cat("Lean result (only events):") print(lean_result_1)# Example usage of simulate_inflow scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre")) scenario_updated <- update_pathogen(scenario = scenario_test, pathoName = c("Campylobacter jejuni", "Rotavirus")) # Call simulate_inflow with the sample config result_1 <- simulate_inflow(config = scenario_updated$config[[1]], debug = FALSE) # Print the results cat("Parameters used for simulation:") print(result_1$paras) # Example with lean = TRUE lean_result_1 <- simulate_inflow(config = scenario_updated$config[[1]], debug = FALSE, lean = TRUE) cat("Lean result (only events):") print(lean_result_1)
This function simulates treatment data for pathogen processes based on the provided configuration. It generates treatment events and parameters, and can return results in either long or wide format.
simulate_treatment(config, wide = FALSE, debug = TRUE, lean = FALSE)simulate_treatment(config, wide = FALSE, debug = TRUE, lean = FALSE)
config |
A configuration object containing treatment scheme and process information. |
wide |
Logical indicating whether to return results in wide format. |
debug |
Logical indicating whether to print debug information. |
lean |
Logical indicating whether to return only essential results for web applications. |
This function does the same thing as kwb.qmra::simulate_treatment(), but it is bundled with ambre to avoid a hard dependency on the unmaintained package.
If lean is TRUE, returns a list containing only the long-format treatment events.
If wide is TRUE, returns a list containing long-format events, wide-format events,
wide-format scheme events, treatment schemes, and treatment parameters.
If wide is FALSE, returns a list containing long-format events, treatment schemes,
and treatment parameters.
Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0 URL: https://github.com/kwb-r/kwb.utils (MIT Licence)
# Example usage of simulate_treatment scenario_test <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_updated <- update_pathogen(scenario = scenario_test, pathoName = c("Campylobacter jejuni","Rotavirus")) config <- scenario_updated$config[[1]] # Simulate treatment data result <- simulate_treatment(config, wide = TRUE, debug = FALSE, lean = FALSE)# Example usage of simulate_treatment scenario_test <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_updated <- update_pathogen(scenario = scenario_test, pathoName = c("Campylobacter jejuni","Rotavirus")) config <- scenario_updated$config[[1]] # Simulate treatment data result <- simulate_treatment(config, wide = TRUE, debug = FALSE, lean = FALSE)
Calculate the total area of each culture of the simulated scenario
total_area_calculation(scenario)total_area_calculation(scenario)
scenario |
data.frame scenario created with create_scenario function |
surface_total data.frame
scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) total_area_calculation(scenario = scenario_apprentissage)scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) total_area_calculation(scenario = scenario_apprentissage)
Calculates the total investment required to implement risk management processes relating to the reuse of wastewater for each simulated configuration
total_investment_cost( scenario, price_per_m3, membership_fee, grant, allocation_key = NULL )total_investment_cost( scenario, price_per_m3, membership_fee, grant, allocation_key = NULL )
scenario |
data.frame scenario obtained with create_scenario function |
price_per_m3 |
numeric, water price in euro per cubic meter |
membership_fee |
numeric annual membership fee in euro per hectare |
grant |
numeric amount of the grant in percentage |
allocation_key |
numeric allocation_key, NULL by default |
result list
scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) total_investment_cost(scenario = scenario_apprentissage, price_per_m3 = 0.1, membership_fee = 200, grant = 0.5) crop <- scenario_apprentissage$CropName allocation_custom <- data.frame(CropName = crop, allocation = c(0.5, 0.5)) total_investment_cost(scenario = scenario_apprentissage, price_per_m3 = 0.1, membership_fee = 200, grant = 0, allocation_key = allocation_custom)scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) total_investment_cost(scenario = scenario_apprentissage, price_per_m3 = 0.1, membership_fee = 200, grant = 0.5) crop <- scenario_apprentissage$CropName allocation_custom <- data.frame(CropName = crop, allocation = c(0.5, 0.5)) total_investment_cost(scenario = scenario_apprentissage, price_per_m3 = 0.1, membership_fee = 200, grant = 0, allocation_key = allocation_custom)
Calculate total irrigation need according to irrigation need of each culture of the simulated scenario
total_irrigation_need(scenario)total_irrigation_need(scenario)
scenario |
data.frame scenario with irrigation_need_m3an column obtained with irrigation_need_calculation function |
total_irrigation_need
scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) irrigation_need <- irrigation_need_calculation(scenario_apprentissage) total_irrigation_need(irrigation_need)scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) irrigation_need <- irrigation_need_calculation(scenario_apprentissage) total_irrigation_need(irrigation_need)
Update the min, max and distribution law of the concentration in the simulated configuration according to a value defined by the user
update_concentration(scenario, concentration)update_concentration(scenario, concentration)
scenario |
data.frame |
concentration |
data.frame of pathogenName, min, max and distribution law to simulate |
scenario_updated
scenario_test <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) pathogenName <- c("Norovirus", "Rotavirus") concentration_custom <- data.frame(PathogenName = pathogenName, min = c(1, 1), max = c(2,2), type = c("uniform", "uniform")) scenario_updated_patho <- update_pathogen(scenario = scenario_test, pathoName = pathogenName) result <- update_concentration(scenario = scenario_updated_patho , concentration = concentration_custom) dplyr::filter(result$config[[1]]$inflow, PathogenName == "Norovirus")scenario_test <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) pathogenName <- c("Norovirus", "Rotavirus") concentration_custom <- data.frame(PathogenName = pathogenName, min = c(1, 1), max = c(2,2), type = c("uniform", "uniform")) scenario_updated_patho <- update_pathogen(scenario = scenario_test, pathoName = pathogenName) result <- update_concentration(scenario = scenario_updated_patho , concentration = concentration_custom) dplyr::filter(result$config[[1]]$inflow, PathogenName == "Norovirus")
Update the configuration with max frequency to be simulated according to path ID
update_frequency(scenario)update_frequency(scenario)
scenario |
dataframe scenario obtained with function create_scenario |
scenario_updated list configuration updated with the min and max volumes to be simulated
scenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) updated_scenario <- update_frequency(scenario_example) updated_scenario$config[[1]]$exposurescenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) updated_scenario <- update_frequency(scenario_example) updated_scenario$config[[1]]$exposure
Update the value of the frequency in the simulated configuration according to a value defined by the user
update_frequency_with_desired_value(scenario, frequency)update_frequency_with_desired_value(scenario, frequency)
scenario |
data.frame |
frequency |
numeric, list of max frequency to simulate |
scenario_updated
scenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_example_updated <- update_frequency_with_desired_value(scenario = scenario_example, frequency = c(2L,3L)) print(scenario_example_updated$config[[1]]$exposure) print(scenario_example_updated$config[[2]]$exposure)scenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_example_updated <- update_frequency_with_desired_value(scenario = scenario_example, frequency = c(2L,3L)) print(scenario_example_updated$config[[1]]$exposure) print(scenario_example_updated$config[[2]]$exposure)
Update the log reduction value for the decay barrier according to crop and population simulated
update_logreduction_decay(config, cropHeight, popID, barrierID, nb_day_decay)update_logreduction_decay(config, cropHeight, popID, barrierID, nb_day_decay)
config |
list configuration simulated |
cropHeight |
numeric, height of th crop simulated |
popID |
numeric, ID of the population simulated |
barrierID |
numeric, ID of the barrier simulated |
nb_day_decay |
numeric, number of day of natural decay for the simulated crop |
config_updated
scenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_example$config <- purrr::pmap( list( config = scenario_example$config, barrierID = scenario_example$SupplementaryProcessID, cropHeight = scenario_example$CropHeight, popID = scenario_example$PopulationID, decay = scenario_example$nb_day_decay ), function(config, barrierID, cropHeight, popID, decay) { if (barrierID %in% c(12)) { update_logreduction_decay( config = config, cropHeight = cropHeight, barrierID = barrierID, popID = popID, nb_day_decay = decay ) } else { config } } )scenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_example$config <- purrr::pmap( list( config = scenario_example$config, barrierID = scenario_example$SupplementaryProcessID, cropHeight = scenario_example$CropHeight, popID = scenario_example$PopulationID, decay = scenario_example$nb_day_decay ), function(config, barrierID, cropHeight, popID, decay) { if (barrierID %in% c(12)) { update_logreduction_decay( config = config, cropHeight = cropHeight, barrierID = barrierID, popID = popID, nb_day_decay = decay ) } else { config } } )
Update the log reduction value for specific barrier according to path and population simulated
update_logreduction_path(config, matrixID, popID, barrierID)update_logreduction_path(config, matrixID, popID, barrierID)
config |
list configuration simulated |
matrixID |
numeric, ID of the matrix simulated |
popID |
numeric, ID of the population simulated |
barrierID |
numeric, ID of the barrier simulated |
config_updated
scenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_example$config <- purrr::pmap( list( config = scenario_example$config, barrierID = scenario_example$SupplementaryProcessID, matrixID = scenario_example$MatrixID, popID = scenario_example$PopulationID ), function(config, barrierID, matrixID, popID) { if (barrierID %in% c(9,13,14,15,16,17,18,24,26,27,28)) { update_logreduction_path( config = config, matrixID = matrixID, barrierID = barrierID, popID = popID ) } else { config } } )scenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_example$config <- purrr::pmap( list( config = scenario_example$config, barrierID = scenario_example$SupplementaryProcessID, matrixID = scenario_example$MatrixID, popID = scenario_example$PopulationID ), function(config, barrierID, matrixID, popID) { if (barrierID %in% c(9,13,14,15,16,17,18,24,26,27,28)) { update_logreduction_path( config = config, matrixID = matrixID, barrierID = barrierID, popID = popID ) } else { config } } )
Update log reduction value according to treatment, crop, and population simulated
update_logreduction_specific_barrier(config, cropHeight, barrierID)update_logreduction_specific_barrier(config, cropHeight, barrierID)
config |
list configuration simulated |
cropHeight |
numeric, height of th crop simulated |
barrierID |
numeric, ID of the barrier simulated |
config_updated
scenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_example$config <- purrr::pmap( list( config = scenario_example$config, barrierID = scenario_example$SupplementaryProcessID, matrixID = scenario_example$MatrixID, cropHeight = scenario_example$CropHeight ), function(config, barrierID, matrixID, cropHeight) { if (barrierID %in% c(24, 26, 27, 28) && matrixID %in% c(3, 5)) { update_logreduction_specific_barrier( config = config, cropHeight = cropHeight, barrierID = barrierID ) } else { config } } )scenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_example$config <- purrr::pmap( list( config = scenario_example$config, barrierID = scenario_example$SupplementaryProcessID, matrixID = scenario_example$MatrixID, cropHeight = scenario_example$CropHeight ), function(config, barrierID, matrixID, cropHeight) { if (barrierID %in% c(24, 26, 27, 28) && matrixID %in% c(3, 5)) { update_logreduction_specific_barrier( config = config, cropHeight = cropHeight, barrierID = barrierID ) } else { config } } )
Update number_of_repeating in config$exposure database
update_monte_carlo(scenario, monte_carlo = 1000)update_monte_carlo(scenario, monte_carlo = 1000)
scenario |
data.frame scenario obtained with create_scenario function |
monte_carlo |
integer number of simulation iterations for Monte Carlo |
scenario_updated
scenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_updated <- update_monte_carlo(scenario = scenario_example, monte_carlo = 2000) scenario_updated$config[[1]]$exposurescenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_updated <- update_monte_carlo(scenario = scenario_example, monte_carlo = 2000) scenario_updated$config[[1]]$exposure
Update the configuration with list of pathogen to be simulated according to pathogen ID
update_pathogen(scenario, pathoName)update_pathogen(scenario, pathoName)
scenario |
list obtain from create_scenario() |
pathoName |
character name of the pathogens simulated |
scenario_updated list scenario updated with the pathogens to be simulated
scenario_test <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_updated <- update_pathogen(scenario = scenario_test, pathoName = c("Campylobacter jejuni", "Rotavirus"))scenario_test <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_updated <- update_pathogen(scenario = scenario_test, pathoName = c("Campylobacter jejuni", "Rotavirus"))
Update treatment scheme list in config data frame according to scenario define
update_treatment_scheme(scenario, initial_situation = TRUE)update_treatment_scheme(scenario, initial_situation = TRUE)
scenario |
created with function create_scenario |
initial_situation |
boolean to retrieve simulate treatment train if TRUE or from Barrier train if FALSE |
updated_scenario
scenario_test <- create_scenario( system.file("input_cas_apprentissage_complet.xlsx", package = "ambre") ) scenario_ini <- update_treatment_scheme(scenario_test, initial_situation = TRUE) scenario_supp <- update_treatment_scheme(scenario_test, initial_situation = FALSE)scenario_test <- create_scenario( system.file("input_cas_apprentissage_complet.xlsx", package = "ambre") ) scenario_ini <- update_treatment_scheme(scenario_test, initial_situation = TRUE) scenario_supp <- update_treatment_scheme(scenario_test, initial_situation = FALSE)
Update the configuration with min and max volumes to be simulated according to path ID
update_volume(scenario)update_volume(scenario)
scenario |
dataframe scenario obtained with function create_scenario |
scenario_updated list configuration updated with the min and max volumes to be simulated
scenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_updated <- update_volume(scenario_example) scenario_updated$config[[1]]$exposurescenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) scenario_updated <- update_volume(scenario_example) scenario_updated$config[[1]]$exposure
Update the min and max value of the volume in the simulated configuration according to a value defined by the user
update_volume_with_desired_value(scenario, volume)update_volume_with_desired_value(scenario, volume)
scenario |
data.frame |
volume |
numeric, named list of min and max value to simulate |
scenario_updated
scenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) volumes <- data.frame("min" = c(1.1, 1.2), "max" = c(1.3,1.4), "type" = c("triangle", "triangle")) scenario_example_updated <- update_volume_with_desired_value(scenario = scenario_example, volume = volumes) print(scenario_example_updated$config[[1]]$exposure) print(scenario_example_updated$config[[2]]$exposure)scenario_example <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) volumes <- data.frame("min" = c(1.1, 1.2), "max" = c(1.3,1.4), "type" = c("triangle", "triangle")) scenario_example_updated <- update_volume_with_desired_value(scenario = scenario_example, volume = volumes) print(scenario_example_updated$config[[1]]$exposure) print(scenario_example_updated$config[[2]]$exposure)
Calculate cost of water charge
water_price(scenario, price_per_m3, membership_fee)water_price(scenario, price_per_m3, membership_fee)
scenario |
data.frame, with irrigation_need_m3an obtained with irrigation_need_calculation function |
price_per_m3 |
numeric, water price in euro per cubic meter |
membership_fee |
numeric annual membership fee in euro per hectare |
updated_scenario
scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) irrigation_need <- irrigation_need_calculation(scenario_apprentissage) water_price(scenario = irrigation_need, price_per_m3 = 0.01, membership_fee = 200)scenario_apprentissage <- create_scenario( system.file("input_1culture_2pop.xlsx", package = "ambre") ) irrigation_need <- irrigation_need_calculation(scenario_apprentissage) water_price(scenario = irrigation_need, price_per_m3 = 0.01, membership_fee = 200)