Skip to content

Commit

Permalink
Merge pull request #337 from USEPA/cristinamullin-updates
Browse files Browse the repository at this point in the history
Contributing files, depth unit conversion update
  • Loading branch information
cristinamullin committed Sep 6, 2023
2 parents 5fcd3f5 + a6a6020 commit 1d4292f
Show file tree
Hide file tree
Showing 21 changed files with 797 additions and 1,723 deletions.
255 changes: 146 additions & 109 deletions R/Figures.R

Large diffs are not rendered by default.

38 changes: 22 additions & 16 deletions R/GenerateRefTables.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ TADA_GetWQXCharValRef <- function() {
# # Convert all NONE to NA in Value and Value.Unit columns
# WQXcharValRef = WQXcharValRef %>% dplyr::mutate(Value = replace(Value, Value%in%c("NONE"),NA),
# Value.Unit = replace(Value.Unit, Value.Unit%in%c("NONE"),NA)) %>% dplyr::distinct()
#
#

# Save updated table in cache
WQXCharValRef_Cached <- WQXcharValRef

Expand Down Expand Up @@ -248,15 +248,20 @@ TADA_GetDetCondRef <- function() {

# If the download failed fall back to internal data (and report it)
if (is.null(raw.data)) {
message("Downloading latest Measure Unit Reference Table failed!")
message("Downloading latest Result Detection Condition Reference Table failed!")
message("Falling back to (possibly outdated) internal file.")
return(utils::read.csv(system.file("extdata", "WQXResultDetectionConditionRef.csv", package = "TADA")))
}

# Add detection type for all domain values. New domains are automatically assigned to the
# Non-Detect category. Review this closely when updating the reference table when new domains are added.
WQXDetCondRef <- raw.data %>%
dplyr::mutate(TADA.Detection_Type = dplyr::case_when(
Name %in% c("Above Operating Range", "Present Above Quantification Limit") ~ as.character("Over-Detect"),
Name %in% c("Value Decensored", "Reported in Raw Data (attached)", "High Moisture") ~ as.character("Other"),
Name %in% c(
"Value Decensored", "Reported in Raw Data (attached)", "High Moisture",
"Unable to Measure"
) ~ as.character("Other"),
TRUE ~ as.character("Non-Detect")
)) %>%
dplyr::distinct()
Expand Down Expand Up @@ -469,15 +474,17 @@ TADA_GetActivityTypeRef <- function() {
TRUE ~ as.character("Non_QC")
)) %>%
dplyr::distinct()

# Hard-code add activity types from NWIS
## Add USGS limits not in WQX domain table
new.atcs = data.frame(Code = c("Quality Control Sample-Blind", "Unknown"),
Description = c("Hard-coded activity type not in WQX domain","Hard-coded activity type not in WQX domain"),
TADA.ActivityType.Flag = c("QC_duplicate","Non_QC"),
Last.Change.Date = rep("8/11/2023 12:00:00 PM",2))

WQXActivityTypeRef = plyr::rbind.fill(WQXActivityTypeRef, new.atcs)
new.atcs <- data.frame(
Code = c("Quality Control Sample-Blind", "Unknown"),
Description = c("Hard-coded activity type not in WQX domain", "Hard-coded activity type not in WQX domain"),
TADA.ActivityType.Flag = c("QC_duplicate", "Non_QC"),
Last.Change.Date = rep("8/11/2023 12:00:00 PM", 2)
)

WQXActivityTypeRef <- plyr::rbind.fill(WQXActivityTypeRef, new.atcs)

# Save updated table in cache
WQXActivityTypeRef_Cached <- WQXActivityTypeRef
Expand Down Expand Up @@ -605,7 +612,7 @@ TADA_GetMeasureQualifierCodeRef <- function() {
"RPO", "S2", "SCA", "SCF", "SCP", "SCX", "SD%EL", "SDROL", "SSR",
"SUS", "V", "^", "F", "FEQ", "G", "UDL", "MDL"
)
keep <- c(
pass <- c(
"&", ")", "*", "=", "A", "AC", "AL", "ALK", "ALT",
"AP", "B", "BAC", "C25", "CAJ", "CBG", "CBL", "CC",
"CDI", "CG", "CKB", "CKBJ", "CKG", "CKJ", "CLC", "CNT", "CON", "CUG",
Expand All @@ -617,7 +624,7 @@ TADA_GetMeasureQualifierCodeRef <- function() {
"O", "OA3", "OS3", "OTHER", "OUT", "PB", "PK", "PPD", "PQL", "PRE",
"QCI", "RC", "REX", "RIN", "RLRS", "RMAX", "RNAF", "RP",
"RPDX", "RR", "RV", "RVB", "SBB", "SLB", "SM", "SS", "SSRV", "T",
"TMLF", "TOC", "TT", "UNC", "VS", "VVRR", "VVRR2", "UDQ"
"TMLF", "TOC", "TT", "UNC", "VS", "VVRR", "VVRR2", "UDQ", "ZZ"
)
nondetect <- c("BQL", "2-5B", "RNON", "U", "LTGTE", "K", "IDL", "<2B", "BRL", "D>T", "DL")
overdetect <- c("E", "EE", "GT")
Expand All @@ -627,10 +634,9 @@ TADA_GetMeasureQualifierCodeRef <- function() {
Code %in% nondetect ~ "Non-Detect",
Code %in% overdetect ~ "Over-Detect",
Code %in% suspect ~ "Suspect",
Code %in% keep ~ "Pass",
Code %in% pass ~ "Pass",
Code %in% NA ~ "Pass",
TRUE ~ as.character("Non-Detect"),
TRUE ~ as.character("Over-Detect")
TRUE ~ as.character("NewValue_NeedsReview")
)) %>%
dplyr::distinct()

Expand Down
Loading

0 comments on commit 1d4292f

Please sign in to comment.