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
3f2283b5
Commit
3f2283b5
authored
10 years ago
by
Laura A DeCicco
Browse files
Options
Downloads
Plain Diff
Merge pull request #97 from ldecicco-USGS/master
Adding qwdata to readNWISdata
parents
d3aef09f
08c9f444
No related branches found
Branches containing commit
Tags
2.1.0
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
DESCRIPTION
+2
-1
2 additions, 1 deletion
DESCRIPTION
NEWS
+6
-0
6 additions, 0 deletions
NEWS
R/readNWISdata.r
+40
-5
40 additions, 5 deletions
R/readNWISdata.r
man/readNWISdata.Rd
+6
-1
6 additions, 1 deletion
man/readNWISdata.Rd
tests/testthat/tests_general.R
+7
-0
7 additions, 0 deletions
tests/testthat/tests_general.R
with
61 additions
and
7 deletions
DESCRIPTION
+
2
−
1
View file @
3f2283b5
Package: dataRetrieval
Type: Package
Title: Retrieval Functions for USGS and EPA Hydrologic and Water Quality Data
Version: 2.1.3
Version: 2.1.4
Date: 2015-03-09
Authors@R: c( person("Robert", "Hirsch", role = c("aut"),
email = "rhirsch@usgs.gov"),
person("Laura", "DeCicco", role = c("aut","cre"),
...
...
This diff is collapsed.
Click to expand it.
NEWS
+
6
−
0
View file @
3f2283b5
dataRetrieval 2.1.4
===========
* Expanded readNWISdata to qw data
* Improved citation file
dataRetrieval 2.1.1
===========
* Removed tests that call external web services, server upgrades have been causing false negative results
...
...
This diff is collapsed.
Click to expand it.
R/readNWISdata.r
+
40
−
5
View file @
3f2283b5
...
...
@@ -4,7 +4,8 @@
#' Arguments to the function should be based on \url{http://waterservices.usgs.gov} service calls.
#'
#' @param service string. Possible values are "iv" (for instantaneous), "dv" (for daily values), "gwlevels"
#' (for groundwater levels), and "site" (for site service)
#' (for groundwater levels), "site" (for site service), and "qw" (water-quality). Note: "qw" calls go to:
#' \url{http://nwis.waterdata.usgs.gov/usa/nwis/qwdata} for data requests, and use different call requests schemes.
#' @param \dots see \url{http://waterservices.usgs.gov/rest/Site-Service.html#Service} for a complete list of options
#' @keywords data import NWIS web service
#' @return A data frame with the following columns:
...
...
@@ -53,15 +54,21 @@
#' service="dv", startDate=startDate, endDate=endDate)
#' siteInfo <- readNWISdata(stateCd="WI", parameterCd="00010",
#' hasDataTypeCd="iv", service="site")
#' qwData <- readNWISdata(bBox=c(-82.5,41.52,-81,41),startDate=as.Date("2000-01-01"),
#' drain_area_va_min=50, qw_count_nu=50,qw_attributes="expanded",
#' qw_sample_wide="wide",list_of_search_criteria=c("lat_long_bounding_box",
#' "drain_area_va","obs_count_nu"),service="qw")
#' }
readNWISdata
<-
function
(
service
=
"dv"
,
...
){
matchReturn
<-
list
(
...
)
match.arg
(
service
,
c
(
"dv"
,
"iv"
,
"gwlevels"
,
"site"
,
"uv"
))
match.arg
(
service
,
c
(
"dv"
,
"iv"
,
"gwlevels"
,
"site"
,
"uv"
,
"qw"
,
"qwdata"
))
if
(
service
==
"uv"
){
service
<-
"iv"
}
else
if
(
service
==
"qw"
){
service
<-
"qwdata"
}
if
(
length
(
service
)
>
1
){
...
...
@@ -75,29 +82,57 @@ readNWISdata <- function(service="dv", ...){
names
(
values
)[
names
(
values
)
==
"siteNumber"
]
<-
"sites"
names
(
values
)[
names
(
values
)
==
"siteNumbers"
]
<-
"sites"
urlCall
<-
paste
(
paste
(
names
(
values
),
values
,
sep
=
"="
),
collapse
=
"&"
)
format
<-
"waterml,1.1"
baseURL
<-
"http://waterservices.usgs.gov/nwis/"
if
(
service
==
"iv"
){
baseURL
<-
"http://nwis.waterservices.usgs.gov/nwis/"
}
else
if
(
service
==
"qwdata"
){
baseURL
<-
"http://nwis.waterdata.usgs.gov/nwis/"
format
<-
"rdb"
names
(
values
)[
names
(
values
)
==
"startDT"
]
<-
"begin_date"
names
(
values
)[
names
(
values
)
==
"endDT"
]
<-
"end_date"
values
[
"rdb_inventory_output"
]
<-
"file"
values
[
"TZoutput"
]
<-
"0"
values
[
"date_format"
]
<-
"YYYY-MM-DD"
values
[
"qw_sample_wide"
]
<-
"wide"
if
(
"bBox"
%in%
names
(
values
)){
values
[
"nw_longitude_va"
]
<-
as.character
(
matchReturn
$
bBox
[
1
])
values
[
"nw_latitude_va"
]
<-
as.character
(
matchReturn
$
bBox
[
2
])
values
[
"se_longitude_va"
]
<-
as.character
(
matchReturn
$
bBox
[
3
])
values
[
"se_latitude_va"
]
<-
as.character
(
matchReturn
$
bBox
[
4
])
values
[
"coordinate_format"
]
<-
"decimal_degrees"
values
<-
values
[
-
which
(
"bBox"
%in%
names
(
values
))]
}
}
if
(
service
==
"site"
){
format
<-
"rdb"
}
urlCall
<-
paste
(
paste
(
names
(
values
),
values
,
sep
=
"="
),
collapse
=
"&"
)
baseURL
<-
paste0
(
baseURL
,
service
,
"/?format="
,
format
,
"&"
)
urlCall
<-
paste0
(
baseURL
,
urlCall
)
if
(
service
==
"site"
){
retval
<-
importRDB1
(
urlCall
,
asDateTime
=
FALSE
,
qw
=
FALSE
)
}
else
{
}
else
if
(
service
!=
"qwdata"
)
{
retval
<-
importWaterML1
(
urlCall
,
asDateTime
=
(
"iv"
==
service
))
if
(
"dv"
==
service
){
retval
$
dateTime
<-
as.POSIXct
(
retval
$
dateTime
)
}
}
else
{
possibleError
<-
tryCatch
({
retval
<-
importRDB1
(
urlCall
,
asDateTime
=
TRUE
,
qw
=
TRUE
)
},
error
=
function
(
e
)
{
stop
(
e
,
"with url:"
,
urlCall
)
})
}
return
(
retval
)
...
...
This diff is collapsed.
Click to expand it.
man/readNWISdata.Rd
+
6
−
1
View file @
3f2283b5
...
...
@@ -8,7 +8,8 @@ readNWISdata(service = "dv", ...)
}
\arguments{
\item{service}{string. Possible values are "iv" (for instantaneous), "dv" (for daily values), "gwlevels"
(for groundwater levels), and "site" (for site service)}
(for groundwater levels), "site" (for site service), and "qw" (water-quality). Note: "qw" calls go to:
\url{http://nwis.waterdata.usgs.gov/usa/nwis/qwdata} for data requests, and use different call requests schemes.}
\item{\dots}{see \url{http://waterservices.usgs.gov/rest/Site-Service.html#Service} for a complete list of options}
}
...
...
@@ -61,6 +62,10 @@ waterYear <- readNWISdata(bBox=c(-83,36.5,-81,38.5), parameterCd="00010",
service="dv", startDate=startDate, endDate=endDate)
siteInfo <- readNWISdata(stateCd="WI", parameterCd="00010",
hasDataTypeCd="iv", service="site")
qwData <- readNWISdata(bBox=c(-82.5,41.52,-81,41),startDate=as.Date("2000-01-01"),
drain_area_va_min=50, qw_count_nu=50,qw_attributes="expanded",
qw_sample_wide="wide",list_of_search_criteria=c("lat_long_bounding_box",
"drain_area_va","obs_count_nu"),service="qw")
}
}
\seealso{
...
...
This diff is collapsed.
Click to expand it.
tests/testthat/tests_general.R
+
7
−
0
View file @
3f2283b5
...
...
@@ -18,6 +18,13 @@ test_that("General NWIS retrievals working", {
siteInfo
<-
readNWISdata
(
stateCd
=
"WI"
,
parameterCd
=
"00010"
,
hasDataTypeCd
=
"iv"
,
service
=
"site"
)
expect_is
(
siteInfo
$
station_nm
,
"character"
)
qwData
<-
readNWISdata
(
bBox
=
c
(
-82.5
,
41.52
,
-81
,
41
),
startDate
=
as.Date
(
"2000-01-01"
),
drain_area_va_min
=
50
,
qw_count_nu
=
50
,
qw_attributes
=
"expanded"
,
qw_sample_wide
=
"wide"
,
list_of_search_criteria
=
c
(
"lat_long_bounding_box"
,
"drain_area_va"
,
"obs_count_nu"
),
service
=
"qw"
)
expect_is
(
qwData
$
startDateTime
,
"POSIXct"
)
})
...
...
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