| Title: | Water Quality Models for Drinking Water Treatment Processes |
|---|---|
| Description: | Provides multiple water chemistry-based models and published empirical models in one standard format. As many models have been included as possible, however, users should be aware that models have varying degrees of accuracy and applicability. To learn more, read the references provided below for the models implemented. Functions can be chained together to model a complete treatment process and are designed to work in a 'tidyverse' workflow. Models are primarily based on these sources: Benjamin, M. M. (2002, ISBN:147862308X), Crittenden, J. C., Trussell, R., Hand, D., Howe, J. K., & Tchobanoglous, G., Borchardt, J. H. (2012, ISBN:9781118131473), USEPA. (2001) <https://www.epa.gov/sites/default/files/2017-03/documents/wtp_model_v._2.0_manual_508.pdf>. |
| Authors: | Sierra Johnson [aut, cre], Libby McKenna [aut], Riley Mulhern [aut] (ORCID: <https://orcid.org/0000-0001-6293-3672>), Chris Corwin [aut] (ORCID: <https://orcid.org/0000-0002-9462-0352>), Rachel Merrifield [ctb], Mayuri Namasivayam [ctb], Phoebe Chen [ctb], Jiaming Yuan [ctb], USEPA [cph] (Copyright holder of included TELSS fragments (dissolve_pb function)), Brown and Caldwell [fnd, cph] |
| Maintainer: | Sierra Johnson <[email protected]> |
| License: | Apache License (>= 2) | MIT + file LICENSE |
| Version: | 0.10.9000 |
| Built: | 2026-06-05 06:13:02 UTC |
| Source: | https://github.com/brownandcaldwell-public/tidywater |
This function takes a water defined by define_water and balances charge.
For a single water use balance_ions; for a dataframe use balance_ions_df.
Use pluck_cols = TRUE to get values from the output water as new dataframe columns.
balance_ions(water, anion = "cl", cation = "na") balance_ions_df( df, input_water = "defined", output_water = "balanced", pluck_cols = FALSE, water_prefix = TRUE, anion = "cl", cation = "na" )balance_ions(water, anion = "cl", cation = "na") balance_ions_df( df, input_water = "defined", output_water = "balanced", pluck_cols = FALSE, water_prefix = TRUE, anion = "cl", cation = "na" )
water |
Water created with define_water, which may have some ions set to 0 when unknown |
anion |
Selected anion to use to for ion balance when more cations are present. Defaults to "cl". Choose one of c("cl", "so4"). |
cation |
Selected cation to use to for ion balance when more anions are present. Defaults to "na". Choose one of c("na", "k", "ca", or "mg"). |
df |
a data frame containing a water class column, which has already been computed using define_water_df |
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 water classes. Default is "balanced_water". |
pluck_cols |
Extract water slots modified by the function (selected cation and anion) into new numeric columns for easy access. Default to FALSE. |
water_prefix |
Append the output_water name to the start of the plucked columns. Default is TRUE. |
If more cations are needed, sodium will be added. User may specify which cation ("na", "k", "ca", or "mg") to use for balancing. If calcium and magnesium are not specified when defining a water with define_water, they will default to 0 and not be changed by this function unless specified in the cation argument. Anions are added by default with chloride. User may specify which anion ("cl", "so4") to use for balancing. This function is purely mathematical. User should always check the outputs to make sure values are reasonable for the input source water.
balance_ions returns a single water class object with updated ions to balance water charge.
balance_ions_df returns a dataframe with a new column with the ion balanced water
water_defined <- define_water(7, 20, 50, 100, 80, 10, 10, 10, 10) %>% balance_ions() water_defined <- define_water(7, 20, 50, tot_hard = 150) %>% balance_ions(anion = "so4") example_df <- water_df %>% define_water_df() %>% balance_ions_df(anion = "so4", cation = "ca")water_defined <- define_water(7, 20, 50, 100, 80, 10, 10, 10, 10) %>% balance_ions() water_defined <- define_water(7, 20, 50, tot_hard = 150) %>% balance_ions(anion = "so4") example_df <- water_df %>% define_water_df() %>% balance_ions_df(anion = "so4", cation = "ca")
This function applies the Terry model to a water created by define_water to determine biofiltered
DOC (mg/L). All particulate TOC is assumed to be removed so TOC = DOC.
For a single water use biofilter_toc; for a dataframe use biofilter_toc_df.
Use pluck_cols = TRUE to get values from the output water as new dataframe columns.
For most arguments in the _df 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.
biofilter_toc(water, ebct, ozonated = TRUE) biofilter_toc_df( df, input_water = "defined", output_water = "biofiltered", pluck_cols = FALSE, water_prefix = TRUE, ebct = "use_col", ozonated = "use_col" )biofilter_toc(water, ebct, ozonated = TRUE) biofilter_toc_df( df, input_water = "defined", output_water = "biofiltered", pluck_cols = FALSE, water_prefix = TRUE, ebct = "use_col", ozonated = "use_col" )
water |
Source water object of class "water" created by define_water. |
ebct |
The empty bed contact time (min) used for the biofilter. |
ozonated |
Logical; TRUE if the water is ozonated (default), FALSE otherwise. |
df |
a data frame containing a water class column, which has already been computed using define_water_df. The df may include a column indicating the EBCT or whether the water is ozonated. |
input_water |
name of the column of water class data to be used as the input for this function. Default is "defined". |
output_water |
name of the output column storing updated water class object. Default is "biofiltered". |
pluck_cols |
Extract water slots modified by the function (doc, toc, bdoc) into new numeric columns for easy access. Default to FALSE. |
water_prefix |
Append the output_water name to the start of the plucked columns. Default is TRUE. |
biofilter_toc returns water class object with modeled DOC removal from biofiltration.
biofilter_toc_df returns a data frame containing a water class column with updated DOC, TOC, and BDOC
concentrations. Optionally, it also adds columns for each of those slots individually.
Terry and Summers 2018
water <- define_water(ph = 7, temp = 25, alk = 100, toc = 5.0, doc = 4.0, uv254 = .1) %>% biofilter_toc(ebct = 10, ozonated = FALSE) example_df <- water_df %>% define_water_df() %>% biofilter_toc_df(input_water = "defined", ebct = c(10, 15), ozonated = FALSE) example_df <- water_df %>% define_water_df() %>% dplyr::mutate( BiofEBCT = c(10, 10, 10, 15, 15, 15, 20, 20, 20, 25, 25, 25), ozonated = c(rep(TRUE, 6), rep(FALSE, 6)) ) %>% biofilter_toc_df(input_water = "defined", ebct = BiofEBCT)water <- define_water(ph = 7, temp = 25, alk = 100, toc = 5.0, doc = 4.0, uv254 = .1) %>% biofilter_toc(ebct = 10, ozonated = FALSE) example_df <- water_df %>% define_water_df() %>% biofilter_toc_df(input_water = "defined", ebct = c(10, 15), ozonated = FALSE) example_df <- water_df %>% define_water_df() %>% dplyr::mutate( BiofEBCT = c(10, 10, 10, 15, 15, 15, 20, 20, 20, 25, 25, 25), ozonated = c(rep(TRUE, 6), rep(FALSE, 6)) ) %>% biofilter_toc_df(input_water = "defined", ebct = BiofEBCT)
This function takes a vector of waters defined by define_water
and a vector of ratios and outputs a new water object with updated ions and pH.
For a single blend use blend_waters; for a dataframe use blend_waters_df.
Use pluck_water to get values from the output water as new dataframe columns.
blend_waters(waters, ratios) blend_waters_df(df, waters, ratios, output_water = "blended")blend_waters(waters, ratios) blend_waters_df(df, waters, ratios, output_water = "blended")
waters |
Vector of source waters created by define_water. For |
ratios |
Vector of ratios in the same order as waters. (Blend ratios must sum to 1). For |
df |
a data frame containing a water class column, which has already been computed using define_water_df |
output_water |
name of output column storing updated parameters with the class, water. Default is "blended_water". |
blend_waters returns a water class object with blended water quality parameters.
blend_waters_df returns a data frame with a water class column containing blended water quality
water1 <- define_water(7, 20, 50) water2 <- define_water(7.5, 20, 100, tot_nh3 = 2) blend_waters(c(water1, water2), c(.4, .6)) example_df <- water_df %>% dplyr::slice_head(n = 3) %>% define_water_df() %>% chemdose_ph_df(naoh = 22) %>% dplyr::mutate( ratios1 = .4, ratios2 = .6 ) %>% blend_waters_df( waters = c("defined", "dosed_chem"), ratios = c("ratios1", "ratios2"), output_water = "Blending_after_chemicals" ) waterA <- define_water(7, 20, 100, tds = 100) example_df <- water_df %>% dplyr::slice_head(n = 3) %>% define_water_df() %>% blend_waters_df(waters = c("defined", waterA), ratios = c(.8, .2))water1 <- define_water(7, 20, 50) water2 <- define_water(7.5, 20, 100, tot_nh3 = 2) blend_waters(c(water1, water2), c(.4, .6)) example_df <- water_df %>% dplyr::slice_head(n = 3) %>% define_water_df() %>% chemdose_ph_df(naoh = 22) %>% dplyr::mutate( ratios1 = .4, ratios2 = .6 ) %>% blend_waters_df( waters = c("defined", "dosed_chem"), ratios = c("ratios1", "ratios2"), output_water = "Blending_after_chemicals" ) waterA <- define_water(7, 20, 100, tds = 100) example_df <- water_df %>% dplyr::slice_head(n = 3) %>% define_water_df() %>% blend_waters_df(waters = c("defined", waterA), ratios = c(.8, .2))
A dataset containing coefficients for calculating ozone formation
bromatecoeffsbromatecoeffs
A dataframe with 30 rows and 10 columns
First author of source model
Either T or F, depending on whether the model applies to waters with ammonia present.
First coefficient in bromate model
Exponent in bromate model, associated with Br-
Exponent in bromate model, associated with DOC
Exponent in bromate model, associated with UVA
Exponent in bromate model, associated with pH
Exponent in bromate model, associated with Alkalinity
Exponent in bromate model, associated with ozone dose
Exponent in bromate model, associated with reaction time
Exponent in bromate model, associated with ammonia (NH4+)
Exponent in bromate model, associated with temperature
Coefficient in bromate model, associated with temperature in the exponent. Either i or I are used, not both.
Ozekin (1994), Sohn et al (2004), Song et al (1996), Galey et al (1997), Siddiqui et al (1994)
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
This function calculates activity coefficients at a given temperature based on equation 5-43 from Davies (1967), Crittenden et al. (2012)
calculate_activity(z, is, temp)calculate_activity(z, is, temp)
z |
Charge of ions in the solution |
is |
Ionic strength of the solution |
temp |
Temperature of the solution in Celsius |
A numeric value for the activity coefficient.
calculate_activity(2, 0.1, 25)calculate_activity(2, 0.1, 25)
This function takes an object created by define_water and calculates
corrosion and scaling indices. For a single water, use calculate_corrosion; to apply the calculations to a
dataframe, use calculate_corrosion_df.
calculate_corrosion( water, index = c("aggressive", "ryznar", "langelier", "ccpp", "larsonskold", "csmr"), form = "calcite" ) calculate_corrosion_df( df, input_water = "defined", water_prefix = TRUE, index = c("aggressive", "ryznar", "langelier", "ccpp", "larsonskold", "csmr"), form = "calcite" )calculate_corrosion( water, index = c("aggressive", "ryznar", "langelier", "ccpp", "larsonskold", "csmr"), form = "calcite" ) calculate_corrosion_df( df, input_water = "defined", water_prefix = TRUE, index = c("aggressive", "ryznar", "langelier", "ccpp", "larsonskold", "csmr"), form = "calcite" )
water |
Source water of class "water" created by define_water |
index |
The indices to be calculated. Default calculates all six indices: "aggressive", "ryznar", "langelier", "ccpp", "larsonskold", "csmr" CCPP may not be able to be calculated sometimes, so it may be advantageous to leave this out of the function to avoid errors |
form |
Form of calcium carbonate mineral to use for modelling solubility: "calcite" (default), "aragonite", or "vaterite" |
df |
a data frame containing a water class column, created using define_water |
input_water |
name of the column of water class data to be used as the input. Default is "defined". |
water_prefix |
append water name to beginning of output columns. Defaults to TRUE |
Aggressiveness Index (AI), unitless - the corrosive tendency of water and its effect on asbestos cement pipe.
Ryznar Index (RI), unitless - a measure of scaling potential.
Langelier Saturation Index (LSI), unitless - describes the potential for calcium carbonate scale formation. Equations use empirical calcium carbonate solubilities from Plummer and Busenberg (1982) and Crittenden et al. (2012) rather than calculated from the concentrations of calcium and carbonate in the water.
Larson-skold Index (LI), unitless - describes the corrosivity towards mild steel.
Chloride-to-sulfate mass ratio (CSMR), mg Cl/mg SO4 - indicator of galvanic corrosion for lead solder pipe joints.
Calcium carbonate precipitation potential (CCPP), mg/L as CaCO3 - a prediction of the mass of calcium carbonate that will precipitate at equilibrium. A positive CCPP value indicates the amount of CaCO3 (mg/L as CaCO3) that will precipitate. A negative CCPP indicates how much CaCO3 can be dissolved in the water.
calculate_corrosion returns a data frame with corrosion and scaling indices as individual columns.
calculate_corrosion_df returns the a data frame containing specified corrosion and scaling indices as columns.
AWWA (1977)
Crittenden et al. (2012)
Langelier (1936)
Larson and Skold (1958)
Merrill and Sanks (1977a)
Merrill and Sanks (1977b)
Merrill and Sanks (1978)
Nguyen et al. (2011)
Plummer and Busenberg (1982)
Ryznar (1944)
Schock (1984)
Trussell (1998)
U.S. EPA (1980)
See reference list at https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
water <- define_water( ph = 8, temp = 25, alk = 200, tot_hard = 200, tds = 576, cl = 150, so4 = 200 ) corrosion_indices <- calculate_corrosion(water) water <- define_water(ph = 8, temp = 25, alk = 100, tot_hard = 50, tds = 200) corrosion_indices <- calculate_corrosion(water, index = c("aggressive", "ccpp")) example_df <- water_df %>% define_water_df() %>% calculate_corrosion_df(index = c("aggressive", "ccpp"))water <- define_water( ph = 8, temp = 25, alk = 200, tot_hard = 200, tds = 576, cl = 150, so4 = 200 ) corrosion_indices <- calculate_corrosion(water) water <- define_water(ph = 8, temp = 25, alk = 100, tot_hard = 50, tds = 200) corrosion_indices <- calculate_corrosion(water, index = c("aggressive", "ccpp")) example_df <- water_df %>% define_water_df() %>% calculate_corrosion_df(index = c("aggressive", "ccpp"))
This function takes Ca and Mg in mg/L and returns hardness in mg/L as CaCO3
calculate_hardness(ca, mg, type = "total", startunit = "mg/L")calculate_hardness(ca, mg, type = "total", startunit = "mg/L")
ca |
Calcium concentration in mg/L as Ca |
mg |
Magnesium concentration in mg/L as Mg |
type |
"total" returns total hardness, "ca" returns calcium hardness. Defaults to "total" |
startunit |
Units of Ca and Mg. Defaults to mg/L |
A numeric value for the total hardness in mg/L as CaCO3.
calculate_hardness(50, 10) water_defined <- define_water(7, 20, 50, 100, 80, 10, 10, 10, 10, tot_po4 = 1) calculate_hardness(water_defined@ca, water_defined@mg, "total", "M")calculate_hardness(50, 10) water_defined <- define_water(7, 20, 50, 100, 80, 10, 10, 10, 10, tot_po4 = 1) calculate_hardness(water_defined@ca, water_defined@mg, "total", "M")
chemdose_chloramine, adopted from the U.S. EPA's Chlorine Breakpoint Curve Simulator,
calculates chlorine and chloramine concentrations based on the two papers Jafvert & Valentine
(Environ. Sci. Technol., 1992, 26 (3), pp 577-586) and Vikesland et al. (Water Res., 2001, 35 (7), pp 1766-1776).
Required arguments include an object of class "water" created by define_water, chlorine dose, and reaction time.
The function also requires additional water quality parameters defined in define_water
including temperature, pH, and alkalinity.
For a single water use chemdose_chloramine; for a dataframe use chemdose_chloramine_df.
Use pluck_cols = TRUE to get values from the output water as new dataframe columns.
For most arguments in the _df 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_chloramine( water, time, cl2 = 0, nh3 = 0, use_free_cl_slot = FALSE, use_tot_nh3_slot = FALSE ) chemdose_chloramine_df( df, input_water = "defined", output_water = "chloraminated", pluck_cols = FALSE, water_prefix = TRUE, time = "use_col", cl2 = "use_col", nh3 = "use_col", use_free_cl_slot = "use_col", use_tot_nh3_slot = "use_col" )chemdose_chloramine( water, time, cl2 = 0, nh3 = 0, use_free_cl_slot = FALSE, use_tot_nh3_slot = FALSE ) chemdose_chloramine_df( df, input_water = "defined", output_water = "chloraminated", pluck_cols = FALSE, water_prefix = TRUE, time = "use_col", cl2 = "use_col", nh3 = "use_col", use_free_cl_slot = "use_col", use_tot_nh3_slot = "use_col" )
water |
Source water object of class "water" created by define_water |
time |
Reaction time (minutes). Time defined needs to be greater or equal to 1 minute. |
cl2 |
Applied chlorine dose (mg/L as Cl2), defaults to 0.If not specified, use free_chlorine slot in water. |
nh3 |
Applied ammonia dose (mg/L as N), defaults to 0. If not specified, use tot_nh3 slot in water. |
use_free_cl_slot |
Defaults to FALSE. If TRUE, uses free_chlorine slot in water. If TRUE AND there is a cl2 input, both the free_chlorine water slot and chlorine dose will be used. |
use_tot_nh3_slot |
Defaults to FALSE. If TRUE, uses tot_nh3 slot in water. If TRUE AND there is a nh3 input, both the tot_nh3 water slot and ammonia dose will be used. |
df |
a data frame containing a water class column, which has already been computed using define_water_df. The df may include a column named for the applied chlorine dose (cl2_dose), and a column for time in hours. |
input_water |
name of the column of water class data to be used as the input for this function. Default is "defined". |
output_water |
name of the output column storing updated water class object. Default is "chloraminated". |
pluck_cols |
Extract water slots modified by the function ("free_chlorine", "nh2cl", "nhcl2", "ncl3", "combined_chlorine", "tot_nh3") into new numeric columns for easy access. Default to FALSE. |
water_prefix |
Append the output_water name to the start of the plucked columns. Default is TRUE. |
chemdose_chloramine returns a water class object with predicted chlorine and chloramine concentrations.
chemdose_chloramine_df returns a data frame containing water class column with updated chlorine/chloramine slots:
free_chlorine, nh2cl, nhcl2, ncl3, combined_chlorine, tot_nh3. Optionally, it also adds columns for each of those slots individually.
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
breakpoint <- define_water(7.5, 20, 65, free_chlorine = 5, tot_nh3 = 1) %>% chemdose_chloramine(time = 40, cl2 = 2, nh3 = 1, use_free_cl_slot = TRUE) breakpoint <- water_df %>% dplyr::mutate(free_chlorine = 5, tot_nh3 = 1) %>% define_water_df() %>% dplyr::mutate( time = 8, cl2dose = rep(c(2, 3, 4), 4) ) %>% chemdose_chloramine_df( output_water = "final", cl2 = cl2dose, use_free_cl_slot = TRUE, use_tot_nh3_slot = TRUE, pluck_cols = TRUE )breakpoint <- define_water(7.5, 20, 65, free_chlorine = 5, tot_nh3 = 1) %>% chemdose_chloramine(time = 40, cl2 = 2, nh3 = 1, use_free_cl_slot = TRUE) breakpoint <- water_df %>% dplyr::mutate(free_chlorine = 5, tot_nh3 = 1) %>% define_water_df() %>% dplyr::mutate( time = 8, cl2dose = rep(c(2, 3, 4), 4) ) %>% chemdose_chloramine_df( output_water = "final", cl2 = cl2dose, use_free_cl_slot = TRUE, use_tot_nh3_slot = TRUE, pluck_cols = TRUE )
calculates the decay of chlorine or chloramine based on the U.S. EPA's
Water Treatment Plant Model (U.S. EPA, 2001).
For a single water use chemdose_chlordecay; for a dataframe use chemdose_chlordecay_df.
Use pluck_cols = TRUE to get values from the output water as new dataframe columns.
For most arguments in the _df 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_chlordecay( water, cl2_dose, time, treatment = "raw", cl_type = "chlorine", use_chlorine_slot = FALSE ) chemdose_chlordecay_df( df, input_water = "defined", output_water = "disinfected", pluck_cols = FALSE, water_prefix = TRUE, cl2_dose = "use_col", time = "use_col", treatment = "use_col", cl_type = "use_col", use_chlorine_slot = "use_col" )chemdose_chlordecay( water, cl2_dose, time, treatment = "raw", cl_type = "chlorine", use_chlorine_slot = FALSE ) chemdose_chlordecay_df( df, input_water = "defined", output_water = "disinfected", pluck_cols = FALSE, water_prefix = TRUE, cl2_dose = "use_col", time = "use_col", treatment = "use_col", cl_type = "use_col", use_chlorine_slot = "use_col" )
water |
Source water object of class "water" created by |
cl2_dose |
Applied chlorine or chloramine dose (mg/L as cl2). Model results are valid for doses between 0.995 and 41.7 mg/L for raw water, and for doses between 1.11 and 24.7 mg/L for coagulated water. |
time |
Reaction time (hours). Chlorine decay model results are valid for reaction times between 0.25 and 120 hours.Chloramine decay model does not have specified boundary conditions. |
treatment |
Type of treatment applied to the water. Options include "raw" for no treatment (default), "coag" for water that has been coagulated or softened. |
cl_type |
Type of chlorination applied, either "chlorine" (default) or "chloramine". |
use_chlorine_slot |
Defaults to FALSE. When TRUE, uses either free_chlorine or combined_chlorine slot in water (depending on cl_type). If 'cl2_dose' argument, not specified, chlorine slot will be used. If 'cl2_dose' specified and use_chlorine_slot is TRUE, all chlorine will be summed. |
df |
a data frame containing a water class column, which has already been computed using define_water_df. The df may include a column named for the applied chlorine dose (cl2), and a column for time in hours. |
input_water |
name of the column of water class data to be used as the input for this function. Default is "defined". |
output_water |
name of the output column storing updated water class object. Default is "disinfected". |
pluck_cols |
Extract water slots modified by the function (free_chlorine, combined_chlorine) into new numeric columns for easy access. Default to FALSE. |
water_prefix |
Append the output_water name to the start of the plucked columns. Default is TRUE. |
Required arguments include an object of class "water" created by define_water, applied chlorine/chloramine dose, type, reaction time, and treatment applied (options include "raw" for no treatment, or "coag" for coagulated water). The function also requires additional water quality parameters defined in define_water including TOC and UV254. The output is a new "water" class with the calculated total chlorine value stored in the 'free_chlorine' or 'combined_chlorine' slot, depending on what type of chlorine is dosed. When modeling residual concentrations through a unit process, the U.S. EPA Water Treatment Plant Model applies a correction factor based on the influent and effluent residual concentrations (see U.S. EPA (2001) equation 5-118) that may need to be applied manually by the user based on the output.
chemdose_chlordecay returns an updated disinfectant residual in the free_chlorine or combined_chlorine water slot in units of M.
Use convert_units to convert to mg/L.
chemdose_chlordecay_df returns a data frame containing a water class column with updated free_chlorine or
combined_chlorine residuals. Optionally, it also adds columns for each of those slots individually.
U.S. EPA (2001)
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
example_cl2 <- define_water(8, 20, 66, toc = 4, uv254 = 0.2) %>% chemdose_chlordecay(cl2_dose = 2, time = 8) example_cl2 <- define_water(8, 20, 66, toc = 4, uv254 = 0.2, free_chlorine = 3) %>% chemdose_chlordecay(cl2_dose = 2, time = 8, use_chlorine_slot = TRUE) example_df <- water_df %>% dplyr::mutate(br = 50) %>% define_water_df() %>% chemdose_chlordecay_df(input_water = "defined", cl2_dose = 4, time = 8) example_df <- water_df %>% dplyr::mutate( br = 50, free_chlorine = 2 ) %>% define_water_df() %>% dplyr::mutate( cl2_dose = seq(2, 24, 2), ClTime = 30 ) %>% chemdose_chlordecay_df( time = ClTime, use_chlorine_slot = TRUE, treatment = "coag", cl_type = "chloramine", pluck_cols = TRUE )example_cl2 <- define_water(8, 20, 66, toc = 4, uv254 = 0.2) %>% chemdose_chlordecay(cl2_dose = 2, time = 8) example_cl2 <- define_water(8, 20, 66, toc = 4, uv254 = 0.2, free_chlorine = 3) %>% chemdose_chlordecay(cl2_dose = 2, time = 8, use_chlorine_slot = TRUE) example_df <- water_df %>% dplyr::mutate(br = 50) %>% define_water_df() %>% chemdose_chlordecay_df(input_water = "defined", cl2_dose = 4, time = 8) example_df <- water_df %>% dplyr::mutate( br = 50, free_chlorine = 2 ) %>% define_water_df() %>% dplyr::mutate( cl2_dose = seq(2, 24, 2), ClTime = 30 ) %>% chemdose_chlordecay_df( time = ClTime, use_chlorine_slot = TRUE, treatment = "coag", cl_type = "chloramine", pluck_cols = TRUE )
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_df.
Use pluck_cols = TRUE to get values from the output water as new dataframe columns.
For most arguments in the _df 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_df( df, input_water = "defined", output_water = "disinfected", pluck_cols = FALSE, water_prefix = TRUE, cl2 = "use_col", time = "use_col", treatment = "use_col", cl_type = "use_col", location = "use_col", correction = TRUE, coeff = NULL )chemdose_dbp( water, cl2, time, treatment = "raw", cl_type = "chorine", location = "plant", correction = TRUE, coeff = NULL ) chemdose_dbp_df( df, input_water = "defined", output_water = "disinfected", pluck_cols = FALSE, water_prefix = TRUE, cl2 = "use_col", time = "use_col", treatment = "use_col", cl_type = "use_col", location = "use_col", correction = TRUE, coeff = NULL )
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". |
output_water |
name of the output column storing updated water class object. Default is "disinfected". |
pluck_cols |
Extract primary water slots modified by the function (tthm, haa5) into new numeric columns for easy access with TRUE. Alternatively, specify "all" to get all DBP species in addition: (tthm, chcl3, chcl2br, chbr2cl, chbr3, haa5, mcaa, dcaa, tcaa, mbaa, dbaa) Defaults to FALSE. |
water_prefix |
Append the output_water name to the start of the plucked columns. Default is TRUE. |
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.
chemdose_dbp returns a single water class object with predicted DBP concentrations.
chemdose_dbp_df returns a data frame containing a water class column with updated tthm, chcl3, chcl2br, chbr2cl, chbr3, haa5, mcaa, dcaa, tcaa, mbaa, dbaa
concentrations. Optionally, it also adds columns for those slots individually.
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") example_df <- water_df %>% dplyr::mutate(br = 50) %>% define_water_df() %>% chemdose_dbp_df(input_water = "defined", cl2 = 4, time = 8) example_df <- water_df %>% dplyr::mutate(br = 50) %>% dplyr::slice_sample(n = 3) %>% define_water_df() %>% dplyr::mutate( cl2_dose = c(2, 3, 4), time = 30 ) %>% chemdose_dbp_df( cl2 = cl2_dose, treatment = "coag", location = "ds", cl_type = "chloramine", pluck_cols = TRUE )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") example_df <- water_df %>% dplyr::mutate(br = 50) %>% define_water_df() %>% chemdose_dbp_df(input_water = "defined", cl2 = 4, time = 8) example_df <- water_df %>% dplyr::mutate(br = 50) %>% dplyr::slice_sample(n = 3) %>% define_water_df() %>% dplyr::mutate( cl2_dose = c(2, 3, 4), time = 30 ) %>% chemdose_dbp_df( cl2 = cl2_dose, treatment = "coag", location = "ds", cl_type = "chloramine", pluck_cols = TRUE )
Calculates the new pH, alkalinity, and ion balance of a water based on different chemical
additions.
For a single water use chemdose_ph; for a dataframe use chemdose_ph_df.
Use pluck_cols = TRUE to get values from the output water as new dataframe columns.
For most arguments in the _df 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_ph( water, hcl = 0, h2so4 = 0, h3po4 = 0, hno3 = 0, ch3cooh = 0, co2 = 0, naoh = 0, caoh2 = 0, mgoh2 = 0, na2co3 = 0, nahco3 = 0, caco3 = 0, caso4 = 0, caocl2 = 0, cacl2 = 0, cl2 = 0, naocl = 0, nh4oh = 0, nh42so4 = 0, alum = 0, ferricchloride = 0, ferricsulfate = 0, ach = 0, pacl = 0, kmno4 = 0, naf = 0, na3po4 = 0, softening_correction = FALSE ) chemdose_ph_df( df, input_water = "defined", output_water = "dosed_chem", na_to_zero = TRUE, pluck_cols = FALSE, water_prefix = TRUE, hcl = "use_col", h2so4 = "use_col", h3po4 = "use_col", hno3 = "use_col", ch3cooh = "use_col", co2 = "use_col", naoh = "use_col", na2co3 = "use_col", nahco3 = "use_col", caoh2 = "use_col", mgoh2 = "use_col", caocl2 = "use_col", cacl2 = "use_col", cl2 = "use_col", naocl = "use_col", nh4oh = "use_col", nh42so4 = "use_col", caco3 = "use_col", caso4 = "use_col", alum = "use_col", ferricchloride = "use_col", ferricsulfate = "use_col", ach = "use_col", pacl = "use_col", kmno4 = "use_col", naf = "use_col", na3po4 = "use_col", softening_correction = "use_col" )chemdose_ph( water, hcl = 0, h2so4 = 0, h3po4 = 0, hno3 = 0, ch3cooh = 0, co2 = 0, naoh = 0, caoh2 = 0, mgoh2 = 0, na2co3 = 0, nahco3 = 0, caco3 = 0, caso4 = 0, caocl2 = 0, cacl2 = 0, cl2 = 0, naocl = 0, nh4oh = 0, nh42so4 = 0, alum = 0, ferricchloride = 0, ferricsulfate = 0, ach = 0, pacl = 0, kmno4 = 0, naf = 0, na3po4 = 0, softening_correction = FALSE ) chemdose_ph_df( df, input_water = "defined", output_water = "dosed_chem", na_to_zero = TRUE, pluck_cols = FALSE, water_prefix = TRUE, hcl = "use_col", h2so4 = "use_col", h3po4 = "use_col", hno3 = "use_col", ch3cooh = "use_col", co2 = "use_col", naoh = "use_col", na2co3 = "use_col", nahco3 = "use_col", caoh2 = "use_col", mgoh2 = "use_col", caocl2 = "use_col", cacl2 = "use_col", cl2 = "use_col", naocl = "use_col", nh4oh = "use_col", nh42so4 = "use_col", caco3 = "use_col", caso4 = "use_col", alum = "use_col", ferricchloride = "use_col", ferricsulfate = "use_col", ach = "use_col", pacl = "use_col", kmno4 = "use_col", naf = "use_col", na3po4 = "use_col", softening_correction = "use_col" )
water |
Source water object of class "water" created by define_water |
hcl |
Amount of hydrochloric acid added in mg/L: HCl -> H + Cl |
h2so4 |
Amount of sulfuric acid added in mg/L: H2SO4 -> 2H + SO4 |
h3po4 |
Amount of phosphoric acid added in mg/L: H3PO4 -> 3H + PO4 |
hno3 |
Amount of nitric acid added in mg/L: HNO3 -> H + NO3 |
ch3cooh |
Amount of acetic acid added in mg/L: CH3COOH -> H + CH3COO- |
co2 |
Amount of carbon dioxide added in mg/L: CO2 (gas) + H2O -> H2CO3* |
naoh |
Amount of caustic added in mg/L: NaOH -> Na + OH |
caoh2 |
Amount of lime added in mg/L: Ca(OH)2 -> Ca + 2OH |
mgoh2 |
Amount of magnesium hydroxide added in mg/L: Mg(OH)2 -> Mg + 2OH |
na2co3 |
Amount of soda ash added in mg/L: Na2CO3 -> 2Na + CO3 |
nahco3 |
Amount of sodium bicarbonate added in mg/L: NaHCO3 -> Na + H + CO3 |
caco3 |
Amount of calcium carbonate added (or removed) in mg/L: CaCO3 -> Ca + CO3 |
caso4 |
Amount of calcium sulfate added (for post-RO condition) in mg/L: CaSO4 -> Ca + SO4 |
caocl2 |
Amount of Calcium hypochlorite added in mg/L as Cl2: CaOCl2 -> Ca + 2OCl |
cacl2 |
Amount of calcium chloride added in mg/L: CaCl2 -> Ca2+ + 2Cl- |
cl2 |
Amount of chlorine gas added in mg/L as Cl2: Cl2(g) + H2O -> HOCl + H + Cl |
naocl |
Amount of sodium hypochlorite added in mg/L as Cl2: NaOCl -> Na + OCl |
nh4oh |
Amount of ammonium hydroxide added in mg/L as N: NH4OH -> NH4 + OH |
nh42so4 |
Amount of ammonium sulfate added in mg/L as N: (NH4)2SO4 -> 2NH4 + SO4 |
alum |
Amount of hydrated aluminum sulfate added in mg/L: Al2(SO4)3*14H2O + 6HCO3 -> 2Al(OH)3(am) +3SO4 + 14H2O + 6CO2 |
ferricchloride |
Amount of ferric Chloride added in mg/L: FeCl3 + 3HCO3 -> Fe(OH)3(am) + 3Cl + 3CO2 |
ferricsulfate |
Amount of ferric sulfate added in mg/L: Fe2(SO4)3*8.8H2O + 6HCO3 -> 2Fe(OH)3(am) + 3SO4 + 8.8H2O + 6CO2 |
ach |
Amount of aluminum chlorohydrate added in mg/L: Al2(OH)5Cl*2H2O + HCO3 -> 2Al(OH)3(am) + Cl + 2H2O + CO2 |
pacl |
Amount of polyaluminum chloride added in mg/L as Al2O3 (assumed Cl:Al ratio = 0.9): Al2(OH)4.2Cl(1.8) + #HCO3 -> 2Al(OH)3(am) + 1.8Cl + #H2O + #CO2.... |
kmno4 |
Amount of potassium permanganate added in mg/L: KMnO4 -> K + MnO4 |
naf |
Amount of sodium fluoride added in mg/L: NaF -> Na + F |
na3po4 |
Amount of trisodium phosphate added in mg/L: Na3PO4 -> 3Na + PO4 |
softening_correction |
Set to TRUE to correct post-softening pH (caco3 must be < 0). Default is FALSE. Based on WTP model equation 5-62 |
df |
a data frame containing a water class column, which has already been computed using define_water_df The df may include columns named for the chemical(s) being dosed. |
input_water |
name of the column of water class data to be used as the input for this function. Default is "defined". |
output_water |
name of the output column storing updated water class object. Default is "dosed". |
na_to_zero |
option to convert all NA values in the data frame to zeros. Default value is TRUE. |
pluck_cols |
Extract primary water slots modified by the function (ph, alk) into new numeric columns for easy access. Default to FALSE. |
water_prefix |
Append the output_water name to the start of the plucked columns. Default is TRUE. |
The function takes an object of class "water" created by define_water and user-specified chemical additions and returns a new object of class "water" with updated water quality. Units of all chemical additions are in mg/L as chemical (not as product).
chemdose_ph works by evaluating all the user-specified chemical additions and solving for what the new pH
must be using uniroot to satisfy the principle of electroneutrality in pure water while correcting for the existing alkalinity
of the water that the chemical is added to. Multiple chemicals can be added simultaneously or each addition can be
modeled independently through sequential doses.
chemdose_ph returns a water class object with updated pH, alkalinity, and ions post-chemical addition.
chemdose_ph_df returns a data frame containing a water class column with updated pH, alkalinity, and ions post-chemical addition.
water <- define_water(ph = 7, temp = 25, alk = 10) # Dose 1 mg/L of hydrochloric acid dosed_water <- chemdose_ph(water, hcl = 1) # Dose 1 mg/L of hydrochloric acid and 5 mg/L of alum simultaneously dosed_water <- chemdose_ph(water, hcl = 1, alum = 5) # Softening: water2 <- define_water(ph = 7, temp = 25, alk = 100, tot_hard = 350) dosed_water2 <- chemdose_ph(water2, caco3 = -100, softening_correction = TRUE) example_df <- water_df %>% define_water_df() %>% dplyr::slice_head(n = 3) %>% dplyr::mutate( hcl = c(2, 4, 6), Caustic = 20 ) %>% chemdose_ph_df(input_water = "defined", mgoh2 = c(20, 55), co2 = 4, naoh = Caustic) example_df <- water_df %>% define_water_df() %>% chemdose_ph_df(naoh = 5, pluck_cols = TRUE)water <- define_water(ph = 7, temp = 25, alk = 10) # Dose 1 mg/L of hydrochloric acid dosed_water <- chemdose_ph(water, hcl = 1) # Dose 1 mg/L of hydrochloric acid and 5 mg/L of alum simultaneously dosed_water <- chemdose_ph(water, hcl = 1, alum = 5) # Softening: water2 <- define_water(ph = 7, temp = 25, alk = 100, tot_hard = 350) dosed_water2 <- chemdose_ph(water2, caco3 = -100, softening_correction = TRUE) example_df <- water_df %>% define_water_df() %>% dplyr::slice_head(n = 3) %>% dplyr::mutate( hcl = c(2, 4, 6), Caustic = 20 ) %>% chemdose_ph_df(input_water = "defined", mgoh2 = c(20, 55), co2 = 4, naoh = Caustic) example_df <- water_df %>% define_water_df() %>% chemdose_ph_df(naoh = 5, pluck_cols = TRUE)
This function applies the Edwards (1997) model to a water created by define_water to determine coagulated
DOC. Model assumes all particulate TOC is removed; therefore TOC = DOC in output.
Coagulated UVA is from U.S. EPA (2001) equation 5-80. Note that the models rely on pH of coagulation. If
only raw water pH is known, utilize chemdose_ph first.
For a single water use chemdose_toc; for a dataframe use chemdose_toc_df.
Use pluck_cols = TRUE to get values from the output water as new dataframe columns.
For most arguments in the _df 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_toc( water, alum = 0, ferricchloride = 0, ferricsulfate = 0, ach = 0, pacl = 0, coeff = "Alum", caoh2 = 0 ) chemdose_toc_df( df, input_water = "defined", output_water = "coagulated", pluck_cols = FALSE, water_prefix = TRUE, alum = "use_col", ferricchloride = "use_col", ferricsulfate = "use_col", ach = "use_col", pacl = "use_col", caoh2 = "use_col", coeff = "use_col" )chemdose_toc( water, alum = 0, ferricchloride = 0, ferricsulfate = 0, ach = 0, pacl = 0, coeff = "Alum", caoh2 = 0 ) chemdose_toc_df( df, input_water = "defined", output_water = "coagulated", pluck_cols = FALSE, water_prefix = TRUE, alum = "use_col", ferricchloride = "use_col", ferricsulfate = "use_col", ach = "use_col", pacl = "use_col", caoh2 = "use_col", coeff = "use_col" )
water |
Source water object of class "water" created by define_water. Water must include ph, doc, and uv254 |
alum |
Amount of hydrated aluminum sulfate added in mg/L: Al2(SO4)3*14H2O + 6HCO3 -> 2Al(OH)3(am) +3SO4 + 14H2O + 6CO2 |
ferricchloride |
Amount of ferric chloride added in mg/L: FeCl3 + 3HCO3 -> Fe(OH)3(am) + 3Cl + 3CO2 |
ferricsulfate |
Amount of ferric sulfate added in mg/L: Fe2(SO4)3*8.8H2O + 6HCO3 -> 2Fe(OH)3(am) + 3SO4 + 8.8H2O + 6CO2 |
ach |
Amount of aluminum chlorohydrate added in mg/L: Al2(OH)5Cl*2H2O + HCO3 -> 2Al(OH)3(am) + Cl + 2H2O + CO2 |
pacl |
Amount of polyaluminum chloride added in mg/L as Al2O3 (assumed Cl:Al ratio = 0.9): Al2(OH)4.2Cl(1.8) + #HCO3 -> 2Al(OH)3(am) + 1.8Cl + #H2O + #CO2.... |
coeff |
String specifying the Edwards coefficients to be used from "Alum", "Ferric", "General Alum", "General Ferric", or "Low DOC" or data frame of coefficients, which must include: k1, k2, x1, x2, x3, b |
caoh2 |
Option to add caoh2 in mg/L to soften the water. Will predict DOC, TOC, UV254 using a modified equation (see reference list). Defaults to zero. |
df |
a data frame containing a water class column, which has already been computed using define_water_df. The df may include a column named for the coagulant being dosed, and a column named for the set of coefficients to use. |
input_water |
name of the column of water class data to be used as the input for this function. Default is "defined". |
output_water |
name of the output column storing updated water class object. Default is "coagulated". |
pluck_cols |
Extract water slots modified by the function (doc, toc, uv254) into new numeric columns for easy access. Default to FALSE. |
water_prefix |
Append the output_water name to the start of the plucked columns. Default is TRUE. |
chemdose_toc returns a single water class object with an updated DOC, TOC, and UV254 concentration.
chemdose_toc_df returns a data frame containing a water class column with updated DOC, TOC, and UV254
concentrations. Optionally, it also adds columns for each of those slots individually.
Edwards (1997)
U.S. EPA (2001)
See reference list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
water <- define_water(ph = 7, temp = 25, alk = 100, toc = 3.7, doc = 3.5, uv254 = .1) dosed_water <- chemdose_ph(water, alum = 30) %>% chemdose_toc(alum = 30, coeff = "Alum") dosed_water <- chemdose_ph(water, alum = 10, h2so4 = 10) %>% chemdose_toc(alum = 10, coeff = data.frame( x1 = 280, x2 = -73.9, x3 = 4.96, k1 = -0.028, k2 = 0.23, b = 0.068 )) example_df <- water_df %>% define_water_df() %>% dplyr::mutate(FerricDose = seq(1, 12, 1)) %>% chemdose_toc_df(ferricchloride = FerricDose, coeff = "Ferric") example_df <- water_df %>% define_water_df() %>% dplyr::mutate(ferricchloride = seq(1, 12, 1)) %>% chemdose_toc_df(coeff = "Ferric", pluck_cols = TRUE)water <- define_water(ph = 7, temp = 25, alk = 100, toc = 3.7, doc = 3.5, uv254 = .1) dosed_water <- chemdose_ph(water, alum = 30) %>% chemdose_toc(alum = 30, coeff = "Alum") dosed_water <- chemdose_ph(water, alum = 10, h2so4 = 10) %>% chemdose_toc(alum = 10, coeff = data.frame( x1 = 280, x2 = -73.9, x3 = 4.96, k1 = -0.028, k2 = 0.23, b = 0.068 )) example_df <- water_df %>% define_water_df() %>% dplyr::mutate(FerricDose = seq(1, 12, 1)) %>% chemdose_toc_df(ferricchloride = FerricDose, coeff = "Ferric") example_df <- water_df %>% define_water_df() %>% dplyr::mutate(ferricchloride = seq(1, 12, 1)) %>% chemdose_toc_df(coeff = "Ferric", pluck_cols = TRUE)
A dataset containing conversion factors for calculating DBP formation
chloramine_convchloramine_conv
A dataframe with 17 rows and 3 columns
abbreviation of dbp species
full name of dbp species
specifies the percent of DBP formation predicted from chloramines compared to chlorine, assuming the same chlorine dose applied
U.S. EPA (2001), Table 5-10
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
A dataset containing coefficients for calculating Cl2 decay
cl2coeffscl2coeffs
A dataframe with 3 rows and 4 columns
Specifies the treatment applied to the water
Coefficient in chlorine decay model, associated with chlorine dose and time
Coefficient in chlorine decay model, associated with chlorine dose & organics
Exponent in chlorine decay model, associated with chlorine dose & organics
U.S. EPA (2001)
This function takes a value and converts units based on compound name.
convert_units(value, formula, startunit = "mg/L", endunit = "M")convert_units(value, formula, startunit = "mg/L", endunit = "M")
value |
Value to be converted |
formula |
Chemical formula of compound. Accepts compounds in mweights for conversions between g and mol or eq |
startunit |
Units of current value, currently accepts g/L; g/L CaCO3; g/L N; M; eq/L; and the same units with "m", "u", "n" prefixes |
endunit |
Desired units, currently accepts same as start units |
A numeric value for the converted parameter.
convert_units(50, "ca") # converts from mg/L to M by default convert_units(50, "ca", "mg/L", "mg/L CaCO3") convert_units(50, "ca", startunit = "mg/L", endunit = "eq/L")convert_units(50, "ca") # converts from mg/L to M by default convert_units(50, "ca", "mg/L", "mg/L CaCO3") convert_units(50, "ca", startunit = "mg/L", endunit = "eq/L")
water class object to a dataframeThis converts a water class to a dataframe with individual columns for each slot (water quality parameter) in the water.
This is useful for one-off checks. For typical applications,
use pluck_cols = TRUE in any _df function or pluck_water to choose relevant slots.
Use convert_water to keep all slots in the same units as the water.
Use convert_watermg to convert to more typical units. Converts the following slots from M to mg/L: na, ca, mg, k, cl, so4, hco3, co3, h2po4, hpo4, po4, ocl, bro3, f, fe, al. Converts these slots to ug/L: br, mn. All other values remain unchanged.
convert_water(water) convert_watermg(water)convert_water(water) convert_watermg(water)
water |
A water class object |
A data frame containing columns for all non-NA water slots.
A data frame containing columns for all non-NA water slots with ions in mg/L.
# Generates 1 row dataframe example_df <- define_water(ph = 7, temp = 20, alk = 100) %>% convert_water() example_df <- water_df %>% define_water_df() %>% dplyr::mutate(to_dataframe = purrr::map(defined, convert_water)) %>% tidyr::unnest(to_dataframe) %>% dplyr::select(-defined) water_defined <- define_water(7, 20, 50, 100, 80, 10, 10, 10, 10, tot_po4 = 1) %>% convert_watermg()# Generates 1 row dataframe example_df <- define_water(ph = 7, temp = 20, alk = 100) %>% convert_water() example_df <- water_df %>% define_water_df() %>% dplyr::mutate(to_dataframe = purrr::map(defined, convert_water)) %>% tidyr::unnest(to_dataframe) %>% dplyr::select(-defined) water_defined <- define_water(7, 20, 50, 100, 80, 10, 10, 10, 10, tot_po4 = 1) %>% convert_watermg()
This function calculates the corrected equilibrium constant for temperature and ionic strength
correct_k(water)correct_k(water)
water |
Defined water with values for temperature and ion concentrations |
A dataframe with equilibrium constants for co3, po4, so4, ocl, and nh4.
water_defined <- define_water(7, 20, 50, 100, 80, 10, 10, 10, 10, tot_po4 = 1) correct_k(water_defined)water_defined <- define_water(7, 20, 50, 100, 80, 10, 10, 10, 10, tot_po4 = 1) correct_k(water_defined)
A dataset containing correction factors for calculating DBP formation
dbp_correctiondbp_correction
A dataframe with 17 rows and 4 columns
abbreviation of dbp species
full name of dbp species
specifies the correction factor for modelling DBP formation within a treatment plant
specifies the correction factor for modelling DBP formation within the distribution system
U.S. EPA (2001), Table 5-7
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
A dataset containing coefficients for calculating DBP formation
dbpcoeffsdbpcoeffs
A dataframe with 30 rows and 10 columns
abbreviation of dbp species
full name of dbp species
specifies which model the constants apply to, either treated or untreated water
First coefficient in DBP model
Second coefficient in DBP model, associated with TOC or DOC
Third coefficient in DBP model, associated with Cl2
Fourth coefficient in DBP model, associated with Br-
Fifth coefficient in DBP model, associated with temperature
Sixth coefficient in DBP model, associated with pH
Seventh coefficient in DBP model, associated with reaction time
U.S. EPA (2001)
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
Calculates the new water quality (pH, alkalinity, etc) after a specified amount of CO2 is removed (removed as bicarbonate).
The function takes an object of class "water" and a fraction of CO2 removed, then returns a water class object with updated water slots.
For a single water, use decarbonate_ph; to apply the model to a dataframe, use decarbonate_ph_df.
For a single water use chemdose_toc; for a dataframe use chemdose_toc_df.
Use pluck_cols = TRUE to get values from the output water as new dataframe columns.
For most arguments in the _df 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.
decarbonate_ph(water, co2_removed) decarbonate_ph_df( df, input_water = "defined", output_water = "decarbonated", pluck_cols = FALSE, water_prefix = TRUE, co2_removed = "use_col" )decarbonate_ph(water, co2_removed) decarbonate_ph_df( df, input_water = "defined", output_water = "decarbonated", pluck_cols = FALSE, water_prefix = TRUE, co2_removed = "use_col" )
water |
Source water of class "water" created by define_water |
co2_removed |
Fraction of CO2 removed |
df |
a data frame containing a water class column, which has already been computed using define_water_df. The df may include a column with names for each of the chemicals being dosed. |
input_water |
name of the column of water class data to be used as the input for this function. Default is "defined". |
output_water |
name of the output column storing updated water class object. Default is "decarbonated". |
pluck_cols |
Extract water slots modified by the function (ph, alk) into new numeric columns for easy access. Default to FALSE. |
water_prefix |
Append the output_water name to the start of the plucked columns. Default is TRUE. |
decarbonate_ph uses water@h2co3 to determine the existing CO2 in water, then applies chemdose_ph to match the CO2 removal.
A water with updated pH/alk/etc.
decarbonate_ph_df returns a data frame containing a water class column with updated ph and alk (and pH dependent ions).
Optionally, it also adds columns for each of those slots individually.
water <- define_water(ph = 4, temp = 25, alk = 5) %>% decarbonate_ph(co2_removed = .95) example_df <- water_df %>% define_water_df() %>% decarbonate_ph_df( input_water = "defined", output_water = "decarb", co2_removed = .95, pluck_cols = TRUE )water <- define_water(ph = 4, temp = 25, alk = 5) %>% decarbonate_ph(co2_removed = .95) example_df <- water_df %>% define_water_df() %>% decarbonate_ph_df( input_water = "defined", output_water = "decarb", co2_removed = .95, pluck_cols = TRUE )
This function takes user-defined water quality parameters and creates an S4 "water" class object that forms the input and output of all tidywater models.
define_water( ph, temp = 25, alk, tot_hard, ca, mg, na, k, cl, so4, mno4, free_chlorine = 0, combined_chlorine = 0, tot_po4 = 0, tot_nh3 = 0, tot_ch3coo = 0, tot_bo3 = 0, tot_sio4 = 0, tds, cond, toc, doc, uv254, br, f, fe, al, mn, no3 )define_water( ph, temp = 25, alk, tot_hard, ca, mg, na, k, cl, so4, mno4, free_chlorine = 0, combined_chlorine = 0, tot_po4 = 0, tot_nh3 = 0, tot_ch3coo = 0, tot_bo3 = 0, tot_sio4 = 0, tds, cond, toc, doc, uv254, br, f, fe, al, mn, no3 )
ph |
water pH |
temp |
Temperature in degree C |
alk |
Alkalinity in mg/L as CaCO3 |
tot_hard |
Total hardness in mg/L as CaCO3 |
ca |
Calcium in mg/L Ca2+ |
mg |
Magnesium in mg/L Mg2+ |
na |
Sodium in mg/L Na+ |
k |
Potassium in mg/L K+ |
cl |
Chloride in mg/L Cl- |
so4 |
Sulfate in mg/L SO42- |
mno4 |
Permanganate in mg/L MnO4- |
free_chlorine |
Free chlorine in mg/L as Cl2. Used when a starting water has a free chlorine residual. |
combined_chlorine |
Combined chlorine (chloramines) in mg/L as Cl2. Used when a starting water has a chloramine residual. |
tot_po4 |
Phosphate in mg/L as PO4 3-. Used when a starting water has a phosphate residual. |
tot_nh3 |
Total ammonia in mg/L as N |
tot_ch3coo |
Total acetate in mg/L |
tot_bo3 |
Total borate (B(OH)4 -) in mg/L as B |
tot_sio4 |
Total silicate in mg/L as SiO2 |
tds |
Total Dissolved Solids in mg/L (optional if ions are known) |
cond |
Electrical conductivity in uS/cm (optional if ions are known) |
toc |
Total organic carbon (TOC) in mg/L |
doc |
Dissolved organic carbon (DOC) in mg/L |
uv254 |
UV absorbance at 254 nm (cm-1) |
br |
Bromide in ug/L Br- |
f |
Fluoride in mg/L F- |
fe |
Iron in mg/L Fe3+ |
al |
Aluminum in mg/L Al3+ |
mn |
Manganese in ug/L Mn2+ |
no3 |
Nitrate in mg/L as N |
Carbonate balance is calculated and units are converted to mol/L. Ionic strength is determined from ions, TDS, or conductivity. Missing values are handled by defaulting to 0 or NA. Calcium defaults to 65 percent of the total hardness when not specified. DOC defaults to 95 percent of TOC.
define_water outputs a water class object where slots are filled or calculated based on input parameters. Water slots have different units than those input into the define_water function, as listed below.
pH, numeric, in standard units (SU).
temperature, numeric, in °C.
alkalinity, numeric, mg/L as CaCO3.
total dissolved solids, numeric, mg/L.
electrical conductivity, numeric, uS/cm.
total hardness, numeric, mg/L as CaCO3.
dissociation constant for water, numeric, unitless.
total alkalinity as equivalents, numeric, equivalent (eq).
carbonate alkalinity as equivalents, numeric, equivalent (eq).
phosphate alkalinity as equivalents, numeric, equivalent (eq).
ammonium alkalinity as equivalents, numeric, equivalent (eq).
borate alkalinity as equivalents, numeric, equivalent (eq).
silicate alkalinity as equivalents, numeric, equivalent (eq).
hypochlorite alkalinity as equivalents, numeric, equivalent (eq).
total organic carbon, numeric, mg/L.
dissolved organic carbon, numeric, mg/L.
biodegradable organic carbon, numeric, mg/L.
light absorption at 254 nm, numeric, cm-1.
dissolved inorganic carbon, numeric, mg/L as C.
ionic strength, numeric, mol/L.
sodium, numeric, mols/L.
calcium, numeric, mols/L.
magnesium, numeric, mols/L.
potassium, numeric, mols/L.
chloride, numeric, mols/L.
sulfate, numeric, mols/L.
permanganate, numeric, mols/L.
nitrate, numeric, mols/L.
bicarbonate, numeric, mols/L.
carbonate, numeric, mols/L.
phosphoric acid, numeric, mols/L.
hydrogen phosphate, numeric, mols/L.
phosphate, numeric, mols/L.
ammonium, numeric, mol/L as N.
borate, numeric, mol/L.
trihydrogen silicate, numeric, mol/L.
dihydrogen silicate, numeric, mol/L.
acetate, numeric, mol/L.
hydrogen ion, numeric, mol/L.
hydroxide ion, numeric, mol/L.
total phosphate, numeric, mol/L.
total ammonia, numeric, mol/L.
total carbonate, numeric, mol/L.
total borate, numeric, mol/L.
total silicate, numeric, mol/L.
total acetate, numeric, mol/L.
bromide, numeric, mol/L.
bromate, numeric, mol/L.
fluoride, numeric, mol/L.
iron, numeric, mol/L.
aluminum, numeric, mol/L.
manganese, numeric, mol/L.
free chlorine, numeric, mol/L.
hypochlorite ion, numeric, mol/L.
sum of chloramines, numeric, mol/L.
monochloramine, numeric, mol/L.
dichloramine, numeric, mol/L.
trichloramine, numeric, mol/L.
chloroform, numeric, ug/L.
bromodichloromethane, numeric, ug/L.
dibromodichloromethane, numeric, ug/L.
bromoform, numeric, ug/L.
total trihalomethanes, numeric, ug/L.
chloroacetic acid, numeric, ug/L.
dichloroacetic acid, numeric, ug/L.
trichloroacetic acid, numeric, ug/L.
bromoacetic acid, numeric, ug/L.
dibromoacetic acid, numeric, ug/L.
sum of haloacetic acids, numeric, ug/L.
bromochloroacetic acid, numeric, ug/L.
chlorodibromoacetic acid, numeric, ug/L.
dichlorobromoacetic acid, numeric, ug/L.
tribromoacetic acid, numeric, ug/L.
Crittenden et al. (2012) equation 5-38 - ionic strength from TDS
Snoeyink & Jenkins (1980) - ionic strength from conductivity
Lewis and Randall (1921), Crittenden et al. (2012) equation 5-37 - ionic strength from ion concentrations
Harned and Owen (1958), Crittenden et al. (2012) equation 5-45 - Temperature correction of dielectric constant (relative permittivity)
water_missingions <- define_water(ph = 7, temp = 15, alk = 100, tds = 10) water_defined <- define_water(7, 20, 50, 100, 80, 10, 10, 10, 10, tot_po4 = 1)water_missingions <- define_water(ph = 7, temp = 15, alk = 100, tds = 10) water_defined <- define_water(7, 20, 50, 100, 80, 10, 10, 10, 10, tot_po4 = 1)
define_water within a dataframe and output a column of water class to be chained to other tidywater functionsThis function allows define_water to be added to a piped data frame.
Its output is a water class, and can therefore be chained with "downstream" tidywater functions.
define_water_df( df, output_water = "defined", pluck_cols = FALSE, water_prefix = TRUE )define_water_df( df, output_water = "defined", pluck_cols = FALSE, water_prefix = TRUE )
df |
a data frame containing columns with all the desired parameters with column names matching argument names in define_water |
output_water |
name of the output column storing updated parameters with the class, water. Default is "defined". |
pluck_cols |
Extract primary water slots (ph, alk, doc, uv254) into new numeric columns for easy access. Default to FALSE. |
water_prefix |
Append the output_water name to the start of the plucked columns. Default is TRUE. |
A data frame containing a water class column.
example_df <- water_df %>% define_water_df() %>% balance_ions_df() example_df <- water_df %>% define_water_df(output_water = "This is a column of water") %>% balance_ions_df(input_water = "This is a column of water")example_df <- water_df %>% define_water_df() %>% balance_ions_df() example_df <- water_df %>% define_water_df(output_water = "This is a column of water") %>% balance_ions_df(input_water = "This is a column of water")
Equilibrium constants (k) and corresponding standard enthalpy of reaction values (deltah) for significant acids in water influencing pH at equilibrium. Includes carbonate, sulfate, phosphate, and hypochlorite. Standard enthalpy of reaction is calculated by taking the sum of the enthalpy of formation of each individual component minus the enthalpy of formation of the final product. e.g., the standard enthalpy of reaction for water can be calculated as: deltah_h2o = deltah_f_oh + deltah_f_h - deltah_f_h2o = -230 + 0 - (-285.83) = 55.83 kJ/mol. See MWH (2012) example 5-5 and Benjamin (2002) eq. 2.96.
disconsdiscons
A dataframe with 8 rows and 3 columns
Coefficient type
Equilibrium constant
Standard enthalpy in J/mol
Benjamin (2015) Appendix A.1 and A.2.
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
This function takes a water defined by defined_water and output a column of dissolved copper. It is an empirical model developed
based on bench-scale copper solubility testing that can be used to predict copper levels as a function of pH, DIC, and orthophosphate.
For a single water, use dissolve_cu; to apply the model to a dataframe use dissolve_cu_df.
dissolve_cu(water)dissolve_cu(water)
water |
Source water object of class "water" created by |
Dissolved copper is a function of pH, DIC, and PO4. Output units are in mg/L.
dissolve_cu returns a column containing dissolved copper concentration in mg/L.
Lytle et al (2018)
example_cu <- define_water(ph = 7.5, alk = 125, tot_po4 = 2) %>% dissolve_cu()example_cu <- define_water(ph = 7.5, alk = 125, tot_po4 = 2) %>% dissolve_cu()
Calculate Dissolved Copper Concentration
dissolve_cu_df(df, input_water = "defined", water_prefix = TRUE)dissolve_cu_df(df, input_water = "defined", water_prefix = TRUE)
df |
a data frame containing a water class column, which has already been computed using define_water_df |
input_water |
name of the column of Water class data to be used as the input for this function. Default is "defined_water". |
water_prefix |
Append the output_water name to the start of the plucked columns. Default is TRUE. |
dissolve_cu_df returns a data frame containing the original data frame and a column for dissolved copper in mg/L.
cu_calc <- water_df %>% define_water_df() %>% dissolve_cu_df()cu_calc <- water_df %>% define_water_df() %>% dissolve_cu_df()
This function takes a water data frame defined by define_water
and outputs a dataframe of the controlling lead solid and total lead solubility.
Lead solid solubility is calculated based on controlling solid.
Total dissolved lead species (tot_dissolved_pb, M) are calculated based on lead complex calculations.
For a single water, use dissolve_pb; to apply the model to a dataframe, use dissolve_pb_df.
For most arguments, the _df
"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.
dissolve_pb( water, hydroxypyromorphite = "Schock", pyromorphite = "Topolska", laurionite = "Nasanen" ) dissolve_pb_df( df, input_water = "defined", output_col_solid = "controlling_solid", output_col_result = "pb", hydroxypyromorphite = "Schock", pyromorphite = "Topolska", laurionite = "Nasanen", water_prefix = TRUE )dissolve_pb( water, hydroxypyromorphite = "Schock", pyromorphite = "Topolska", laurionite = "Nasanen" ) dissolve_pb_df( df, input_water = "defined", output_col_solid = "controlling_solid", output_col_result = "pb", hydroxypyromorphite = "Schock", pyromorphite = "Topolska", laurionite = "Nasanen", water_prefix = TRUE )
water |
Source water object of class "water" created by define_water. Water must include alk and is. If po4, cl, and so4 are known, those should also be included. |
hydroxypyromorphite |
defaults to "Schock", the constant, K, developed by Schock et al (1996). Can also use "Zhu". |
pyromorphite |
defaults to "Topolska", the constant, K, developed by Topolska et al (2016). Can also use "Xie". |
laurionite |
defaults to "Nasanen", the constant, K, developed by Nasanen & Lindell (1976). Can also use "Lothenbach". |
df |
a data frame containing a water class column, which has already been computed using define_water_df |
input_water |
name of the column of water class data to be used as the input. Default is "defined_water". |
output_col_solid |
name of the output column storing the controlling lead solid. Default is "controlling_solid". |
output_col_result |
name of the output column storing dissolved lead in M. Default is "pb". |
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 solid with lowest solubility will form the lead scale (controlling lead solid). Some lead solids have two k-constant options. The function will default to the EPA's default constants. The user may change the constants to hydroxypyromorphite = "Zhu" or pyromorphite = "Xie" or laurionite = "Lothenbach"
Make sure that total dissolved solids, conductivity, or
ca, na, cl, so4 are used in define_water so that an ionic strength is calculated.
dissolve_pb returns a one row data frame containing only the controlling lead solid and modeled dissolved lead concentration.
dissolve_pb_df returns a data frame containing the controlling lead solid and modeled dissolved lead concentration as new columns.
Code is from EPA's TELSS lead solubility dashboard https://github.com/USEPA/TELSS which is licensed under MIT License: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
Wahman et al. (2021)
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
example_pb <- define_water( ph = 7.5, temp = 25, alk = 93, cl = 240, tot_po4 = 0, so4 = 150, tds = 200 ) %>% dissolve_pb() example_pb <- define_water( ph = 7.5, temp = 25, alk = 93, cl = 240, tot_po4 = 0, so4 = 150, tds = 200 ) %>% dissolve_pb(pyromorphite = "Xie") example_df <- water_df %>% define_water_df() %>% dissolve_pb_df(output_col_result = "dissolved_lead", pyromorphite = "Xie")example_pb <- define_water( ph = 7.5, temp = 25, alk = 93, cl = 240, tot_po4 = 0, so4 = 150, tds = 200 ) %>% dissolve_pb() example_pb <- define_water( ph = 7.5, temp = 25, alk = 93, cl = 240, tot_po4 = 0, so4 = 150, tds = 200 ) %>% dissolve_pb(pyromorphite = "Xie") example_df <- water_df %>% define_water_df() %>% dissolve_pb_df(output_col_result = "dissolved_lead", pyromorphite = "Xie")
A dataset containing coefficients from the Edwards (1997) model for coagulation TOC removal.
edwardscoeffedwardscoeff
A dataframe with 5 rows and 7 columns:
Coefficient type
x3 parameter
x2 parameter
x1 parameter
k1 parameter
k2 parameter
b parameter
Edwards (1997) Table 2.
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
Calculates TOC concentration after passing through GAC treatment according to the model developed in
"Modeling TOC Breakthrough in Granular Activated Carbon Adsorbers" by Zachman and Summers (2010), or the logistics curve approach in EPA WTP Model v. 2.0 Manual (2001).
For a single water use gac_toc; for a dataframe use gac_toc_df.
Use pluck_water to get values from the output water as new dataframe columns.
For most arguments in the _df 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.
Water must contain DOC or TOC value.
gac_toc( water, ebct = 10, model = "Zachman", media_size = "12x40", bed_vol, pretreat = "coag" ) gac_toc_df( df, input_water = "defined", output_water = "gaced", model = "use_col", pluck_cols = FALSE, water_prefix = TRUE, media_size = "use_col", ebct = "use_col", bed_vol = "use_col", pretreat = "use_col" )gac_toc( water, ebct = 10, model = "Zachman", media_size = "12x40", bed_vol, pretreat = "coag" ) gac_toc_df( df, input_water = "defined", output_water = "gaced", model = "use_col", pluck_cols = FALSE, water_prefix = TRUE, media_size = "use_col", ebct = "use_col", bed_vol = "use_col", pretreat = "use_col" )
water |
Source water object of class "water" created by define_water |
ebct |
Empty bed contact time (minutes). Model results are valid for 10 or 20 minutes. Defaults to 10 minutes. |
model |
Specifies which GAC TOC removal model to apply. Options are Zachman and WTP. Defaults to Zachman. |
media_size |
Size of GAC filter mesh. Model includes 12x40 and 8x30 mesh sizes. Defaults to 12x40. |
bed_vol |
Bed volume of GAC filter to predict effluent TOC for. |
pretreat |
Specifies the level of pretreatment prior to GAC treatment. Defaults to "coag". Other option is coagulant, ozonation, and biotreatment, called "o3biof". |
df |
a data frame containing a water class column, which has already been computed using define_water_df. The df may include columns named for the media_size, ebct, and bed volume. |
input_water |
name of the column of water class data to be used as the input for this function. Default is "defined". |
output_water |
name of the output column storing updated parameters with the class, water. Default is "gaced". |
pluck_cols |
Extract water slots modified by the function (doc, toc, uv254) into new numeric columns for easy access. Default to FALSE. |
water_prefix |
Append the output_water name to the start of the plucked columns. Default is TRUE. |
GAC model for TOC removal
The function will calculate TOC concentration by GAC adsorption in drinking water treatment. UV254 concentrations are predicted based on a linear relationship with DOC from WTP Model Equation 5-93 and 5-94.
gac_toc returns a water class object with updated DOC, TOC, and UV254 slots.
gac_toc_df returns a data frame containing a water class column with updated DOC, TOC, and UV254 slots
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
Zachman and Summers (2010)
U.S. EPA (2001)
water <- define_water(ph = 8, toc = 2.5, uv254 = .05, doc = 1.5) %>% gac_toc(media_size = "8x30", ebct = 20, model = "Zachman", bed_vol = 15000) example_df <- water_df %>% define_water_df() %>% dplyr::mutate( model = "WTP", media_size = "8x30", ebct = 10, bed_vol = rep(c(12000, 15000, 18000), 4) ) %>% gac_toc_df() example_df <- water_df %>% define_water_df("raw") %>% dplyr::mutate( model = "WTP", bed_vol = 15000 ) %>% gac_toc_df(input_water = "raw")water <- define_water(ph = 8, toc = 2.5, uv254 = .05, doc = 1.5) %>% gac_toc(media_size = "8x30", ebct = 20, model = "Zachman", bed_vol = 15000) example_df <- water_df %>% define_water_df() %>% dplyr::mutate( model = "WTP", media_size = "8x30", ebct = 10, bed_vol = rep(c(12000, 15000, 18000), 4) ) %>% gac_toc_df() example_df <- water_df %>% define_water_df("raw") %>% dplyr::mutate( model = "WTP", bed_vol = 15000 ) %>% gac_toc_df(input_water = "raw")
Calculates GAC filter bed volumes to achieve target effluent DOC according to the model developed in
"Modeling TOC Breakthrough in Granular Activated Carbon Adsorbers" by Zachman and Summers (2010), or the USEPA WTP Model v. 2.0 Manual (2001).
For a single water use gacbv_toc; for a dataframe use gacbv_toc_df.
For most arguments in the _df 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.
Water must contain DOC or TOC value.
gacbv_toc( water, ebct = 10, model = "Zachman", media_size = "12x40", target_doc ) gacbv_toc_df( df, input_water = "defined", model = "use_col", media_size = "use_col", ebct = "use_col", target_doc = "use_col", water_prefix = TRUE )gacbv_toc( water, ebct = 10, model = "Zachman", media_size = "12x40", target_doc ) gacbv_toc_df( df, input_water = "defined", model = "use_col", media_size = "use_col", ebct = "use_col", target_doc = "use_col", water_prefix = TRUE )
water |
Source water object of class "water" created by define_water |
ebct |
Empty bed contact time (minutes). Model results are valid for 10 or 20 minutes. Default is 10 minutes. |
model |
Specifies which GAC TOC removal model to apply. Options are Zachman and WTP. |
media_size |
Size of GAC filter mesh. Model includes 12x40 and 8x30 mesh sizes. Default is 12x40. |
target_doc |
Optional input to set a target DOC concentration and calculate necessary bed volume |
df |
a data frame containing a water class column, which has already been computed using define_water_df The df may include columns named for the chemical(s) being dosed. |
input_water |
name of the column of water class data to be used as the input for this function. Default is "defined". |
water_prefix |
Append the output_water name to the start of the plucked columns. Default is TRUE. |
GAC model for TOC removal
The function will calculate bed volume required to achieve given target DOC values.
gacbv_toc returns a data frame of bed volumes that achieve the target DOC.
gacbv_toc_df returns a data frame with columns for bed volumes.
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
Zachman and Summers (2010)
USEPA (2001)
water <- define_water(ph = 8, toc = 2.5, uv254 = .05, doc = 1.5) bed_volume <- gacbv_toc(water, media_size = "8x30", ebct = 20, model = "Zachman", target_doc = 0.8) library(dplyr) example_df <- water_df %>% define_water_df() %>% dplyr::mutate( model = "WTP", media_size = "8x30", ebct = 10, target_doc = rep(c(0.5, 0.8, 1), 4) ) %>% gacbv_toc_df()water <- define_water(ph = 8, toc = 2.5, uv254 = .05, doc = 1.5) bed_volume <- gacbv_toc(water, media_size = "8x30", ebct = 20, model = "Zachman", target_doc = 0.8) library(dplyr) example_df <- water_df %>% define_water_df() %>% dplyr::mutate( model = "WTP", media_size = "8x30", ebct = 10, target_doc = rep(c(0.5, 0.8, 1), 4) ) %>% gacbv_toc_df()
Returns a data frame with a breakthrough curve based on the TOC concentration after passing through GAC treatment, according to the model developed in "Modeling TOC Breakthrough in Granular Activated Carbon Adsorbers" by Zachman and Summers (2010), or the USEPA WTP Model v. 2.0 Manual (2001).
Water must contain DOC or TOC value.
gacrun_toc( water, ebct = 10, model = "Zachman", media_size = "12x40", bvs = c(2000, 20000, 100) ) gacrun_toc_df( df, input_water = "defined", water_prefix = TRUE, ebct = "use_col", model = "use_col", media_size = "use_col", bvs = "use_col" )gacrun_toc( water, ebct = 10, model = "Zachman", media_size = "12x40", bvs = c(2000, 20000, 100) ) gacrun_toc_df( df, input_water = "defined", water_prefix = TRUE, ebct = "use_col", model = "use_col", media_size = "use_col", bvs = "use_col" )
water |
Source water object of class "water" created by define_water |
ebct |
Empty bed contact time (minutes). Model results are valid for 10 or 20 minutes. Default is 10 minutes. |
model |
Specifies which GAC TOC removal model to apply. Options are Zachman and WTP. |
media_size |
Size of GAC filter mesh. If model is Zachman, can choose between 12x40 and 8x30 mesh sizes, otherwise leave as default. Defaults to 12x40. |
bvs |
If using WTP model, option to run the WTP model for a specific sequence of bed volumes, otherwise leave as default. Defaults c(2000, 20000, 100). |
df |
a data frame containing a water class column, which has already been computed using define_water_df. The df may include a column named for the coagulant being dosed, and a column named for the set of coefficients to use. |
input_water |
name of the column of water class data to be used as the input for this function. Default is "defined". |
water_prefix |
Append the input_water name to the start of the output columns. Default is TRUE. |
GAC model for TOC removal
The function will calculate bed volumes and normalized TOC breakthrough (TOCeff/TOCinf) given model type. Both models were developed using data sets from bench-scale GAC treatment studies using bituminous GAC and EBCTs of either 10 or 20 minutes. The specific mesh sizes used to develop the Zachman and Summers model were 12x40 or 8x30. The models were also developed using influent pH and TOC between specific ranges. Refer to the papers included in the references for more details.
gacrun_toc returns a data frame with bed volumes and breakthrough TOC values.
gacrun_toc_df returns a data frame containing columns of the breakthrough curve (breakthrough and bed volume).
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
Zachman and Summers (2010)
USEPA (2001)
water <- define_water(ph = 8, toc = 2.5, uv254 = .05, doc = 1.5) %>% gacrun_toc(media_size = "8x30", ebct = 20, model = "Zachman") example_df <- water_df %>% define_water_df() %>% gacrun_toc_df()water <- define_water(ph = 8, toc = 2.5, uv254 = .05, doc = 1.5) %>% gacrun_toc(media_size = "8x30", ebct = 20, model = "Zachman") example_df <- water_df %>% define_water_df() %>% gacrun_toc_df()
A dataset containing equilibrium constants for lead solubility
leadsol_constantsleadsol_constants
A dataframe with 38 rows and 3 columns
Solids:
Name of lead solid or complex with possible _letter to cite different references
Reference ID for constants
Equilibrium constant log value
Source for equilibrium constant value
Benjamin (2010)
Lothenbach et al. (1999)
Nasanen & Lindell (1976)
Powell et al. (2009)
Powell et al. (2005)
Schock et al. (1996)
Topolska et al. (2016)
Xie & Giammar (2007)
Zhu et al. (2015)
Wahman et al. (2021)
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
water class objectThis function modifies selected slots of a water class object without impacting the other parameters. For example, you can
manually update "tthm" and the new speciation will not be calculated. This function is designed to make sure all parameters
are stored in the correct units when manually updating a water. Some slots cannot be modified with this function because
they are interconnected with too many others (usually pH dependent, eg, hco3). For those parameters, update define_water.
modify_water(water, slot, value, units) modify_water_df( df, input_water = "defined", output_water = "modified", slot = "use_col", value = "use_col", units = "use_col" )modify_water(water, slot, value, units) modify_water_df( df, input_water = "defined", output_water = "modified", slot = "use_col", value = "use_col", units = "use_col" )
water |
A water class object |
slot |
A vector of slots in the water to modify, eg, "tthm" |
value |
A vector of new values for the modified slots |
units |
A vector of units for each value being entered, typically one of c("mg/L", "ug/L", "M", "cm-1"). For ions any units supported by convert_units are allowed. For organic carbon, one of "mg/L", "ug/L". For uv254 one of "cm-1", "m-1". For DBPs, one of "ug/L" or "mg/L". |
df |
a data frame containing a water class column, which has already been computed using define_water_df |
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 "modified_water". |
A data frame containing columns of selected parameters from a list of water class objects.
modify_water_df returns a data frame containing a water class column with updated slot
water1 <- define_water(ph = 7, alk = 100, tds = 100, toc = 5) %>% modify_water(slot = "toc", value = 4, units = "mg/L") water2 <- define_water(ph = 7, alk = 100, tds = 100, toc = 5, ca = 10) %>% modify_water(slot = c("ca", "toc"), value = c(20, 10), units = c("mg/L", "mg/L")) example_df <- water_df %>% define_water_df() %>% dplyr::mutate(bromide = 50) %>% modify_water_df(slot = "br", value = bromide, units = "ug/L") example_df <- water_df %>% define_water_df() %>% modify_water_df( slot = c("br", "na"), value = c(50, 60), units = c("ug/L", "mg/L") )water1 <- define_water(ph = 7, alk = 100, tds = 100, toc = 5) %>% modify_water(slot = "toc", value = 4, units = "mg/L") water2 <- define_water(ph = 7, alk = 100, tds = 100, toc = 5, ca = 10) %>% modify_water(slot = c("ca", "toc"), value = c(20, 10), units = c("mg/L", "mg/L")) example_df <- water_df %>% define_water_df() %>% dplyr::mutate(bromide = 50) %>% modify_water_df(slot = "br", value = bromide, units = "ug/L") example_df <- water_df %>% define_water_df() %>% modify_water_df( slot = c("br", "na"), value = c(50, 60), units = c("ug/L", "mg/L") )
A dataset containing the molar weights of several compounds in g/mol. Column names are lowercase chemical formulas (with no charge), with the exception of the following coagulants: alum = Al2(SO4)314H2O, ferricchloride = FeCl3, ferricsulfate = Fe2(SO4)38.8H2O,
mweightsmweights
A dataframe with one row and one column per compound
Calculates the new water quality (pH, alkalinity, pH dependent ions) for a water in an open system where CO2(aq) is at equilibrium with atmospheric CO2.
The function takes an object of class "water" and the partial pressure of CO2, then returns a water class object with updated water slots.
For a single water, use opensys_ph; to apply the model to a dataframe, use opensys_ph_df.
For most arguments, the '_df 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.
opensys_ph(water, partialpressure = 10^-3.42) opensys_ph_df( df, input_water = "defined", output_water = "opensys", pluck_cols = FALSE, water_prefix = TRUE, partialpressure = "use_col" )opensys_ph(water, partialpressure = 10^-3.42) opensys_ph_df( df, input_water = "defined", output_water = "opensys", pluck_cols = FALSE, water_prefix = TRUE, partialpressure = "use_col" )
water |
Source water of class "water" created by define_water |
partialpressure |
Partial pressure of CO2 in the air in atm. Default is 10^-3.5 atm, which is approximately Pco2 at sea level. |
df |
a data frame containing a water class column, which has already been computed using define_water_df. The df may include a column with names for each of the chemicals being dosed. |
input_water |
name of the column of water class data to be used as the input for this function. Default is "defined". |
output_water |
name of the output column storing updated water class object. Default is "opensys". |
pluck_cols |
Extract water slots modified by the function (ph, alk) into new numeric columns for easy access. Default to FALSE. |
water_prefix |
Append the output_water name to the start of the plucked columns. Default is TRUE. |
opensys_ph uses the equilibrium concentration of CO2(aq) to determine the concentrations of carbonate species in the water and the pH by solving for
the CO2 dose that results in a H2CO3 concentration equal to CO2(aq).
A water with updated pH/alk/etc.
opensys_ph_df returns a data frame containing a water class column with updated ph and alk (and pH dependent ions).
Optionally, it also adds columns for each of those slots individually.
water <- define_water(ph = 7, temp = 25, alk = 5) %>% opensys_ph() example_df <- water_df %>% define_water_df() %>% opensys_ph_df( input_water = "defined", output_water = "opensys", partialpressure = 10^-4, pluck_cols = TRUE )water <- define_water(ph = 7, temp = 25, alk = 5) %>% opensys_ph() example_df <- water_df %>% define_water_df() %>% opensys_ph_df( input_water = "defined", output_water = "opensys", partialpressure = 10^-4, pluck_cols = TRUE )
Calculates bromate (BrO3-, ug/L) formation based on selected model. Required arguments include an object of class "water"
created by define_water ozone dose, reaction time, and desired model.
The function also requires additional water quality parameters defined in define_water
including bromide, DOC or UV254 (depending on the model), pH, alkalinity (depending on the model), and
optionally, ammonia (added when defining water using the tot_nh3 argument.)
For a single water use ozonate_bromate; for a dataframe use ozonate_bromate_df.
Use pluck_cols = TRUE to get values from the output water as new dataframe columns.
For most arguments in the _df 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.
ozonate_bromate(water, dose, time, model = "Ozekin") ozonate_bromate_df( df, input_water = "defined", output_water = "ozonated", pluck_cols = FALSE, water_prefix = TRUE, dose = "use_col", time = "use_col", model = "use_col" )ozonate_bromate(water, dose, time, model = "Ozekin") ozonate_bromate_df( df, input_water = "defined", output_water = "ozonated", pluck_cols = FALSE, water_prefix = TRUE, dose = "use_col", time = "use_col", model = "use_col" )
water |
Source water object of class "water" created by define_water |
dose |
Applied ozone dose (mg/L as O3). Results typically valid for 1-10 mg/L, but varies depending on model. |
time |
Reaction time (minutes). Results typically valid for 1-120 minutes, but varies depending on model. |
model |
Model to apply. One of c("Ozekin", "Sohn", "Song", "Galey", "Siddiqui") |
df |
a data frame containing a water class column, which has already been computed using define_water_df. The df may include a column named for the applied chlorine dose (cl2), and a column for time in minutes. |
input_water |
name of the column of water class data to be used as the input for this function. Default is "defined". |
output_water |
name of the output column storing updated water class object. Default is "ozonated". |
pluck_cols |
Extract water slots modified by the function (bro3) into new numeric columns for easy access. Default to FALSE. |
water_prefix |
Append the output_water name to the start of the plucked columns. Default is TRUE. |
ozonate_bromate returns a single water class object with calculated bromate (ug/L).
ozonate_bromate_df returns a data frame containing a water class column with updated bro3
concentration. Optionally, it also adds columns for each of those slots individually.
Ozekin (1994), Sohn et al (2004), Song et al (1996), Galey et al (1997), Siddiqui et al (1994)
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) %>% ozonate_bromate(dose = 1.5, time = 5, model = "Ozekin") example_dbp <- define_water(7.5, 20, 66, toc = 4, uv254 = .2, br = 50) %>% ozonate_bromate(dose = 3, time = 15, model = "Sohn") example_df <- water_df %>% dplyr::slice_head(n = 6) %>% dplyr::mutate(br = 50) %>% define_water_df() %>% dplyr::mutate( dose = c(seq(.5, 3, .5)), OzoneTime = 30 ) %>% ozonate_bromate_df(time = OzoneTime, model = "Sohn", pluck_cols = TRUE)example_dbp <- define_water(8, 20, 66, toc = 4, uv254 = .2, br = 50) %>% ozonate_bromate(dose = 1.5, time = 5, model = "Ozekin") example_dbp <- define_water(7.5, 20, 66, toc = 4, uv254 = .2, br = 50) %>% ozonate_bromate(dose = 3, time = 15, model = "Sohn") example_df <- water_df %>% dplyr::slice_head(n = 6) %>% dplyr::mutate(br = 50) %>% define_water_df() %>% dplyr::mutate( dose = c(seq(.5, 3, .5)), OzoneTime = 30 ) %>% ozonate_bromate_df(time = OzoneTime, model = "Sohn", pluck_cols = TRUE)
Calculates DOC concentration multiple linear regression model found in 2-METHYLISOBORNEOL AND NATURAL ORGANIC MATTER
ADSORPTION BY POWDERED ACTIVATED CARBON by HYUKJIN CHO (2007).
Assumes all particulate TOC is removed when PAC is removed; therefore TOC = DOC in output.
For a single water use pac_toc; for a dataframe use pac_toc_df.
Use pluck_cols = TRUE to get values from the output water as new dataframe columns.
For most arguments in the _df 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.
water must contain DOC or TOC value.
pac_toc(water, dose, time, type = "bituminous") pac_toc_df( df, input_water = "defined", output_water = "paced", pluck_cols = FALSE, water_prefix = TRUE, dose = "use_col", time = "use_col", type = "use_col" )pac_toc(water, dose, time, type = "bituminous") pac_toc_df( df, input_water = "defined", output_water = "paced", pluck_cols = FALSE, water_prefix = TRUE, dose = "use_col", time = "use_col", type = "use_col" )
water |
Source water object of class "water" created by define_water |
dose |
Applied PAC dose (mg/L). Model results are valid for doses concentrations between 5 and 30 mg/L. |
time |
Contact time (minutes). Model results are valid for reaction times between 10 and 1440 minutes |
type |
Type of PAC applied, either "bituminous", "lignite", "wood". |
df |
a data frame containing a water class column, which has already been computed using define_water_df. The df may include columns named for the dose, time, and type |
input_water |
name of the column of water class data to be used as the input for this function. Default is "defined". |
output_water |
name of the output column storing updated water class object. Default is "paced". Pronouced P.A.ceed (not ideal we know). |
pluck_cols |
Extract water slots modified by the function (doc, toc, uv254) into new numeric columns for easy access. Default to FALSE. |
water_prefix |
Append the output_water name to the start of the plucked columns. Default is TRUE. |
The function will calculate DOC concentration by PAC adsorption in drinking water treatment. UV254 concentrations are predicted based on a linear relationship with DOC.
pac_toc returns a water class object with updated DOC, TOC, and UV254 slots.
pac_toc_df returns a data frame containing a water class column with updated DOC, TOC, and UV254
concentrations. Optionally, it also adds columns for each of those slots individually.
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
CHO(2007)
water <- define_water(toc = 2.5, uv254 = .05, doc = 1.5) %>% pac_toc(dose = 15, time = 50, type = "wood") example_df <- water_df %>% define_water_df("raw") %>% dplyr::mutate(dose = seq(11, 22, 1), PACTime = 30) %>% pac_toc_df(input_water = "raw", time = PACTime, type = "wood", pluck_cols = TRUE)water <- define_water(toc = 2.5, uv254 = .05, doc = 1.5) %>% pac_toc(dose = 15, time = 50, type = "wood") example_df <- water_df %>% define_water_df("raw") %>% dplyr::mutate(dose = seq(11, 22, 1), PACTime = 30) %>% pac_toc_df(input_water = "raw", time = PACTime, type = "wood", pluck_cols = TRUE)
A dataset containing coefficients for calculating PAC TOC removal
pactoccoeffspactoccoeffs
A dataframe with 4 rows and 3 columns
Specifies PAC type
Constant in the PAC model
Coefficient in PAC model, associated with DOC0
Coefficient in PAC model, associated with dose
Coefficient in PAC model, associated with time
Cho (2007)
This function takes a water data frame defined by define_water and outputs an ion balance plot.
plot_ions(water)plot_ions(water)
water |
Source water vector created by link function here |
A ggplot object displaying the water's ion balance.
water <- define_water(7, 20, 50, 100, 20, 10, 10, 10, 10, tot_po4 = 1) plot_ions(water)water <- define_water(7, 20, 50, 100, 20, 10, 10, 10, 10, tot_po4 = 1) plot_ions(water)
This function takes a data frame and outputs a contour plot of dissolved lead and DIC plot. Assumes that the range of pH and dissolved inorganic carbon (DIC) occurs at a single temperature and TDS.
plot_lead(df, temp, tds, ph_range, dic_range)plot_lead(df, temp, tds, ph_range, dic_range)
df |
Source data as a data frame. Must have pH and DIC columns. Columns containing a single temperature and TDS can also be included. |
temp |
Temperature used to calculate dissolved lead concentrations. Defaults to a column in df. |
tds |
Total dissolved solids used to calculate dissolved lead concentrations. Defaults to a column in df. |
ph_range |
Optional argument to modify the plotted pH range. Input as c(minimum pH, maximum pH). |
dic_range |
Optional argument to modify the plotted DIC range. Input as c(minimum DIC, maximum DIC). |
A ggplot object displaying a contour plot of dissolved lead, pH, and DIC
historical <- data.frame( ph = c(7.7, 7.86, 8.31, 7.58, 7.9, 8.06, 7.95, 8.02, 7.93, 7.61), dic = c( 14.86, 16.41, 16.48, 16.63, 16.86, 16.94, 17.05, 17.23, 17.33, 17.34 ), temp = 25, tds = 200 ) plot_lead(historical)historical <- data.frame( ph = c(7.7, 7.86, 8.31, 7.58, 7.9, 8.06, 7.95, 8.02, 7.93, 7.61), dic = c( 14.86, 16.41, 16.48, 16.63, 16.86, 16.94, 17.05, 17.23, 17.33, 17.34 ), temp = 25, tds = 200 ) plot_lead(historical)
water class objectThis function plucks one or more selected parameters from selected columns of water class objects.
The names of the output columns will follow the form water_parameter
pluck_water(df, input_waters = c("defined"), parameter)pluck_water(df, input_waters = c("defined"), parameter)
df |
a data frame containing a water class column, which has already been computed using define_water |
input_waters |
vector of names of the columns of water class data to be used as the input for this function. |
parameter |
vector of water class parameters to view outside the water column. Can also specify "all" to get all non-NA water slots. |
A data frame containing columns of selected parameters from a list of water class objects.
pluck_example <- water_df %>% define_water_df("raw") %>% pluck_water(input_waters = c("raw"), parameter = c("hco3", "doc"))pluck_example <- water_df %>% define_water_df("raw") %>% pluck_water(input_waters = c("raw"), parameter = c("hco3", "doc"))
This function takes raw water alkalinity, raw water TOC, and finished water TOC. It then calculates the TOC removal percentage and checks compliance with the Stage 1 DBP Rule.
regulate_toc(alk_raw, toc_raw, toc_finished) regulate_toc_df( df, alk_raw = "use_col", toc_raw = "use_col", toc_finished = "use_col" )regulate_toc(alk_raw, toc_raw, toc_finished) regulate_toc_df( df, alk_raw = "use_col", toc_raw = "use_col", toc_finished = "use_col" )
alk_raw |
Raw water alkalinity (mg/L as calcium carbonate). |
toc_raw |
Raw water total organic carbon (mg/L). |
toc_finished |
Finished water total organic carbon (mg/L). |
df |
a data frame optionally containing columns for raw water alkalinity, raw water TOC, and finished water TOC |
The function prints the input parameters and the calculated removal percentage for TOC. It checks compliance with regulations considering the raw TOC, alkalinity, and removal percentage. If the conditions are met, it prints "In compliance"; otherwise, it prints "Not in compliance" and stops execution with an error message.
A data frame containing the TOC removal compliance status.
A data frame with compliance status, removal percent, and optional note columns.
regulate_toc(50, 5, 2) regulated <- water_df %>% dplyr::select(toc_raw = toc, alk_raw = alk) %>% regulate_toc_df(toc_finished = seq(0, 1.2, 0.1)) regulated <- water_df %>% define_water_df() %>% chemdose_ph_df(alum = 30, output_water = "dosed") %>% chemdose_toc_df("dosed") %>% pluck_water(c("coagulated", "defined"), c("toc", "alk")) %>% dplyr::select(toc_finished = coagulated_toc, toc_raw = defined_toc, alk_raw = defined_alk) %>% regulate_toc_df()regulate_toc(50, 5, 2) regulated <- water_df %>% dplyr::select(toc_raw = toc, alk_raw = alk) %>% regulate_toc_df(toc_finished = seq(0, 1.2, 0.1)) regulated <- water_df %>% define_water_df() %>% chemdose_ph_df(alum = 30, output_water = "dosed") %>% chemdose_toc_df("dosed") %>% pluck_water(c("coagulated", "defined"), c("toc", "alk")) %>% dplyr::select(toc_finished = coagulated_toc, toc_raw = defined_toc, alk_raw = defined_alk) %>% regulate_toc_df()
This function takes a chemical dose in mg/L, plant flow, chemical strength, and $/lb and calculates cost.
solvecost_chem(dose, flow, strength = 100, cost, time = "day")solvecost_chem(dose, flow, strength = 100, cost, time = "day")
dose |
Chemical dose in mg/L as chemical |
flow |
Plant flow in MGD |
strength |
Chemical product strength in percent. Defaults to 100 percent. |
cost |
Chemical product cost in $/lb |
time |
Desired output units, one of c("day", "month", "year"). Defaults to "day". |
A numeric value for chemical cost, $/time.
alum_cost <- solvecost_chem(dose = 20, flow = 10, strength = 49, cost = .22) cost_data <- data.frame( dose = seq(10, 50, 10), flow = 10 ) %>% dplyr::mutate(costs = solvecost_chem(dose = dose, flow = flow, strength = 49, cost = .22))alum_cost <- solvecost_chem(dose = 20, flow = 10, strength = 49, cost = .22) cost_data <- data.frame( dose = seq(10, 50, 10), flow = 10 ) %>% dplyr::mutate(costs = solvecost_chem(dose = dose, flow = flow, strength = 49, cost = .22))
This function takes number of FTE and annual $/FTE and determines labor cost
solvecost_labor(fte, cost, time = "day")solvecost_labor(fte, cost, time = "day")
fte |
Number of FTEs. Can be decimal. |
cost |
$/year per FTE |
time |
Desired output units, one of c("day", "month", "year"). Defaults to "day". |
A numeric value for labor $/time.
laborcost <- solvecost_labor(1.5, 50000) cost_data <- data.frame( fte = seq(1, 10, 1) ) %>% dplyr::mutate(costs = solvecost_labor(fte = fte, cost = .08))laborcost <- solvecost_labor(1.5, 50000) cost_data <- data.frame( fte = seq(1, 10, 1) ) %>% dplyr::mutate(costs = solvecost_labor(fte = fte, cost = .08))
This function takes kW, % utilization, $/kWhr and determines power cost.
solvecost_power(power, utilization = 100, cost, time = "day")solvecost_power(power, utilization = 100, cost, time = "day")
power |
Power consumed in kW |
utilization |
Amount of time equipment is running in percent. Defaults to continuous. |
cost |
Power cost in $/kWhr |
time |
Desired output units, one of c("day", "month", "year"). Defaults to "day". |
A numeric value for power, $/time.
powercost <- solvecost_power(50, 100, .08) cost_data <- data.frame( power = seq(10, 50, 10), utilization = 80 ) %>% dplyr::mutate(costs = solvecost_power(power = power, utilization = utilization, cost = .08))powercost <- solvecost_power(50, 100, .08) cost_data <- data.frame( power = seq(10, 50, 10), utilization = 80 ) %>% dplyr::mutate(costs = solvecost_power(power = power, utilization = utilization, cost = .08))
This function takes coagulant doses in mg/L as chemical, removed turbidity, and cost ($/lb) to determine disposal cost.
solvecost_solids( alum = 0, ferricchloride = 0, ferricsulfate = 0, flow, toc_removed = 0, caco3_removed = 0, turb, b = 1.5, cost, time = "day" )solvecost_solids( alum = 0, ferricchloride = 0, ferricsulfate = 0, flow, toc_removed = 0, caco3_removed = 0, turb, b = 1.5, cost, time = "day" )
alum |
Hydrated aluminum sulfate Al2(SO4)3*14H2O + 6HCO3 -> 2Al(OH)3(am) +3SO4 + 14H2O + 6CO2 |
ferricchloride |
Ferric Chloride FeCl3 + 3HCO3 -> Fe(OH)3(am) + 3Cl + 3CO2 |
ferricsulfate |
Amount of ferric sulfate added in mg/L: Fe2(SO4)3*8.8H2O + 6HCO3 -> 2Fe(OH)3(am) + 3SO4 + 8.8H2O + 6CO2 |
flow |
Plant flow in MGD |
toc_removed |
Amount of total organic carbon removed by the treatment process in mg/L |
caco3_removed |
Amount of hardness removed by softening as mg/L CaCO3 |
turb |
Turbidity removed in NTU |
b |
Correlation factor from turbidity to suspended solids. Defaults to 1.5. |
cost |
Disposal cost in $/lb |
time |
Desired output units, one of c("day", "month", "year"). Defaults to "day". |
A numeric value for disposal costs, $/time.
https://water.mecc.edu/courses/ENV295Residuals/lesson3b.htm#:~:text=From%20the%20diagram%2C%20for%20example,million%20gallons%20of%20water%20produced.
alum_solidscost <- solvecost_solids(alum = 50, flow = 10, turb = 2, cost = 0.05) cost_data <- data.frame( alum = seq(10, 50, 10), flow = 10 ) %>% dplyr::mutate(costs = solvecost_solids(alum = alum, flow = flow, turb = 2, cost = 0.05))alum_solidscost <- solvecost_solids(alum = 50, flow = 10, turb = 2, cost = 0.05) cost_data <- data.frame( alum = seq(10, 50, 10), flow = 10 ) %>% dplyr::mutate(costs = solvecost_solids(alum = alum, flow = flow, turb = 2, cost = 0.05))
This function takes a water defined by define_water and other disinfection parameters
and outputs a data frame of the required CT (ct_required), actual CT (ct_actual), and giardia log removal (glog_removal).
For a single water, use solvect_chlorine; to apply the model to a dataframe, use solvect_chlorine_df.
For most arguments, the _df helpers
"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.
solvect_chlorine(water, time, residual, baffle, free_cl_slot = "residual_only") solvect_chlorine_df( df, input_water = "defined", time = "use_col", residual = "use_col", baffle = "use_col", free_cl_slot = "residual_only", water_prefix = TRUE )solvect_chlorine(water, time, residual, baffle, free_cl_slot = "residual_only") solvect_chlorine_df( df, input_water = "defined", time = "use_col", residual = "use_col", baffle = "use_col", free_cl_slot = "residual_only", water_prefix = TRUE )
water |
Source water object of class "water" created by |
time |
Retention time of disinfection segment in minutes. |
residual |
Minimum chlorine residual in disinfection segment in mg/L as Cl2. |
baffle |
Baffle factor - unitless value between 0 and 1. |
free_cl_slot |
Defaults to "residual_only", which uses the residual argument. If "slot_only", the model will use the free_chlorine slot in the input water. "sum_with_residual", will use the sum of the residual argument and the free_chlorine slot. |
df |
a data frame containing a water class column, which has already been computed using define_water_df |
input_water |
name of the column of Water class data to be used as the input for this function. Default is "defined_water". |
water_prefix |
name of the input water used for the calculation will be appended to the start of output columns. Default is TRUE. |
CT actual is a function of time, chlorine residual, and baffle factor, whereas CT required is a function of pH, temperature, chlorine residual, and the standard 0.5 log removal of giardia requirement. CT required is an empirical regression equation developed by Smith et al. (1995) to provide conservative estimates for CT tables in USEPA Disinfection Profiling Guidance. Log removal is a rearrangement of the CT equations.
solvect_chlorine returns a data frame containing required CT (mg/Lmin), actual CT (mg/Lmin), giardia log removal, and virus log removal.
solvect_chlorine_df returns a data frame containing the original data frame and columns for required CT, actual CT, and giardia log removal.
Smith et al. (1995)
USEPA (2020)
USEPA (1991)
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
example_ct <- define_water(ph = 7.5, temp = 25) %>% solvect_chlorine(time = 30, residual = 1, baffle = 0.7) ct_calc <- water_df %>% define_water_df() %>% solvect_chlorine_df(residual = 2, time = 10, baffle = .5) chlor_resid <- water_df %>% dplyr::mutate(br = 50) %>% define_water_df() %>% dplyr::mutate( residual = seq(1, 12, 1), time = seq(2, 24, 2), baffle = 0.7 ) %>% solvect_chlorine_df()example_ct <- define_water(ph = 7.5, temp = 25) %>% solvect_chlorine(time = 30, residual = 1, baffle = 0.7) ct_calc <- water_df %>% define_water_df() %>% solvect_chlorine_df(residual = 2, time = 10, baffle = .5) chlor_resid <- water_df %>% dplyr::mutate(br = 50) %>% define_water_df() %>% dplyr::mutate( residual = seq(1, 12, 1), time = seq(2, 24, 2), baffle = 0.7 ) %>% solvect_chlorine_df()
This function takes a water defined by define_water() and the first order decay curve parameters
from an ozone dose and outputs a dataframe of actual CT, and log removal for giardia, virus, and crypto.
For a single water, use solvect_o3; to apply the model to a dataframe, use solvect_o3_df.
For most arguments, the _df 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.
solvect_o3(water, time, dose, kd, baffle) solvect_o3_df( df, input_water = "defined", time = "use_col", dose = "use_col", kd = "use_col", baffle = "use_col", water_prefix = TRUE )solvect_o3(water, time, dose, kd, baffle) solvect_o3_df( df, input_water = "defined", time = "use_col", dose = "use_col", kd = "use_col", baffle = "use_col", water_prefix = TRUE )
water |
Source water object of class "water" created by |
time |
Retention time of disinfection segment in minutes. |
dose |
Ozone dose in mg/L. This value can also be the y intercept of the decay curve (often slightly lower than ozone dose.) |
kd |
First order decay constant. This parameter is optional. If not specified, the default ozone decay equations will be used. |
baffle |
Baffle factor - unitless value between 0 and 1. |
df |
a data frame containing a water class column, which has already been computed using |
input_water |
name of the column of Water class data to be used as the input for this function. Default is "defined_water". |
water_prefix |
name of the input water used for the calculation will be appended to the start of output columns. Default is TRUE. |
First order decay curve for ozone has the form: residual = dose * exp(kd*time). kd should be a negative number.
Actual CT is an integration of the first order curve. The first 30 seconds are removed from the integral to account for
instantaneous demand.
When kd is not specified, a default decay curve is used from the Water Treatment Plant Model (2002). This model does
not perform well for ozone decay, so specifying the decay curve is recommended.
solvect_o3 returns a data frame containing actual CT (mg/L*min), giardia log removal, virus log removal, and crypto log removal.
solvect_o3_df returns a data frame containing the original data frame and columns for required CT, actual CT, and giardia log removal.
USEPA (2020) Equation 4-4 through 4-7 https://www.epa.gov/system/files/documents/2022-02/disprof_bench_3rules_final_508.pdf
See references list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
# Use kd from experimental data (recommended): define_water(ph = 7.5, temp = 25) %>% solvect_o3(time = 10, dose = 2, kd = -0.5, baffle = 0.9) # Use modeled decay curve: define_water(ph = 7.5, alk = 100, doc = 2, uv254 = .02, br = 50) %>% solvect_o3(time = 10, dose = 2, baffle = 0.5) ct_calc <- water_df %>% dplyr::mutate(br = 50) %>% define_water_df() %>% dplyr::mutate( dose = 2, O3time = 10, ) %>% solvect_o3_df(time = O3time, baffle = .7)# Use kd from experimental data (recommended): define_water(ph = 7.5, temp = 25) %>% solvect_o3(time = 10, dose = 2, kd = -0.5, baffle = 0.9) # Use modeled decay curve: define_water(ph = 7.5, alk = 100, doc = 2, uv254 = .02, br = 50) %>% solvect_o3(time = 10, dose = 2, baffle = 0.5) ct_calc <- water_df %>% dplyr::mutate(br = 50) %>% define_water_df() %>% dplyr::mutate( dose = 2, O3time = 10, ) %>% solvect_o3_df(time = O3time, baffle = .7)
This function calculates the required amount of a chemical to dose based on a target alkalinity and existing water quality.
Returns numeric value for dose in mg/L. Uses uniroot on the chemdose_ph function.
For a single water, use solvedose_alk; to apply the model to a dataframe, use solvedose_alk_df.
For most arguments, the _df 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.
solvedose_alk(water, target_alk, chemical) solvedose_alk_df( df, input_water = "defined", output_column = "dose", target_alk = "use_col", chemical = "use_col" )solvedose_alk(water, target_alk, chemical) solvedose_alk_df( df, input_water = "defined", output_column = "dose", target_alk = "use_col", chemical = "use_col" )
water |
Source water of class "water" created by |
target_alk |
The final alkalinity in mg/L as CaCO3 to be achieved after the specified chemical is added. |
chemical |
The chemical to be added. Current supported chemicals include: acids: "hcl", "h2so4", "h3po4", "co2", bases: "naoh", "na2co3", "nahco3", "caoh2", "mgoh2" |
df |
a data frame containing a water class column, which has already been computed using define_water_df. The df may include a column with names for each of the chemicals being dosed. |
input_water |
name of the column of water class data to be used as the input. Default is "defined_water". |
output_column |
name of the output column storing doses in mg/L. Default is "dose_required". |
solvedose_alk uses stats::uniroot() on chemdose_ph to match the required dose for the requested alkalinity target.
solvedose_alk returns a numeric value for the required chemical dose.
solvedose_alk_df returns a data frame containing the original data frame and columns for target alkalinity, chemical dosed, and required chemical dose.
dose_required <- define_water(ph = 7.9, temp = 22, alk = 100, 80, 50) %>% solvedose_alk(target_alk = 150, "naoh") example_df <- water_df %>% define_water_df() %>% dplyr::mutate(finAlk = seq(100, 210, 10)) %>% solvedose_alk_df(chemical = "na2co3", target_alk = finAlk)dose_required <- define_water(ph = 7.9, temp = 22, alk = 100, 80, 50) %>% solvedose_alk(target_alk = 150, "naoh") example_df <- water_df %>% define_water_df() %>% dplyr::mutate(finAlk = seq(100, 210, 10)) %>% solvedose_alk_df(chemical = "na2co3", target_alk = finAlk)
Calculates the required amount of a chemical to dose based on a target pH and existing water quality.
The function takes an object of class "water", and user-specified chemical and target pH
and returns a numeric value for the required dose in mg/L.
For a single water, use solvedose_ph; to apply the model to a dataframe, use solvedose_ph_df.
For most arguments, the _df 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.
solvedose_ph(water, target_ph, chemical) solvedose_ph_df( df, input_water = "defined", output_column = "dose", target_ph = "use_col", chemical = "use_col" )solvedose_ph(water, target_ph, chemical) solvedose_ph_df( df, input_water = "defined", output_column = "dose", target_ph = "use_col", chemical = "use_col" )
water |
Source water of class "water" created by define_water |
target_ph |
The final pH to be achieved after the specified chemical is added. |
chemical |
The chemical to be added. Current supported chemicals include: acids: "hcl", "h2so4", "h3po4", "co2"; bases: "naoh", "na2co3", "nahco3", "caoh2", "mgoh2" |
df |
a data frame containing a water class column, which has already been computed using define_water_df. The df may include a column with names for each of the chemicals being dosed. |
input_water |
name of the column of water class data to be used as the input. Default is "defined". |
output_column |
name of the output column storing doses in mg/L. Default is "dose". |
solvedose_ph uses stats::uniroot() on chemdose_ph to match the required dose for the requested pH target.
solvedose_ph returns a numeric value for the required chemical dose.
solvedose_ph_df returns a data frame containing the original data frame and columns for target pH, chemical dosed, and required chemical dose.
water <- define_water(ph = 7, temp = 25, alk = 10) # Calculate required dose of lime to reach pH 8 solvedose_ph(water, target_ph = 8, chemical = "caoh2") example_df <- water_df %>% define_water_df() %>% solvedose_ph_df(input_water = "defined", target_ph = 8.8, chemical = "naoh")water <- define_water(ph = 7, temp = 25, alk = 10) # Calculate required dose of lime to reach pH 8 solvedose_ph(water, target_ph = 8, chemical = "caoh2") example_df <- water_df %>% define_water_df() %>% solvedose_ph_df(input_water = "defined", target_ph = 8.8, chemical = "naoh")
This function takes a chemical dose in mg/L, plant flow in MGD, and chemical strength and calculates lb/day of product
solvemass_chem(dose, flow, strength = 100)solvemass_chem(dose, flow, strength = 100)
dose |
Chemical dose in mg/L as chemical |
flow |
Plant flow in MGD |
strength |
Chemical product strength in percent. Defaults to 100 percent. |
A numeric value for the chemical mass in lb/day.
alum_mass <- solvemass_chem(dose = 20, flow = 10, strength = 49) library(dplyr) mass_data <- tibble( dose = seq(10, 50, 10), flow = 10 ) %>% mutate(mass = solvemass_chem(dose = dose, flow = flow, strength = 49))alum_mass <- solvemass_chem(dose = 20, flow = 10, strength = 49) library(dplyr) mass_data <- tibble( dose = seq(10, 50, 10), flow = 10 ) %>% mutate(mass = solvemass_chem(dose = dose, flow = flow, strength = 49))
This function takes coagulant doses in mg/L as chemical, removed turbidity, and plant flow as MGD to determine solids production.
solvemass_solids( alum = 0, ferricchloride = 0, ferricsulfate = 0, flow, toc_removed = 0, caco3_removed = 0, turb, b = 1.5 )solvemass_solids( alum = 0, ferricchloride = 0, ferricsulfate = 0, flow, toc_removed = 0, caco3_removed = 0, turb, b = 1.5 )
alum |
Amount of hydrated aluminum sulfate added in mg/L as chemical: Al2(SO4)3*14H2O + 6HCO3 -> 2Al(OH)3(am) +3SO4 + 14H2O + 6CO2 |
ferricchloride |
Amount of ferric chloride added in mg/L as chemical: FeCl3 + 3HCO3 -> Fe(OH)3(am) + 3Cl + 3CO2 |
ferricsulfate |
Amount of ferric sulfate added in mg/L as chemical: Fe2(SO4)3*8.8H2O + 6HCO3 -> 2Fe(OH)3(am) + 3SO4 + 8.8H2O + 6CO2 |
flow |
Plant flow in MGD |
toc_removed |
Amount of total organic carbon removed by the treatment process in mg/L |
caco3_removed |
Amount of hardness removed by softening as mg/L CaCO3 |
turb |
Turbidity removed in NTU |
b |
Correlation factor from turbidity to suspended solids. Defaults to 1.5. |
A numeric value for solids mass in lb/day.
https://water.mecc.edu/courses/ENV295Residuals/lesson3b.htm#:~:text=From%20the%20diagram%2C%20for%20example,million%20gallons%20of%20water%20produced.
solids_mass <- solvemass_solids(alum = 50, flow = 10, turb = 20) library(dplyr) mass_data <- tibble( alum = seq(10, 50, 10), flow = 10 ) %>% mutate(mass = solvemass_solids(alum = alum, flow = flow, turb = 20)) #'solids_mass <- solvemass_solids(alum = 50, flow = 10, turb = 20) library(dplyr) mass_data <- tibble( alum = seq(10, 50, 10), flow = 10 ) %>% mutate(mass = solvemass_solids(alum = alum, flow = flow, turb = 20)) #'
This function applies the ozone decay model to a water
from U.S. EPA (2001) equation 5-128.
For a single water, use solveresid_o3; to apply the model to a dataframe, use solveresid_o3_df.
For most arguments, the _df 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.
solveresid_o3(water, dose, time) solveresid_o3_df( df, input_water = "defined", output_column = "o3resid", dose = "use_col", time = "use_col" )solveresid_o3(water, dose, time) solveresid_o3_df( df, input_water = "defined", output_column = "o3resid", dose = "use_col", time = "use_col" )
water |
Source water object of class |
dose |
Applied ozone dose in mg/L |
time |
Ozone contact time in minutes |
df |
a data frame containing a water class column, which has already been computed using |
input_water |
name of the column of Water class data to be used as the input for this function. Default is "defined". |
output_column |
name of the output column storing doses in mg/L. Default is "dose_required". |
solveresid_o3 returns a numeric value for the residual ozone.
solveresid_o3_df returns a data frame containing the original data frame and columns for ozone dosed, time, and ozone residual.
U.S. EPA (2001)
See reference list at: https://github.com/BrownandCaldwell-Public/tidywater/wiki/References
ozone_resid <- define_water(7, 20, 100, doc = 2, toc = 2.2, uv254 = .02, br = 50) %>% solveresid_o3(dose = 2, time = 10) ozone_resid <- water_df %>% dplyr::mutate(br = 50) %>% define_water_df() %>% solveresid_o3_df(dose = 2, time = 10) ozone_resid <- water_df %>% dplyr::mutate(br = 50) %>% define_water_df() %>% dplyr::mutate( dose = seq(1, 12, 1), time = seq(2, 24, 2) ) %>% solveresid_o3_df()ozone_resid <- define_water(7, 20, 100, doc = 2, toc = 2.2, uv254 = .02, br = 50) %>% solveresid_o3(dose = 2, time = 10) ozone_resid <- water_df %>% dplyr::mutate(br = 50) %>% define_water_df() %>% solveresid_o3_df(dose = 2, time = 10) ozone_resid <- water_df %>% dplyr::mutate(br = 50) %>% define_water_df() %>% dplyr::mutate( dose = seq(1, 12, 1), time = seq(2, 24, 2) ) %>% solveresid_o3_df()
This function takes a water data frame defined by define_water and outputs a formatted summary table of
specified water quality parameters.
summarise_wq() and summarize_wq() are synonyms.
summarize_wq(water, params = c("general")) summarise_wq(water, params = c("general"))summarize_wq(water, params = c("general")) summarise_wq(water, params = c("general"))
water |
Source water vector created by |
params |
List of water quality parameters to be summarized. Options include "general", "ions", and "dbps". Defaults to "general" only. |
Use chemdose_dbp for modeled DBP concentrations.
A knitr_kable table of specified water quality parameters.
# Summarize general parameters water_defined <- define_water(7, 20, 50, 100, 80, 10, 10, 10, 10, tot_po4 = 1) summarize_wq(water_defined) # Summarize major cations and anions summarize_wq(water_defined, params = list("ions"))# Summarize general parameters water_defined <- define_water(7, 20, 50, 100, 80, 10, 10, 10, 10, tot_po4 = 1) summarize_wq(water_defined) # Summarize major cations and anions summarize_wq(water_defined, params = list("ions"))
A dataset containing required TOC removal based on raw alkalinity and TOC
toc_compliance_tabletoc_compliance_table
A dataframe with 9 rows and 5 columns
Minimum raw water TOC for compliance
Maximum raw water TOC for compliance
Minimum raw water alkalinity for compliance
Maximum raw water alkalinity for compliance
Required percent TOC removal based on raw TOC andn alklalinity range
Stage 1 Disinfection Byproduct Rule (1998)
A table of virus log removal by disinfection with free chlorine, based on pH, temperature, and contact time
vlog_removalctsvlog_removalcts
A dataframe with 35 rows and 4 columns
Specifies the pH of the input water
Specifies the temperature of the input water
Specifies the range of contact times to achieve virus removal
Level of log virus removal corresponding to ph, temp, and ct
US EPA (1991) Table E-7
A dataset containing fabricated water quality to use as tidywater inputs. Parameters are set to reasonable water quality ranges. Parameters are as follows:
water_dfwater_df
A dataframe with 12 rows and 11 columns:
pH in standard units (SU)
Temperature in degree C
Alkalinity in mg/L as CaCO3
Total hardness in mg/L as CaCO3
Calcium hardness in mg/L as CaCO3
Sodium in mg/L Na+
Potassium in mg/L K+
Chloride in mg/L Cl-
Sulfate in mg/L SO42-
Total chlorine in mg/L as Cl2
Total phosphate in mg/L as PO42-
Fabricated for use in examples.