chemdose_dbp | R Documentation |
Calculates disinfection byproduct (DBP) formation based on the U.S. EPA's
Water Treatment Plant Model (U.S. EPA, 2001). Required arguments include an object of class "water"
created by define_water chlorine dose, type, reaction time, and treatment applied (if any).
The function also requires additional water quality parameters defined in define_water
including bromide, TOC, UV254, temperature, and pH.
For a single water use chemdose_dbp
; for a dataframe use chemdose_dbp_chain
.
For most arguments in the _chain
helper
"use_col" default looks for a column of the same name in the dataframe. The argument can be specified directly in the
function instead or an unquoted column name can be provided.
chemdose_dbp(
water,
cl2,
time,
treatment = "raw",
cl_type = "chorine",
location = "plant",
correction = TRUE,
coeff = NULL
)
chemdose_dbp_chain(
df,
input_water = "defined_water",
output_water = "disinfected_water",
cl2 = "use_col",
time = "use_col",
treatment = "use_col",
cl_type = "use_col",
location = "use_col",
correction = TRUE,
coeff = NULL
)
chemdose_dbp_once(
df,
input_water = "defined_water",
cl2 = "use_col",
time = "use_col",
treatment = "use_col",
cl_type = "use_col",
location = "use_col",
correction = TRUE,
coeff = NULL,
water_prefix = TRUE
)
water |
Source water object of class "water" created by |
cl2 |
Applied chlorine dose (mg/L as Cl2). Model results are valid for doses between 1.51 and 33.55 mg/L. |
time |
Reaction time (hours). Model results are valid for reaction times between 2 and 168 hours. |
treatment |
Type of treatment applied to the water. Options include "raw" for no treatment (default), "coag" for water that has been coagulated or softened, and "gac" for water that has been treated by granular activated carbon (GAC). GAC treatment has also been used for estimating formation after membrane treatment with good results. |
cl_type |
Type of chlorination applied, either "chlorine" (default) or "chloramine". |
location |
Location for DBP formation, either in the "plant" (default), or in the distributions system, "ds". |
correction |
Model calculations are adjusted based on location and cl_type. Default value is TRUE. |
coeff |
Optional input to specify custom coefficients to the dbp model. Must be a data frame with the following columns: ID, and the corresponding coefficients A, a, b, c, d, e, f, and ph_const for each dbp of interest. Default value is NULL. |
df |
a data frame containing a water class column, which has already been computed using define_water. The df may include columns for the other function arguments. |
input_water |
name of the column of water class data to be used as the input for this function. Default is "defined_water". |
output_water |
name of the output column storing updated parameters with the class, water. Default is "disinfected_water". |
water_prefix |
name of the input water used for the calculation, appended to the start of output columns. Default is TRUE. Change to FALSE to remove the water prefix from output column names. |
The function will calculate haloacetic acids (HAA) as HAA5, and total trihalomethanes (TTHM).
Use summarize_wq(water, params = c("dbps"))
to quickly tabulate the results.
For large datasets, using fn_once
or fn_chain
may take many minutes to run. These types of functions use the furrr package
for the option to use parallel processing and speed things up. To initialize parallel processing, use
plan(multisession)
or plan(multicore)
(depending on your operating system) prior to your piped code with the
fn_once
or fn_chain
functions. Note, parallel processing is best used when your code block takes more than a minute to run,
shorter run times will not benefit from parallel processing.
chemdose_dbp
returns a single water class object with predicted DBP concentrations.
chemdose_dbp_chain
returns a data frame containing a water class column with predicted DBP concentrations.
chemdose_dbp_once
returns a data frame containing predicted DBP concentrations as columns.
TTHMs, raw: U.S. EPA (2001) equation 5-131
HAAs, raw: U.S. EPA (2001) equation 5-134
TTHMs, treated: U.S. EPA (2001) equation 5-139
HAAs, treated: U.S. EPA (2001) equation 5-142
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
example_dbp <- define_water(8, 20, 66, toc = 4, uv254 = .2, br = 50) %>%
chemdose_dbp(cl2 = 2, time = 8)
example_dbp <- define_water(7.5, 20, 66, toc = 4, uv254 = .2, br = 50) %>%
chemdose_dbp(cl2 = 3, time = 168, treatment = "coag", location = "ds")
library(dplyr)
example_df <- water_df %>%
mutate(br = 50) %>%
define_water_chain() %>%
chemdose_dbp_chain(input_water = "defined_water", cl2 = 4, time = 8)
example_df <- water_df %>%
mutate(br = 50) %>%
slice_sample(n = 3) %>%
define_water_chain() %>%
mutate(
cl2_dose = c(2, 3, 4),
time = 30
) %>%
chemdose_dbp_chain(cl2 = cl2_dose, treatment = "coag", location = "ds", cl_type = "chloramine")
# Initialize parallel processing
library(furrr)
# plan(multisession)
example_df <- water_df %>%
mutate(br = 50) %>%
define_water_chain() %>%
chemdose_dbp_chain(cl2 = 4, time = 8)
# Optional: explicitly close multisession processing
# plan(sequential)
library(dplyr)
water <- water_df %>%
slice(1) %>%
mutate(br = 50) %>%
define_water_chain() %>%
chemdose_dbp_once(cl2 = 10, time = 8)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.