Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Water
dataRetrieval
Commits
152ecda9
Commit
152ecda9
authored
Mar 17, 2017
by
Laura A DeCicco
Browse files
Clean up some notes
parent
a3c3e59f
Changes
8
Hide whitespace changes
Inline
Side-by-side
NAMESPACE
View file @
152ecda9
...
...
@@ -9,14 +9,13 @@ export(constructWQPURL)
export(countyCd)
export(countyCdLookup)
export(getWebServiceData)
export(importNGWMN
_wml2
)
export(importNGWMN)
export(importRDB1)
export(importWQP)
export(importWaterML1)
export(importWaterML2)
export(pCodeToName)
export(parameterCdFile)
export(parseWaterML2Timeseries)
export(readNGWMNdata)
export(readNGWMNlevels)
export(readNGWMNsites)
...
...
@@ -45,7 +44,6 @@ export(whatWQPmetrics)
export(whatWQPsamples)
export(whatWQPsites)
export(zeroPad)
import(lubridate)
import(stats)
import(utils)
importFrom(curl,curl_version)
...
...
@@ -58,7 +56,6 @@ importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
importFrom(dplyr,mutate_)
importFrom(dplyr,mutate_each_)
importFrom(dplyr,rbind_all)
importFrom(dplyr,select)
importFrom(dplyr,select_)
importFrom(httr,GET)
...
...
R/importNGWMN_wml2.R
View file @
152ecda9
...
...
@@ -7,7 +7,7 @@
#' @param asDateTime logical, if \code{TRUE} returns date and time as POSIXct, if \code{FALSE}, character
#' @param tz character to set timezone attribute of datetime. Default is an empty quote, which converts the
#' datetimes to UTC (properly accounting for daylight savings times based on the data's provided time zone offset).
#' Possible values
to provide
are "America/New_York","America/Chicago", "America/Denver","America/Los_Angeles",
#' Possible values are "America/New_York","America/Chicago", "America/Denver","America/Los_Angeles",
#' "America/Anchorage","America/Honolulu","America/Jamaica","America/Managua","America/Phoenix", and "America/Metlakatla"
#' @return mergedDF a data frame source, time, value, uom, uomTitle, comment, gmlID
#' @export
...
...
@@ -19,14 +19,18 @@
#' @importFrom lubridate parse_date_time
#' @examples
#' \dontrun{
#' obs_url <- paste0("http://cida.usgs.gov/ngwmn_cache/sos?request=GetObservation&service=SOS&version=2.0.0",
#' "&observedProperty=urn:ogc:def:property:OGC:GroundWaterLevel&responseFormat=text/xml&featureOf",
#' "Interest=VW_GWDP_GEOSERVER.USGS.403836085374401")
#' obs_url <- paste("http://cida.usgs.gov/ngwmn_cache/sos?request=GetObservation",
#' "service=SOS","version=2.0.0",
#' "observedProperty=urn:ogc:def:property:OGC:GroundWaterLevel",
#' "responseFormat=text/xml",
#' "featureOfInterest=VW_GWDP_GEOSERVER.USGS.403836085374401",sep="&")
#' data <- importNGWMN(obs_url)
#'
#' obs_url <- paste0("http://cida.usgs.gov/ngwmn_cache/sos?request=GetObservation&service=SOS&version=2.0.0",
#' "&observedProperty=urn:ogc:def:property:OGC:GroundWaterLevel&responseFormat=text/xml&featureOf",
#' "Interest=VW_GWDP_GEOSERVER.USGS.474011117072901")
#' obs_url <- paste("http://cida.usgs.gov/ngwmn_cache/sos?request=GetObservation",
#' "service=SOS","version=2.0.0",
#' "observedProperty=urn:ogc:def:property:OGC:GroundWaterLevel",
#' "responseFormat=text/xml",
#' "featureOfInterest=VW_GWDP_GEOSERVER.USGS.474011117072901",sep="&")
#' data <- importNGWMN(obs_url)
#' }
#'
...
...
@@ -117,6 +121,11 @@ importNGWMN <- function(input, asDateTime=FALSE, tz="UTC"){
#' Anything defined as a default, is returned as an attribute of that data frame.
#'
#' @param input XML with only the wml2:MeasurementTimeseries node and children
#' @param asDateTime logical, if \code{TRUE} returns date and time as POSIXct, if \code{FALSE}, character
#' @param tz character to set timezone attribute of datetime. Default is an empty quote, which converts the
#' datetimes to UTC (properly accounting for daylight savings times based on the data's provided time zone offset).
#' Possible values are "America/New_York","America/Chicago", "America/Denver","America/Los_Angeles",
#' "America/Anchorage","America/Honolulu","America/Jamaica","America/Managua","America/Phoenix", and "America/Metlakatla"
#' @importFrom xml2 xml_attr xml_find_all xml_text
#' @importFrom dplyr mutate
#' @importFrom lubridate parse_date_time
...
...
R/importWaterML2.r
deleted
100644 → 0
View file @
a3c3e59f
#' Function to return data from the WaterML2 data
#'
#' This function accepts a url parameter for a WaterML2 getObservation. This function is still under development,
#' but the general functionality is correct.
#'
#' @param obs_url character or raw, containing the url for the retrieval or a path to the data file, or raw XML.
#' @param asDateTime logical, if \code{TRUE} returns date and time as POSIXct, if \code{FALSE}, character
#' @param tz character to set timezone attribute of datetime. Default converts the datetimes to UTC
#' (properly accounting for daylight savings times based on the data's provided tz_cd column).
#' Recommended US values include "UTC","America/New_York","America/Chicago", "America/Denver","America/Los_Angeles",
#' "America/Anchorage","America/Honolulu","America/Jamaica","America/Managua","America/Phoenix", and "America/Metlakatla".
#' For a complete list, see \url{https://en.wikipedia.org/wiki/List_of_tz_database_time_zones}
#' @return mergedDF a data frame time, value, description, qualifier, and identifier
#' @export
#' @importFrom xml2 read_xml
#' @importFrom xml2 xml_find_all
#' @importFrom xml2 xml_text
#' @importFrom xml2 xml_attr
#' @importFrom dplyr rbind_all select
#' @importFrom lubridate parse_date_time
#' @examples
#' baseURL <- "https://waterservices.usgs.gov/nwis/dv/?format=waterml,2.0"
#' URL <- paste(baseURL, "sites=01646500",
#' "startDT=2014-09-01",
#' "endDT=2014-09-08",
#' "statCd=00003",
#' "parameterCd=00060",sep="&")
#' \dontrun{
#' dataReturned1 <- importWaterML2(URL)
#' URLmulti <- paste(baseURL,
#' "sites=04024430,04024000",
#' "startDT=2014-09-01",
#' "endDT=2014-09-08",
#' "statCd=00003",
#' "parameterCd=00060",sep="&")
#' dataReturnMulti <- importWaterML2(URLmulti)
#' }
#' filePath <- system.file("extdata", package="dataRetrieval")
#' fileName <- "WaterML2Example.xml"
#' fullPath <- file.path(filePath, fileName)
#' UserData <- importWaterML2(fullPath)
#'
importWaterML2
<-
function
(
obs_url
,
asDateTime
=
FALSE
,
tz
=
"UTC"
){
if
(
tz
!=
""
){
tz
=
"UTC"
}
tz
<-
match.arg
(
tz
,
OlsonNames
())
raw
<-
FALSE
if
(
class
(
obs_url
)
==
"character"
&&
file.exists
(
obs_url
)){
returnedDoc
<-
read_xml
(
obs_url
)
}
else
if
(
class
(
obs_url
)
==
'raw'
){
returnedDoc
<-
read_xml
(
obs_url
)
raw
<-
TRUE
}
else
{
returnedDoc
<-
xml_root
(
getWebServiceData
(
obs_url
,
encoding
=
'gzip'
))
}
timeSeries
<-
xml_find_all
(
returnedDoc
,
"//wml2:Collection"
)
#each parameter/site combo
if
(
0
==
length
(
timeSeries
)){
df
<-
data.frame
()
if
(
!
raw
){
attr
(
df
,
"url"
)
<-
obs_url
}
return
(
df
)
}
mergedDF
<-
NULL
for
(
t
in
timeSeries
){
df
<-
parseWaterML2Timeseries
(
t
,
asDateTime
,
tz
)
#need to save attributes first, and create identifier column
saveAttribs
<-
attributes
(
df
)[
-
(
1
:
3
)]
#remove time and date columns, add site col
df
<-
mutate
(
df
,
identifier
=
saveAttribs
$
gmlID
,
qualifier
=
ifelse
(
is.null
(
saveAttribs
$
defaultQualifier
),
NA
,
saveAttribs
$
defaultQualifier
))
if
(
all
(
is.na
(
df
$
dateTime
))){
df
<-
subset
(
df
,
select
=-
c
(
dateTime
,
time
))
#should the remaining column be changed to dateTime?
}
else
{
df
<-
subset
(
df
,
select
=-
c
(
date
,
time
))
}
if
(
is.null
(
mergedDF
)){
mergedDF
<-
df
}
else
{
similarNames
<-
intersect
(
colnames
(
mergedDF
),
colnames
(
df
))
mergedDF
<-
full_join
(
mergedDF
,
df
,
by
=
similarNames
)
}
attributes
(
mergedDF
)
<-
append
(
attributes
(
mergedDF
),
saveAttribs
)
}
return
(
mergedDF
)
}
man/importNGWMN
_wml2
.Rd
→
man/importNGWMN.Rd
View file @
152ecda9
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/importNGWMN_wml2.R
\name{importNGWMN
_wml2
}
\alias{importNGWMN
_wml2
}
\name{importNGWMN}
\alias{importNGWMN}
\title{Function to return data from the National Ground Water Monitoring Network waterML2 format}
\usage{
importNGWMN
_wml2
(input, asDateTime = FALSE, tz)
importNGWMN(input, asDateTime = FALSE, tz
= "UTC"
)
}
\arguments{
\item{input}{character or raw, containing the url for the retrieval or a path to the data file, or raw XML.}
...
...
@@ -13,7 +13,7 @@ importNGWMN_wml2(input, asDateTime = FALSE, tz)
\item{tz}{character to set timezone attribute of datetime. Default is an empty quote, which converts the
datetimes to UTC (properly accounting for daylight savings times based on the data's provided time zone offset).
Possible values
to provide
are "America/New_York","America/Chicago", "America/Denver","America/Los_Angeles",
Possible values are "America/New_York","America/Chicago", "America/Denver","America/Los_Angeles",
"America/Anchorage","America/Honolulu","America/Jamaica","America/Managua","America/Phoenix", and "America/Metlakatla"}
}
\value{
...
...
@@ -25,16 +25,19 @@ but the general functionality is correct.
}
\examples{
\dontrun{
url <- "http://cida.usgs.gov/ngwmn_cache/sos?request=GetObservation&service=SOS&version=2.0.0
&observedProperty=urn:ogc:def:property:OGC:GroundWaterLevel&responseFormat=text/xml&featureOf
Interest=VW_GWDP_GEOSERVER.USGS.403836085374401"
data <- importNGWMN_wml2(url)
obs_url <- paste("http://cida.usgs.gov/ngwmn_cache/sos?request=GetObservation",
"service=SOS","version=2.0.0",
"observedProperty=urn:ogc:def:property:OGC:GroundWaterLevel",
"responseFormat=text/xml",
"featureOfInterest=VW_GWDP_GEOSERVER.USGS.403836085374401",sep="&")
data <- importNGWMN(obs_url)
url <- "http://cida.usgs.gov/ngwmn_cache/sos?request=GetObservation&service=SOS&version=2.0.0
&observedProperty=urn:ogc:def:property:OGC:GroundWaterLevel&responseFormat=text/xml&featureOf
Interest=VW_GWDP_GEOSERVER.USGS.474011117072901"
data <- importNGWMN_wml2(url)
obs_url <- paste("http://cida.usgs.gov/ngwmn_cache/sos?request=GetObservation",
"service=SOS","version=2.0.0",
"observedProperty=urn:ogc:def:property:OGC:GroundWaterLevel",
"responseFormat=text/xml",
"featureOfInterest=VW_GWDP_GEOSERVER.USGS.474011117072901",sep="&")
data <- importNGWMN(obs_url)
}
}
man/importWaterML2.Rd
View file @
152ecda9
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/import
WaterML
2.
r
% Please edit documentation in R/import
NGWMN_wml
2.
R
\name{importWaterML2}
\alias{importWaterML2}
\title{
Function to return data from the W
aterML2
data
}
\title{
Parse the WaterML2 timeseries portion of a w
aterML2
file
}
\usage{
importWaterML2(
obs_url
, asDateTime = FALSE, tz = "UTC")
importWaterML2(
input
, asDateTime = FALSE, tz = "UTC")
}
\arguments{
\item{
obs_url}{character or raw, containing the url for the retrieval or a path to the data file, or raw XML.
}
\item{
input}{XML with only the wml2:MeasurementTimeseries node and children
}
\item{asDateTime}{logical, if \code{TRUE} returns date and time as POSIXct, if \code{FALSE}, character}
\item{tz}{character to set timezone attribute of datetime. Default converts the datetimes to UTC
(properly accounting for daylight savings times based on the data's provided tz_cd column).
Recommended US values include "UTC","America/New_York","America/Chicago", "America/Denver","America/Los_Angeles",
"America/Anchorage","America/Honolulu","America/Jamaica","America/Managua","America/Phoenix", and "America/Metlakatla".
For a complete list, see \url{https://en.wikipedia.org/wiki/List_of_tz_database_time_zones}}
}
\value{
mergedDF a data frame time, value, description, qualifier, and identifier
\item{tz}{character to set timezone attribute of datetime. Default is an empty quote, which converts the
datetimes to UTC (properly accounting for daylight savings times based on the data's provided time zone offset).
Possible values are "America/New_York","America/Chicago", "America/Denver","America/Los_Angeles",
"America/Anchorage","America/Honolulu","America/Jamaica","America/Managua","America/Phoenix", and "America/Metlakatla"}
}
\description{
This function accepts a url parameter for a WaterML2 getObservation. This function is still under develop
ment
,
but the general functionality is correct
.
Returns data frame columns of all information with each time series measure
ment
;
Anything defined as a default, is returned as an attribute of that data frame
.
}
\examples{
baseURL <- "https://waterservices.usgs.gov/nwis/dv/?format=waterml,2.0"
...
...
@@ -32,18 +28,6 @@ URL <- paste(baseURL, "sites=01646500",
"statCd=00003",
"parameterCd=00060",sep="&")
\dontrun{
dataReturned1 <- importWaterML2(URL)
URLmulti <- paste(baseURL,
"sites=04024430,04024000",
"startDT=2014-09-01",
"endDT=2014-09-08",
"statCd=00003",
"parameterCd=00060",sep="&")
dataReturnMulti <- importWaterML2(URLmulti)
}
filePath <- system.file("extdata", package="dataRetrieval")
fileName <- "WaterML2Example.xml"
fullPath <- file.path(filePath, fileName)
UserData <- importWaterML2(fullPath)
timesereies <- importWaterML2(URL, asDateTime=TRUE, tz="UTC")
}
}
man/parseWaterML2Timeseries.Rd
deleted
100644 → 0
View file @
a3c3e59f
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/importNGWMN_wml2.R
\name{parseWaterML2Timeseries}
\alias{parseWaterML2Timeseries}
\title{parse the timeseries portion of a waterML2 file}
\usage{
parseWaterML2Timeseries(input, asDateTime, tz)
}
\arguments{
\item{input}{XML with only the wml2:MeasurementTimeseries node and children}
}
\description{
Returns data frame columns of all information with each time series measurement;
Anything defined as a default, is returned as an attribute of that data frame.
}
man/readNGWMNdata.Rd
View file @
152ecda9
...
...
@@ -44,7 +44,7 @@ noDataSite <- readNGWMNdata(featureID = noDataSite, service = "observation")
#bounding box
bboxSites <- readNGWMNdata(service = "featureOfInterest", bbox = c(30, -99, 31, 102))
#retrieve 100 sites. Set asDateTime to false since one site has an invalid date
bboxData <- readNGWMNdata(service = "observation", featureID = bboxSites$site[1:
100
],
bboxData <- readNGWMNdata(service = "observation", featureID = bboxSites$site[1:
3
],
asDateTime = FALSE)
}
...
...
tests/testthat/tests_imports.R
View file @
152ecda9
...
...
@@ -178,7 +178,7 @@ test_that("importWaterML2 internal test", {
UserData
<-
importWaterML2
(
fullPath
)
# saveRDS(UserData, "rds/UserData.rds")
expect_is
(
UserData
$
value
,
'numeric'
)
expect_is
(
UserData
$
qualifier
,
'character'
)
#
expect_is(UserData$qualifier, 'character')
})
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment