Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New defaults #733

Merged
merged 20 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 18 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
15 changes: 9 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
Package: dataRetrieval
Type: Package
Title: Retrieval Functions for USGS and EPA Hydrology and Water Quality Data
Version: 2.7.16.1
Version: 2.7.17
Authors@R: c(
person("Laura", "DeCicco", role = c("aut","cre"),
email = "[email protected]",
comment=c(ORCID="0000-0002-3915-9487")),
person("Robert", "Hirsch", role = c("aut"),
comment=c(ORCID="0000-0002-4534-075X")),
comment=c(ORCID = "0000-0002-4534-075X")),
person("David","Lorenz", role=c("aut")),
person("Jordan", "Read", role = c("ctb")),
person("Jordan", "Walker", role = c("ctb")),
person("Lindsay","Platt", role=c("ctb")),
person("David","Watkins", role=c("aut"),
email = "[email protected]",
comment=c(ORCID="0000-0002-7544-0700")),
comment=c(ORCID = "0000-0002-7544-0700")),
person("David", "Blodgett", role="aut",
comment=c(ORCID="0000-0001-9489-1710"),
comment=c(ORCID = "0000-0001-9489-1710"),
email = "[email protected]"),
person("Mike", "Johnson", role=c("aut"),
email = "[email protected]",
comment=c(ORCID="0000-0002-5288-8350")),
comment=c(ORCID = "0000-0002-5288-8350")),
person("Aliesha", "Krall", role="ctb",
email = "[email protected]",
comment=c(ORCID="0000-0003-2521-5043")))
comment=c(ORCID = "0000-0003-2521-5043")),
person("Lee", "Stanish", role="ctb",
email = "[email protected]",
comment=c(ORCID = "0000-0002-9775-6861")))
Description: Collection of functions to help retrieve U.S. Geological Survey
and U.S. Environmental Protection Agency water quality and
hydrology data from web services. Data are discovered from
Expand Down
8 changes: 5 additions & 3 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
dataRetrieval 2.7.16.1
dataRetrieval 2.7.17
===================
* Fixed bug with server problems causing errors.
* Added message of service URL.
* Removed the forced "empty returns" for WQP, since the WQP now has properly formatted empty returns.
* Moved the column parsing to a dedicated function for WQP.
* Took out zip option for WQP calls, they are not allowed on WQP anymore.
* Deprecated getQuerySummary. Users should use readWQPsummary instead.
* Added WQX 3.0 profiles
* Added deprecated message getQuerySummary. Users should use readWQPsummary instead.
* Added WQX 3.0 profiles.
* siteInfo attribute for WQP queries converted to a full station return.
* Cleaned up date conversion in WQP
* Updated source for groundwater level data from waterservices to waterdata. Note that waterdata services will ALSO need updating within the next year, but this change will allow for some time to make changes.
Expand Down
23 changes: 4 additions & 19 deletions R/AAA.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,13 @@ is_dataRetrieval_user <- function() {
identical(Sys.getenv("NOT_CRAN"), "true")
}


