Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 3 additions & 50 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,56 +13,9 @@ TADA.Rproj
# Session Data files
.RData

# tempdata folder files for TADABigdataRetrieval
AL_raw_data.rds
AR_raw_data.rds
AZ_raw_data.rds
CA_raw_data.rds
CO_raw_data.rds
CT_raw_data.rds
DC_raw_data.rds
DE_raw_data.rds
FL_raw_data.rds
GA_raw_data.rds
ID_raw_data.rds
IA_raw_data.rds
IL_raw_data.rds
IN_raw_data.rds
KS_raw_data.rds
KY_raw_data.rds
LA_raw_data.rds
ME_raw_data.rds
MD_raw_data.rds
MA_raw_data.rds
MI_raw_data.rds
MN_raw_data.rds
MS_raw_data.rds
MO_raw_data.rds
MT_raw_data.rds
NE_raw_data.rds
NV_raw_data.rds
NH_raw_data.rds
NJ_raw_data.rds
NM_raw_data.rds
NY_raw_data.rds
NC_raw_data.rds
ND_raw_data.rds
OH_raw_data.rds
OK_raw_data.rds
OR_raw_data.rds
PA_raw_data.rds
RI_raw_data.rds
SC_raw_data.rds
SD_raw_data.rds
TN_raw_data.rds
TX_raw_data.rds
UT_raw_data.rds
VT_raw_data.rds
VA_raw_data.rds
WA_raw_data.rds
WV_raw_data.rds
WI_raw_data.rds
WY_raw_data.rds
.Rdata
.httr-oauth
.DS_Store

#
_snaps
18 changes: 12 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Authors@R:
role = "aut"),
person(given = "Laura",
family = "Shumway",
role = "aut"),
person(given = "Elise",
family = "Hinman",
role = "aut"),
person(given = "Kathleen",
family = "Healy",
role = "aut")
)
Description: Assists data partners in performing automated assessments with
Expand All @@ -30,23 +36,23 @@ RoxygenNote: 7.2.3
Imports:
plyr,
data.table,
dataRetrieval,
dplyr,
ggplot2,
grDevices,
magrittr,
stringr,
utils,
RColorBrewer,
stats,
gganimate,
lubridate,
maps
maps,
dataRetrieval,
ggplot2,
gganimate,
gifski
Depends:
R (>= 3.5.0)
Suggests:
readr,
gifski,
rlang,
remotes,
tidyverse,
Expand All @@ -62,6 +68,6 @@ Suggests:
VignetteBuilder: knitr, rmarkdown
Language: en-US
Config/testthat/edition: 3
Config/testthat/load-all: list(export_all = FALSE, helpers = FALSE
Config/testthat/load-all: list(export_all = FALSE, helpers = FALSE)
URL: https://usepa.github.io/TADA/, https://github.com/USEPA/TADA
LazyData: true
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export(AggregatedContinuousData)
export(BelowNationalWQXLowerThreshold)
export(ConvertDepthUnits)
export(ConvertResultUnits)
export(CreateAnimatedMap)
export(FilterFieldReview)
export(FilterFields)
export(FilterParFieldReview)
Expand Down
43 changes: 33 additions & 10 deletions R/DataDiscoveryRetrieval.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#' to the "ResultMeasureValue" and "DetectionLimitMeasureValue" columns;
#' and to provide information about the result values that is needed to address
#' censored data later on (i.e., nondetections)
#'
#' Users can reference the \href{https://www.epa.gov/waterdata/storage-and-retrieval-and-water-quality-exchange-domain-services-and-downloads}{WQX domain tables}
#' to find allowable vales for queries, e.g., reference the WQX domain table to find countycode and statecode: https://cdx.epa.gov/wqx/download/DomainValues/County_CSV.zip
#' Alternatively, you can use the WQP services to find areas where data is available in the US: https://www.waterqualitydata.us/Codes/countycode
#'
#' See ?MeasureValueSpecialCharacters and ?autoclean documentation for more information.
#'
Expand All @@ -37,7 +41,7 @@
#' @param siteid Unique monitoring station identifier
#' @param siteType Type of waterbody
#' @param characteristicName Name of parameter
#' @param ActivityMediaName Sampling substrate such as water, air, or sediment
#' @param sampleMedia Sampling substrate such as water, air, or sediment
#' @param ProjectIdentifier A string of letters and/or numbers (some additional characters also possible) used to signify a project with data in the Water Quality Portal
#' @param OrganizationIdentifier A string of letters and/or numbers (some additional characters also possible) used to signify an organization with data in the Water Quality Portal
#' @param endDate End Date in the format YYYY-MM-DD
Expand All @@ -52,14 +56,32 @@
#' tada1 <- TADAdataRetrieval(statecode = "WI",
#' countycode = "Dane",
#' characteristicName = "Phosphorus")
#'
#' tada2 <- TADAdataRetrieval(ProjectIdentifier = "Anchorage Bacteria 20-21")
#'
#' tada3 <- TADAdataRetrieval(statecode = "UT",
#' characteristicName = c("Ammonia", "Nitrate", "Nitrogen"),
#' startDate = "10-01-2020")
#'
#' tada4 <- TADAdataRetrieval(statecode = "SC", countycode = "Abbeville")
#'
#' # countycode queries require a statecode
#' tada5 <- TADAdataRetrieval(countycode = "US:02:020")
#'
#' tada6 <- TADABigdataRetrieval(startDate = "2019-01-01",
#' endDate = "2021-12-31",
#' characteristicName = "Temperature, water",
#' statecode = c("AK","AL"))
#'
#' }
#'
TADAdataRetrieval <- function(statecode = "null",
startDate = "null",
countycode = "null",
siteid = "null",
siteType = "null",
characteristicName = "null",
ActivityMediaName = "null",
sampleMedia = "null",
ProjectIdentifier = "null",
OrganizationIdentifier = "null",
endDate = "null",
Expand Down Expand Up @@ -104,10 +126,10 @@ TADAdataRetrieval <- function(statecode = "null",
WQPquery <- c(WQPquery, characteristicName = characteristicName)
}

if (length(ActivityMediaName)>1) {
WQPquery <- c(WQPquery, ActivityMediaName = list(ActivityMediaName))
} else if (ActivityMediaName != "null") {
WQPquery <- c(WQPquery, ActivityMediaName = ActivityMediaName)
if (length(sampleMedia)>1) {
WQPquery <- c(WQPquery, sampleMedia = list(sampleMedia))
} else if (sampleMedia != "null") {
WQPquery <- c(WQPquery, sampleMedia = sampleMedia)
}

if (length(ProjectIdentifier)>1) {
Expand Down Expand Up @@ -151,6 +173,7 @@ TADAdataRetrieval <- function(statecode = "null",
Sites = sites.DR,
Narrow = narrow.DR,
Projects = projects.DR)

# run autoclean function
if(applyautoclean==TRUE){

Expand Down Expand Up @@ -270,7 +293,7 @@ TADAReadWQPWebServices <- function(webservice) {
#' @param startDate Start Date YYYY-MM-DD format, for example, "1995-01-01"
#' @param endDate end date in YYYY-MM-DD format, for example, "2020-12-31"
#' @param statecode Character/character vector. State/territory abbreviations from FIPS codes consist of two letters
#' @param huc An 8-digit numeric code denoting a hydrologic unit. Example: "04030202"
#' @param huc A numeric code denoting a hydrologic unit. Example: "04030202". Different size hucs can be entered.
#' @param characteristicName Name of water quality parameter
#' @param siteType Name of water body type (e.g., "Stream", "Lake, Reservoir, Impoundment")
#' @param sampleMedia Defaults to "Water". Refer to WQP domain tables for other options.
Expand Down Expand Up @@ -506,7 +529,7 @@ JoinWQPProfiles <- function(FullPhysChem = "null",
if(nrow(Sites.df)>0){
join1 <- FullPhysChem.df %>%
# join stations to results
dplyr::left_join(Sites.df, by = "MonitoringLocationIdentifier") %>%
dplyr::left_join(Sites.df, by = "MonitoringLocationIdentifier", multiple = "all") %>%
# remove ".x" suffix from column names
dplyr::rename_at(dplyr::vars(dplyr::ends_with(".x")), ~ stringr::str_replace(., "\\..$", "")) %>%
# remove columns with ".y" suffix
Expand Down Expand Up @@ -545,8 +568,8 @@ JoinWQPProfiles <- function(FullPhysChem = "null",
),
by = c(
"OrganizationIdentifier", "OrganizationFormalName",
"ProjectIdentifier","ProjectName"
)
"ProjectIdentifier","ProjectName"),
multiple = "all"
)
}else{join3 = join2}

Expand Down
9 changes: 5 additions & 4 deletions R/ResultFlagsIndependent.R
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,7 @@ QAPPDocAvailable <- function(.data, clean = FALSE) {
#'
#' # Remove data with imprecise coordinates or coordinates outside the USA from the dataframe:
#' InvalidCoord_removed <- InvalidCoordinates(Nutrients_Utah, clean_outsideUSA = "remove", clean_imprecise = TRUE)
#'

InvalidCoordinates <- function(.data,
clean_outsideUSA = c("no", "remove", "change sign"),
Expand All @@ -996,7 +997,7 @@ InvalidCoordinates <- function(.data,
checkType(clean_imprecise, "logical")
# check .data has required columns
checkColumns(.data, c("LatitudeMeasure", "LongitudeMeasure"))
#check lat and long are "numeric"
# check lat and long are "numeric"
if (class(.data$LongitudeMeasure) != "numeric") {
warning("LongitudeMeasure field must be numeric")
}
Expand All @@ -1017,7 +1018,7 @@ InvalidCoordinates <- function(.data,
LongitudeMeasure > 0 & LongitudeMeasure < 145 ~ "LONG_OutsideUSA",
grepl("999", LatitudeMeasure) ~ "Imprecise_Latincludes999",
grepl("999", LongitudeMeasure) ~ "Imprecise_Longincludes999",
#for below, lat and long fields must be numeric
# for below, lat and long fields must be numeric
# this checks if there are at least 3 significant figures to the
# right of the decimal point
sapply(.data$LatitudeMeasure, decimalplaces) < 3
Expand All @@ -1043,7 +1044,7 @@ InvalidCoordinates <- function(.data,

# if clean_outsideUSA is "change sign", change the sign of lat/long coordinates outside of USA
if (clean_outsideUSA == "change sign") {
print("Note: This is a temporary solution. Data owner should fix the raw data to address invalid coordinates through WQX. For assistance, email the WQX helpdesk ([email protected]).")
print("When clean_outsideUSA == change sign, the sign for any lat/long coordinates flagged as outside of USA are switched. This is a temporary solution. Data owners should fix the raw data to address invalid coordinates through WQX. For assistance fixing data errors you see in the WQP, email the WQX helpdesk ([email protected]).")
.data <- .data %>%
dplyr::mutate(
LatitudeMeasure = dplyr::case_when(
Expand All @@ -1055,7 +1056,7 @@ InvalidCoordinates <- function(.data,
)
}

#return only flagged data if errorsonly = true
# return only flagged data if errorsonly = true
if ((errorsonly == TRUE)) {
.data <- dplyr::filter(.data, is.na(TADA.InvalidCoordinates) != TRUE)
}
Expand Down
68 changes: 0 additions & 68 deletions R/Visualizations.R
Original file line number Diff line number Diff line change
@@ -1,71 +1,3 @@
#' @title Generate Animated Map
#'
#' @description
#' Animated map code adapted from USGS blog: https://waterdata.usgs.gov/blog/large_sample_pull/
#'
#' @param .data TADA dataframe
#'
#' @return Animated map
#'
#' @export
#'

CreateAnimatedMap <- function(.data) {

# code adapted from USGS blog: https://waterdata.usgs.gov/blog/large_sample_pull/

# pull the year from the date
.data$year <- base::format(as.Date(.data$ActivityStartDate, format="%Y-%m-%d"),"%Y")

# create new data frame of summarized result data by year
n_bysite <-
.data %>%
dplyr::group_by(MonitoringLocationIdentifier, LatitudeMeasure, LongitudeMeasure, year) %>%
dplyr::summarize(mean = mean(.data$ResultMeasureValue, na.rm = TRUE),
median = stats::median(.data$ResultMeasureValue, na.rm = TRUE))

# create a new character column with total nitrogen acceptable range designations
n_bysite <-
n_bysite %>% dplyr::mutate(TN_mean=
dplyr::case_when(mean<2 ~ "<2 mg/l",
mean>=2 & mean<=6 ~ "2-6 mg/l",
mean>6 ~ ">6 mg/l"))

# convert latitude, longitude, and year data to numeric form
n_bysite$LatitudeMeasure <- as.numeric(n_bysite$LatitudeMeasure)
n_bysite$LongitudeMeasure <- as.numeric(n_bysite$LongitudeMeasure)
n_bysite$year <- as.numeric(n_bysite$year)

# first, create the base map data frame
all_state <- "usa"

usa <- map_data("state", interior=TRUE)
base_map <- ggplot2::ggplot(data = usa, mapping = aes(x = long,
y = lat,
group = group)) +
ggplot2::geom_polygon(color = "black", fill = "white") +
ggplot2::coord_quickmap() +
ggplot2::theme_void()

# second, plot the base map and add data to it
map_with_data <- base_map +
ggplot2::geom_point(data = n_bysite, aes(x = LongitudeMeasure,
y = LatitudeMeasure,
color = TN_mean,
group = year,
frame = year)) +
gganimate::transition_time(year) +
ggplot2::ggtitle('Year: {frame_time}', # add year to the title
subtitle = 'Frame {frame} of {nframes}') +
ggplot2::scale_colour_manual(values = c("blue", "red", "green"))
num_years <- max(n_bysite$year)-min(n_bysite$year) + 1

# lastly, run the animation
gganimate::animate(map_with_data, nframes = num_years, fps = 1)

}


#' @title Generate Map
#'
#' @description
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE.html

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

4 changes: 2 additions & 2 deletions docs/articles/CONTRIBUTING.html

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/articles/index.html

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

Loading