Learn R Programming

tidywater (version 0.8.2)

chemdose_dbp: Calculate DBP formation

Description

Calculates disinfection byproduct (DBP) formation based on the U.S. EPA's Water Treatment Plant Model (U.S. EPA, 2001). Required arguments include an object of class "water" created by define_water chlorine dose, type, reaction time, and treatment applied (if any). The function also requires additional water quality parameters defined in define_water including bromide, TOC, UV254, temperature, and pH. For a single water use chemdose_dbp; for a dataframe use chemdose_dbp_chain. For most arguments in the _chain helper "use_col" default looks for a column of the same name in the dataframe. The argument can be specified directly in the function instead or an unquoted column name can be provided.

Usage

chemdose_dbp(
  water,
  cl2,
  time,
  treatment = "raw",
  cl_type = "chorine",
  location = "plant"
)

chemdose_dbp_chain( df, input_water = "defined_water", output_water = "disinfected_water", cl2 = "use_col", time = "use_col", treatment = "use_col", cl_type = "use_col", location = "use_col" )

Value

chemdose_dbp returns a single water class object with predicted DBP concentrations.

chemdose_dbp_chain returns a data frame containing a water class column with predicted DBP concentrations.

Arguments

water

Source water object of class "water" created by define_water

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".

df

a data frame containing a water class column, which has already been computed using define_water. The df may include columns for the other function arguments.

input_water

name of the column of water class data to be used as the input for this function. Default is "defined_water".

output_water

name of the output column storing updated parameters with the class, water. Default is "disinfected_water".

Details

The function will calculate haloacetic acids (HAA) as HAA5, and total trihalomethanes (TTHM). Use summarize_wq(water, params = c("dbps")) to quickly tabulate the results.

For large datasets, using fn_once or fn_chain may take many minutes to run. These types of functions use the furrr package for the option to use parallel processing and speed things up. To initialize parallel processing, use plan(multisession) or plan(multicore) (depending on your operating system) prior to your piped code with the fn_once or fn_chain functions. Note, parallel processing is best used when your code block takes more than a minute to run, shorter run times will not benefit from parallel processing.

Examples

Run this code
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")

# \donttest{
library(dplyr)

example_df <- water_df %>%
  mutate(br = 50) %>%
  define_water_chain() %>%
  chemdose_dbp_chain(input_water = "defined_water", cl2 = 4, time = 8)

example_df <- water_df %>%
  mutate(br = 50) %>%
  slice_sample(n = 3) %>%
  define_water_chain() %>%
  mutate(
    cl2_dose = c(2, 3, 4),
    time = 30
  ) %>%
  chemdose_dbp_chain(cl2 = cl2_dose, treatment = "coag", location = "ds", cl_type = "chloramine")

# Initialize parallel processing
library(furrr)
plan(multisession, workers = 2) # Remove the workers argument to use all available compute
example_df <- water_df %>%
  mutate(br = 50) %>%
  define_water_chain() %>%
  chemdose_dbp_chain(cl2 = 4, time = 8)

# Optional: explicitly close multisession processing
plan(sequential)
# }

Run the code above in your browser using DataLab