Skip to content

Commit

Permalink
minor changes to documentation, data-raw entero files use here
Browse files Browse the repository at this point in the history
  • Loading branch information
fawda123 committed Jul 18, 2024
1 parent 8a5c8f4 commit a098cfe
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 26 deletions.
7 changes: 3 additions & 4 deletions R/anlz_enteromap.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions R/anlz_fibmatrix.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
#'
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions R/anlz_fibwetdry.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand All @@ -15,6 +15,7 @@
#'
#' @examples
#' entero_wetdry <- anlz_fibwetdry(enterodata, catch_precip)
#' head(entero_wetdry)
anlz_fibwetdry <- function(fibdata,
precipdata,
temporal_window = 2,
Expand Down Expand Up @@ -45,12 +46,12 @@ 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,
by = c("station", "date")) %>%
dplyr::mutate(wet_sample = rain_total >= wet_threshold)

return(out)

}
2 changes: 1 addition & 1 deletion R/catch_pixels.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
7 changes: 4 additions & 3 deletions data-raw/catch_pixels-raw.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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')
5 changes: 3 additions & 2 deletions data-raw/catch_precip-raw.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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')
4 changes: 3 additions & 1 deletion data-raw/enterodata-raw.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
library(here)

stations <- c('21FLHILL_WQX-101',
'21FLHILL_WQX-102',
'21FLHILL_WQX-501',
Expand All @@ -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')
3 changes: 2 additions & 1 deletion data-raw/enterodata_since1995-raw.R
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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')
6 changes: 3 additions & 3 deletions man/anlz_enteromap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/anlz_fibmatrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/anlz_fibwetdry.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/catch_pixels.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/show_enteromap.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/show_fibmatrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a098cfe

Please sign in to comment.