Skip to content

Commit

Permalink
put readNWISSample back in, but send to WQP
Browse files Browse the repository at this point in the history
  • Loading branch information
ldecicco-USGS committed Oct 26, 2024
1 parent 73da2f1 commit 986514f
Show file tree
Hide file tree
Showing 15 changed files with 161 additions and 36 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export(randomSubset)
export(readDataFromFile)
export(readNWISDaily)
export(readNWISInfo)
export(readNWISSample)
export(readUserDaily)
export(readUserInfo)
export(readUserSample)
Expand Down
3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
EGRET 3.0.10
===========
* Removed readNWISSample because the underlying data from NWIS is retired.
* Fix bug with 0 concentration values in readWQPSample.
* Style updates.
* Port readNWISSample to Water Quality Portal. NWIS services are retired.


EGRET 3.0.9
Expand Down
8 changes: 4 additions & 4 deletions R/EGRET.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ NULL

#' Constants included with EGRET
#'
#'\itemize{
#' \item{fluxConst}{Flux conversion object}
#' \item{qConst}{Flow conversion object}
#' \item{monthInfo}{Month object}
#'\tabular{ll}{
#' fluxConst \tab Flux conversion object\cr
#' qConst \tab Flow conversion object\cr
#' monthInfo \tab Month object\cr
#'}
#'
#'@aliases fluxConst qConst monthInfo concConst
Expand Down
2 changes: 1 addition & 1 deletion R/boxConcMonth.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' @param tinyPlot logical variable, if TRUE plot is designed to be plotted small as part of a multi-plot figure, default is FALSE.
#' @param logScale logical if TRUE y plotted in log axis
#' @param customPar logical defaults to FALSE. If TRUE, par() should be set by user before calling this function
#' @param las numeric in {0,1,2,3}; the style of axis labels, see ?par
#' @param las numeric in c(0,1,2,3); the style of axis labels, see ?par
#' @param showXLabels logical defaults to TRUE. If FALSE, the x axis label is not plotted
#' @param showYLabels logical defaults to TRUE. If FALSE, the y axis label is not plotted
#' @param showXAxis logical defaults to TRUE. If FALSE, the x axis is not plotted
Expand Down
2 changes: 1 addition & 1 deletion R/boxQTwice.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#' @param logScale logical if TRUE y plotted in log axis. Defaults to TRUE.
#' @param tinyPlot logical variable, if TRUE plot is designed to be plotted small as part of a multi-plot figure, default is FALSE.
#' @param customPar logical defaults to FALSE. If TRUE, par() should be set by user before calling this function
#' @param las numeric in {0,1,2,3}; the style of axis labels, see ?par
#' @param las numeric in c(0,1,2,3); the style of axis labels, see ?par
#' @param usgsStyle logical option to use USGS style guidelines. Setting this option
#' to TRUE does NOT guarantee USGS compliance. It will only change automatically
#' generated labels.
Expand Down
2 changes: 1 addition & 1 deletion R/boxResidMonth.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#' @param cex.main magnification to be used for main titles relative to the current setting of cex
#' @param font.main font to be used for plot main titles
#' @param customPar logical defaults to FALSE. If TRUE, par() should be set by user before calling this function
#' @param las numeric in {0,1,2,3}; the style of axis labels
#' @param las numeric in c(0,1,2,3); the style of axis labels
#' @param randomCensored logical. Show censored residuals as randomized. Default = FALSE.
#' @param monthLab object of monthLabel class, or numeric represented the short code,
#' or character representing the descriptive name.
Expand Down
61 changes: 61 additions & 0 deletions R/readNWISSample.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#' Import NWIS Sample Data for EGRET analysis
#'
#' Imports data from NWIS web service.
#' A list of parameter and statistic codes can be found here: \url{https://help.waterdata.usgs.gov/codes-and-parameters}
#' For raw data, use \code{\link[dataRetrieval]{readNWISqw}} from the dataRetrieval package.
#' This function will retrieve the raw data, and compress it (summing constituents) if
#' more than 1 parameter code is supplied. See
#' section 3.2.4 of the vignette for more details.
#'
#' @param siteNumber character USGS site number. This is usually an 8 digit number
#' @param parameterCd character USGS parameter code. This is usually an 5 digit number.
#' @param startDate character starting date for data retrieval in the form YYYY-MM-DD.
#' Default is empty quotes "" which will retrieve the full period of record.
#' @param endDate character ending date for data retrieval in the form YYYY-MM-DD.
#' Default is empty quotes "" which will retrieve the full period of record.
#' @param verbose logical specifying whether or not to display progress message
#' @keywords data import USGS WRTDS
#' @export
#' @return A data frame 'Sample' with the following columns:
#' \tabular{lll}{
#' Name \tab Type \tab Description \cr
#' Date \tab Date \tab Date \cr
#' ConcLow \tab numeric \tab Lower limit of concentration \cr
#' ConcHigh \tab numeric \tab Upper limit of concentration \cr
#' Uncen \tab integer \tab Uncensored data (1=TRUE, 0=FALSE) \cr
#' ConcAve \tab numeric \tab Average concentration \cr
#' Julian \tab integer \tab Number of days since Jan. 1, 1850\cr
#' Month \tab integer \tab Month of the year [1-12] \cr
#' Day \tab integer \tab Day of the year [1-366] \cr
#' DecYear \tab numeric \tab Decimal year \cr
#' MonthSeq \tab integer \tab Number of months since January 1, 1850 \cr
#' SinDY \tab numeric \tab Sine of the DecYear \cr
#' CosDY \tab numeric \tab Cosine of the DecYear
#' }
#' @seealso \code{\link{compressData}}, \code{\link{populateSampleColumns}},
#' \code{\link[dataRetrieval]{readNWISqw}}
#' @examples
#' \donttest{
#' # These examples require an internet connection to run
#'
#' Sample_01075 <- readNWISSample('01594440','01075', '1985-01-01', '1985-03-31')
#' }
readNWISSample <- function(siteNumber,
parameterCd,
startDate = "",
endDate = "",
verbose = TRUE){


siteNumber <- paste0("USGS-", siteNumber)

Sample <- readWQPSample(siteNumber = siteNumber,
characteristicName = parameterCd,
startDate = startDate,
endDate = endDate,
verbose = verbose)

return(Sample)

}

2 changes: 1 addition & 1 deletion R/readWQPSample.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ readWQPSample <- function(siteNumber,
"ResultStatusIdentifier",
"ResultValueTypeName")

if(packageVersion("dataRetrieval") >= "2.7.17"){
if(utils::packageVersion("dataRetrieval") >= "2.7.17"){
data <- suppressMessages(dataRetrieval::readWQPqw(siteNumbers = siteNumber,
parameterCd = characteristicName,
startDate = startDate,
Expand Down
8 changes: 4 additions & 4 deletions man/Constants.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/boxConcMonth.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/boxQTwice.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/boxResidMonth.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions man/readNWISSample.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 16 additions & 17 deletions tests/testthat/tests_imports.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,25 @@ test_that("External NWIS Sample tests", {
SampleNames <- c("Date","ConcLow","ConcHigh","Uncen","ConcAve","Julian","Month",
"Day","DecYear","MonthSeq","waterYear","SinDY","CosDY")

expect_warning(Sample_01075 <- readNWISSample('01594440',
Sample_01075 <- readNWISSample('01594440',
'01075',
'1985-01-01',
'1985-03-31'))
'1985-03-31')

expect_true(all(SampleNames %in% names(Sample_01075)))

expect_warning(Sample_All2 <- readNWISSample('05114000',
Sample_All2 <- readNWISSample('05114000',
c('00915','00931'),
'1985-01-01',
'1985-03-31'))
'1985-03-31')

expect_true(all(SampleNames %in% names(Sample_All2)))

Sample_Select <- expect_warning(readNWISSample('05114000',
Sample_Select <- readNWISSample('05114000',
c('00915','00931'),
'', ''))
'', '')

expect_true(all(names(Sample_Select) %in% SampleNames))
expect_true(all(SampleNames %in% names(Sample_Select)))

expect_is(Sample_Select$Date, 'Date')
expect_is(Sample_Select$ConcAve, 'numeric')
Expand Down Expand Up @@ -73,16 +73,15 @@ test_that("External INFO tests", {
INFO <- readNWISInfo('05114000','00010',interactive=FALSE)
expect_true(all(requiredColumns %in% names(INFO)))

# nameToUse <- 'Specific conductance'
# pcodeToUse <- '00095'
#
# INFO_WQP <- readWQPInfo('USGS-04024315',pcodeToUse,interactive=FALSE)
# expect_true(all(requiredColumns %in% names(INFO_WQP)))
#
# INFO2 <- readWQPInfo('WIDNR_WQX-10032762',nameToUse,interactive=FALSE)
# expect_true(all(requiredColumns %in% names(INFO2)))
#
#
nameToUse <- 'Specific conductance'
pcodeToUse <- '00095'

INFO_WQP <- readWQPInfo('USGS-04024315',pcodeToUse,interactive=FALSE)
expect_true(all(requiredColumns %in% names(INFO_WQP)))

INFO2 <- readWQPInfo('WIDNR_WQX-10032762',nameToUse,interactive=FALSE)
expect_true(all(requiredColumns %in% names(INFO2)))

})

test_that("User tests", {
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/tests_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ test_that("data functions work", {
compressed <- compressData(dataInput)
expect_is(compressed, "data.frame")
expect_gt(nrow(compressed), 1)
expect_equal(names(compressed), c("dateTime", "ConcLow", "ConcHigh",
"Uncen"))
expect_true(all(c("dateTime", "ConcLow", "ConcHigh", "Uncen") %in%
names(compressed)))

#mergeReport

siteNumber <- '01594440'
pCode <- '01075'
Daily <- readNWISDaily(siteNumber,'00060', '1985-01-01', '1990-03-31')
expect_warning(Sample <- readNWISSample(siteNumber,pCode, '1985-01-01', '1990-03-31'))
Sample <- readNWISSample(siteNumber,pCode, '1985-01-01', '1990-03-31')
INFO <- readNWISInfo(siteNumber,pCode,interactive=FALSE)
eList <- mergeReport(INFO, Daily, Sample)
expect_equal(names(eList), c("INFO", "Daily", "Sample", "surfaces"))
Expand Down

0 comments on commit 986514f

Please sign in to comment.