Skip to content
Snippets Groups Projects
Commit d94e47b1 authored by Laura A DeCicco's avatar Laura A DeCicco
Browse files

Fixes #141

parent 7ac40462
No related branches found
No related tags found
1 merge request!142No data
......@@ -32,6 +32,10 @@ getWebServiceData <- function(obs_url){
if(headerInfo['status'] != "200"){
stop("Status:", headerInfo['status'], ": ", headerInfo['statusMessage'], "\nFor: ", obs_url)
} else {
if(grepl("No sites/data found using the selection criteria specified", returnedDoc)){
message(returnedDoc)
headerInfo['warn'] <- returnedDoc
}
attr(returnedDoc, "headerInfo") <- headerInfo
return(returnedDoc)
}
......
......@@ -93,10 +93,16 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE,
} else {
rawData <- getWebServiceData(obs_url)
doc <- textConnection(rawData)
if("warn" %in% names(attr(rawData,"header"))){
data <- data.frame()
attr(data, "header") <- attr(rawData,"header")
attr(data, "url") <- obs_url
attr(data, "queryTime") <- Sys.time()
return(data)
}
}
tmp <- read.delim(
doc,
header = TRUE,
......@@ -244,6 +250,10 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE,
comment(data) <- hdr
attr(data, "url") <- obs_url
attr(data, "queryTime") <- Sys.time()
if(!file.exists(obs_url)){
attr(data, "header") <- attr(rawData, "header")
}
return(data)
......
......@@ -130,26 +130,28 @@ readNWISpeak <- function (siteNumbers,startDate="",endDate="", asDateTime=TRUE){
data <- importRDB1(url, asDateTime=FALSE)
if(asDateTime){
badDates <- which(grepl("[0-9]*-[0-9]*-00",data$peak_dt))
if(length(badDates) > 0){
data <- data[-badDates,]
if(nrow(data) > 0){
if(asDateTime){
badDates <- which(grepl("[0-9]*-[0-9]*-00",data$peak_dt))
if(length(badDates) > 0){
warning(length(badDates), " rows were thrown out due to incomplete dates")
data <- data[-badDates,]
if(length(badDates) > 0){
warning(length(badDates), " rows were thrown out due to incomplete dates")
}
}
data$peak_dt <- as.Date(data$peak_dt)
}
data$peak_dt <- as.Date(data$peak_dt)
}
data$gage_ht <- as.numeric(data$gage_ht)
siteInfo <- readNWISsite(siteNumbers)
attr(data, "siteInfo") <- siteInfo
attr(data, "variableInfo") <- NULL
attr(data, "statisticInfo") <- NULL
data$gage_ht <- as.numeric(data$gage_ht)
return (data)
siteInfo <- readNWISsite(siteNumbers)
attr(data, "siteInfo") <- siteInfo
attr(data, "variableInfo") <- NULL
attr(data, "statisticInfo") <- NULL
}
return (data)
}
#' Rating table for an active USGS streamgage retrieval
......@@ -197,19 +199,21 @@ readNWISrating <- function (siteNumber,type="base"){
data <- importRDB1(url, asDateTime=FALSE)
if(type == "base") {
Rat <- grep("//RATING ", comment(data), value=TRUE, fixed=TRUE)
Rat <- sub("# //RATING ", "", Rat)
Rat <- scan(text=Rat, sep=" ", what="")
attr(data, "RATING") <- Rat
if(nrow(data) > 0){
if(type == "base") {
Rat <- grep("//RATING ", comment(data), value=TRUE, fixed=TRUE)
Rat <- sub("# //RATING ", "", Rat)
Rat <- scan(text=Rat, sep=" ", what="")
attr(data, "RATING") <- Rat
}
siteInfo <- readNWISsite(siteNumber)
attr(data, "siteInfo") <- siteInfo
attr(data, "variableInfo") <- NULL
attr(data, "statisticInfo") <- NULL
}
siteInfo <- readNWISsite(siteNumber)
attr(data, "siteInfo") <- siteInfo
attr(data, "variableInfo") <- NULL
attr(data, "statisticInfo") <- NULL
return (data)
}
......@@ -261,16 +265,18 @@ readNWISmeas <- function (siteNumbers,startDate="",endDate="", tz=""){
data <- importRDB1(url,asDateTime=TRUE,tz=tz)
if("diff_from_rating_pc" %in% names(data)){
data$diff_from_rating_pc <- as.numeric(data$diff_from_rating_pc)
if(nrow(data) > 0){
if("diff_from_rating_pc" %in% names(data)){
data$diff_from_rating_pc <- as.numeric(data$diff_from_rating_pc)
}
siteInfo <- readNWISsite(siteNumbers)
attr(data, "siteInfo") <- siteInfo
attr(data, "variableInfo") <- NULL
attr(data, "statisticInfo") <- NULL
}
siteInfo <- readNWISsite(siteNumbers)
attr(data, "siteInfo") <- siteInfo
attr(data, "variableInfo") <- NULL
attr(data, "statisticInfo") <- NULL
return (data)
}
......@@ -323,16 +329,17 @@ readNWISmeas <- function (siteNumbers,startDate="",endDate="", tz=""){
#' }
readNWISgwl <- function (siteNumbers,startDate="",endDate=""){
# url <- constructNWISURL(siteNumbers,NA,startDate,endDate,"gwlevels",format="wml1")
# data <- importWaterML1(url,asDateTime=FALSE)
# data$tz_cd <- NULL
url <- constructNWISURL(siteNumbers,NA,startDate,endDate,"gwlevels",format="tsv")
data <- importRDB1(url,asDateTime=FALSE)
data$lev_dt <- as.Date(data$lev_dt)
siteInfo <- readNWISsite(siteNumbers)
if(nrow(data) > 0){
data$lev_dt <- as.Date(data$lev_dt)
attr(data, "siteInfo") <- siteInfo
siteInfo <- readNWISsite(siteNumbers)
attr(data, "siteInfo") <- siteInfo
}
return (data)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment