diff --git a/.Rbuildignore b/.Rbuildignore new file mode 100644 index 0000000..b143f46 --- /dev/null +++ b/.Rbuildignore @@ -0,0 +1,5 @@ +^.*\.Rproj$ +^\.Rproj\.user$ +.travis.yml +images +CONDUCT.md \ No newline at end of file diff --git a/.gitignore b/.gitignore index 7ed5508..ab715f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ src-i386 src-x64 -.Rbuildignore .Rproj.user .Rhistory .RData diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..16aa537 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,52 @@ +# Sample .travis.yml for R projects. +# +# See README.md for instructions, or for more configuration options, +# see the wiki: +# https://github.com/craigcitro/r-travis/wiki + +language: r +cache: packages +dist: trusty + +matrix: + include: + - os: linux + r: release + - os: linux + r: devel + env: R_CODECOV=true + +addons: + apt: + packages: + - libcurl4-openssl-dev + +env: + global: + - R_BUILD_ARGS="--no-build-vignettes --no-manual" + - R_CHECK_ARGS="--no-build-vignettes --no-manual --as-cran" + - NOT_CRAN="true" + - _R_CHECK_FORCE_SUGGESTS_=false + +repos: + CRAN: https://cran.rstudio.com + GRAN: https://owi.usgs.gov/R + +warnings_are_errors: true + +script: + - | + R CMD build . + travis_wait 20 R CMD check rloadest*tar.gz + +r_github_packages: + - jimhester/covr + +after_success: + - if [[ "${R_CODECOV}" ]]; then R -e 'covr::coveralls()'; fi + +notifications: + email: + on_success: change + on_failure: change + diff --git a/CONDUCT.md b/CONDUCT.md new file mode 100644 index 0000000..9150e26 --- /dev/null +++ b/CONDUCT.md @@ -0,0 +1,25 @@ +# Contributor Code of Conduct + +As contributors and maintainers of this project, we pledge to respect all people who +contribute through reporting issues, posting feature requests, updating documentation, +submitting pull requests or patches, and other activities. + +We are committed to making participation in this project a harassment-free experience for +everyone, regardless of level of experience, gender, gender identity and expression, +sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. + +Examples of unacceptable behavior by participants include the use of sexual language or +imagery, derogatory comments or personal attacks, trolling, public or private harassment, +insults, or other unprofessional conduct. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, +commits, code, wiki edits, issues, and other contributions that are not aligned to this +Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed +from the project team. + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by +opening an issue or contacting one or more of the project maintainers. + +This Code of Conduct is adapted from the Contributor Covenant +(http:contributor-covenant.org), version 1.0.0, available at +http://contributor-covenant.org/version/1/0/0/ \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 8f48f03..9253db4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,13 +1,13 @@ Package: rloadest Type: Package Title: River Load Estimation -Version: 0.4.4 -Date: 2017-01-10 -Authors@R: c( person("Dave", "Lorenz", email = "lorenz@usgs.gov", role = "cre"), +Version: 0.4.5 +Date: 2017-07-26 +Authors@R: c( person("Dave", "Lorenz", role = "cre", email = "gs-w_r_admin@usgs.gov"), person("Rob", "Runkel", role = "aut"), person("Laura", "De Cicco", role = "aut"), - person("David", "Watkins", role = "ctb")) -Maintainer: Dave Lorenz + person("David", "Watkins", role = "ctb"), + person("Joseph", "Stachelek", role = "ctb")) Description: Collection of functions to make constituent load estimations based on the LOADEST program. License: CC0 @@ -26,6 +26,7 @@ Suggests: EGRET, survival, knitr +BugReports: https://github.com/USGS-R/rloadest/issues LazyLoad: yes LazyData: yes RoxygenNote: 6.0.1 diff --git a/R/rloadest-package.R b/R/rloadest-package.R index 9200512..44bbd5e 100644 --- a/R/rloadest-package.R +++ b/R/rloadest-package.R @@ -3,8 +3,6 @@ #' \tabular{ll}{ #' Package: \tab rloadest\cr #' Type: \tab Package\cr -#' Version: \tab 0.4.3\cr -#' Date: \tab 2015-12-03\cr #' License: \tab CC0\cr #' LazyLoad: \tab yes\cr #' } @@ -31,9 +29,19 @@ #' #' @name rloadest-package #' @docType package -#' @author Dave Lorenz \email{lorenz@@usgs.gov} #' @keywords load estimation NULL .onAttach <- function(libname, pkgname) { - packageStartupMessage("Although this software program has been used by the U.S. Geological Survey (USGS), no warranty, expressed or implied, is made by the USGS or the U.S. Government as to the accuracy and functioning of the program and related program material nor shall the fact of distribution constitute any such warranty, and no responsibility is assumed by the USGS in connection therewith.") + packageStartupMessage("This information is preliminary or provisional and +is subject to revision. It is being provided to meet +the need for timely best science. The information +has not received final approval by the U.S. Geological +Survey (USGS) and is provided on the condition that +neither the USGS nor the U.S. Government shall be held +liable for any damages resulting from the authorized +or unauthorized use of the information. + +****Orphaned Package**** +This package is looking for a new maintainer. For more information, +see: https://owi.usgs.gov/R/packages.html#orphan") } diff --git a/README.md b/README.md index 0936022..54b389d 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,42 @@ rloadest USGS water science R functions for LOAD ESTimation of constituents in rivers and streams. -##Package Installation +## Package Status +[![status](https://img.shields.io/badge/USGS-Orphan-red.svg)](https://owi.usgs.gov/R/packages.html#orphan) + +This package is currently in an 'orphaned' state, and +looking for a new maintainer. For more information, see: +[https://owi.usgs.gov/R/packages.html#orphan](https://owi.usgs.gov/R/packages.html#orphan) + +If you are interested in becoming the official maintainer of `rloadest`, please email gs-w_r_admin@usgs.gov. + +In the meantime, we rely on community involvement to report and fix bugs. + +### Current build tests: + +|Linux|Test Coverage| +|----------|------------| +| [![travis](https://travis-ci.org/USGS-R/rloadest.svg?branch=master)](https://travis-ci.org/USGS-R/rloadest)|[![Coverage Status](https://coveralls.io/repos/github/USGS-R/rloadest/badge.svg?branch=master)](https://coveralls.io/github/USGS-R/rloadest?branch=master)| + +### Reporting bugs + +Please consider reporting bugs and asking questions on the Issues page: +[https://github.com/USGS-R/rloadest/issues](https://github.com/USGS-R/rloadest/issues) + +Follow `@USGS_R` on Twitter for updates on USGS R packages: + +[![Twitter Follow](https://img.shields.io/twitter/follow/USGS_R.svg?style=social&label=Follow%20USGS_R)](https://twitter.com/USGS_R) + + +## Code of Conduct + +We want to encourage a warm, welcoming, and safe environment for contributing to this project. See the [code of conduct](https://github.com/USGS-R/rloadest/blob/master/CONDUCT.md) for more information. + +## Package Installation To install the `rloadest` package: +USGS R Installation Instructions: [https://owi.usgs.gov/R/training-curriculum/installr/](https://owi.usgs.gov/R/training-curriculum/installr/) + 1. Install R (version 3.0 or greater) from: [https://cran.r-project.org/](https://cran.r-project.org/) 2. Install RStudio from: [https://www.rstudio.com/products/rstudio/download/](https://www.rstudio.com/products/rstudio/download/) @@ -39,9 +72,108 @@ To install the `rloadest` package: 7. Make sure to keep your version of R up-to-date. CRAN and the USGS repository will only update packages for the most recent version of R, and one version behind that. +## Model Archive + +When using the `rloadest` model, it is important to be able to reproduce the results in the future. The following version of R and package dependencies were used most recently to pass the embedded tests within this package. There is no guarantee of reproducible results using future versions of R or updated versions of package dependencies. + +``` +devtools::session_info() +Session info ----------------------------------------------------------------------------- + setting value + version R version 3.4.1 (2017-06-30) + system x86_64, mingw32 + ui RStudio (1.0.143) + language (EN) + collate English_United States.1252 + tz America/Chicago + date 2017-07-27 + +Packages --------------------------------------------------------------------------------- + package * version date source + akima 0.6-2 2016-12-20 CRAN (R 3.4.0) + assertthat 0.2.0 2017-04-11 CRAN (R 3.4.0) + base * 3.4.1 2017-06-30 local + bindr 0.1 2016-11-13 CRAN (R 3.4.0) + bindrcpp 0.2 2017-06-17 CRAN (R 3.4.0) + boot 1.3-19 2017-02-11 CRAN (R 3.4.1) + car 2.1-5 2017-07-04 CRAN (R 3.4.1) + codetools 0.2-15 2016-10-05 CRAN (R 3.4.1) + coin 1.2-1 2017-07-17 CRAN (R 3.4.1) + compiler 3.4.1 2017-06-30 local + curl 2.8.1 2017-07-21 CRAN (R 3.4.1) + dataRetrieval * 2.7.2 2017-05-23 CRAN (R 3.4.1) + datasets * 3.4.1 2017-06-30 local + devtools 1.13.2 2017-06-02 CRAN (R 3.4.1) + digest 0.6.12 2017-01-27 CRAN (R 3.4.0) + dplyr 0.7.2 2017-07-20 CRAN (R 3.4.1) + glue 1.1.1 2017-06-21 CRAN (R 3.4.0) + graphics * 3.4.1 2017-06-30 local + grDevices * 3.4.1 2017-06-30 local + grid 3.4.1 2017-06-30 local + hms 0.3 2016-11-22 CRAN (R 3.4.0) + httr 1.2.1 2016-07-03 CRAN (R 3.3.1) + jsonlite 1.5 2017-06-01 CRAN (R 3.4.0) + KernSmooth 2.23-15 2015-06-29 CRAN (R 3.4.1) + lattice 0.20-35 2017-03-25 CRAN (R 3.4.1) + leaps 3.0 2017-01-10 CRAN (R 3.4.0) + lme4 1.1-13 2017-04-19 CRAN (R 3.4.0) + lubridate * 1.6.0 2016-09-13 CRAN (R 3.4.0) + magrittr 1.5 2014-11-22 CRAN (R 3.4.0) + MASS 7.3-47 2017-02-26 CRAN (R 3.4.1) + Matrix 1.2-10 2017-05-03 CRAN (R 3.4.1) + MatrixModels 0.4-1 2015-08-22 CRAN (R 3.4.0) + memoise 1.1.0 2017-04-21 CRAN (R 3.4.0) + methods * 3.4.1 2017-06-30 local + mgcv 1.8-17 2017-02-08 CRAN (R 3.4.0) + minqa 1.2.4 2014-10-09 CRAN (R 3.4.0) + modeltools 0.2-21 2013-09-02 CRAN (R 3.4.0) + multcomp 1.4-6 2016-07-14 CRAN (R 3.4.0) + mvtnorm 1.0-6 2017-03-02 CRAN (R 3.4.0) + NADA 1.6-1 2017-03-31 CRAN (R 3.4.0) + nlme 3.1-131 2017-02-06 CRAN (R 3.4.1) + nloptr 1.0.4 2014-08-04 CRAN (R 3.4.0) + nnet 7.3-12 2016-02-02 CRAN (R 3.4.1) + parallel 3.4.1 2017-06-30 local + pbkrtest 0.4-7 2017-03-15 CRAN (R 3.4.0) + pkgconfig 2.0.1 2017-03-21 CRAN (R 3.4.0) + plyr 1.8.4 2016-06-08 CRAN (R 3.3.1) + quantreg 5.33 2017-04-18 CRAN (R 3.4.0) + R6 2.2.2 2017-06-17 CRAN (R 3.4.0) + randtests 1.0 2014-11-17 CRAN (R 3.4.0) + Rcpp 0.12.12 2017-07-15 CRAN (R 3.4.1) + readr 1.1.1 2017-05-16 CRAN (R 3.4.0) + reshape2 1.4.2 2016-10-22 CRAN (R 3.4.0) + rlang 0.1.1 2017-05-18 CRAN (R 3.4.1) + rloadest * 0.4.5 2017-07-26 local + rstudioapi 0.6 2016-06-27 CRAN (R 3.3.1) + sandwich 2.3-4 2015-09-24 CRAN (R 3.4.0) + segmented 0.5-2.1 2017-06-14 CRAN (R 3.4.0) + smwrBase * 1.1.3 2017-05-02 Github (USGS-R/smwrBase@f7bef98) + smwrGraphs * 1.1.3 2017-07-27 local + smwrQW * 0.7.13 2017-07-26 local + smwrStats * 0.7.6 2017-07-26 local + sp 1.2-5 2017-06-29 CRAN (R 3.4.1) + SparseM 1.77 2017-04-23 CRAN (R 3.4.0) + splines 3.4.1 2017-06-30 local + stats * 3.4.1 2017-06-30 local + stats4 3.4.1 2017-06-30 local + stringi 1.1.5 2017-04-07 CRAN (R 3.4.0) + stringr 1.2.0 2017-02-18 CRAN (R 3.4.0) + survival 2.41-3 2017-04-04 CRAN (R 3.4.0) + TH.data 1.0-8 2017-01-23 CRAN (R 3.4.0) + tibble 1.3.3 2017-05-28 CRAN (R 3.4.0) + tools 3.4.1 2017-06-30 local + truncnorm 1.0-7 2014-01-21 CRAN (R 3.3.0) + utils * 3.4.1 2017-06-30 local + withr 1.0.2 2016-06-20 CRAN (R 3.3.1) + XML 3.98-1.9 2017-06-19 CRAN (R 3.4.0) + xml2 1.1.1 2017-01-24 CRAN (R 3.4.0) + zCompositions 1.0.3-1 2016-04-14 CRAN (R 3.4.0) + zoo 1.8-0 2017-04-12 CRAN (R 3.4.0) +``` + +## Disclaimer -Disclaimer ----------- This software is in the public domain because it contains materials that originally came from the U.S. Geological Survey, an agency of the United States Department of Interior. For more information, see the official USGS copyright policy at [https://www.usgs.gov/visual-id/credit_usgs.html#copyright](https://www.usgs.gov/visual-id/credit_usgs.html#copyright) Although this software program has been used by the U.S. Geological Survey (USGS), no warranty, expressed or implied, is made by the USGS or the U.S. Government as to the accuracy and functioning of the program and related program material nor shall the fact of distribution constitute any such warranty, and no responsibility is assumed by the USGS in connection therewith. diff --git a/inst/doc/IncorporatingHysteresis.pdf b/inst/doc/IncorporatingHysteresis.pdf index 5da4768..65ed5f3 100644 Binary files a/inst/doc/IncorporatingHysteresis.pdf and b/inst/doc/IncorporatingHysteresis.pdf differ diff --git a/inst/doc/InstantaneousTimeStep.R b/inst/doc/InstantaneousTimeStep.R index 420e72f..2ed41bc 100644 --- a/inst/doc/InstantaneousTimeStep.R +++ b/inst/doc/InstantaneousTimeStep.R @@ -1,23 +1,14 @@ ### R code from vignette source 'InstantaneousTimeStep.Rnw' ################################################### -### code chunk number 1: InstantaneousTimeStep.Rnw:8-12 -################################################### -library(knitr) -opts_chunk$set( -concordance=TRUE -) - - -################################################### -### code chunk number 2: InstantaneousTimeStep.Rnw:28-52 +### code chunk number 1: InstantaneousTimeStep.Rnw:23-47 ################################################### # Load the necessary packages and the data library(rloadest) library(dataRetrieval) # What unit values are available? -subset(whatNWISdata("04027000"), data_type_cd=="uv", - select=c("parm_cd", "srsname", "begin_date", "end_date")) +subset(whatNWISdata(siteNumber = "04027000"), data_type_cd=="uv", + select=c("parm_cd", "begin_date", "end_date")) # Get the QW data BadQW <- importNWISqw("04027000", "00940", begin.date="2011-04-01", end.date="2014-09-30") @@ -39,14 +30,14 @@ names(BadData)[which(names(BadData)=='dateTime.left')] <- "dateTime" ################################################### -### code chunk number 3: InstantaneousTimeStep.Rnw:60-62 +### code chunk number 2: InstantaneousTimeStep.Rnw:55-57 ################################################### # Print the number of missing values in each column sapply(BadData, function(col) sum(is.na(col))) ################################################### -### code chunk number 4: InstantaneousTimeStep.Rnw:67-74 +### code chunk number 3: InstantaneousTimeStep.Rnw:62-69 ################################################### # Create and print the candidate model. BadChloride.lr <- selBestSubset(Chloride ~ log(Flow) + fourier(dateTime) + @@ -58,7 +49,7 @@ print(BadChloride.lr) ################################################### -### code chunk number 5: InstantaneousTimeStep.Rnw:81-85 +### code chunk number 4: InstantaneousTimeStep.Rnw:76-80 ################################################### # Plot the overall fit, choose plot number 2. setSweave("graph01", 6, 6) @@ -67,7 +58,7 @@ dev.off() ################################################### -### code chunk number 6: InstantaneousTimeStep.Rnw:94-98 +### code chunk number 5: InstantaneousTimeStep.Rnw:89-93 ################################################### # Plot the residual Q-normal graph. setSweave("graph02", 6, 6) @@ -76,7 +67,7 @@ dev.off() ################################################### -### code chunk number 7: InstantaneousTimeStep.Rnw:107-111 +### code chunk number 6: InstantaneousTimeStep.Rnw:102-106 ################################################### # Plot the residual Q-normal graph. setSweave("graph03", 6, 6) @@ -85,7 +76,7 @@ dev.off() ################################################### -### code chunk number 8: InstantaneousTimeStep.Rnw:120-127 +### code chunk number 7: InstantaneousTimeStep.Rnw:115-122 ################################################### # Create the and print the revised model. BadChloride.lr <- loadReg(Chloride ~ log(Flow) + fourier(dateTime) + @@ -97,7 +88,7 @@ print(BadChloride.lr, load.only=FALSE) ################################################### -### code chunk number 9: InstantaneousTimeStep.Rnw:135-139 +### code chunk number 8: InstantaneousTimeStep.Rnw:130-134 ################################################### # Plot the overall fit, choose plot number 2. setSweave("graph04", 6, 6) @@ -106,7 +97,7 @@ dev.off() ################################################### -### code chunk number 10: InstantaneousTimeStep.Rnw:148-152 +### code chunk number 9: InstantaneousTimeStep.Rnw:143-147 ################################################### # Plot the S-L grpah. setSweave("graph05", 6, 6) @@ -115,7 +106,7 @@ dev.off() ################################################### -### code chunk number 11: InstantaneousTimeStep.Rnw:161-165 +### code chunk number 10: InstantaneousTimeStep.Rnw:156-160 ################################################### # Plot the residual Q-normal graph. setSweave("graph06", 6, 6) @@ -124,7 +115,7 @@ dev.off() ################################################### -### code chunk number 12: InstantaneousTimeStep.Rnw:175-179 +### code chunk number 11: InstantaneousTimeStep.Rnw:170-174 ################################################### # Plot the residual Q-normal graph. setSweave("graph07", 6, 6) @@ -133,7 +124,7 @@ dev.off() ################################################### -### code chunk number 13: InstantaneousTimeStep.Rnw:193-209 +### code chunk number 12: InstantaneousTimeStep.Rnw:188-204 ################################################### # Extract one day from the UV data Bad063014 <- subset(BadUV, as.Date(as.POSIXlt(dateTime)) == "2014-06-30") @@ -154,7 +145,7 @@ with(Bad063014.est, mean(Conc)) ################################################### -### code chunk number 14: InstantaneousTimeStep.Rnw:221-248 +### code chunk number 13: InstantaneousTimeStep.Rnw:216-243 ################################################### # Extract one month from the UV data, done in two steps Bad0714 <- subset(BadUV, as.Date(as.POSIXlt(dateTime)) >= "2014-07-01") diff --git a/inst/doc/InstantaneousTimeStep.Rnw b/inst/doc/InstantaneousTimeStep.Rnw index cdf24b9..7fc7297 100644 --- a/inst/doc/InstantaneousTimeStep.Rnw +++ b/inst/doc/InstantaneousTimeStep.Rnw @@ -5,12 +5,7 @@ \begin{document} -<>= -library(knitr) -opts_chunk$set( -concordance=TRUE -) -@ +\SweaveOpts{concordance=TRUE} \raggedright @@ -30,8 +25,8 @@ This example uses data from the Bad River near Odanah, Wisc., USGS gaging statio library(rloadest) library(dataRetrieval) # What unit values are available? -subset(whatNWISdata("04027000"), data_type_cd=="uv", - select=c("parm_cd", "srsname", "begin_date", "end_date")) +subset(whatNWISdata(siteNumber = "04027000"), data_type_cd=="uv", + select=c("parm_cd", "begin_date", "end_date")) # Get the QW data BadQW <- importNWISqw("04027000", "00940", begin.date="2011-04-01", end.date="2014-09-30") diff --git a/inst/doc/InstantaneousTimeStep.pdf b/inst/doc/InstantaneousTimeStep.pdf index 80fc643..f37ba7a 100644 Binary files a/inst/doc/InstantaneousTimeStep.pdf and b/inst/doc/InstantaneousTimeStep.pdf differ diff --git a/inst/doc/SubDailyTimeSteps.R b/inst/doc/SubDailyTimeSteps.R deleted file mode 100644 index 4c21075..0000000 --- a/inst/doc/SubDailyTimeSteps.R +++ /dev/null @@ -1,123 +0,0 @@ -### R code from vignette source 'SubDailyTimeSteps.Rnw' - -################################################### -### code chunk number 1: SubDailyTimeSteps.Rnw:10-14 -################################################### -library(knitr) -opts_chunk$set( -concordance=TRUE -) - - -################################################### -### code chunk number 2: SubDailyTimeSteps.Rnw:35-59 -################################################### -# Load the necessary packages and the data -library(rloadest) -library(dataRetrieval) -# Get the QW data -Brushy <- "02207400" -# Parameter code 00665 is whole-water phosphorus -# Parameter code 71123 is mean streamflow for peak flow -# Parameter code 00060 is the daily mean streamflow -# Parameter code 00061 is the measured streamflow -# 71123 will be used as the flow for peak flows and 00061 -# for base flow or 00060 if 00061 is missing. -BrushyQW <- importNWISqw("02207400", - params=c("00625", "72123", "00060", "00061"), - begin.date="2004-10-02", end.date="2013-09-30") -# Convert the separate columns of dates and times to a single column -# Uses functions from smwrBase -BrushyQW <- transform(BrushyQW, - StartDateTime = setTZ(sample_dt + as.timeDay(sample_tm), tzone_cd, force.stz=TRUE), - EndDateTime = setTZ(sample_end_dt + as.timeDay(sample_end_tm), tzone_cd, force.stz=TRUE)) -# A few rows of data: -head(BrushyQW) -# Subset to remove the missing values in Kjeldahl_WW.N.00625 -# Note that this works only because we are interested in Kjeldahl_WW.N.00625 -BrushyQW <- subset(BrushyQW, !is.na(Kjeldahl_WW.N.00625)) - - -################################################### -### code chunk number 3: SubDailyTimeSteps.Rnw:67-82 -################################################### -# Compute the median peak duration. -with(BrushyQW, median(EndDateTime - StartDateTime, na.rm=T)) -# Compute the sample date and time -BrushyQW <- transform(BrushyQW, - dateTime=ifelse(is.na(EndDateTime), StartDateTime, - StartDateTime + (EndDateTime - StartDateTime)/2)) -# Need to convert to POSIXct. Note that the original data were -# recorded in standard time only, so the correct time zone is -# "America/Jamaica," which preserves the correct time offset. -BrushyQW <- transform(BrushyQW, dateTime=as.POSIXct(dateTime, - origin="1970-01-01", tz="America/Jamaica")) -# Now the flow, coalesce is in smwrBase -BrushyQW <- transform(BrushyQW, - Flow=ifelse(!is.na(EndDateTime), DischargeMeanStorm_cfs, - coalesce(InstDischarge_cfs, Discharge_cfs))) - - -################################################### -### code chunk number 4: SubDailyTimeSteps.Rnw:90-94 -################################################### -# Find the "best" predefined model -Brushy.lreg <- selBestModel("Kjeldahl_WW.N.00625", BrushyQW, flow="Flow", - dates="dateTime", time.step="6 hour", station=Brushy) -print(Brushy.lreg) - - -################################################### -### code chunk number 5: SubDailyTimeSteps.Rnw:99-103 -################################################### -# Set up for graph in vignette -setSweave("graph01", 6, 6) -plot(Brushy.lreg, which = 1, set.up=FALSE) -dev.off() - - -################################################### -### code chunk number 6: SubDailyTimeSteps.Rnw:111-115 -################################################### -# Set up for graph in vignette -setSweave("graph02", 6, 6) -plot(Brushy.lreg, which = 4, set.up=FALSE) -dev.off() - - -################################################### -### code chunk number 7: SubDailyTimeSteps.Rnw:123-127 -################################################### -# Set up for graph in vignette -setSweave("graph03", 6, 6) -plot(Brushy.lreg, which = 5, set.up=FALSE) -dev.off() - - -################################################### -### code chunk number 8: SubDailyTimeSteps.Rnw:137-139 -################################################### -# Jackknife statistics -jackStats(Brushy.lreg) - - -################################################### -### code chunk number 9: SubDailyTimeSteps.Rnw:147-162 -################################################### -# Get the data for May, 2013 -BrushyQ <- readNWISuv(Brushy, "00060", startDate="2013-05-01", - endDate="2013-05-31", tz="America/New_York") -# Rename the Flow column, must be done manually as renameNWISColumns -# appends _Inst -# Detect the Flow column position based on the expectation -# that it will be numeric -flowColumn <- seq(4, 6, 1)[ - which.min(lapply(BrushyQ[,4:6], - function(x) sum(is.na(as.numeric(x)))))] -names(BrushyQ)[flowColumn] <- "Flow" -# Show the gap in the record: -BrushyQ[2030:2040,] -# predict the load -predLoad(Brushy.lreg, BrushyQ, by="month") - - diff --git a/inst/doc/SubDailyTimeSteps.Rnw b/inst/doc/SubDailyTimeSteps.Rnw deleted file mode 100644 index bcfc8ca..0000000 --- a/inst/doc/SubDailyTimeSteps.Rnw +++ /dev/null @@ -1,172 +0,0 @@ -\documentclass{article} -\parskip 6pt -\usepackage[margin=1.25in]{geometry} -\usepackage[colorlinks=true,urlcolor=blue]{hyperref} - -%\VignetteIndexEntry{Subdaily Time-Step Models} -%\VignetteDepends{rloadest} - -\begin{document} -<>= -library(knitr) -opts_chunk$set( -concordance=TRUE -) -@ -\raggedright - -\title{Subdaily Time-Step Models} - -\author{Dave Lorenz} - -\maketitle - -\begin{abstract} -This example illustrates how to set up and build a rating curve model for a sub-daily time step. Sub-daily time steps can be used for small streams that have peak durations less than one day and have sampling schemes that measure the mean concentration over part or all of the peak flow. This example build a simple model and assumes that the user is familiar with the general steps in build a rating curve model using the functions in \textbf{rloadest}. -\end{abstract} - -\tableofcontents - -\eject -\section{Introduction} - -This example builds on and extends the analysis of Landers and others (2007) and Joiner and others (2014) of whole-water ammonia plus organic nitrogen in the Brushy Fork Creek at Beaver Road near Loganville, Georgia, USGS streamgage 02207400. This example covers the period beginning in water year 2005 through water year 2013. - -<>= -# Load the necessary packages and the data -library(rloadest) -library(dataRetrieval) -# Get the QW data -Brushy <- "02207400" -# Parameter code 00665 is whole-water phosphorus -# Parameter code 71123 is mean streamflow for peak flow -# Parameter code 00060 is the daily mean streamflow -# Parameter code 00061 is the measured streamflow -# 71123 will be used as the flow for peak flows and 00061 -# for base flow or 00060 if 00061 is missing. -BrushyQW <- importNWISqw("02207400", - params=c("00625", "72123", "00060", "00061"), - begin.date="2004-10-02", end.date="2013-09-30") -# Convert the separate columns of dates and times to a single column -# Uses functions from smwrBase -BrushyQW <- transform(BrushyQW, - StartDateTime = setTZ(sample_dt + as.timeDay(sample_tm), tzone_cd, force.stz=TRUE), - EndDateTime = setTZ(sample_end_dt + as.timeDay(sample_end_tm), tzone_cd, force.stz=TRUE)) -# A few rows of data: -head(BrushyQW) -# Subset to remove the missing values in Kjeldahl_WW.N.00625 -# Note that this works only because we are interested in Kjeldahl_WW.N.00625 -BrushyQW <- subset(BrushyQW, !is.na(Kjeldahl_WW.N.00625)) -@ - -\eject -\section{Determine the Time Step} - -There is no set method to determine the time step. The approach should determine a typical peak duration. For new sites, with little streamflow record, the user must examine the history of peaks and determine a sampling strategy that can characterize the peak flow. Landers and others (2007) has a brief description of the process. For the Brushy Fork Creek data, with a fairly long history of composite sample collection designed to characterize the peak flow volume, the median duration of the composite sample can be used. The median duration, from the code shown following this paragraph is 352 minutes---the closest even divisor into 24 hours is 6 hours. The code following this paragraph also computes the sample date and time and flow for the regression model. - -<>= -# Compute the median peak duration. -with(BrushyQW, median(EndDateTime - StartDateTime, na.rm=T)) -# Compute the sample date and time -BrushyQW <- transform(BrushyQW, - dateTime=ifelse(is.na(EndDateTime), StartDateTime, - StartDateTime + (EndDateTime - StartDateTime)/2)) -# Need to convert to POSIXct. Note that the original data were -# recorded in standard time only, so the correct time zone is -# "America/Jamaica," which preserves the correct time offset. -BrushyQW <- transform(BrushyQW, dateTime=as.POSIXct(dateTime, - origin="1970-01-01", tz="America/Jamaica")) -# Now the flow, coalesce is in smwrBase -BrushyQW <- transform(BrushyQW, - Flow=ifelse(!is.na(EndDateTime), DischargeMeanStorm_cfs, - coalesce(InstDischarge_cfs, Discharge_cfs))) -@ - -\eject -\section{Build the Model} - -Surrogate data including turbidity and specific conductance are available for this site, but only as daily values. If those unit or instantaneous values were available, then it would be best to examine models that included surrogate data. The model must be built using streamflow and time. The code following this paragraph builds the 6-hour time step model, using the best-model selection process. - -<>= -# Find the "best" predefined model -Brushy.lreg <- selBestModel("Kjeldahl_WW.N.00625", BrushyQW, flow="Flow", - dates="dateTime", time.step="6 hour", station=Brushy) -print(Brushy.lreg) -@ - -Model 1 was selected---including only flow. The residual variance is quite large at 0.5673, but the printed diagnostics in general indicate an acceptable model. The diagnostic plots in figures 1-3 also indicate an acceptable model: the fit is reasonably linear and appear to have uniform scatter, there are no issues with serial correlation, and the standardized residuals fall very near the 1:1 line. - -<>= -# Set up for graph in vignette -setSweave("graph01", 6, 6) -plot(Brushy.lreg, which = 1, set.up=FALSE) -dev.off() -@ - -\includegraphics{graph01.pdf} -\paragraph{} - -\textbf{Figure 1.} The overall fit. - -<>= -# Set up for graph in vignette -setSweave("graph02", 6, 6) -plot(Brushy.lreg, which = 4, set.up=FALSE) -dev.off() -@ - -\includegraphics{graph02.pdf} -\paragraph{} - -\textbf{Figure 2.} The correlogram. - -<>= -# Set up for graph in vignette -setSweave("graph03", 6, 6) -plot(Brushy.lreg, which = 5, set.up=FALSE) -dev.off() -@ - -\includegraphics{graph03.pdf} -\paragraph{} - -\textbf{Figure 3.} The q-normal plot. - -As a final check on the simple model, compute the jackknife estimates of the parameters. The code following this paragraph demonstrates the use of the \texttt{jackStats} function. The relative bias is small, not indicating a problem with the model. - -<>= -# Jackknife statistics -jackStats(Brushy.lreg) -@ - -\eject -\section{Load Estimation} - -Load estimation can easily be done using unit-value data, rather than the user aggregating data by the time step. The code following this paragraph demonstrates a simple load estimation for the month of May, 2013. The data are retrieved, making sure the time zone is set to the local time. The unit-value data are aggregated into 6-hour time steps, taking all of the unit values within the time period; a complete record is not required, but each 6-hour period must have at least one unit value. The Brushy Fork Creek data do not have any unit values for 5:15 through 6:00 on May 22, as indicated in the code below. The user must check for gaps in the record; \texttt{predLoad} will fail if there are gaps greater than the time step. - -<>= -# Get the data for May, 2013 -BrushyQ <- readNWISuv(Brushy, "00060", startDate="2013-05-01", - endDate="2013-05-31", tz="America/New_York") -BrushyQ <- renameNWISColumns(BrushyQ) -# Rename the Flow column, must be done manually as renameNWISColumns -# appends _Inst -names(BrushyQ)[names(BrusyQ) == "Flow_Inst"] <- "Flow" -# Show the gap in the record: -BrushyQ[2030:2040,] -# predict the load -predLoad(Brushy.lreg, BrushyQ, by="month") -@ - -\begin{thebibliography}{9} - -\bibitem{Jo} -Joiner, J.K., Aulenbach, B.T., and Landers, M.N., 2014, Watershed characteristics and water-quality trends and loads in 12 watersheds in Gwinnett County, Georgia: U.S. Geological Survey Scientific Investigations Report 2014-5141, -79 p., https://dx.doi.org/10.3133/sir20145141. - -\bibitem{Lo} -Landers, M.N., Ankcorn, P.D., and McFadden, K.W., 2007, Watershed effects on streamflow quantity and quality in six watersheds of Gwinnett Count, Georgia: U.S. Geological Survey Scientific Investigations Report 2007-5132, 62 p., Web-only publication at https://pubs.usgs.gov/sir/2007/5132/ - -\end{thebibliography} - -\end{document} diff --git a/inst/doc/SubDailyTimeSteps.pdf b/inst/doc/SubDailyTimeSteps.pdf deleted file mode 100644 index 98a0088..0000000 Binary files a/inst/doc/SubDailyTimeSteps.pdf and /dev/null differ diff --git a/inst/doc/UsingEGRETData.pdf b/inst/doc/UsingEGRETData.pdf index 3417f92..a703d4b 100644 Binary files a/inst/doc/UsingEGRETData.pdf and b/inst/doc/UsingEGRETData.pdf differ diff --git a/inst/doc/app1.pdf b/inst/doc/app1.pdf index 3b6944d..1e76201 100644 Binary files a/inst/doc/app1.pdf and b/inst/doc/app1.pdf differ diff --git a/inst/doc/app2.pdf b/inst/doc/app2.pdf index 36c4606..90f66e2 100644 Binary files a/inst/doc/app2.pdf and b/inst/doc/app2.pdf differ diff --git a/inst/doc/app3.pdf b/inst/doc/app3.pdf index a92c838..2fa915e 100644 Binary files a/inst/doc/app3.pdf and b/inst/doc/app3.pdf differ diff --git a/inst/doc/app4.pdf b/inst/doc/app4.pdf index d8f767b..669f96f 100644 Binary files a/inst/doc/app4.pdf and b/inst/doc/app4.pdf differ diff --git a/inst/doc/app5.pdf b/inst/doc/app5.pdf index 5494103..d3f1084 100644 Binary files a/inst/doc/app5.pdf and b/inst/doc/app5.pdf differ diff --git a/inst/doc/app6.pdf b/inst/doc/app6.pdf index 797755f..cd2940b 100644 Binary files a/inst/doc/app6.pdf and b/inst/doc/app6.pdf differ diff --git a/man/app5.1999.Rd b/man/app5.1999.Rd index 40d570a..ef9edcc 100644 --- a/man/app5.1999.Rd +++ b/man/app5.1999.Rd @@ -20,7 +20,7 @@ Data frame with 13 rows and 3 columns\cr } \source{ Retrieved from NWISweb on July 26, 2013 from URL: -\url{http://nwis.waterdata.usgs.gov/ks/nwis/qwdata} +\url{https://nwis.waterdata.usgs.gov/ks/nwis/qwdata} } \examples{ data(app5.1999) diff --git a/man/rloadest-package.Rd b/man/rloadest-package.Rd index 4ec9111..343744b 100644 --- a/man/rloadest-package.Rd +++ b/man/rloadest-package.Rd @@ -8,8 +8,6 @@ \tabular{ll}{ Package: \tab rloadest\cr Type: \tab Package\cr -Version: \tab 0.4.3\cr -Date: \tab 2015-12-03\cr License: \tab CC0\cr LazyLoad: \tab yes\cr } @@ -35,8 +33,5 @@ the printed output from LOADEST. Furthermore, the model building capability in the rloadest functions make easier to explore other forms of rating-curve models than LOADEST. } -\author{ -Dave Lorenz \email{lorenz@usgs.gov} -} \keyword{estimation} \keyword{load} diff --git a/man/selBestSubset.Rd b/man/selBestSubset.Rd index f57807f..004ca34 100644 --- a/man/selBestSubset.Rd +++ b/man/selBestSubset.Rd @@ -22,25 +22,25 @@ acceptable. In some rare cases, the log of flow may be needed.} \item{na.action}{what to do with missing values.} -\item{flow}{character string indicating the name of the +\item{flow}{character string indicating the name of the flow column.} -\item{dates}{character string indicating the name of the +\item{dates}{character string indicating the name of the date column.} \item{flow.units}{character string describing the flow unit.} -\item{conc.units}{character string describing the concentration +\item{conc.units}{character string describing the concentration unit.} \item{load.units}{character string describing the load unit.} -\item{time.step}{character string describing the time step of +\item{time.step}{character string describing the time step of the calibration data.} \item{station}{character string description of the station.} -\item{criterion}{the criterion to use for subset selection, must be +\item{criterion}{the criterion to use for subset selection, must be one of "AIC," "SPCC," or "AICc."} } \value{ @@ -51,7 +51,7 @@ Select the "best" subset of a user-defined rating-curve (regression) model for rver load estimation. } \note{ -The printed output of the model inlcudes the \code{anova} component from +The printed output of the model inlcudes the \code{anova} component from \code{step}. That table summarizes the step wise selection and the criterion used for each step. The statistics possibly represent a smaller sample size than used for the final model because the \code{step} function requires a data set with no diff --git a/vignettes/InstantaneousTimeStep.Rnw b/vignettes/InstantaneousTimeStep.Rnw index cdf24b9..7fc7297 100644 --- a/vignettes/InstantaneousTimeStep.Rnw +++ b/vignettes/InstantaneousTimeStep.Rnw @@ -5,12 +5,7 @@ \begin{document} -<>= -library(knitr) -opts_chunk$set( -concordance=TRUE -) -@ +\SweaveOpts{concordance=TRUE} \raggedright @@ -30,8 +25,8 @@ This example uses data from the Bad River near Odanah, Wisc., USGS gaging statio library(rloadest) library(dataRetrieval) # What unit values are available? -subset(whatNWISdata("04027000"), data_type_cd=="uv", - select=c("parm_cd", "srsname", "begin_date", "end_date")) +subset(whatNWISdata(siteNumber = "04027000"), data_type_cd=="uv", + select=c("parm_cd", "begin_date", "end_date")) # Get the QW data BadQW <- importNWISqw("04027000", "00940", begin.date="2011-04-01", end.date="2014-09-30")