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

Updated functions that retrieve NWIS data to use the WaterML1.1 format.

parent 6b4a53b1
No related branches found
No related tags found
No related merge requests found
......@@ -25,46 +25,7 @@
retrieveNWISData <- function (siteNumber,ParameterCd,StartDate,EndDate,StatCd="00003",interactive=TRUE){
url <- constructNWISURL(siteNumber,ParameterCd,StartDate,EndDate,"dv",StatCd)
tmp <- read.delim(
url,
header = TRUE,
quote="\"",
dec=".",
sep='\t',
colClasses=c('character'),
fill = TRUE,
comment.char="#")
# This takes slightly longer than the original method, but handles "Ice" or other characters in the numeric columns without error.
dataType <- tmp[1,]
data <- tmp[-1,]
data[,regexpr('d$', dataType) > 0] <- as.Date(data[,regexpr('d$', dataType) > 0])
tempDF <- data[,which(regexpr('n$', dataType) > 0)]
tempDF <- suppressWarnings(sapply(tempDF, function(x) as.numeric(x)))
data[,which(regexpr('n$', dataType) > 0)] <- tempDF
row.names(data) <- NULL
# originalMethod <- function(SiteFile){
# col.nm <- make.names(unlist(SiteFile[1,, drop=TRUE]), allow_=FALSE)
# retval <- lapply(SiteFile, function(x) {
# Typ <- x[1] # The type
# x <- x[-c(1)] # the data
# if(regexpr('d$', Typ) > 0) { # Must be date
# ret.val <- try(as.Date(x)) # The data are in standard format, but...
# if(class(ret.val) == "try-error")
# ret.val <- x
# }
# else if(regexpr('n$', Typ) > 0) # Must be numeric
# ret.val <- as.numeric(x)
# else # Must be character
# ret.val <- x
# return(ret.val)})
# data <- as.data.frame(retval, stringsAsFactors=FALSE)
# names(data) <- col.nm
# return(data)
# }
data <- getWaterML1Data(url)
return (data)
}
\ No newline at end of file
......@@ -22,24 +22,7 @@
retrieveUnitNWISData <- function (siteNumber,ParameterCd,StartDate,EndDate,interactive=TRUE){
url <- constructNWISURL(siteNumber,ParameterCd,StartDate,EndDate,"uv")
tmp <- read.delim(
url,
header = TRUE,
quote="\"",
dec=".",
sep='\t',
colClasses=c('character'),
fill = TRUE,
comment.char="#")
data <- getWaterML1Data(url)
dataType <- tmp[1,]
data <- tmp[-1,]
data[,regexpr('d$', dataType) > 0] <- as.POSIXct(strptime(data[,regexpr('d$', dataType) > 0], "%Y-%m-%d %H:%M"))
tempDF <- data[,which(regexpr('n$', dataType) > 0)]
tempDF <- suppressWarnings(sapply(tempDF, function(x) as.numeric(x)))
data[,which(regexpr('n$', dataType) > 0)] <- tempDF
row.names(data) <- NULL
return (data)
}
\ No newline at end of file
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