Commit 8bf08357 authored by Laura A DeCicco's avatar Laura A DeCicco
Browse files

Adding parameter to readNWISgwl

parent 07a8309f
Package: dataRetrieval
Type: Package
Title: Retrieval Functions for USGS and EPA Hydrologic and Water Quality Data
Version: 2.7.6.9003
Version: 2.7.7
Authors@R: c(
person("Laura", "DeCicco", role = c("aut","cre"),
email = "ldecicco@usgs.gov",
......
dataRetrieval 2.7.6
dataRetrieval 2.7.7
==================
* The NLDI service is now available through the `findNLDI` function.
* Adjusted Water Quality Portal (WPQ) URLs to follow new structure
......@@ -6,6 +6,7 @@ dataRetrieval 2.7.6
* Added an argument to readWQPdata to ignore fetching site and parameter attributes.
* Fixed timezone bug in RDB requests that had mixed timezones.
* Updated internal data for parameter codes
* Added parameterCd argument to readNWISgwl as the services had changed
dataRetrieval 2.7.5
==========
......
......@@ -85,7 +85,13 @@ calcWaterYear <- function(dateVec){
},
error = function(e){
date_vec <- as.Date(dateVec)
date_vec <- tryCatch({
as.Date(dateVec)
},
error = function(e){
return(rep(NA, length(dateVec)))
})
if(any(is.na(date_vec))){
dateVec <- as.character(dateVec)
......
......@@ -208,7 +208,7 @@ constructNWISURL <- function(siteNumbers,parameterCd="00060",startDate="",endDat
},
rdb = {
if("gwlevels" == service){
"rdb"
"rdb,3.0"
} else {
"rdb,1.0"
}
......@@ -232,7 +232,7 @@ constructNWISURL <- function(siteNumbers,parameterCd="00060",startDate="",endDat
url <- appendDrURL(baseURL, site=siteNumbers, format=formatURL)
if("gwlevels"!= service){
if(!is.na(parameterCd)){
url <- appendDrURL(url, ParameterCd=parameterCd)
}
......
......@@ -17,8 +17,9 @@ tc <- function(x) {
#' @importFrom httr RETRY content
#' @importFrom jsonlite fromJSON
#' @examples
#' \donttest{
#' get_nldi_sources()
#' }
get_nldi_sources <- function() {
res <-
httr::RETRY("GET",
......@@ -53,14 +54,13 @@ get_nldi_sources <- function() {
#' @importFrom httr content RETRY
#' @importFrom jsonlite fromJSON
#' @examples
#' \dontrun{
#' \donttest{
#' base = "https://labs.waterdata.usgs.gov/api/nldi/linked-data/"
#' get_nldi(paste0(base, "comid/101"), type = "feature", use_sf = FALSE)
#' get_nldi(paste0(base, "comid/101"), type = "feature", use_sf = TRUE)
#' get_nldi(url = paste0(base, "nwissite/USGS-11120000"), type = "feature", use_sf = TRUE)
#' get_nldi(paste0(base, "nwissite/USGS-11120000"), type = "feature", use_sf = TRUE)
#' }
get_nldi = function(url, type = "", use_sf = FALSE){
# The features names are different across features, navigation, and basin returns
......@@ -144,7 +144,6 @@ get_nldi = function(url, type = "", use_sf = FALSE){
#' @return the input object with potentially modified identifiers
#' @keywords nldi internal
#' @noRd
clean_nwis_ids = function(tmp) {
# If data.frame, and of type NWIS, then strip "USGS-" from identifiers
if (is.data.frame(tmp)) {
......@@ -167,10 +166,9 @@ clean_nwis_ids = function(tmp) {
#' @keywords nldi internal
#' @noRd
#' @examples
#' \dontrun{
#' \donttest{
#' valid_ask(all = get_nldi_sources(), "nwis")
#' }
valid_ask = function(all, type){
# those where the requested pattern is included in a nldi_source ...
# means we will catch nwis - not just nwissite ...
......@@ -219,7 +217,7 @@ valid_ask = function(all, type){
#' @export
#' @keywords nldi
#' @examples
#'
#' \donttest{
#' # Find Features / Define origin features
#'
#' ## Find feature by COMID
......@@ -259,8 +257,7 @@ valid_ask = function(all, type){
#' # Control Distance
#' ## Limit search to 50 km
#' findNLDI(comid = 101, nav = "DM", find = c("nwis", "wqp", "flowlines"), distance_km = 50)
#'}
findNLDI <- function(comid = NULL,
nwis = NULL,
wqp = NULL,
......
......@@ -365,6 +365,7 @@ readNWISmeas <- function (siteNumbers,startDate="",endDate="", tz="UTC", expande
#' 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 parameterCd character USGS parameter code. This is usually an 5 digit number. Default is "".
#' @param convertType logical, defaults to \code{TRUE}. If \code{TRUE}, the function will convert the data to dates, datetimes,
#' numerics based on a standard algorithm. If false, everything is returned as a character
#' @param tz character to set timezone attribute of dateTime. Default is "UTC", and converts the
......@@ -402,17 +403,22 @@ readNWISmeas <- function (siteNumbers,startDate="",endDate="", tz="UTC", expande
#' @examples
#' site_id <- "434400121275801"
#' \donttest{
#' data <- readNWISgwl(site_id, '','')
#' data <- readNWISgwl(site_id)
#' sites <- c("434400121275801", "375907091432201")
#' data2 <- readNWISgwl(site_id, '','')
#' data3 <- readNWISgwl("420125073193001", '','')
#' #handling of data where date has no day
#' data4 <- readNWISgwl("425957088141001", startDate = "1980-01-01")
#'
#' data5 <- readNWISgwl("263819081585801", parameterCd = "72019")
#'
#' }
readNWISgwl <- function (siteNumbers,startDate="",endDate="", convertType = TRUE, tz="UTC"){
readNWISgwl <- function(siteNumbers, startDate = "", endDate = "",
parameterCd = NA,
convertType = TRUE, tz = "UTC"){
url <- constructNWISURL(siteNumbers,NA,startDate,endDate,"gwlevels",format="tsv")
data <- importRDB1(url,asDateTime=TRUE, convertType = convertType, tz=tz)
url <- constructNWISURL(siteNumbers, parameterCd, startDate,endDate,"gwlevels",format="rdb")
data <- importRDB1(url, asDateTime= TRUE, convertType = convertType, tz=tz)
if(nrow(data) > 0 && !all(is.na(data$lev_dt))){
if(convertType){
......
......@@ -5,12 +5,13 @@ bibentry(bibtype = "Manual",
as.person("Laura A. De Cicco"),
as.person("David Lorenz"),
as.person("Robert M. Hirsch"),
as.person("William Watkins")
as.person("William Watkins"),
as.person("Mike Johnson")
),
title = "dataRetrieval: R packages for discovering and retrieving water data available from U.S. federal hydrologic web services",
publisher = "U.S. Geological Survey",
address="Reston, VA",
version = "2.7.6",
version = "2.7.7",
institution = "U.S. Geological Survey",
year = 2018,
doi = "10.5066/P9X4L3GE",
......
......@@ -63,7 +63,7 @@ navigated paths. Valid starting options can be given by one of the following
arguments: comid, nwis, huc12, wqp, location, and start.
}
\examples{
\donttest{
# Find Features / Define origin features
## Find feature by COMID
......@@ -104,4 +104,5 @@ arguments: comid, nwis, huc12, wqp, location, and start.
## Limit search to 50 km
findNLDI(comid = 101, nav = "DM", find = c("nwis", "wqp", "flowlines"), distance_km = 50)
}
}
\keyword{nldi}
......@@ -13,6 +13,8 @@ data.frame
Used to query the current resources available through the NLDI
}
\examples{
\donttest{
get_nldi_sources()
}
}
\keyword{nldi}
......@@ -8,6 +8,7 @@ readNWISgwl(
siteNumbers,
startDate = "",
endDate = "",
parameterCd = NA,
convertType = TRUE,
tz = "UTC"
)
......@@ -21,6 +22,8 @@ retrieval for the earliest possible record.}
\item{endDate}{character ending date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates
retrieval for the latest possible record.}
\item{parameterCd}{character USGS parameter code. This is usually an 5 digit number. Default is "".}
\item{convertType}{logical, defaults to \code{TRUE}. If \code{TRUE}, the function will convert the data to dates, datetimes,
numerics based on a standard algorithm. If false, everything is returned as a character}
......@@ -66,12 +69,15 @@ See \url{https://waterservices.usgs.gov/rest/GW-Levels-Service.html} for more in
\examples{
site_id <- "434400121275801"
\donttest{
data <- readNWISgwl(site_id, '','')
data <- readNWISgwl(site_id)
sites <- c("434400121275801", "375907091432201")
data2 <- readNWISgwl(site_id, '','')
data3 <- readNWISgwl("420125073193001", '','')
#handling of data where date has no day
data4 <- readNWISgwl("425957088141001", startDate = "1980-01-01")
data5 <- readNWISgwl("263819081585801", parameterCd = "72019")
}
}
\seealso{
......
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