Skip to contents

Calculate the difference of achieve concentration in effluent according to regulation

Usage

regulation_matrix_concentration(scenario, regulation)

Arguments

scenario

data.frame with log_reduction column obtained with simulate_treatment function

regulation

data.frame regulation table to compare to simulation results

Value

formattable

Examples

# \donttest{
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)))
#> Simulated exposure: volume per event
#> Create 1000 random distribution(s): triangle (n: 365, min: 0.500000, max: 3.000000, mode = 1.750000)
#> Simulated exposure: volume per event
#> Create 1000 random distribution(s): triangle (n: 365, min: 0.500000, max: 3.000000, mode = 1.750000)

scenario_patho <- update_pathogen(scenario = scenario_exposure, 
                                  pathoName = c("Rotavirus", "Campylobacter jejuni", "Norovirus"))
concentration = map(.x = scenario_patho$config,
                   .f= ~ simulate_inflow(.x))
#> Simulated pathogen: Campylobacter jejuni
#> Create 1000 random distribution(s): uniform (n: 365, min: 100.000000, max: 5000.000000)
#> Simulated pathogen: Norovirus
#> Create 1000 random distribution(s): uniform (n: 365, min: 0.000000, max: 1000000.000000)
#> Simulated pathogen: Rotavirus
#> Create 1000 random distribution(s): uniform (n: 365, min: 100.000000, max: 5000.000000)
#> Providing inflow events ... ok. (0.09 secs) 
#> Providing inflow paras ... ok. (0.00 secs) 
#> Simulated pathogen: Campylobacter jejuni
#> Create 1000 random distribution(s): uniform (n: 365, min: 100.000000, max: 5000.000000)
#> Simulated pathogen: Norovirus
#> Create 1000 random distribution(s): uniform (n: 365, min: 0.000000, max: 1000000.000000)
#> Simulated pathogen: Rotavirus
#> Create 1000 random distribution(s): uniform (n: 365, min: 100.000000, max: 5000.000000)
#> Providing inflow events ... ok. (0.09 secs) 
#> Providing inflow paras ... ok. (0.00 secs) 
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))
#> Create 1000 random distribution(s): uniform (n: 365, min: 1.000000, max: 2.000000)
#> Create 1000 random distribution(s): uniform (n: 365, min: 1.000000, max: 2.000000)
#> Create 1000 random distribution(s): uniform (n: 365, min: 1.000000, max: 3.000000)
#> Create 1000 random distribution(s): uniform (n: 365, min: 1.000000, max: 2.000000)
#> Create 1000 random distribution(s): uniform (n: 365, min: 5.000000, max: 7.000000)
#> Create 1000 random distribution(s): uniform (n: 365, min: 2.000000, max: 4.000000)
#> Simulated treatment: Q.1 - Activated Sludge for Bacteria
#> Simulated treatment: Q.1 - Activated Sludge for Viruses
#> Simulated treatment: Q.2 - Maturation Pond for Bacteria
#> Simulated treatment: Q.2 - Maturation Pond for Viruses
#> Simulated treatment: Q.6 - Chlorination for Bacteria
#> Simulated treatment: Q.6 - Chlorination for Viruses
#> Simulated treatment: Q.1 - Activated Sludge for Bacteria
#> Simulated treatment: Q.1 - Activated Sludge for Viruses
#> Simulated treatment: Q.2 - Maturation Pond for Bacteria
#> Simulated treatment: Q.2 - Maturation Pond for Viruses
#> Simulated treatment: Q.6 - Chlorination for Bacteria
#> Simulated treatment: Q.6 - Chlorination for Viruses
#> Joining with `by = join_by(TreatmentID)`
#> Joining with `by = join_by(TreatmentID)`
#> Create 1000 random distribution(s): uniform (n: 365, min: 1.000000, max: 2.000000)
#> Create 1000 random distribution(s): uniform (n: 365, min: 1.000000, max: 2.000000)
#> Create 1000 random distribution(s): uniform (n: 365, min: 1.000000, max: 3.000000)
#> Create 1000 random distribution(s): uniform (n: 365, min: 1.000000, max: 2.000000)
#> Create 1000 random distribution(s): uniform (n: 365, min: 5.000000, max: 7.000000)
#> Create 1000 random distribution(s): uniform (n: 365, min: 2.000000, max: 4.000000)
#> Simulated treatment: Q.1 - Activated Sludge for Bacteria
#> Simulated treatment: Q.1 - Activated Sludge for Viruses
#> Simulated treatment: Q.2 - Maturation Pond for Bacteria
#> Simulated treatment: Q.2 - Maturation Pond for Viruses
#> Simulated treatment: Q.6 - Chlorination for Bacteria
#> Simulated treatment: Q.6 - Chlorination for Viruses
#> Simulated treatment: Q.1 - Activated Sludge for Bacteria
#> Simulated treatment: Q.1 - Activated Sludge for Viruses
#> Simulated treatment: Q.2 - Maturation Pond for Bacteria
#> Simulated treatment: Q.2 - Maturation Pond for Viruses
#> Simulated treatment: Q.6 - Chlorination for Bacteria
#> Simulated treatment: Q.6 - Chlorination for Viruses
#> Joining with `by = join_by(TreatmentID)`
#> Joining with `by = join_by(TreatmentID)`

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)
# }