Skip to content

Commit 9c23ddb

Browse files
committed
Updates for instantaneous vignette
1 parent 13b11af commit 9c23ddb

File tree

9 files changed

+327
-18
lines changed

9 files changed

+327
-18
lines changed

R/predConc.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#' If \code{allow.incomplete} is \code{TRUE}, then concentrations will be
1010
#'computed based on all nonmissing values, otherwise missing values
1111
#'\code{NAs} will be returned. For this application, missing values
12-
#'includes \code{NAs} and incomplete days.
12+
#'includes \code{NAs} and incomplete days. For prediction by "day" when
13+
#'there are variable number of unit values per day, \code{allow.incomplete}
14+
#'must be set to \code{TRUE}.
1315
#'
1416
#' The term confidence interval is used here as in the original
1517
#'documentation for LOADEST, but the values that are reported are
@@ -211,6 +213,9 @@ predConc <- function(fit, newdata, by="day",
211213
Kdy <- as.integer(KDate)
212214
KDate <- unique(KDate)
213215
Kdy <- Kdy - Kdy[1L] + 1L # make relative to first day (Index)
216+
if(length(unique(table(Kdy))) > 1L && !allow.incomplete) {
217+
warning("Variable observations per day, either set the allow.incomplete argument to TRUE or use the resampleUVdata function to construct a uniform series")
218+
}
214219
KinAll <- unique(Kdy)
215220
## Make it daily flow, Flow0 indicates a partial 0 flow
216221
Flow0 <- tapply(Flow, Kdy, min)

R/predLoad.R

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
#'\code{NAs} will be returned. For this application, missing values
1515
#'includes \code{NAs} and gaps in the record, except for \code{by}
1616
#'set to "total" or user defined groups where missing values only
17-
#'includes \code{NAs}.
17+
#'includes \code{NAs}. For prediction by "day" when there are variable
18+
#'number of unit values per day, \code{allow.incomplete} must be
19+
#'set to \code{TRUE}.
1820
#'
1921
#' The term confidence interval is used here as in the original
2022
#'documentation for LOADEST, but the values that are reported are
@@ -52,7 +54,6 @@
5254
#' @useDynLib rloadest estlday
5355
#' @useDynLib rloadest estltot
5456
#' @export
55-
5657
predLoad <- function(fit, newdata, load.units=fit$load.units, by="total",
5758
seopt="exact", allow.incomplete=FALSE,
5859
conf.int=0.95, print=FALSE) {
@@ -239,6 +240,9 @@ predLoad <- function(fit, newdata, load.units=fit$load.units, by="total",
239240
Kdy <- as.integer(KDate)
240241
KDate <- unique(KDate)
241242
Kdy <- Kdy - Kdy[1L] + 1L # make relative to first day (Index)
243+
if(length(unique(table(Kdy))) > 1L && !allow.incomplete) {
244+
warning("Variable observations per day, either set the allow.incomplete argument to TRUE or use the resampleUVdata function to construct a uniform series")
245+
}
242246
KinAll <- unique(Kdy)
243247
## Make it daily flow, Flow0 indicates a partial 0 flow
244248
Flow0 <- tapply(Flow, Kdy, min)
@@ -470,14 +474,19 @@ predLoad <- function(fit, newdata, load.units=fit$load.units, by="total",
470474
cat("Streamflow Summary Statistics\n",
471475
"-------------------------------------------\n\n", sep="")
472476
Qsum <- rbind(Cal.=fit$Sum.flow, Est.=summary(Flow))
473-
if(diff(range(Qsum[, ncol(Qsum)])) > 0)
477+
if(Qsum[2L, ncol(Qsum)] > Qsum[1L, ncol(Qsum)]) {
474478
cat("WARNING: The maximum estimation data set steamflow exceeds the maximum\n",
475479
"calibration data set streamflow. Load estimates require extrapolation.\n\n",
476480
sep="")
477-
else
481+
} else if(Qsum[2L, 1L] < Qsum[1L, 1L]) {
482+
cat("WARNING: The minimum estimation data set steamflow exceeds the minimum\n",
483+
"calibration data set streamflow. Load estimates require extrapolation.\n\n",
484+
sep="")
485+
} else {
478486
cat("The maximum estimation data set streamflow does not exceed the maximum\n",
479487
"calibration data set streamflow. No extrapolation is required.\n\n",
480488
sep="")
489+
}
481490
if(!(by %in% c("day", "unit"))) {
482491
cat("\n-------------------------------------------------------------\n",
483492
"Constituent Output File Part IIb: Estimation (Load Estimates)\n",

R/print.loadReg.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ print.loadReg <- function(x, digits=4, brief=TRUE, load.only=brief, ...) {
116116
else
117117
pval <- format(round(pval, 4), scientific=5)
118118
## Compute the PPCC
119-
Res <- residuals(x$lfit, type="working")
119+
Res <- residuals(x$lfit, type="working", suppress.na.action=TRUE)
120120
ppcc <- censPPCC.test(as.lcens(Res, censor.codes=x$lfit$CENSFLAG))
121121
cat("\n", x$method, " Regression Statistics\n",
122122
"Residual variance: ",

R/rloadest-package.R

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,11 @@
2727
#'Furhtermore, the model building capability in the rloadest functions make easier
2828
#'to explore other forms of rating-curve models than LOADEST.
2929
#'
30-
#' @name LOADEST-package
30+
#' @name rloadest-package
3131
#' @docType package
3232
#' @author Dave Lorenz \email{lorenz@@usgs.gov}
3333
#' @keywords load estimation
3434
NULL
35-
36-
#' Example Atrazine data included in LOADEST package
37-
#'
38-
#' Example data representing atrazine
39-
#'
40-
#' @name Atrazine
41-
#' @docType data
42-
#' @keywords water quality data
43-
NULL
35+
.onAttach <- function(libname, pkgname) {
36+
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.")
37+
}

demo/00Index

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
BatchLoad A script for batch data retrieval and load estimation.
2+
ChangeLoadGraph Create a surface plot showing the change in loading between two years.

demo/ChangeLoadGraph.r

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Use app1 (model7) from the vignette
2+
library(rloadest)
3+
data(app1.calib)
4+
# construct the model, see the vignette for app1 for details
5+
app1.lr7 <- loadReg(Phosphorus ~ model(7), data = app1.calib, flow = "FLOW",
6+
dates = "DATES", conc.units="mg/L",
7+
station="Illinois River at Marseilles, Ill.")
8+
# construct the grids
9+
FLOW <- seq(3000, 60000, length.out=21)
10+
DATES75 <- seq(as.Date("1975-01-01"), as.Date("1976-01-01"), length.out=24)
11+
Tmp75 <- expand.grid(DATES=DATES75, FLOW=FLOW)
12+
Tmp75$C <- predConc(app1.lr7, Tmp75)$Conc
13+
Tmp75$L <- predLoad(app1.lr7, Tmp75, by="day")$Flux
14+
Z.conc75 <- matrix(Tmp75$C, nrow=24)
15+
Z.load75 <- matrix(Tmp75$L, nrow=24)
16+
17+
DATES84 <- seq(as.Date("1984-01-01"), as.Date("1985-01-01"), length.out=24)
18+
Tmp84 <- expand.grid(DATES=DATES84, FLOW=FLOW)
19+
Tmp84$C <- predConc(app1.lr7, Tmp84)$Conc
20+
Tmp84$L <- predLoad(app1.lr7, Tmp84, by="day")$Flux
21+
Z.conc84 <- matrix(Tmp84$C, nrow=24)
22+
Z.load84 <- matrix(Tmp84$L, nrow=24)
23+
24+
# The range in concentration should be from .24 to .92
25+
AA.lev <- seq(.24, .92, by=.02)
26+
# the maximum load is 84,000+, so set range to 100,000
27+
# Construct the 1975 load/concentration surface
28+
# The shape of the surface indicates the potential loading given
29+
# The date and flow. The color of the surface indicates the
30+
# potential concentration given the date and flow.
31+
preSurface(DATES75, FLOW, Z.load75, zaxis.range = c(0, 100000),
32+
batch="I") -> AA75.pre
33+
# I selected
34+
# Construct the 1984 load/concentration surface
35+
preSurface(DATES84, FLOW, Z.load84, zaxis.range = c(0, 100000),
36+
batch="I") -> AA84.pre
37+
# I selected
38+
# Proceed:
39+
#set the page to landscape
40+
setPDF("land", basename="Change_Load")
41+
setLayout(width=c(4.5,4.5), height=5.5, explanation=list(right=1.2)) -> AA.lo
42+
setGraph(1, AA.lo)
43+
surfacePlot(pre=AA75.pre, z.color=Z.conc75,
44+
Surface=list(name="Concentration", levels=AA.lev),
45+
xtitle="1975", ytitle="Streamflow", ztitle="Load") -> AA75.pl
46+
addCaption("Change in Phosphorus Loading in the Illinois River at Marseilles, Ill. from 1975 to 1984")
47+
# Construct the 1984 load/concentration surface
48+
setGraph(2, AA.lo)
49+
surfacePlot(pre=AA84.pre, z.color=Z.conc84,
50+
Surface=list(name="Concentration", levels=AA.lev),
51+
xtitle="1984", ytitle="Streamflow", ztitle="Load") -> AA84.pl
52+
# The
53+
setGraph("explanation", AA.lo)
54+
addExplanation(AA84.pl)
55+
dev.off()
56+

inst/doc/InstantaneousTimeStep.pdf

196 KB
Binary file not shown.

0 commit comments

Comments
 (0)