-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added entero_stationdata and associated docs
- Loading branch information
Showing
4 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.