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

Merge pull request #50 from ldecicco-USGS/master

UTC
parents 9a833355 6162e162
No related branches found
No related tags found
No related merge requests found
...@@ -2,7 +2,7 @@ Package: dataRetrieval ...@@ -2,7 +2,7 @@ Package: dataRetrieval
Type: Package Type: Package
Title: Retrieval Functions for USGS and EPA Hydrologic and Water Quality Data Title: Retrieval Functions for USGS and EPA Hydrologic and Water Quality Data
Version: 2.0.1.9000 Version: 2.0.1.9000
Date: 2014-11-24 Date: 2014-12-02
Authors@R: c( person("Robert", "Hirsch", role = c("aut"), Authors@R: c( person("Robert", "Hirsch", role = c("aut"),
email = "rhirsch@usgs.gov"), email = "rhirsch@usgs.gov"),
person("Laura", "DeCicco", role = c("aut","cre"), person("Laura", "DeCicco", role = c("aut","cre"),
......
...@@ -203,12 +203,13 @@ constructNWISURL <- function(siteNumber,parameterCd="00060",startDate="",endDate ...@@ -203,12 +203,13 @@ constructNWISURL <- function(siteNumber,parameterCd="00060",startDate="",endDate
} }
) )
# This was waaay to slow:
if(url.exists(url)){ # if(url.exists(url)){
return(url) # return(url)
} else { # } else {
stop("The following url doesn't seem to exist:\n",url) # stop("The following url doesn't seem to exist:\n",url)
} # }
return(url)
} }
......
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
#' comment \tab character \tab Header comments from the RDB file \cr #' comment \tab character \tab Header comments from the RDB file \cr
#' } #' }
#' @export #' @export
#' @import RCurl
#' @examples #' @examples
#' siteNumber <- "02177000" #' siteNumber <- "02177000"
#' startDate <- "2012-09-01" #' startDate <- "2012-09-01"
...@@ -81,7 +80,14 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE, ...@@ -81,7 +80,14 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE,
"America/Phoenix","America/Metlakatla")) "America/Phoenix","America/Metlakatla"))
} }
if(url.exists(obs_url)){ if(file.exists(obs_url)){
doc <- obs_url
fileVecChar <- scan(obs_url, what = "", sep = "\n", quiet=TRUE)
pndIndx<-regexpr("^#", fileVecChar)
hdr <- fileVecChar[pndIndx > 0L]
} else {
# 400 bad site id # 400 bad site id
# 404 outside date range, wrong pcode # 404 outside date range, wrong pcode
...@@ -111,11 +117,6 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE, ...@@ -111,11 +117,6 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE,
message(e) message(e)
return(NA) return(NA)
}) })
} else {
doc <- obs_url
fileVecChar <- scan(obs_url, what = "", sep = "\n", quiet=TRUE)
pndIndx<-regexpr("^#", fileVecChar)
hdr <- fileVecChar[pndIndx > 0L]
} }
tmp <- read.delim( tmp <- read.delim(
...@@ -179,6 +180,8 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE, ...@@ -179,6 +180,8 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE,
if(tz != ""){ if(tz != ""){
attr(data[,regexpr('d$', dataType) > 0], "tzone") <- tz attr(data[,regexpr('d$', dataType) > 0], "tzone") <- tz
} else {
attr(data[,regexpr('d$', dataType) > 0], "tzone") <- "UTC"
} }
} else if (qw){ } else if (qw){
...@@ -222,6 +225,8 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE, ...@@ -222,6 +225,8 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE,
if(tz != ""){ if(tz != ""){
attr(data$startDateTime, "tzone") <- tz attr(data$startDateTime, "tzone") <- tz
} else {
attr(data$startDateTime, "tzone") <- "UTC"
} }
if(composite){ if(composite){
...@@ -231,6 +236,8 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE, ...@@ -231,6 +236,8 @@ importRDB1 <- function(obs_url, asDateTime=FALSE, qw=FALSE, convertType = TRUE,
if(tz != ""){ if(tz != ""){
attr(data$endDateTime, "tzone") <- tz attr(data$endDateTime, "tzone") <- tz
} else {
attr(data$endDateTime, "tzone") <- "UTC"
} }
} }
......
...@@ -86,7 +86,9 @@ ...@@ -86,7 +86,9 @@
#' inactiveAndAcitive <- importWaterML1(inactiveAndAcitive) #' inactiveAndAcitive <- importWaterML1(inactiveAndAcitive)
importWaterML1 <- function(obs_url,asDateTime=FALSE, tz=""){ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz=""){
if(url.exists(obs_url)){ if(file.exists(obs_url)){
doc <- xmlTreeParse(obs_url, getDTD = FALSE, useInternalNodes = TRUE)
} else {
doc = tryCatch({ doc = tryCatch({
h <- basicHeaderGatherer() h <- basicHeaderGatherer()
returnedDoc <- getURI(obs_url, headerfunction = h$update) returnedDoc <- getURI(obs_url, headerfunction = h$update)
...@@ -106,8 +108,6 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz=""){ ...@@ -106,8 +108,6 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz=""){
message(e) message(e)
return(NA) return(NA)
}) })
} else {
doc <- xmlTreeParse(obs_url, getDTD = FALSE, useInternalNodes = TRUE)
} }
if(tz != ""){ if(tz != ""){
...@@ -274,19 +274,21 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz=""){ ...@@ -274,19 +274,21 @@ importWaterML1 <- function(obs_url,asDateTime=FALSE, tz=""){
datetime <- substr(datetime,1,23) datetime <- substr(datetime,1,23)
datetime <- as.POSIXct(datetime, "%Y-%m-%dT%H:%M:%OS", tz = "UTC") datetime <- as.POSIXct(datetime, "%Y-%m-%dT%H:%M:%OS", tz = "UTC")
datetime <- datetime + tzHours*60*60 datetime <- datetime - tzHours*60*60
df$tz_cd <- as.character(zoneAbbrievs[tzOffset]) df$tz_cd <- as.character(zoneAbbrievs[tzOffset])
} }
if(!("tz_cd" %in% names(df))){ if(!("tz_cd" %in% names(df))){
df$tz_cd <- zoneAbbrievs[1] df$tz_cd <- zoneAbbrievs[1]
tzHours <- as.numeric(substr(names(zoneAbbrievs[1]),1,3)) tzHours <- as.numeric(substr(names(zoneAbbrievs[1]),1,3))
datetime <- datetime + tzHours*60*60 datetime <- datetime - tzHours*60*60
} }
} }
if(tz != ""){ if(tz != ""){
attr(datetime, "tzone") <- tz attr(datetime, "tzone") <- tz
} else {
attr(datetime, "tzone") <- "UTC"
} }
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#' agency \tab character \tab The NWIS code for the agency reporting the data\cr #' agency \tab character \tab The NWIS code for the agency reporting the data\cr
#' site \tab character \tab The USGS site number \cr #' site \tab character \tab The USGS site number \cr
#' datetime \tab Date \tab The date of the value \cr #' datetime \tab Date \tab The date of the value \cr
#' tz_cd \tab character \tab The time zone code for datetime \cr
#' code \tab character \tab Any codes that qualify the corresponding value\cr #' code \tab character \tab Any codes that qualify the corresponding value\cr
#' value \tab numeric \tab The numeric value for the parameter \cr #' value \tab numeric \tab The numeric value for the parameter \cr
#' } #' }
...@@ -66,6 +65,7 @@ readNWISdv <- function (siteNumber,parameterCd,startDate="",endDate="",statCd="0 ...@@ -66,6 +65,7 @@ readNWISdv <- function (siteNumber,parameterCd,startDate="",endDate="",statCd="0
data <- importWaterML1(url, asDateTime=FALSE) data <- importWaterML1(url, asDateTime=FALSE)
if(nrow(data)>0){ if(nrow(data)>0){
data$dateTime <- as.Date(data$dateTime) data$dateTime <- as.Date(data$dateTime)
data$tz_cd <- NULL
} }
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#' @param pCodes character of USGS parameter code(s). This is usually an 5 digit number. #' @param pCodes character of USGS parameter code(s). This is usually an 5 digit number.
#' @param startDate character starting date for data retrieval in the form YYYY-MM-DD. #' @param startDate character starting date for data retrieval in the form YYYY-MM-DD.
#' @param endDate character ending date for data retrieval in the form YYYY-MM-DD. #' @param endDate character ending date for data retrieval in the form YYYY-MM-DD.
#' @param expanded logical defaults to FALSE. If TRUE, retrieves additional information. Expanded data includes #' @param expanded logical defaults to TRUE. If TRUE, retrieves additional information. Expanded data includes
#' remark_cd (remark code), result_va (result value), val_qual_tx (result value qualifier code), meth_cd (method code), #' remark_cd (remark code), result_va (result value), val_qual_tx (result value qualifier code), meth_cd (method code),
#' dqi_cd (data-quality indicator code), rpt_lev_va (reporting level), and rpt_lev_cd (reporting level type). #' dqi_cd (data-quality indicator code), rpt_lev_va (reporting level), and rpt_lev_cd (reporting level type).
#' @param reshape logical. Will reshape the data if TRUE (default) #' @param reshape logical. Will reshape the data if TRUE (default)
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
#' startDate,endDate,expanded=TRUE,reshape=FALSE) #' startDate,endDate,expanded=TRUE,reshape=FALSE)
#' #'
readNWISqw <- function (siteNumber,pCodes,startDate="",endDate="", readNWISqw <- function (siteNumber,pCodes,startDate="",endDate="",
expanded=FALSE,reshape=TRUE,tz=""){ expanded=TRUE,reshape=FALSE,tz=""){
url <- constructNWISURL(siteNumber,pCodes,startDate,endDate,"qw",expanded=expanded) url <- constructNWISURL(siteNumber,pCodes,startDate,endDate,"qw",expanded=expanded)
......
...@@ -24,7 +24,6 @@ Name \tab Type \tab Description \cr ...@@ -24,7 +24,6 @@ Name \tab Type \tab Description \cr
agency \tab character \tab The NWIS code for the agency reporting the data\cr agency \tab character \tab The NWIS code for the agency reporting the data\cr
site \tab character \tab The USGS site number \cr site \tab character \tab The USGS site number \cr
datetime \tab Date \tab The date of the value \cr datetime \tab Date \tab The date of the value \cr
tz_cd \tab character \tab The time zone code for datetime \cr
code \tab character \tab Any codes that qualify the corresponding value\cr code \tab character \tab Any codes that qualify the corresponding value\cr
value \tab numeric \tab The numeric value for the parameter \cr value \tab numeric \tab The numeric value for the parameter \cr
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
\title{Raw Data Import for USGS NWIS QW Data} \title{Raw Data Import for USGS NWIS QW Data}
\usage{ \usage{
readNWISqw(siteNumber, pCodes, startDate = "", endDate = "", readNWISqw(siteNumber, pCodes, startDate = "", endDate = "",
expanded = FALSE, reshape = TRUE, tz = "") expanded = TRUE, reshape = FALSE, tz = "")
} }
\arguments{ \arguments{
\item{siteNumber}{character of USGS site numbers. This is usually an 8 digit number} \item{siteNumber}{character of USGS site numbers. This is usually an 8 digit number}
...@@ -15,7 +15,7 @@ readNWISqw(siteNumber, pCodes, startDate = "", endDate = "", ...@@ -15,7 +15,7 @@ readNWISqw(siteNumber, pCodes, startDate = "", endDate = "",
\item{endDate}{character ending date for data retrieval in the form YYYY-MM-DD.} \item{endDate}{character ending date for data retrieval in the form YYYY-MM-DD.}
\item{expanded}{logical defaults to FALSE. If TRUE, retrieves additional information. Expanded data includes \item{expanded}{logical defaults to TRUE. If TRUE, retrieves additional information. Expanded data includes
remark_cd (remark code), result_va (result value), val_qual_tx (result value qualifier code), meth_cd (method code), remark_cd (remark code), result_va (result value), val_qual_tx (result value qualifier code), meth_cd (method code),
dqi_cd (data-quality indicator code), rpt_lev_va (reporting level), and rpt_lev_cd (reporting level type).} dqi_cd (data-quality indicator code), rpt_lev_va (reporting level), and rpt_lev_cd (reporting level type).}
......
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