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

Adding peak, rating, and meas NWIS functions.

parent 90b2814b
No related branches found
No related tags found
1 merge request!39Overhaul of function names. Move some functionality to EGRET.
......@@ -9,8 +9,11 @@ export(importWaterML2)
export(padVariable)
export(readNWISdata)
export(readNWISdv)
export(readNWISmeas)
export(readNWISpCode)
export(readNWISpeak)
export(readNWISqw)
export(readNWISrating)
export(readNWISsite)
export(readNWISunit)
export(readWQPdata)
......
#' Function to return data from the NWIS RDB 1.0 format
#'
#' This function accepts a url parameter that already contains the desired
......@@ -166,7 +167,10 @@ importRDB1 <- function(obs_url,asDateTime=FALSE, qw=FALSE){
} else {
for (i in grep('d$', dataType)){
data[,i] <- as.Date(data[,i])
if (all(data[,i] != "")){
data[,i] <- as.Date(data[,i])
}
}
}
}
......
......@@ -15,12 +15,11 @@
#' \dontrun{
#' ## Examples take longer than 5 seconds:
#' rawSampleURL <- constructWQPURL('USGS-01594440','01075', '', '')
#' rawSample <- importWQP(rawSampleURL, TRUE)
#' url2 <- paste0("http://www.waterqualitydata.us/Result/search?",
#' "siteid=USGS-01594440&pCode=01075&mimeType=tsv")
#' rawSample2 <- importWQP(url2, FALSE)
#' rawSample <- importWQP(rawSampleURL)
#' url2 <- paste0(rawSampleURL,"&zip=yes")
#' rawSample2 <- importWQP(url2, TRUE)
#' }
importWQP <- function(url, zip=TRUE){
importWQP <- function(url, zip=FALSE){
h <- basicHeaderGatherer()
......@@ -28,11 +27,11 @@ importWQP <- function(url, zip=TRUE){
if(zip){
headerInfo <- HEAD(url)$headers
temp <- tempfile()
origTimeout <- getOption("timeout")
# origTimeout <- getOption("timeout")
options(timeout = 120)
download.file(url,temp, quiet=TRUE, mode='wb')
doc <- unzip(temp)
options(timeout = origTimeout)
# options(timeout = origTimeout)
} else {
doc <- getURL(url, headerfunction = h$update)
headerInfo <- h$value()
......
......@@ -35,3 +35,59 @@ readNWISunit <- function (siteNumber,parameterCd,startDate,endDate,format="xml")
return (data)
}
#' Reads peak flow data from NWISweb.
#'
#'
#'
#' @param siteNumber string USGS site number. This is usually an 8 digit number
#' @param startDate string starting date for data retrieval in the form YYYY-MM-DD.
#' @param endDate string ending date for data retrieval in the form YYYY-MM-DD.
#' @export
#' @examples
#' siteNumber <- '01594440'
#' data <- readNWISpeak(siteNumber, '','')
readNWISpeak <- function (siteNumber,startDate,endDate){
url <- constructNWISURL(siteNumber,NA,startDate,endDate,"peak")
data <- importRDB1(url)
return (data)
}
#' Reads the current rating table for an active USGS streamgage.
#'
#'
#'
#' @param siteNumber string USGS site number. This is usually an 8 digit number
#' @param type string can be "base", "corr", or "exsa"
#' @export
#' @examples
#' siteNumber <- '01594440'
#' data <- readNWISrating(siteNumber, "base")
readNWISrating <- function (siteNumber,type){
url <- constructNWISURL(siteNumber,service="rating",ratingType = type)
data <- importRDB1(url)
return (data)
}
#'Reads surface-water measurement data from NWISweb.
#'
#'
#'
#' @param siteNumber string USGS site number. This is usually an 8 digit number
#' @param startDate string starting date for data retrieval in the form YYYY-MM-DD.
#' @param endDate string ending date for data retrieval in the form YYYY-MM-DD.
#' @export
#' @examples
#' siteNumber <- '01594440'
#' data <- readNWISmeas(siteNumber, '','')
readNWISmeas <- function (siteNumber,startDate,endDate){
url <- constructNWISURL(siteNumber,NA,startDate,endDate,"meas")
data <- importRDB1(url)
return (data)
}
......@@ -34,9 +34,9 @@ readWQPdata <- function(...){
baseURL <- "http://www.waterqualitydata.us/Result/search?"
urlCall <- paste0(baseURL,
urlCall,
"&mimeType=tsv&zip=yes")
"&mimeType=tsv")
retVal <- importWQP(urlCall,TRUE)
retVal <- importWQP(urlCall,FALSE)
return(retVal)
}
\ No newline at end of file
......@@ -3,8 +3,9 @@
\alias{constructNWISURL}
\title{Construct NWIS url for data retrieval}
\usage{
constructNWISURL(siteNumber, parameterCd, startDate, endDate, service,
statCd = "00003", format = "xml", expanded = FALSE)
constructNWISURL(siteNumber, parameterCd, startDate = "", endDate = "",
service, statCd = "00003", format = "xml", expanded = FALSE,
ratingType = "base")
}
\arguments{
\item{siteNumber}{string or vector of strings USGS site number. This is usually an 8 digit number}
......@@ -15,7 +16,8 @@ constructNWISURL(siteNumber, parameterCd, startDate, endDate, service,
\item{endDate}{string ending date for data retrieval in the form YYYY-MM-DD.}
\item{service}{string USGS service to call. Possible values are "dv" (daily values), "uv" (unit/instantaneous values), "qw" (water quality data), "gwlevels" (groundwater),and "wqp" (water quality portal, which can include STORET).}
\item{service}{string USGS service to call. Possible values are "dv" (daily values), "uv" (unit/instantaneous values),
"qw" (water quality data), "gwlevels" (groundwater),and "rating" (rating curve), "peak", "meas" (discrete streamflow measurements).}
\item{statCd}{string or vector USGS statistic code only used for daily value service. This is usually 5 digits. Daily mean (00003) is the default.}
......@@ -24,6 +26,8 @@ but will offer a warning if the file was incomplete (for example, if there was a
but the user must carefully check the results to see if the data returns matches what is expected. The default is therefore "xml".}
\item{expanded}{logical defaults to FALSE. If TRUE, retrieves additional information, only applicable for qw data.}
\item{ratingType}{can be "base", "corr", or "exsa". Only applies to rating curve data.}
}
\value{
url string
......@@ -47,6 +51,9 @@ url_qw <- constructNWISURL(siteNumber,c('01075','00029','00453'),
startDate,endDate,'qw')
url_daily_tsv <- constructNWISURL(siteNumber,pCode,startDate,endDate,'dv',
statCd=c("00003","00001"),format="tsv")
url_rating <- constructNWISURL(siteNumber,service="rating",ratingType="base")
url_peak <- constructNWISURL(siteNumber, service="peak")
url_meas <- constructNWISURL(siteNumber, service="meas")
}
}
\keyword{USGS}
......
......@@ -3,7 +3,7 @@
\alias{importWQP}
\title{Basic Water Quality Portal Data grabber}
\usage{
importWQP(url, zip = TRUE)
importWQP(url, zip = FALSE)
}
\arguments{
\item{url}{string URL to Water Quality Portal#'}
......@@ -22,10 +22,9 @@ Imports data from the Water Quality Portal based on a specified url.
\dontrun{
## Examples take longer than 5 seconds:
rawSampleURL <- constructWQPURL('USGS-01594440','01075', '', '')
rawSample <- importWQP(rawSampleURL, TRUE)
url2 <- paste0("http://www.waterqualitydata.us/Result/search?",
"siteid=USGS-01594440&pCode=01075&mimeType=tsv")
rawSample2 <- importWQP(url2, FALSE)
rawSample <- importWQP(rawSampleURL)
url2 <- paste0(rawSampleURL,"&zip=yes")
rawSample2 <- importWQP(url2, TRUE)
}
}
\keyword{USGS}
......
% Generated by roxygen2 (4.0.2): do not edit by hand
\name{readNWISmeas}
\alias{readNWISmeas}
\title{Reads surface-water measurement data from NWISweb.}
\usage{
readNWISmeas(siteNumber, startDate, endDate)
}
\arguments{
\item{siteNumber}{string USGS site number. This is usually an 8 digit number}
\item{startDate}{string starting date for data retrieval in the form YYYY-MM-DD.}
\item{endDate}{string ending date for data retrieval in the form YYYY-MM-DD.}
}
\description{
Reads surface-water measurement data from NWISweb.
}
\examples{
siteNumber <- '01594440'
data <- readNWISmeas(siteNumber, '','')
}
% Generated by roxygen2 (4.0.2): do not edit by hand
\name{readNWISpeak}
\alias{readNWISpeak}
\title{Reads peak flow data from NWISweb.}
\usage{
readNWISpeak(siteNumber, startDate, endDate)
}
\arguments{
\item{siteNumber}{string USGS site number. This is usually an 8 digit number}
\item{startDate}{string starting date for data retrieval in the form YYYY-MM-DD.}
\item{endDate}{string ending date for data retrieval in the form YYYY-MM-DD.}
}
\description{
Reads peak flow data from NWISweb.
}
\examples{
siteNumber <- '01594440'
data <- readNWISpeak(siteNumber, '','')
}
% Generated by roxygen2 (4.0.2): do not edit by hand
\name{readNWISrating}
\alias{readNWISrating}
\title{Reads the current rating table for an active USGS streamgage.}
\usage{
readNWISrating(siteNumber, type)
}
\arguments{
\item{siteNumber}{string USGS site number. This is usually an 8 digit number}
\item{type}{string can be "base", "corr", or "exsa"}
}
\description{
Reads the current rating table for an active USGS streamgage.
}
\examples{
siteNumber <- '01594440'
data <- readNWISrating(siteNumber, "base")
}
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