Commit 57578d42 authored by David Watkins's avatar David Watkins
Browse files

tests

parent e8e6c19c
......@@ -32,7 +32,7 @@
#'
#'
#TODO: separate id and agency name, give also as separate dimensions
importNGWMN_wml2 <- function(input, asDateTime=FALSE, tz=""){
importNGWMN_wml2 <- function(input, asDateTime=FALSE, tz){
if(tz != ""){
tz <- match.arg(tz, OlsonNames())
}else{tz = "UTC"}
......
......@@ -116,9 +116,9 @@ readNGWMNdata <- function(service, ..., asDateTime = TRUE, tz = ""){
#' noDataSite <- readNGWMNlevels(featureID = noDataSite)
#' }
readNGWMNlevels <- function(featureID, asDateTime = TRUE){
readNGWMNlevels <- function(featureID, asDateTime = TRUE, tz = ""){
data <- readNGWMNdata(featureID = featureID, service = "observation",
asDateTime = asDateTime)
asDateTime = asDateTime, tz = tz)
return(data)
}
......@@ -155,7 +155,6 @@ readNGWMNsites <- function(featureID){
return(sites)
}
retrieveObservation <- function(featureID, asDateTime, attrs, tz){
url <- drURL(base.name = "NGWMN", access = pkg.env$access, request = "GetObservation",
service = "SOS", version = "2.0.0", observedProperty = "urn:ogc:def:property:OGC:GroundWaterLevel",
......@@ -206,7 +205,7 @@ retrieveFeatureOfInterest <- function(..., asDateTime, srsName="urn:ogc:def:crs:
stop("Geographical filter not specified. Please use featureID or bbox")
}
siteDF <- importNGWMN_wml2(url, asDateTime)
siteDF <- importNGWMN_wml2(url, asDateTime, tz = "")
attr(siteDF, "url") <- url
attr(siteDF, "queryTime") <- Sys.time()
return(siteDF)
......
......@@ -4,7 +4,7 @@
\alias{importNGWMN_wml2}
\title{Function to return data from the National Ground Water Monitoring Network waterML2 format}
\usage{
importNGWMN_wml2(input, asDateTime = FALSE, tz = "")
importNGWMN_wml2(input, asDateTime = FALSE, tz)
}
\arguments{
\item{input}{character or raw, containing the url for the retrieval or a path to the data file, or raw XML.}
......
......@@ -4,7 +4,7 @@
\alias{readNGWMNlevels}
\title{Retrieve groundwater levels from the National Ground Water Monitoring Network \url{http://cida.usgs.gov/ngwmn/}.}
\usage{
readNGWMNlevels(featureID, asDateTime = TRUE)
readNGWMNlevels(featureID, asDateTime = TRUE, tz = "")
}
\arguments{
\item{featureID}{character Vector of feature IDs formatted with agency code and site number
......
......@@ -217,3 +217,58 @@ test_that("readWQPdots working", {
expect_true("statecode" %in% names(formArgs))
expect_false("stateCd" %in% names(formArgs))
})
context("NGWMN")
test_that("NGWMN functions working", {
testthat::skip_on_cran()
noDataSite <- "UTGS.401544112060301"
noDataSite <- readNGWMNlevels(featureID = noDataSite)
expect_true(is.data.frame(noDataSite))
#bounding box and a bigger request
bboxSites <- readNGWMNdata(service = "featureOfInterest", bbox = c(30, -99, 31, 102))
expect_gt(nrow(bboxSites), 0)
siteInfo <- readNGWMNsites(bboxSites$site[1:100])
expect_gt(nrow(siteInfo), 90)
#one site
site <- "USGS.430427089284901"
oneSite <- readNGWMNlevels(featureID = site)
siteInfo <- readNGWMNsites(site)
expect_true(is.numeric(oneSite$value))
expect_true(is.character(oneSite$site))
expect_true(is.data.frame(siteInfo))
expect_true(nrow(siteInfo) > 0)
expect_true(nrow(oneSite) > 0)
#non-USGS site
data <- readNGWMNlevels(featureID = "MBMG.1388")
expect_true(nrow(data) > 1)
expect_true(is.numeric(oneSite$value))
#sites with colons and NAs work
na_colons <- c(NA, bboxSites$site[200:212], NA, NA)
returnDF <- readNGWMNdata(service = "observation",
featureID = na_colons, asDateTime = FALSE)
expect_is(returnDF, "data.frame")
expect_true(nrow(returnDF) > 1)
expect_true(!is.null(attributes(returnDF)$siteInfo))
sites <- c("USGS:424427089494701", NA)
siteInfo <- readNGWMNsites(sites)
expect_is(siteInfo, "data.frame")
expect_true(nrow(siteInfo) == 1)
#time zones
tzSite <- "USGS.385111104214403"
tzDataUTC <- readNGWMNlevels(tzSite, asDateTime = TRUE)
tzDataMT <- readNGWMNlevels(tzSite, asDateTime = TRUE,
tz = "US/Mountain")
expect_gt(nrow(tzDataMT), 1)
expect_gt(nrow(tzDataUTC), 1)
expect_is(tzDataUTC$dateTime, "POSIXct")
expect_is(tzDataMT$dateTime, "POSIXct")
expect_equal(attr(tzDataMT$dateTime, 'tzone'), "US/Mountain")
expect_warning(tzDataUTC$dateTime == tzDataMT$dateTime)
})
......@@ -224,50 +224,6 @@ test_that("state county tests",{
expect_equal(fromIDs, "Bacon County")
})
context("NGWMN")
test_that("NGWMN functions working", {
testthat::skip_on_cran()
noDataSite <- "UTGS.401544112060301"
noDataSite <- readNGWMNlevels(featureID = noDataSite)
expect_true(is.data.frame(noDataSite))
#bounding box and a bigger request
bboxSites <- readNGWMNdata(service = "featureOfInterest", bbox = c(30, -99, 31, 102))
expect_gt(nrow(bboxSites), 0)
siteInfo <- readNGWMNsites(bboxSites$site[1:100])
expect_gt(nrow(siteInfo), 90)
#one site
site <- "USGS.430427089284901"
oneSite <- readNGWMNlevels(featureID = site)
siteInfo <- readNGWMNsites(site)
expect_true(is.numeric(oneSite$value))
expect_true(is.character(oneSite$site))
expect_true(is.data.frame(siteInfo))
expect_true(nrow(siteInfo) > 0)
expect_true(nrow(oneSite) > 0)
#non-USGS site
data <- readNGWMNlevels(featureID = "MBMG.1388")
expect_true(nrow(data) > 1)
expect_true(is.numeric(oneSite$value))
#sites with colons and NAs work
na_colons <- c(NA, bboxSites$site[200:212], NA, NA)
returnDF <- readNGWMNdata(service = "observation",
featureID = na_colons, asDateTime = FALSE)
expect_is(returnDF, "data.frame")
expect_true(nrow(returnDF) > 1)
expect_true(!is.null(attributes(returnDF)$siteInfo))
sites <- c("USGS:424427089494701", NA)
siteInfo <- readNGWMNsites(sites)
expect_is(siteInfo, "data.frame")
expect_true(nrow(siteInfo) == 1)
})
context("water year column")
df_test <- data.frame(site_no = as.character(1:13),
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment