Skip to content

Commit

Permalink
added entero_stationdata and associated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
swmpkim committed Jul 11, 2024
1 parent d30e5b6 commit 156fa5e
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
16 changes: 16 additions & 0 deletions R/entero_stationdata.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#' Enterococcus station location metadata
#'
#' @format A data frame with 50 rows and 5 columns:
#' \describe{
#' \item{station}{character, sample station, as named in the Water Quality Portal}
#' \item{latitude}{numeric, latitude in decimal degrees}
#' \item{longitude}{numeric, longitude in decimal degrees}
#' \item{bay_segment}{character, full name of Bay Segment in which the station lies}
#' \item{bay_segment_abbrev}{character, abbreviated version of Bay Segment in which the station lies}
#' }
#' @details Latitude, Longitude, and Bay Segment information for each of the identified key Enterococcus stations. Generated by \code{data-raw/entero_stationdata-raw.R} ( \link[https://github.com/tbep-tech/tbeptools/blob/master/data-raw/bsmap-raw.R]{view on github})
#'
#' @source Lat/Long information from Water Quality Portal, https://waterqualitydata.us
#'

"entero_stationdata"
65 changes: 65 additions & 0 deletions data-raw/entero_stationdata-raw.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#' compile metadata on key Enterococcus stations
#' primarily so bay segments are easily available

library(dplyr)
library(sf)
library(tbeptools)


# load stations
stns <- unique(catch_precip$station)


# download data to get lat/longs
entero_names <- c('Enterococci',
'Enterococcus')
startDate <- as.Date('2013-01-01')
endDate <- as.Date('2023-12-31')
args <- list(
siteid = stns,
characteristicName = entero_names,
startDateLo = format(startDate, '%m-%d-%Y'),
startDateHi = format(endDate, '%m-%d-%Y')
)

dat_in <- read_importentero(args = args) %>%
dplyr::select(-qualifier,
-LabComments)


# refine the data frame
# there are a few with multiple lat/longs, but from eyeballing it nothing
# is obscenely different - so take an average
dat <- dat_in %>%
select(station, Latitude, Longitude) %>%
distinct() %>%
summarize(.by = station,
latitude = mean(Latitude),
longitude = mean(Longitude))

# three of our original stations don't show up in the last 10 years
# make sure it's no mistake but otherwise we can ignore - if
# no longer sampled, they won't show up in anything else anyway
stns[which(!(stns %in% dat$station))]



# intersect with spatial object
# containing bay segment delineations

# first make the spatial object valid
tbsegshed2 <- st_make_valid(tbsegshed)

# intersect and refine the data frame
entero_stationdata <- st_as_sf(dat,
coords = c("longitude", "latitude"),
crs = "EPSG:4326",
remove = FALSE) %>%
st_intersection(tbsegshed2) %>%
st_drop_geometry() %>%
rename(bay_segment_abbrev = bay_segment,
bay_segment = long_name)

# save it
save(entero_stationdata, file = 'data/entero_stationdata.RData', compress = 'xz')

Binary file added data/entero_stationdata.RData
Binary file not shown.
29 changes: 29 additions & 0 deletions man/entero_stationdata.Rd

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

0 comments on commit 156fa5e

Please sign in to comment.