From 156fa5e50dc09302a46fc6dfe7579e7be38da3fb Mon Sep 17 00:00:00 2001 From: Kim Cressman Date: Thu, 11 Jul 2024 15:01:58 -0500 Subject: [PATCH] added entero_stationdata and associated docs --- R/entero_stationdata.R | 16 ++++++++ data-raw/entero_stationdata-raw.R | 65 ++++++++++++++++++++++++++++++ data/entero_stationdata.RData | Bin 0 -> 1312 bytes man/entero_stationdata.Rd | 29 +++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 R/entero_stationdata.R create mode 100644 data-raw/entero_stationdata-raw.R create mode 100644 data/entero_stationdata.RData create mode 100644 man/entero_stationdata.Rd diff --git a/R/entero_stationdata.R b/R/entero_stationdata.R new file mode 100644 index 00000000..7d453322 --- /dev/null +++ b/R/entero_stationdata.R @@ -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" diff --git a/data-raw/entero_stationdata-raw.R b/data-raw/entero_stationdata-raw.R new file mode 100644 index 00000000..ee24207e --- /dev/null +++ b/data-raw/entero_stationdata-raw.R @@ -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') + diff --git a/data/entero_stationdata.RData b/data/entero_stationdata.RData new file mode 100644 index 0000000000000000000000000000000000000000..e08156048d29f8d485ca24253705179d2bd685ba GIT binary patch literal 1312 zcmV+*1>gGpH+ooF0004LBHlIv03iV!0000G&sfah5SawzT>vQ&2UKVgRpfklJ zUb}0Y*Nam(57p9}vK1-^1o+4Z^XcawqFuPlU6s=Mc*Meuy=Xl7Us6;Vy>1@`ybV-1 z1-&Cg9ECw*=kd^#wdVvkwZ9)4 z%E5#8cG<|W_lJR3atkSWFwINGgEJN`5JF-<@&&IkI-%Z-b#Yp+FY5ajnn9Ox z(l_Vh5TOp!i1@TC%KtrM?wNpAIk)HD0{Sbm#PQO9K;u0nzriw;v2bkj9%&(Pxl4hM z^p8Pk=?P2kyu_-$pOnZvg+1eZTX59!>|7yZ8@Bt?gY%KLC?F$> zQ!UFBQh(E|BW4o$w8J9`3W=PyuP@qUqu!%Tkox&>n+;9$Po;)q;x#g0moV#wlGk() zFRn`{&!k`QK;O7Dz8kHQ@M1|iKCE>)-rqiT)h%v^ByNZBjw5fcdMKt6q{)XPbuRk9 z50X}fiW*+iiQEEGwUr(r4dbU=_3e;=BIbE8^{&&B5ylEi!VUT@Pittl?tpZgAud$Br75it@h{53@Rvi!&jo_q$%_ba zTbf>Ou>aRm_xur^WWteR(9Oz>5o>2l0KVUck^f0leCNqQ|11`zH*+Z5x4^D~)cNG9 z@ekJzX0MO+JIWx4ufwEzhCJs$kH86RqDFW>uT(~qet}izWwfCZjYPq{`^30Lm2GPn z&!b)oyS+8iAq> zs#Y4mG1NE++uYpUXR=hlgjFac1EqVFFwA*Ysm%!!=pPLijBFpXC`FZQ*S~{d`fZql zQcs5TpR+M{gjaP~g(#C6BVIh7m(>QHC#r@^o}^QYh9w^ttkW%$h5!H;WvDy=0sIM? WApii`LT5)lFb#_W000000a;o~&V>U2 literal 0 HcmV?d00001 diff --git a/man/entero_stationdata.Rd b/man/entero_stationdata.Rd new file mode 100644 index 00000000..1b30b3cb --- /dev/null +++ b/man/entero_stationdata.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/entero_stationdata.R +\docType{data} +\name{entero_stationdata} +\alias{entero_stationdata} +\title{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} +} +} +\source{ +Lat/Long information from Water Quality Portal, https://waterqualitydata.us +} +\usage{ +entero_stationdata +} +\description{ +Enterococcus station location metadata +} +\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}) +} +\keyword{datasets}