wqp_message_only_legacy <- function(){
message("NEWS: Legacy profile requested, and no equivalent/similar WQX 3.0
profile currently exists. Legacy profiles do not include USGS data newer
than March 11, 2024.
More details:
wqp_message <- function(){
message("NEWS: Data does not include USGS data newer than March 11, 2024. More details:
https://doi-usgs.github.io/dataRetrieval/articles/Status.html")
}

wqp_message <- function(){
message("NEWS: Legacy data profiles will be retired. Please begin converting
workflows to the WQX 3.0 profiles. Also, data from legacy profiles do not
include USGS data newer than March 11, 2024. More details:
https://doi-usgs.github.io/dataRetrieval/articles/Status.html")
wqp_message_beta <- function(){
message("WQX3 services are in-development, use with caution.")
}

only_legacy <- function(service){
Expand All @@ -52,14 +45,6 @@ is_legacy <- function(service){
return(legacy)
}

wqp_message_now <- function(service){
if(only_legacy(service)){
return(wqp_message_only_legacy())
} else if (service %in% c("Result", "Station", "Activity")){
return(wqp_message())
}
}

nwis_message <- function(){
return("WARNING: NWIS does not deliver
discrete water quality data newer than March 11, 2024
Expand Down
3 changes: 2 additions & 1 deletion R/constructNWISURL.R
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ constructNWISURL <- function(siteNumbers,
#' retrieval for the earliest possible record.
#' @param endDate character ending date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates
#' retrieval for the latest possible record.
#' @param legacy Logical. If TRUE, uses legacy WQP services. Default is FALSE.
#' @param legacy Logical. If TRUE, uses legacy WQP services. Default is TRUE.
#' Setting legacy = FALSE uses WQX3.0 WQP services, which are in-development, use with caution.
#' @keywords data import WQP web service
#' @return url string
#' @export
Expand Down
2 changes: 1 addition & 1 deletion R/getWebServiceData.R
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ has_internet_2 <- function(obs_url) {
#'
#' @param url the query url
getQuerySummary <- function(url) {
wqp_message_only_legacy()
wqp_message()
queryHEAD <- httr::HEAD(url)
retquery <- httr::headers(queryHEAD)

Expand Down
95 changes: 37 additions & 58 deletions R/readWQPdata.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,9 @@
#'
#' @details
#'
#' There are currently 10 legacy and 4 modern WQX options
#' There are currently 10 legacy options
#' for data provided by the Water Quality Portal:
#'
#' WQX:
#' \tabular{llll}{
#' WQP Radio Button \tab service argument \tab Base URL \tab dataProfile \cr
#' Monitoring Locations \tab StationWQX3 \tab /wqx3/Station/search \tab \cr
#' Full Physical Chemical \tab ResultWQX3 \tab /wqx3/Result/search \tab fullPhysChem \cr
#' Narrow \tab ResultWQX3 \tab /wqx3/Result/search \tab narrow \cr
#' Basic Physical Chemical \tab ResultWQX3 \tab /wqx3/Result/search \tab basicPhysChem \cr
#' Sampling Activity \tab ActivityWQX3 \tab /wqx3/Activity/search \cr
#' }
#'
#' Legacy:
#' \tabular{lll}{
Expand All @@ -37,6 +28,18 @@
#' Organization Data \tab Organization \tab /data/Organization/search \cr
#' }
#'
#' There are 4 WQX3 options. These are still in-development,
#' and should be used with caution.
#'
#' \tabular{llll}{
#' WQP Radio Button \tab service argument \tab Base URL \tab dataProfile \cr
#' Monitoring Locations \tab StationWQX3 \tab /wqx3/Station/search \tab \cr
#' Full Physical Chemical \tab ResultWQX3 \tab /wqx3/Result/search \tab fullPhysChem \cr
#' Narrow \tab ResultWQX3 \tab /wqx3/Result/search \tab narrow \cr
#' Basic Physical Chemical \tab ResultWQX3 \tab /wqx3/Result/search \tab basicPhysChem \cr
#' Sampling Activity \tab ActivityWQX3 \tab /wqx3/Activity/search \cr
#' }
#'
#'
#' @param \dots see \url{https://www.waterqualitydata.us/webservices_documentation} for a complete list of options.
#' A list of arguments can also be supplied. For more information see the above
Expand Down Expand Up @@ -82,36 +85,14 @@
#' @export
#' @examplesIf is_dataRetrieval_user()
#' \donttest{
#'
#' nameToUse <- "pH"
#' pHData <- readWQPdata(siteid = "USGS-04024315",
#' characteristicName = nameToUse)
#' ncol(pHData)
#' attr(pHData, "url")
#' attr(pHData, "siteInfo")
#' attr(pHData, "headerInfo")[["dataProviders"]]
#' attr(pHData, "queryTime")
#'
#' # dataProfile = Basic Physical Chemical
#' pHData_basic <- readWQPdata(siteid = "USGS-04024315",
#' characteristicName = nameToUse,
#' dataProfile = "basicPhysChem")
#' attr(pHData_basic, "url")
#' ncol(pHData_basic)
#'
#' # dataProfile = Narrow
#' pHData_narrow <- readWQPdata(siteid = "USGS-04024315",
#' characteristicName = nameToUse,
#' dataProfile = "narrow")
#' attr(pHData_narrow, "url")
#' ncol(pHData_narrow)
#'
#' # Data profiles: "Site Data Only"
#' site_data <- readWQPdata(
#' statecode = "WI",
#' countycode = "Dane",
#' service = "StationWQX3"
#' )
#'
#' # More examples:
#' # querying by county
#' DeWitt <- readWQPdata(
Expand All @@ -123,83 +104,82 @@
#' # Data profile: "Sampling Activity"
#' activity <- readWQPdata(
#' siteid = "USGS-04024315",
#' service = "ActivityWQX3"
#' service = "Activity"
#' )
#'
#' Dane_activity <- readWQPdata(
#' statecode = "Wisconsin",
#' countycode = "Dane",
#' startDateLo = "2023-01-01",
#' startDateHi = "2023-12-31",
#' service = "ActivityWQX3"
#' service = "Activity"
#' )
#'
#' ########################################################
#' # Legacy examples:
#' # Additional examples:
#'
#' pHData_legacy <- readWQPdata(siteid = "USGS-04024315",
#' characteristicName = nameToUse,
#' service = "Result",
#' dataProfile = "narrowResult")
#' attr(pHData_legacy, "url")
#'
#' # Data profiles: "Organization Data" (legacy)
#'
#' # Data profiles: "Organization Data"
#' org_data <- readWQPdata(
#' statecode = "WI",
#' countycode = "Dane",
#' service = "Organization"
#' )
#'
#' # Data profiles: "Project Data" (legacy)
#' # Data profiles: "Project Data"
#' project_data <- readWQPdata(
#' statecode = "WI",
#' countycode = "Dane",
#' service = "Project"
#' )
#'
#' # Data profiles: "Project Monitoring Location Weighting Data" (legacy)
#' # Data profiles: "Project Monitoring Location Weighting Data"
#' proj_mlwd <- readWQPdata(
#' statecode = "WI",
#' countycode = "Dane",
#' service = "ProjectMonitoringLocationWeighting"
#' )
#'
#' # Data profiles: "Sample Results (physical/chemical metadata)" (legacy)
#' # Data profiles: "Sample Results (physical/chemical metadata)"
#' samp_data <- readWQPdata(
#' siteid = "USGS-04024315",
#' dataProfile = "resultPhysChem",
#' service = "Result"
#' )
#'
#' # Data profiles: "Sample Results (biological metadata)" (legacy)
#' # Data profiles: "Sample Results (biological metadata)"
#' samp_bio <- readWQPdata(
#' siteid = "USGS-04024315",
#' dataProfile = "biological",
#' service = "Result"
#' )
#'
#' # Data profiles: "Sample Results (narrow)" (legacy)
#' # Data profiles: "Sample Results (narrow)"
#' samp_narrow <- readWQPdata(
#' siteid = "USGS-04024315",
#' service = "Result",
#' dataProfile = "narrowResult"
#' )
#'
#' # Data profiles: "Sampling Activity" (legacy)
#' # Data profiles: "Sampling Activity"
#' samp_activity <- readWQPdata(
#' siteid = "USGS-04024315",
#' dataProfile = "activityAll",
#' service = "Activity"
#' )
#'
#' # Data profile: "Sampling Activity Metrics" (legacy)
#' # Data profile: "Sampling Activity Metrics"
#' act_metrics <- readWQPdata(
#' statecode = "WI",
#' countycode = "Dane",
#' service = "ActivityMetric"
#' )
#'
#' # Data profile: "Result Detection Quantitation Limit Data" (legacy)
#' # Data profile: "Result Detection Quantitation Limit Data"
#' dl_data <- readWQPdata(
#' siteid = "USGS-04024315",
#' service = "ResultDetectionQuantitationLimit"
Expand All @@ -215,7 +195,7 @@
#' )
#' }
readWQPdata <- function(...,
service = "ResultWQX3",
service = "Result",
querySummary = FALSE,
tz = "UTC",
ignore_attributes = FALSE,
Expand All @@ -240,9 +220,7 @@ readWQPdata <- function(...,
baseURL <- drURL(service, arg.list = values)

baseURL <- appendDrURL(baseURL, mimeType = "csv")

wqp_message_now(service)


if(!legacy){
if(service == "ResultWQX3" & !"dataProfile" %in% names(values)){
baseURL <- appendDrURL(baseURL, dataProfile = "fullPhysChem")
Expand All @@ -264,19 +242,21 @@ readWQPdata <- function(...,

attr(retval, "legacy") <- legacy

if(!legacy){
attr(retval, "wqp-request-id") <- attr(retval, "headerInfo")$`wqp-request-id`
}

if (!all(is.na(retval)) && !ignore_attributes) {
params <- list(...)
params <- params[!names(params) %in% c("dataProfile", "service")]
retval <- create_WQP_attributes(retval, params)

}

attr(retval, "url") <- baseURL


if(legacy){
wqp_message()
} else {
wqp_message_beta()
attr(retval, "wqp-request-id") <- attr(retval, "headerInfo")$`wqp-request-id`
}

return(retval)
}
}
Expand All @@ -296,7 +276,6 @@ create_WQP_attributes <- function(retval, ...){
attr(retval, "queryTime") <- Sys.time()
}

#If WQP adds a parameter metadata service/files, we could add that here.
return(retval)
}

Expand Down
14 changes: 9 additions & 5 deletions R/readWQPqw.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
#' numerics based on a standard algorithm. If false, everything is returned as a character.
#' @param ignore_attributes logical to choose to ignore fetching site and parameter
#' attributes. Default is \code{FALSE}.
#' @param legacy Logical. If TRUE, use legacy WQP services. Default is FALSE.
#' @param legacy Logical. If TRUE, uses legacy WQP services. Default is TRUE.
#' Setting legacy = FALSE uses WQX3.0 WQP services, which are in-development, use with caution.
#' @keywords data import USGS web service
#' @return A data frame derived from the default data profile.
#'
Expand All @@ -52,10 +53,9 @@
#' \donttest{
#' rawPcode <- readWQPqw("USGS-01594440", "01075", "", "")
#'
#' attr(rawPcode, "url")
#' attr(rawPcode, "siteInfo")
#' attr(rawPcode, "queryTime")
#' attr(rawPcode, "headerInfo")[["dataProviders"]]
#'
#'
#' rawCharacteristicName <- readWQPqw("WIDNR_WQX-10032762", "Specific conductance", "", "")
#' rawPHsites <- readWQPqw(c("USGS-05406450", "USGS-05427949", "WIDNR_WQX-133040"), "pH", "", "")
Expand All @@ -68,7 +68,7 @@ readWQPqw <- function(siteNumbers,
startDate = "",
endDate = "",
tz = "UTC",
legacy = FALSE,
legacy = TRUE,
querySummary = FALSE,
ignore_attributes = FALSE,
convertType = TRUE) {
Expand All @@ -88,7 +88,6 @@ readWQPqw <- function(siteNumbers,

if(legacy){
sites <- unique(retval$MonitoringLocationIdentifier)
wqp_message()
} else {
sites <- unique(retval$Location_Identifier)
}
Expand All @@ -97,6 +96,11 @@ readWQPqw <- function(siteNumbers,
retval <- create_WQP_attributes(retval, siteid = sites)
}

if(legacy){
wqp_message()
} else {
wqp_message_beta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this one need wqp_message_beta()?

}
attr(retval, "url") <- url

return(retval)
Expand Down
Loading
Loading