write_exposure: Write exposure values for specified locations and dates in a...

Description Usage Arguments Value Note Examples

View source: R/06-write.R

Description

For a particular combination of locations and dates, radii, and active ingredients, write_exposure calculates exposure (kg/m^2) and writes out files (exposure values, meta data, and plots) to a specified directory.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
write_exposure(
  clean_pur_df,
  locations_dates_df,
  radii,
  directory,
  chemicals = "all",
  aerial_ground = FALSE,
  write_plots = TRUE,
  verbose = TRUE,
  ...
)

Arguments

clean_pur_df

A data frame returned by pull_clean_pur that includes data for the county of your locations, the time periods, and the active ingredients or cheimcal classes for which you want to calculate exposure.

locations_dates_df

A data frame with three columns: location, character strings of California addresses with street names, cities, state, and 5-digit zip codes, or pairs of coordinates in the form "longitude, latitude". All of the locations should be in the same county. The other two columns are start_date and end_date, with "yyyy-mm-dd" character strings specifying the time period(s) over which you would like to calculate exposure for each location.

radii

A vector of numeric values greater than zero that give the radii in meters defining the buffers around your locations in which you would like to calculate exposure. For reference, the length and width of a PLS section is about 1,609 meters (1 mile). That of a township could range from about 9,656 to 11,265 meters (6-7 miles).

directory

A path to the directory where you would like exposure files to be written. This directory will be created if it doesn't already exist.

chemicals

Either "all" or "chemical_class". The default is "all", which will calculate exposure to the summed active ingredients present in the clean_pur_df data frame. Enter "chemical_class" to calculate exposure to each of the chemical classes present in the chemical_class column of your clean_pur_df data frame.

aerial_ground

TRUE / FALSE for whether you would like to incorporate aerial/ground application into exposure calculations. If aerial_ground = TRUE, there should be an aerial_ground column in the input clean_pur_df data frame. There will be a value of exposure calculated for each chemical ("all" or by chemical class) and for each method of application: aerial or ground. The default is FALSE.

write_plots

TRUE / FALSE for whether you would like to write out plots returned from plot_exposure for each combination of location, date, radius, chemical class, and aerial/ground application. Plots are saved in a subdirectory called "exposure_plots".

verbose

TRUE / FALSE for whether you would like a message to print out while the function is running. The default is TRUE.

...

Additional arguments passed on to plot_exposure.

Value

Two .rds files ("exposure_df" and "meta_data") and a subdirectory ("exposure_plots") with PNG files of plot_exposure plots:

exposure_df.rds

A data frame with 10 columns: exposure, the exposure value in kg/m^2 for that combination of chemicals, date range, aerial/ground application, location, and radius, chemicals, either "all" or a chemical class present in the provided clean_pur_df data frame, start_date and end_date, aerial_ground, which will be NA unless the aerial_ground argument is set to TRUE, location, radius, longitude and latitude of each location, and any error_messages that were returned when calculating exposure.

meta_data.rds

A list with as many elements as there are rows in the exposure_df.rds data frame. Each element is a data frame with meta data relevant to the exposure value in the corresponding row of the exposure_df data frame. For example, meta data for exposure_df[1,] is saved as meta_data[[1]], exposure_df[2,] saved as meta_data[[2]], and so on. Meta data data frames have 13 columns: pls, with each PLS unit intersected by the specified buffer, chemicals, either a chemical class or "all" (indicating exposure was calculated for all active ingredients present in the clean_pur_df data frame), percent, the percent intersection of the PLS unit with the buffer, kg, kg of active ingredients applied in the PLS unit for the given date range/chemicals/aerial_ground combination, kg_intersection, percent multiplied by kg, start_date, end_date, aerial_ground (this will be NA if the aerial_ground argument is set to FALSE or if none_recorded is TRUE), none_recorded, a logical value indicating if there were no active ingredients recorded for the PLS/date range/chemicals combination, location, radius, area, the area of the specified buffer, and error_message, which gives the error message, if any, that was returned.

exposure_plots

A subdirectory with a plot_exposure plot saved for each row of the exposure_df data frame and element of the meta_data list. Plots are saved as #_exposure_plot.png, with numbers corresponding to the row number and element number of the exposure_df data frame and meta_data list, respectively. For example, 12_exposure_plot.png corresponds to exposure_df[12,] and meta_data[[12]].

Note

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
library(magrittr)

chemical_class_df <- rbind(find_chemical_codes(2000:2001, "sulfur"),
                           find_chemical_codes(2000:2001, "methyl bromide")) 
   dplyr::rename(chemical_class = chemical)
pur <- pull_clean_pur(2000:2001, counties = "fresno",
                      chemicals = chemical_class_df$chemname,
                      sum_application = TRUE,
                      sum = "chemical_class",
                      chemical_class = chemical_class_df)
schools <- c("3333 American Ave., Fresno, CA 93725",
             "1111 Van Ness Ave., Fresno, CA 93721",
             "1616 South Fruit Ave., Fresno, CA 93706")
df <- data.frame(location = rep(schools, each = 2),
                 start_date = rep(c("2000-01-01", "2000-05-25", "2001-02-16"),
                                  each = 2),
                 end_date = c("2000-04-01", "2000-07-01",
                              "2000-08-25", "2000-11-25",
                              "2001-05-16", "2001-08-16"))
temp_dir <- tempdir()
write_exposure(pur, df, c(1500, 3000), "chemical_class",
               directory = temp_dir)
exposure_df <- readRDS(paste0(temp_dir, "/exposure_df.rds"))
meta_data <- readRDS(paste0(temp_dir, "/meta_data.rds"))
list.files(paste0(temp_dir, "/exposure_plots"))


spdf <- readRDS(system.file("extdata", "fresno_spdf.rds", package = "purexposure"))
pur <- readRDS(system.file("extdata", "fresno_clean.rds", package = "purexposure"))
df <- data.frame(location = "-119.726751, 36.660967",
                 start_date = "2000-01-01",
                 end_date = "2000-12-31")
temp <- tempdir()
write_exposure(pur, df, 3000, temp, spdf = spdf)

leighseverson/purexposure documentation built on Aug. 13, 2021, 6:34 p.m.