Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
dataRetrieval
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Water
dataRetrieval
Commits
341078bd
Commit
341078bd
authored
9 years ago
by
Laura A DeCicco
Browse files
Options
Downloads
Patches
Plain Diff
Added some logic to deal with incomplete dates.
Fixes
#106
parent
73d9321e
No related branches found
Branches containing commit
No related tags found
1 merge request
!114
Time zone code and bug fixes.
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
R/readNWISunit.r
+17
-3
17 additions, 3 deletions
R/readNWISunit.r
man/readNWISpeak.Rd
+8
-1
8 additions, 1 deletion
man/readNWISpeak.Rd
with
25 additions
and
4 deletions
R/readNWISunit.r
+
17
−
3
View file @
341078bd
...
@@ -83,13 +83,19 @@ readNWISuv <- function (siteNumbers,parameterCd,startDate="",endDate="", tz=""){
...
@@ -83,13 +83,19 @@ readNWISuv <- function (siteNumbers,parameterCd,startDate="",endDate="", tz=""){
#' Peak flow data from USGS (NWIS)
#' Peak flow data from USGS (NWIS)
#'
#'
#' Reads peak flow from NWISweb. Data is retrieved from \url{http://waterdata.usgs.gov/nwis}.
#' Reads peak flow from NWISweb. Data is retrieved from \url{http://waterdata.usgs.gov/nwis}.
#' In some cases, the specific date of the peak data is not know. This function will default to
#' converting the complete dates, dropping rows with incomplete dates. If those incomplete dates are
#' needed, set the `asDateTime` argument to FALSE. No rows will be removed, and no dates will be converted
#' to R Date objects.
#'
#'
#' @param siteNumbers character USGS site number(or multiple sites). This is usually an 8 digit number.
#' @param siteNumbers character USGS site number(or multiple sites). This is usually an 8 digit number.
#' @param startDate character starting date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates
#' @param startDate character starting date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates
#' retrieval for the earliest possible record.
#' retrieval for the earliest possible record.
#' @param endDate character ending date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates
#' @param endDate character ending date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates
#' retrieval for the latest possible record.
#' retrieval for the latest possible record.
#' @param asDateTime logical default to \code{TRUE}. When \code{TRUE}, the peak_dt column is converted
#' to a Date object, and incomplete dates are removed. When \code{FALSE}, no columns are removed, but no dates are converted.
#' @return A data frame with the following columns:
#' @return A data frame with the following columns:
#' \tabular{lll}{
#' \tabular{lll}{
#' Name \tab Type \tab Description \cr
#' Name \tab Type \tab Description \cr
...
@@ -123,14 +129,22 @@ readNWISuv <- function (siteNumbers,parameterCd,startDate="",endDate="", tz=""){
...
@@ -123,14 +129,22 @@ readNWISuv <- function (siteNumbers,parameterCd,startDate="",endDate="", tz=""){
#' \dontrun{
#' \dontrun{
#' data <- readNWISpeak(siteNumbers)
#' data <- readNWISpeak(siteNumbers)
#' }
#' }
readNWISpeak
<-
function
(
siteNumbers
,
startDate
=
""
,
endDate
=
""
){
readNWISpeak
<-
function
(
siteNumbers
,
startDate
=
""
,
endDate
=
""
,
asDateTime
=
TRUE
){
# Doesn't seem to be a peak xml service
# Doesn't seem to be a peak xml service
url
<-
constructNWISURL
(
siteNumbers
,
NA
,
startDate
,
endDate
,
"peak"
)
url
<-
constructNWISURL
(
siteNumbers
,
NA
,
startDate
,
endDate
,
"peak"
)
data
<-
importRDB1
(
url
,
asDateTime
=
FALSE
)
data
<-
importRDB1
(
url
,
asDateTime
=
FALSE
)
data
$
peak_dt
<-
as.Date
(
data
$
peak_dt
)
if
(
asDateTime
){
badDates
<-
which
(
grepl
(
"[0-9]*-[0-9]*-00"
,
data
$
peak_dt
))
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
$
gage_ht
<-
as.numeric
(
data
$
gage_ht
)
data
$
gage_ht
<-
as.numeric
(
data
$
gage_ht
)
siteInfo
<-
readNWISsite
(
siteNumbers
)
siteInfo
<-
readNWISsite
(
siteNumbers
)
...
...
This diff is collapsed.
Click to expand it.
man/readNWISpeak.Rd
+
8
−
1
View file @
341078bd
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
\alias{readNWISpeak}
\alias{readNWISpeak}
\title{Peak flow data from USGS (NWIS)}
\title{Peak flow data from USGS (NWIS)}
\usage{
\usage{
readNWISpeak(siteNumbers, startDate = "", endDate = "")
readNWISpeak(siteNumbers, startDate = "", endDate = ""
, asDateTime = TRUE
)
}
}
\arguments{
\arguments{
\item{siteNumbers}{character USGS site number(or multiple sites). This is usually an 8 digit number.}
\item{siteNumbers}{character USGS site number(or multiple sites). This is usually an 8 digit number.}
...
@@ -14,6 +14,9 @@ retrieval for the earliest possible record.}
...
@@ -14,6 +14,9 @@ retrieval for the earliest possible record.}
\item{endDate}{character ending date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates
\item{endDate}{character ending date for data retrieval in the form YYYY-MM-DD. Default is "" which indicates
retrieval for the latest possible record.}
retrieval for the latest possible record.}
\item{asDateTime}{logical default to \code{TRUE}. When \code{TRUE}, the peak_dt column is converted
to a Date object, and incomplete dates are removed. When \code{FALSE}, no columns are removed, but no dates are converted.}
}
}
\value{
\value{
A data frame with the following columns:
A data frame with the following columns:
...
@@ -45,6 +48,10 @@ siteInfo \tab data.frame \tab A data frame containing information on the request
...
@@ -45,6 +48,10 @@ siteInfo \tab data.frame \tab A data frame containing information on the request
}
}
\description{
\description{
Reads peak flow from NWISweb. Data is retrieved from \url{http://waterdata.usgs.gov/nwis}.
Reads peak flow from NWISweb. Data is retrieved from \url{http://waterdata.usgs.gov/nwis}.
In some cases, the specific date of the peak data is not know. This function will default to
converting the complete dates, dropping rows with incomplete dates. If those incomplete dates are
needed, set the `asDateTime` argument to FALSE. No rows will be removed, and no dates will be converted
to R Date objects.
}
}
\examples{
\examples{
siteNumbers <- c('01594440','040851325')
siteNumbers <- c('01594440','040851325')
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment