diff --git a/R/anlz_enteromap.R b/R/anlz_enteromap.R index 9489a43e..4b0dcc00 100644 --- a/R/anlz_enteromap.R +++ b/R/anlz_enteromap.R @@ -4,9 +4,9 @@ #' @param yrsel optional numeric to filter data by year #' @param mosel optional numeric to filter data by month #' @param wetdry logical; if \code{TRUE}, incorporate wet/dry differences (this will result in a call to \code{\link{anlz_fibwetdry}}, in which case \code{temporal_window} and \code{wet_threshold} are required). if \code{FALSE} (default), do not differentiate between wet and dry samples. -#' @param precipdata input data frame as returned by \code{\link{read_importrain}}. columns should be: station, date (yyyy-mm-dd), rain (in inches). The object \code{\link{catch_precip}} has this data from 1995-2023 for select Enterococcus stations. -#' @param temporal_window numeric; required if \code{subset_wetdry} is not \code{"all"}. number of days precipitation should be summed over (1 = day of sample only; 2 = day of sample + day before; etc.) -#' @param wet_threshold numeric; required if \code{subset_wetdry} is not \code{"all"}. inches accumulated through the defined temporal window, above which a sample should be defined as being from a 'wet' time period +#' @param precipdata input data frame as returned by \code{\link{read_importrain}}. columns should be: station, date (yyyy-mm-dd), rain (in inches). The object \code{\link{catch_precip}} has this data from 1995-2023 for select Enterococcus stations. If \code{NULL}, defaults to \code{\link{catch_precip}}. +#' @param temporal_window numeric; required if \code{wetdry} is \code{TRUE}. number of days precipitation should be summed over (1 = day of sample only; 2 = day of sample + day before; etc.) +#' @param wet_threshold numeric; required if \code{wetdry} is \code{TRUE}. inches accumulated through the defined temporal window, above which a sample should be defined as being from a 'wet' time period #' #' @details This function is based on \code{\link{anlz_fibmap}}, but is specific to Enterococcus data downloaded via \code{\link{read_importentero}}. It creates categories for mapping using \code{\link{show_enteromap}}. Optionally, if samples have been defined as 'wet' or not via \code{\link{anlz_fibwetdry}}, this can be represented via symbols on the map. Categories based on relevant thresholds are assigned to each observation. The categories are specific to Enterococcus in marine waters (\code{class} of 2 or 3M). A station is categorized into one of four ranges defined by the thresholds as noted in the \code{cat} column of the output, with corresponding colors appropriate for each range as noted in the \code{col} column of the output. #' @@ -41,7 +41,6 @@ anlz_enteromap <- function (fibdata, yrsel = NULL, mosel = NULL, wetdry = FALSE, # if precip data isn't specified, use the catch_precip object if(is.null(precipdata)){ precipdata <- catch_precip - message("precipdata not specified; defaulting to tbeptools catch_precip object") } # run the anlz_fibwetdry function wetdry <- anlz_fibwetdry(fibdata = fibdata, diff --git a/R/anlz_fibmatrix.R b/R/anlz_fibmatrix.R index 89834d8f..6026fe1b 100644 --- a/R/anlz_fibmatrix.R +++ b/R/anlz_fibmatrix.R @@ -9,7 +9,7 @@ #' @param threshold optional numeric for threshold against which to calculate exceedances for the indicator bacteria of choice. If not provided, defaults to 400 for \code{fcolif} and 130 for \code{ecocci}. #' @param lagyr numeric for year lag to calculate categories, see details #' @param subset_wetdry character, subset data frame to only wet or dry samples as defined by \code{wet_threshold} and \code{temporal_window}? Defaults to \code{"all"}, which will not subset. If \code{"wet"} or \code{"dry"} is specified, \code{\link{anlz_fibwetdry}} is called using the further specified parameters, and the data frame is subsetted accordingly. -#' @param precipdata input data frame as returned by \code{\link{read_importrain}}. columns should be: station, date (yyyy-mm-dd), rain (in inches). The object \code{\link{catch_precip}} has this data from 1995-2023 for select Enterococcus stations. +#' @param precipdata input data frame as returned by \code{\link{read_importrain}}. columns should be: station, date (yyyy-mm-dd), rain (in inches). The object \code{\link{catch_precip}} has this data from 1995-2023 for select Enterococcus stations. If \code{NULL}, defaults to \code{\link{catch_precip}}. #' @param temporal_window numeric; required if \code{subset_wetdry} is not \code{"all"}. number of days precipitation should be summed over (1 = day of sample only; 2 = day of sample + day before; etc.) #' @param wet_threshold numeric; required if \code{subset_wetdry} is not \code{"all"}. inches accumulated through the defined temporal window, above which a sample should be defined as being from a 'wet' time period #' @@ -68,7 +68,6 @@ anlz_fibmatrix <- function(fibdata, # if precip data isn't specified, use the catch_precip object if(is.null(precipdata)){ precipdata <- catch_precip - message("precipdata not specified; defaulting to tbeptools catch_precip object") } # run the anlz_fibwetdry function dat <- anlz_fibwetdry(fibdata = fibdata, diff --git a/R/anlz_fibwetdry.R b/R/anlz_fibwetdry.R index 9edb8704..6516afe8 100644 --- a/R/anlz_fibwetdry.R +++ b/R/anlz_fibwetdry.R @@ -5,7 +5,7 @@ #' @param temporal_window numeric, number of days precipitation should be summed over (1 = day of sample only; 2 = day of sample + day before; etc.) #' @param wet_threshold numeric, inches accumulated through the defined temporal window, above which a sample should be defined as being from a 'wet' time period #' -#' @return a data frame; the original fibdata data frame with an additional column. wet_sample is logical, indicating whether the rainfall for that station's catchment exceeded the amount over the time period specified in args. +#' @return a data frame; the original fibdata data frame with three additional columns. \code{rain_sampleDay} is the total rain (inches) on the day of sampling, \code{rain_total} is the total rain (inches) for the period of time defined by \code{temporal_window}, and \code{wet_sample} is logical, indicating whether the rainfall for that station's catchment exceeded the amount over the time period specified in args. #' #' @details This function allows the user to specify a threshold for declaring a sample to be taken after an important amount of rain over an important amount of days, and declaring it to be 'wet'. This is of interest because samples taken after significant precipitation (definitions of this vary, which is why the user can specify desired thresholds) are more likely to exceed relevant bacterial thresholds. Identifying samples as 'wet' or not allows for calculation of further indices for wet and dry subsets of samples. #' @@ -15,6 +15,7 @@ #' #' @examples #' entero_wetdry <- anlz_fibwetdry(enterodata, catch_precip) +#' head(entero_wetdry) anlz_fibwetdry <- function(fibdata, precipdata, temporal_window = 2, @@ -45,7 +46,6 @@ anlz_fibwetdry <- function(fibdata, dplyr::rename(rain_sampleDay = rain) %>% dplyr::ungroup() - # left join, fibdata = left, prcipdata = right; on station and date # use threshold to show wet or dry out <- dplyr::left_join(fibdata, prcp_calcd, @@ -53,4 +53,5 @@ anlz_fibwetdry <- function(fibdata, dplyr::mutate(wet_sample = rain_total >= wet_threshold) return(out) + } diff --git a/R/catch_pixels.R b/R/catch_pixels.R index 66e48d59..2dfbbfe0 100644 --- a/R/catch_pixels.R +++ b/R/catch_pixels.R @@ -6,6 +6,6 @@ #' \item{pixel}{a number; each row is a single pixel from the Southwest Florida Water Management District's radar-estimated rainfall shapefile} #' } #' -#' @details Generated by \code{data-raw/catch_pixels-raw.R} (view on github: \url{https://github.com/tbep-tech/tbeptools/blob/master/data-raw/catch_pixels.R}) +#' @details Generated by \code{data-raw/catch_pixels-raw.R} (view on github: \url{https://github.com/tbep-tech/tbeptools/blob/master/data-raw/catch_pixels-raw.R}) "catch_pixels" diff --git a/data-raw/catch_pixels-raw.R b/data-raw/catch_pixels-raw.R index 70720479..e53f673b 100644 --- a/data-raw/catch_pixels-raw.R +++ b/data-raw/catch_pixels-raw.R @@ -2,13 +2,14 @@ library(tidyverse) library(sf) +library(here) # station, catchment data -catchments <- read_sf('data-raw/TB_Select_Fib_Catchments_Dissolved.shp') +catchments <- read_sf(here('data-raw/TB_Select_Fib_Catchments_Dissolved.shp')) # SWFWMD pixel data # this will need to be saved to tbeptools -pixels <- read_sf('data-raw/swfwmd_pixel_2_utm_m_83.shp') +pixels <- read_sf(here('data-raw/swfwmd_pixel_2_utm_m_83.shp')) # put into same crs and join catch2 <- st_transform(catchments, @@ -38,4 +39,4 @@ catch_pixels <- st_intersection(pixels, catch2) |> ) |> select(station, pixel = PIXEL) -save(catch_pixels, file = 'data/catch_pixels.RData', compress = 'xz') +save(catch_pixels, file = here('data/catch_pixels.RData'), compress = 'xz') diff --git a/data-raw/catch_precip-raw.R b/data-raw/catch_precip-raw.R index 050b19af..5fa94b22 100644 --- a/data-raw/catch_precip-raw.R +++ b/data-raw/catch_precip-raw.R @@ -1,7 +1,8 @@ library(tidyverse) +library(here) # load the catch_pixels data file -load('data/catch_pixels.RData') +load(here('data/catch_pixels.RData')) # set up function to loop through several years @@ -40,4 +41,4 @@ catch_precip <- dplyr::bind_rows(prcp_1995.2004, prcp_2015.2023) -save(catch_precip, file = 'data/catch_precip.RData', compress = 'xz') +save(catch_precip, file = here('data/catch_precip.RData'), compress = 'xz') diff --git a/data-raw/enterodata-raw.R b/data-raw/enterodata-raw.R index 001db874..b1542b3a 100644 --- a/data-raw/enterodata-raw.R +++ b/data-raw/enterodata-raw.R @@ -1,3 +1,5 @@ +library(here) + stations <- c('21FLHILL_WQX-101', '21FLHILL_WQX-102', '21FLHILL_WQX-501', @@ -20,4 +22,4 @@ enterodata <- read_importentero(args = args) %>% dplyr::select(-qualifier, -LabComments) -save(enterodata, file = 'data/enterodata.RData', compress = 'xz') +save(enterodata, file = here('data/enterodata.RData'), compress = 'xz') diff --git a/data-raw/enterodata_since1995-raw.R b/data-raw/enterodata_since1995-raw.R index d09dd778..b6af821d 100644 --- a/data-raw/enterodata_since1995-raw.R +++ b/data-raw/enterodata_since1995-raw.R @@ -1,5 +1,6 @@ # all data from key Enterococcus stations, 1995-2023 # although apparently data collection only started in 2000 at the earliest of these stations +library(here) stations <- unique(catch_precip$station) entero_names <- c('Enterococci', @@ -19,4 +20,4 @@ enterodata_since1995 <- read_importentero(args = args) %>% dplyr::select(-qualifier, -LabComments) -save(enterodata_since1995, file = 'data/enterodata_since1995.RData', compress = 'xz') +save(enterodata_since1995, file = here('data/enterodata_since1995.RData'), compress = 'xz') diff --git a/man/anlz_enteromap.Rd b/man/anlz_enteromap.Rd index f1e1b47c..cac9e9f5 100644 --- a/man/anlz_enteromap.Rd +++ b/man/anlz_enteromap.Rd @@ -23,11 +23,11 @@ anlz_enteromap( \item{wetdry}{logical; if \code{TRUE}, incorporate wet/dry differences (this will result in a call to \code{\link{anlz_fibwetdry}}, in which case \code{temporal_window} and \code{wet_threshold} are required). if \code{FALSE} (default), do not differentiate between wet and dry samples.} -\item{precipdata}{input data frame as returned by \code{\link{read_importrain}}. columns should be: station, date (yyyy-mm-dd), rain (in inches). The object \code{\link{catch_precip}} has this data from 1995-2023 for select Enterococcus stations.} +\item{precipdata}{input data frame as returned by \code{\link{read_importrain}}. columns should be: station, date (yyyy-mm-dd), rain (in inches). The object \code{\link{catch_precip}} has this data from 1995-2023 for select Enterococcus stations. If \code{NULL}, defaults to \code{\link{catch_precip}}.} -\item{temporal_window}{numeric; required if \code{subset_wetdry} is not \code{"all"}. number of days precipitation should be summed over (1 = day of sample only; 2 = day of sample + day before; etc.)} +\item{temporal_window}{numeric; required if \code{wetdry} is \code{TRUE}. number of days precipitation should be summed over (1 = day of sample only; 2 = day of sample + day before; etc.)} -\item{wet_threshold}{numeric; required if \code{subset_wetdry} is not \code{"all"}. inches accumulated through the defined temporal window, above which a sample should be defined as being from a 'wet' time period} +\item{wet_threshold}{numeric; required if \code{wetdry} is \code{TRUE}. inches accumulated through the defined temporal window, above which a sample should be defined as being from a 'wet' time period} } \value{ A \code{data.frame} similar to \code{fibdata} with additional columns describing station categories and optionally filtered by arguments passed to the function diff --git a/man/anlz_fibmatrix.Rd b/man/anlz_fibmatrix.Rd index 4438b1b7..0c5184f6 100644 --- a/man/anlz_fibmatrix.Rd +++ b/man/anlz_fibmatrix.Rd @@ -32,7 +32,7 @@ anlz_fibmatrix( \item{subset_wetdry}{character, subset data frame to only wet or dry samples as defined by \code{wet_threshold} and \code{temporal_window}? Defaults to \code{"all"}, which will not subset. If \code{"wet"} or \code{"dry"} is specified, \code{\link{anlz_fibwetdry}} is called using the further specified parameters, and the data frame is subsetted accordingly.} -\item{precipdata}{input data frame as returned by \code{\link{read_importrain}}. columns should be: station, date (yyyy-mm-dd), rain (in inches). The object \code{\link{catch_precip}} has this data from 1995-2023 for select Enterococcus stations.} +\item{precipdata}{input data frame as returned by \code{\link{read_importrain}}. columns should be: station, date (yyyy-mm-dd), rain (in inches). The object \code{\link{catch_precip}} has this data from 1995-2023 for select Enterococcus stations. If \code{NULL}, defaults to \code{\link{catch_precip}}.} \item{temporal_window}{numeric; required if \code{subset_wetdry} is not \code{"all"}. number of days precipitation should be summed over (1 = day of sample only; 2 = day of sample + day before; etc.)} diff --git a/man/anlz_fibwetdry.Rd b/man/anlz_fibwetdry.Rd index 2984026d..f827ec10 100644 --- a/man/anlz_fibwetdry.Rd +++ b/man/anlz_fibwetdry.Rd @@ -16,7 +16,7 @@ anlz_fibwetdry(fibdata, precipdata, temporal_window = 2, wet_threshold = 0.5) \item{wet_threshold}{numeric, inches accumulated through the defined temporal window, above which a sample should be defined as being from a 'wet' time period} } \value{ -a data frame; the original fibdata data frame with an additional column. wet_sample is logical, indicating whether the rainfall for that station's catchment exceeded the amount over the time period specified in args. +a data frame; the original fibdata data frame with three additional columns. \code{rain_sampleDay} is the total rain (inches) on the day of sampling, \code{rain_total} is the total rain (inches) for the period of time defined by \code{temporal_window}, and \code{wet_sample} is logical, indicating whether the rainfall for that station's catchment exceeded the amount over the time period specified in args. } \description{ Identify Fecal Indicator Bacteria samples as coming from a 'wet' or 'dry' time period @@ -26,4 +26,5 @@ This function allows the user to specify a threshold for declaring a sample to b } \examples{ entero_wetdry <- anlz_fibwetdry(enterodata, catch_precip) +head(entero_wetdry) } diff --git a/man/catch_pixels.Rd b/man/catch_pixels.Rd index 82463044..c2e3885d 100644 --- a/man/catch_pixels.Rd +++ b/man/catch_pixels.Rd @@ -18,6 +18,6 @@ catch_pixels Catchments and radar pixels (for precip) of selected Enterococcus stations } \details{ -Generated by \code{data-raw/catch_pixels-raw.R} (view on github: \url{https://github.com/tbep-tech/tbeptools/blob/master/data-raw/catch_pixels.R}) +Generated by \code{data-raw/catch_pixels-raw.R} (view on github: \url{https://github.com/tbep-tech/tbeptools/blob/master/data-raw/catch_pixels-raw.R}) } \keyword{datasets} diff --git a/man/show_enteromap.Rd b/man/show_enteromap.Rd index 3160446b..7d00e8f8 100644 --- a/man/show_enteromap.Rd +++ b/man/show_enteromap.Rd @@ -23,11 +23,11 @@ show_enteromap( \item{wetdry}{logical; if \code{TRUE}, incorporate wet/dry differences (this will result in a call to \code{\link{anlz_fibwetdry}}, in which case \code{temporal_window} and \code{wet_threshold} are required). if \code{FALSE} (default), do not differentiate between wet and dry samples.} -\item{precipdata}{input data frame as returned by \code{\link{read_importrain}}. columns should be: station, date (yyyy-mm-dd), rain (in inches). The object \code{\link{catch_precip}} has this data from 1995-2023 for select Enterococcus stations.} +\item{precipdata}{input data frame as returned by \code{\link{read_importrain}}. columns should be: station, date (yyyy-mm-dd), rain (in inches). The object \code{\link{catch_precip}} has this data from 1995-2023 for select Enterococcus stations. If \code{NULL}, defaults to \code{\link{catch_precip}}.} -\item{temporal_window}{numeric; required if \code{subset_wetdry} is not \code{"all"}. number of days precipitation should be summed over (1 = day of sample only; 2 = day of sample + day before; etc.)} +\item{temporal_window}{numeric; required if \code{wetdry} is \code{TRUE}. number of days precipitation should be summed over (1 = day of sample only; 2 = day of sample + day before; etc.)} -\item{wet_threshold}{numeric; required if \code{subset_wetdry} is not \code{"all"}. inches accumulated through the defined temporal window, above which a sample should be defined as being from a 'wet' time period} +\item{wet_threshold}{numeric; required if \code{wetdry} is \code{TRUE}. inches accumulated through the defined temporal window, above which a sample should be defined as being from a 'wet' time period} } \value{ A \code{leaflet} map for the selected year, month, and area showing stations and FIB concentration category diff --git a/man/show_fibmatrix.Rd b/man/show_fibmatrix.Rd index d94fbdb7..cbb4f6e2 100644 --- a/man/show_fibmatrix.Rd +++ b/man/show_fibmatrix.Rd @@ -39,7 +39,7 @@ show_fibmatrix( \item{subset_wetdry}{character, subset data frame to only wet or dry samples as defined by \code{wet_threshold} and \code{temporal_window}? Defaults to \code{"all"}, which will not subset. If \code{"wet"} or \code{"dry"} is specified, \code{\link{anlz_fibwetdry}} is called using the further specified parameters, and the data frame is subsetted accordingly.} -\item{precipdata}{input data frame as returned by \code{\link{read_importrain}}. columns should be: station, date (yyyy-mm-dd), rain (in inches). The object \code{\link{catch_precip}} has this data from 1995-2023 for select Enterococcus stations.} +\item{precipdata}{input data frame as returned by \code{\link{read_importrain}}. columns should be: station, date (yyyy-mm-dd), rain (in inches). The object \code{\link{catch_precip}} has this data from 1995-2023 for select Enterococcus stations. If \code{NULL}, defaults to \code{\link{catch_precip}}.} \item{temporal_window}{numeric; required if \code{subset_wetdry} is not \code{"all"}. number of days precipitation should be summed over (1 = day of sample only; 2 = day of sample + day before; etc.)}