Commit 4bc24ebd authored by Laura A DeCicco's avatar Laura A DeCicco
Browse files

Fail more gracefully...

parent f62b51b5
......@@ -230,12 +230,13 @@ valid_ask = function(all, type) {
#' # Find Features / Define origin features
#'
#' ## Find feature by COMID
#' if(!httr::http_error("https://labs.waterdata.usgs.gov/api/nldi/linked-data")){
#' findNLDI(comid = 101)
#'
#'
#' ## Find feature by NWIS ID
#' findNLDI(nwis = '11120000')
#'
#' ## Find feature by WQP ID
#' findNLDI(nwis = '11120000')
#'
#' ## Find feature by WQP ID
#' findNLDI(wqp = 'USGS-04024315')
#'
#' ## Find feature by LOCATION
......@@ -267,6 +268,7 @@ valid_ask = function(all, type) {
#' ## 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,
......
......@@ -18,7 +18,9 @@
#' property <- '00060'
#' obs_url <- constructNWISURL(siteNumber,property,startDate,endDate,'dv')
#' \donttest{
#' rawData <- getWebServiceData(obs_url)
#' if(!httr::http_error(obs_url)){
#' rawData <- getWebServiceData(obs_url)
#' }
#' }
getWebServiceData <- function(obs_url, ...){
......
......@@ -25,8 +25,9 @@
#' "observedProperty=urn:ogc:def:property:OGC:GroundWaterLevel",
#' "responseFormat=text/xml",
#' "featureOfInterest=VW_GWDP_GEOSERVER.USGS.403836085374401",sep="&")
#' data <- importNGWMN(obs_url)
#'
#' if(!httr::http_error(obs_url)){
#' data_returned <- importNGWMN(obs_url)
#' }
#' }
#'
importNGWMN <- function(input, asDateTime=FALSE, tz="UTC"){
......@@ -141,8 +142,10 @@ importNGWMN <- function(input, asDateTime=FALSE, tz="UTC"){
#' "statCd=00003",
#' "parameterCd=00060",sep="&")
#' \donttest{
#' timesereies <- importWaterML2(URL, asDateTime=TRUE, tz="UTC")
#' if(!httr::http_error(URL)){
#' timesereies <- importWaterML2(URL, asDateTime=TRUE, tz="UTC")
#' }
#' }
importWaterML2 <- function(input, asDateTime=FALSE, tz="UTC") {
returnedDoc <- check_if_xml(input)
......
......@@ -52,24 +52,34 @@
#' obs_url <- constructNWISURL(site_id,property,
#' startDate,endDate,"dv",format="tsv")
#' \donttest{
#' data <- importRDB1(obs_url)
#' if(!httr::http_error(obs_url)){
#' data <- importRDB1(obs_url)
#' }
#'
#' urlMultiPcodes <- constructNWISURL("04085427",c("00060","00010"),
#' startDate,endDate,"dv",statCd=c("00003","00001"),"tsv")
#' multiData <- importRDB1(urlMultiPcodes)
#' if(!httr::http_error(urlMultiPcodes)){
#' multiData <- importRDB1(urlMultiPcodes)
#' }
#' unitDataURL <- constructNWISURL(site_id,property,
#' "2020-10-30","2020-11-01","uv",format="tsv") #includes timezone switch
#' unitData <- importRDB1(unitDataURL, asDateTime=TRUE)
#' if(!httr::http_error(unitDataURL)){
#' unitData <- importRDB1(unitDataURL, asDateTime=TRUE)
#' }
#' qwURL <- constructNWISURL(c('04024430','04024000'),
#' c('34247','30234','32104','34220'),
#' "2010-11-03","","qw",format="rdb")
#' qwData <- importRDB1(qwURL, asDateTime=TRUE, tz="America/Chicago")
#' "2010-11-03","","qw",format="rdb")
#' if(!httr::http_error(qwURL)){
#' qwData <- importRDB1(qwURL, asDateTime=TRUE, tz="America/Chicago")
#' }
#' iceSite <- '04024000'
#' start <- "2015-11-09"
#' end <- "2015-11-24"
#' urlIce <- constructNWISURL(iceSite,"00060",start, end,"uv",format="tsv")
#' ice <- importRDB1(urlIce, asDateTime=TRUE)
#' iceNoConvert <- importRDB1(urlIce, convertType=FALSE)
#' if(!httr::http_error(urlIce)){
#' ice <- importRDB1(urlIce, asDateTime=TRUE)
#' iceNoConvert <- importRDB1(urlIce, convertType=FALSE)
#' }
#' }
#' # User file:
#' filePath <- system.file("extdata", package="dataRetrieval")
......
......@@ -22,13 +22,19 @@
#' \donttest{
#' rawSampleURL <- constructWQPURL('USGS-01594440','01075', '', '')
#'
#' rawSample <- importWQP(rawSampleURL)
#' if(!httr::http_error(rawSampleURL)){
#' rawSample <- importWQP(rawSampleURL)
#' }
#'
#' rawSampleURL_NoZip <- constructWQPURL('USGS-01594440','01075', '', '', zip=FALSE)
#' rawSample2 <- importWQP(rawSampleURL_NoZip, zip=FALSE)
#'
#' if(!httr::http_error(rawSampleURL_NoZip)){
#' rawSample2 <- importWQP(rawSampleURL_NoZip, zip=FALSE)
#' }
#' #'
#' STORETex <- constructWQPURL('WIDNR_WQX-10032762','Specific conductance', '', '')
#' STORETdata <- importWQP(STORETex)
#' if(!httr::http_error(STORETex)){
#' STORETdata <- importWQP(STORETex)
#' }
#' }
importWQP <- function(obs_url, zip=TRUE, tz="UTC",
csv=FALSE){
......
......@@ -115,7 +115,7 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz="UTC"){
timeSeries <- xml_find_all(returnedDoc, ".//ns1:timeSeries") #each parameter/site combo
#some intial attributes
#some initial attributes
queryNodes <- xml_children(xml_find_all(returnedDoc,".//ns1:queryInfo"))
notes <- queryNodes[xml_name(queryNodes)=="note"]
noteTitles <- xml_attrs(notes)
......@@ -124,7 +124,10 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz="UTC"){
names(noteList) <- noteTitles
if(0 == length(timeSeries)){
df <- data.frame()
df <- data.frame(agency_cd = character(),
site_no = character(),
dateTime = as.POSIXct(character()),
tz_cd = character())
attr(df, "queryInfo") <- noteList
if(!raw){
attr(df, "url") <- obs_url
......
......@@ -153,13 +153,17 @@ readNGWMNlevels <- function(siteNumbers, asDateTime = TRUE, tz = "UTC"){
#' @examples
#' \donttest{
#' #one site
#' site <- "USGS.430427089284901"
#' oneSite <- readNGWMNsites(siteNumbers = site)
#' if(!httr::http_error("https://cida.usgs.gov/ngwmn_cache")){
#' site <- "USGS.430427089284901"
#' oneSite <- readNGWMNsites(siteNumbers = site)
#' }
#'
#'
#' #non-USGS site
#' site <- "MBMG.103306"
#' siteInfo <- readNGWMNsites(siteNumbers = site)
#'
#' if(!httr::http_error("https://cida.usgs.gov/ngwmn_cache")){
#' site <- "MBMG.103306"
#' siteInfo <- readNGWMNsites(siteNumbers = site)
#' }
#' }
readNGWMNsites <- function(siteNumbers){
sites <- readNGWMNdata(siteNumbers = siteNumbers, service = "featureOfInterest")
......
......@@ -69,12 +69,13 @@ arguments: comid, nwis, huc12, wqp, location, and start.
# Find Features / Define origin features
## Find feature by COMID
if(!httr::http_error("https://labs.waterdata.usgs.gov/api/nldi/linked-data")){
findNLDI(comid = 101)
## Find feature by NWIS ID
findNLDI(nwis = '11120000')
findNLDI(nwis = '11120000')
## Find feature by WQP ID
## Find feature by WQP ID
findNLDI(wqp = 'USGS-04024315')
## Find feature by LOCATION
......@@ -107,4 +108,5 @@ arguments: comid, nwis, huc12, wqp, location, and start.
findNLDI(comid = 101, nav = "DM", find = c("nwis", "wqp", "flowlines"), distance_km = 50)
}
}
}
\keyword{nldi}
......@@ -26,6 +26,8 @@ offering <- '00003'
property <- '00060'
obs_url <- constructNWISURL(siteNumber,property,startDate,endDate,'dv')
\donttest{
rawData <- getWebServiceData(obs_url)
if(!httr::http_error(obs_url)){
rawData <- getWebServiceData(obs_url)
}
}
}
......@@ -32,8 +32,9 @@ obs_url <- paste("https://cida.usgs.gov/ngwmn_cache/sos?request=GetObservation",
"observedProperty=urn:ogc:def:property:OGC:GroundWaterLevel",
"responseFormat=text/xml",
"featureOfInterest=VW_GWDP_GEOSERVER.USGS.403836085374401",sep="&")
data <- importNGWMN(obs_url)
if(!httr::http_error(obs_url)){
data_returned <- importNGWMN(obs_url)
}
}
}
......@@ -64,24 +64,34 @@ property <- "00060"
obs_url <- constructNWISURL(site_id,property,
startDate,endDate,"dv",format="tsv")
\donttest{
data <- importRDB1(obs_url)
if(!httr::http_error(obs_url)){
data <- importRDB1(obs_url)
}
urlMultiPcodes <- constructNWISURL("04085427",c("00060","00010"),
startDate,endDate,"dv",statCd=c("00003","00001"),"tsv")
multiData <- importRDB1(urlMultiPcodes)
if(!httr::http_error(urlMultiPcodes)){
multiData <- importRDB1(urlMultiPcodes)
}
unitDataURL <- constructNWISURL(site_id,property,
"2020-10-30","2020-11-01","uv",format="tsv") #includes timezone switch
unitData <- importRDB1(unitDataURL, asDateTime=TRUE)
if(!httr::http_error(unitDataURL)){
unitData <- importRDB1(unitDataURL, asDateTime=TRUE)
}
qwURL <- constructNWISURL(c('04024430','04024000'),
c('34247','30234','32104','34220'),
"2010-11-03","","qw",format="rdb")
qwData <- importRDB1(qwURL, asDateTime=TRUE, tz="America/Chicago")
"2010-11-03","","qw",format="rdb")
if(!httr::http_error(qwURL)){
qwData <- importRDB1(qwURL, asDateTime=TRUE, tz="America/Chicago")
}
iceSite <- '04024000'
start <- "2015-11-09"
end <- "2015-11-24"
urlIce <- constructNWISURL(iceSite,"00060",start, end,"uv",format="tsv")
ice <- importRDB1(urlIce, asDateTime=TRUE)
iceNoConvert <- importRDB1(urlIce, convertType=FALSE)
if(!httr::http_error(urlIce)){
ice <- importRDB1(urlIce, asDateTime=TRUE)
iceNoConvert <- importRDB1(urlIce, convertType=FALSE)
}
}
# User file:
filePath <- system.file("extdata", package="dataRetrieval")
......
......@@ -32,13 +32,19 @@ Imports data from the Water Quality Portal based on a specified url.
\donttest{
rawSampleURL <- constructWQPURL('USGS-01594440','01075', '', '')
rawSample <- importWQP(rawSampleURL)
if(!httr::http_error(rawSampleURL)){
rawSample <- importWQP(rawSampleURL)
}
rawSampleURL_NoZip <- constructWQPURL('USGS-01594440','01075', '', '', zip=FALSE)
rawSample2 <- importWQP(rawSampleURL_NoZip, zip=FALSE)
if(!httr::http_error(rawSampleURL_NoZip)){
rawSample2 <- importWQP(rawSampleURL_NoZip, zip=FALSE)
}
#'
STORETex <- constructWQPURL('WIDNR_WQX-10032762','Specific conductance', '', '')
STORETdata <- importWQP(STORETex)
if(!httr::http_error(STORETex)){
STORETdata <- importWQP(STORETex)
}
}
}
\seealso{
......
......@@ -28,6 +28,8 @@ URL <- paste(baseURL, "sites=01646500",
"statCd=00003",
"parameterCd=00060",sep="&")
\donttest{
timesereies <- importWaterML2(URL, asDateTime=TRUE, tz="UTC")
if(!httr::http_error(URL)){
timesereies <- importWaterML2(URL, asDateTime=TRUE, tz="UTC")
}
}
}
......@@ -25,12 +25,16 @@ Retrieve site data from the National Ground Water Monitoring Network \url{https:
\examples{
\donttest{
#one site
site <- "USGS.430427089284901"
oneSite <- readNGWMNsites(siteNumbers = site)
if(!httr::http_error("https://cida.usgs.gov/ngwmn_cache")){
site <- "USGS.430427089284901"
oneSite <- readNGWMNsites(siteNumbers = site)
}
#non-USGS site
site <- "MBMG.103306"
siteInfo <- readNGWMNsites(siteNumbers = site)
if(!httr::http_error("https://cida.usgs.gov/ngwmn_cache")){
site <- "MBMG.103306"
siteInfo <- readNGWMNsites(siteNumbers = site)
}
}
}
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