Commit 6982ace4 authored by Laura A DeCicco's avatar Laura A DeCicco
Browse files

Adding dataProfile examples

parent aef0beac
......@@ -133,6 +133,54 @@
#' countycode="Lexington",
#' parameterCd = "00010")
#'
#' # Data profiles: "Organization Data"
#' org_data <- readWQPdata(statecode = "WI",
#' countycode = "Dane",
#' service = "Organization")
#'
#' # Data profiles: "Site Data Only"
#' site_data <- readWQPdata(statecode = "WI",
#' countycode = "Dane",
#' service = "Station")
#'
#' # Data profiles: "Project Data"
#' project_data <- readWQPdata(statecode = "WI",
#' countycode = "Dane",
#' service = "Project")
#'
#' # Data profiles: "Project Monitoring Location Weighting Data"
#' proj_mlwd <- readWQPdata(statecode = "WI",
#' countycode = "Dane",
#' service = "ProjectMonitoringLocationWeighting")
#'
#' # Data profiles: "Sample Results (physical/chemical metadata)":
#' samp_data <- readWQPdata(siteid = "USGS-04024315",
#' dataProfile = "resultPhysChem",
#' service = "Result")
#'
#' # Data profiles: "Sample Results (biological metadata)"
#' samp_bio <- readWQPdata(siteid="USGS-04024315",
#' dataProfile = "biological",
#' service = "Result")
#'
#' # Data profiles: "Sample Results (narrow)"
#' samp_narrow <- readWQPdata(siteid="USGS-04024315",
#' dataProfile = "narrowResult",
#' service = "Result")
#'
#' # Data profiles: "Sampling Activity"
#' samp_activity <- readWQPdata(siteid="USGS-04024315",
#' dataProfile = "activityAll",
#' service = "Activity")
#'
#' # Data profile: "Sampling Activity Metrics"
#' act_metrics <- readWQPdata(statecode = "WI",
#' countycode = "Dane",
#' service = "ActivityMetric")
#'
#' # Data profile: "Result Detection Quantitation Limit Data"
#' dl_data <- readWQPdata(siteid="USGS-04024315",
#' service = "ResultDetectionQuantitationLimit")
#' }
readWQPdata <- function(..., querySummary=FALSE, tz="UTC",
ignore_attributes = FALSE){
......@@ -177,33 +225,36 @@ readWQPdata <- function(..., querySummary=FALSE, tz="UTC",
siteInfo <- cbind(siteInfoCommon, siteInfo)
}
retvalVariableInfo <- retval[,c("CharacteristicName","USGSPCode",
"ResultMeasure.MeasureUnitCode","ResultSampleFractionText")]
retvalVariableInfo <- unique(retvalVariableInfo)
variableInfo <- data.frame(characteristicName=retval$CharacteristicName,
parameterCd=retval$USGSPCode,
param_units=retval$ResultMeasure.MeasureUnitCode,
valueType=retval$ResultSampleFractionText,
stringsAsFactors=FALSE)
attr(retval, "siteInfo") <- siteInfo
if(!anyNA(variableInfo$parameterCd)){
pcodes <- unique(variableInfo$parameterCd[!is.na(variableInfo$parameterCd)])
pcodes <- pcodes["" != pcodes]
paramINFO <- readNWISpCode(pcodes)
names(paramINFO)["parameter_cd" == names(paramINFO)] <- "parameterCd"
if(all(c("CharacteristicName","USGSPCode",
"ResultMeasure.MeasureUnitCode","ResultSampleFractionText") %in% names(retval))){
retvalVariableInfo <- retval[,c("CharacteristicName","USGSPCode",
"ResultMeasure.MeasureUnitCode","ResultSampleFractionText")]
retvalVariableInfo <- unique(retvalVariableInfo)
variableInfo <- data.frame(characteristicName=retval$CharacteristicName,
parameterCd=retval$USGSPCode,
param_units=retval$ResultMeasure.MeasureUnitCode,
valueType=retval$ResultSampleFractionText,
stringsAsFactors=FALSE)
pCodeToName <- pCodeToName
varExtras <- pCodeToName[pCodeToName$parm_cd %in% unique(variableInfo$parameterCd[!is.na(variableInfo$parameterCd)]),]
names(varExtras)[names(varExtras) == "parm_cd"] <- "parameterCd"
variableInfo <- merge(variableInfo, varExtras, by="parameterCd", all = TRUE)
variableInfo <- merge(variableInfo, paramINFO, by="parameterCd", all = TRUE)
variableInfo <- unique(variableInfo)
if(!anyNA(variableInfo$parameterCd)){
pcodes <- unique(variableInfo$parameterCd[!is.na(variableInfo$parameterCd)])
pcodes <- pcodes["" != pcodes]
paramINFO <- readNWISpCode(pcodes)
names(paramINFO)["parameter_cd" == names(paramINFO)] <- "parameterCd"
pCodeToName <- pCodeToName
varExtras <- pCodeToName[pCodeToName$parm_cd %in% unique(variableInfo$parameterCd[!is.na(variableInfo$parameterCd)]),]
names(varExtras)[names(varExtras) == "parm_cd"] <- "parameterCd"
variableInfo <- merge(variableInfo, varExtras, by="parameterCd", all = TRUE)
variableInfo <- merge(variableInfo, paramINFO, by="parameterCd", all = TRUE)
variableInfo <- unique(variableInfo)
}
attr(retval, "variableInfo") <- variableInfo
}
attr(retval, "siteInfo") <- siteInfo
attr(retval, "variableInfo") <- variableInfo
} else {
if(!ignore_attributes){
message("The following url returned no data:\n")
......
......@@ -23,7 +23,7 @@ readWQPdots <- function(...){
service <- "Result"
}
match.arg(service, c("Result", "Station", "Activity",
match.arg(service, c("Result", "Station", "Activity", "Organization",
"ActivityMetric", "SiteSummary",
"Project", "ProjectMonitoringLocationWeighting",
"ResultDetectionQuantitationLimit", "BiologicalMetric"))
......
......@@ -65,7 +65,8 @@ setAccess = function(access="public"){
pkg.env$ProjectMonitoringLocationWeighting = "https://www.waterqualitydata.us/data/ProjectMonitoringLocationWeighting/search"
pkg.env$ResultDetectionQuantitationLimit = "https://www.waterqualitydata.us/data/ResultDetectionQuantitationLimit/search"
pkg.env$BiologicalMetric = "https://www.waterqualitydata.us/data/BiologicalMetric/search"
pkg.env$Organization = "https://www.waterqualitydata.us/data/Organization/search"
pkg.env$NGWMN = "https://cida.usgs.gov/ngwmn_cache/sos"
}
......
......@@ -146,6 +146,54 @@ dailyLexingtonVA <- readWQPdata(statecode = "Virginia",
countycode="Lexington",
parameterCd = "00010")
# Data profiles: "Organization Data"
org_data <- readWQPdata(statecode = "WI",
countycode = "Dane",
service = "Organization")
# Data profiles: "Site Data Only"
site_data <- readWQPdata(statecode = "WI",
countycode = "Dane",
service = "Station")
# Data profiles: "Project Data"
project_data <- readWQPdata(statecode = "WI",
countycode = "Dane",
service = "Project")
# Data profiles: "Project Monitoring Location Weighting Data"
proj_mlwd <- readWQPdata(statecode = "WI",
countycode = "Dane",
service = "ProjectMonitoringLocationWeighting")
# Data profiles: "Sample Results (physical/chemical metadata)":
samp_data <- readWQPdata(siteid = "USGS-04024315",
dataProfile = "resultPhysChem",
service = "Result")
# Data profiles: "Sample Results (biological metadata)"
samp_bio <- readWQPdata(siteid="USGS-04024315",
dataProfile = "biological",
service = "Result")
# Data profiles: "Sample Results (narrow)"
samp_narrow <- readWQPdata(siteid="USGS-04024315",
dataProfile = "narrowResult",
service = "Result")
# Data profiles: "Sampling Activity"
samp_activity <- readWQPdata(siteid="USGS-04024315",
dataProfile = "activityAll",
service = "Activity")
# Data profile: "Sampling Activity Metrics"
act_metrics <- readWQPdata(statecode = "WI",
countycode = "Dane",
service = "ActivityMetric")
# Data profile: "Result Detection Quantitation Limit Data"
dl_data <- readWQPdata(siteid="USGS-04024315",
service = "ResultDetectionQuantitationLimit")
}
\dontshow{\}) # examplesIf}
}
......
......@@ -421,6 +421,77 @@ test_that("internal functions",{
})
test_that("profiles", {
# Data profiles: "Organization Data"
org_data <- readWQPdata(statecode = "WI",
countycode = "Dane",
service = "Organization")
expect_true(all(c("OrganizationIdentifier",
"OrganizationFormalName") %in% names(org_data)))
# Data profiles: "Site Data Only"
site_data <- readWQPdata(statecode = "WI",
countycode = "Dane",
service = "Station")
expect_true(all(c("ProviderName", "MonitoringLocationIdentifier") %in% names(site_data)))
# Data profiles: "Project Data"
project_data <- readWQPdata(statecode = "WI",
countycode = "Dane",
service = "Project")
expect_true(all(c("OrganizationIdentifier",
"OrganizationFormalName") %in% names(project_data)))
# Data profiles: "Project Monitoring Location Weighting Data"
proj_mlwd <- readWQPdata(statecode = "WI",
countycode = "Dane",
service = "ProjectMonitoringLocationWeighting")
expect_true(all(c("OrganizationIdentifier",
"OrganizationFormalName") %in% names(proj_mlwd)))
# Data profiles: "Sample Results (physical/chemical metadata)":
samp_data <- readWQPdata(siteid = "USGS-04024315",
dataProfile = "resultPhysChem",
service = "Result")
expect_true(all(c("OrganizationIdentifier",
"OrganizationFormalName") %in% names(samp_data)))
# Data profiles: "Sample Results (biological metadata)"
samp_bio <- readWQPdata(siteid="USGS-04024315",
dataProfile = "biological",
service = "Result")
expect_true(all(c("OrganizationIdentifier",
"OrganizationFormalName") %in% names(samp_bio)))
# Data profiles: "Sample Results (narrow)"
samp_narrow <- readWQPdata(siteid="USGS-04024315",
dataProfile = "narrowResult",
service = "Result")
expect_true(all(c("OrganizationIdentifier",
"OrganizationFormalName") %in% names(samp_narrow)))
# Data profiles: "Sampling Activity"
samp_activity <- readWQPdata(siteid="USGS-04024315",
dataProfile = "activityAll",
service = "Activity")
expect_true(all(c("OrganizationIdentifier",
"OrganizationFormalName") %in% names(samp_activity)))
# Data profile: "Sampling Activity Metrics"
act_metrics <- readWQPdata(statecode = "WI",
countycode = "Dane",
service = "ActivityMetric")
expect_true(all(c("OrganizationIdentifier",
"OrganizationFormalName") %in% names(act_metrics)))
# Data profile: "Result Detection Quantitation Limit Data"
dl_data <- readWQPdata(siteid="USGS-04024315",
service = "ResultDetectionQuantitationLimit")
expect_true(all(c("OrganizationIdentifier",
"OrganizationFormalName") %in% names(dl_data)))
})
test_that("readWQPsummary", {
testthat::skip_on_cran()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment