Skip to content

Commit 3177f98

Browse files
Merge pull request #384 from ldecicco-USGS/wqGraph_updates
Bug fixes
2 parents 2a070f9 + 8f617d6 commit 3177f98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+373
-405
lines changed

.Rbuildignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ deploy_simple.R
6262
cobertura.xml
6363
test-out.xml
6464
^_pkgdown\.yml$
65-
review/*
65+
review/*
66+
docs/*

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ Meta/
77
Newstuff/
88
*.docx
99
vignettes/*.html
10-
vignettes/*.R
1110
vignettes/EGRET.R
1211
vignettes/Enhancements.R
1312
vignettes/TrendsByMonth.R

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: EGRET
22
Type: Package
33
Title: Exploration and Graphics for RivEr Trends
4-
Version: 3.0.9
4+
Version: 3.0.10
55
Authors@R: c( person("Robert", "Hirsch", role = c("aut"),
66
email = "[email protected]",
77
comment=c(ORCID="0000-0002-4534-075X")),
@@ -58,6 +58,6 @@ Copyright: This software is in the public domain because it contains materials
5858
the United States Department of Interior. For more information, see the
5959
official USGS copyright policy at
6060
https://www.usgs.gov/information-policies-and-instructions/copyrights-and-credits
61-
RoxygenNote: 7.2.3
61+
RoxygenNote: 7.3.2
6262
Roxygen: list(old_usage = TRUE)
6363
Encoding: UTF-8

NAMESPACE

-23
Original file line numberDiff line numberDiff line change
@@ -140,35 +140,12 @@ exportClasses(fluxUnit)
140140
exportClasses(monthLabel)
141141
exportClasses(qUnit)
142142
import(methods)
143-
importFrom(grDevices,colorRampPalette)
144-
importFrom(graphics,abline)
145143
importFrom(graphics,axis)
146-
importFrom(graphics,box)
147-
importFrom(graphics,boxplot)
148-
importFrom(graphics,contour)
149-
importFrom(graphics,filled.contour)
150-
importFrom(graphics,grconvertX)
151-
importFrom(graphics,grconvertY)
152-
importFrom(graphics,legend)
153144
importFrom(graphics,lines)
154145
importFrom(graphics,mtext)
155146
importFrom(graphics,par)
156147
importFrom(graphics,plot)
157148
importFrom(graphics,points)
158149
importFrom(graphics,segments)
159150
importFrom(graphics,title)
160-
importFrom(stats,aggregate)
161-
importFrom(stats,filter)
162-
importFrom(stats,lm)
163-
importFrom(stats,median)
164-
importFrom(stats,na.omit)
165-
importFrom(stats,predict)
166-
importFrom(stats,quantile)
167-
importFrom(stats,reshape)
168-
importFrom(stats,rnorm)
169-
importFrom(stats,sd)
170151
importFrom(stats,var)
171-
importFrom(utils,URLencode)
172-
importFrom(utils,read.delim)
173-
importFrom(utils,tail)
174-
importFrom(utils,write.table)

NEWS

+9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
EGRET 3.0.10
2+
===========
3+
* Fix bug with 0 concentration values in readWQPSample.
4+
* Style updates.
5+
* Port readNWISSample to Water Quality Portal. NWIS services are retired.
6+
* Move removing the rows of Sample data with 0 concentration to outside compressData
7+
* Add columns from raw WQP data to be retained in Sample dataframe.
8+
9+
110
EGRET 3.0.9
211
===========
312
* Bug fix for the monthly concentration trend results in runPairs.

R/EGRET.R

+7-30
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
if (!interactive()) return()
44
EGRET_version = utils::packageVersion("EGRET")
55
packageStartupMessage("EGRET ", EGRET_version,"
6-
Extended Documentation: https://rconnect.usgs.gov/EGRET")
6+
Extended Documentation: https://doi-usgs.github.io/EGRET")
77

88
}
99

@@ -26,43 +26,20 @@ Extended Documentation: https://rconnect.usgs.gov/EGRET")
2626
#'
2727
#' @name EGRET-package
2828
#' @docType package
29-
#' @importFrom utils write.table
30-
#' @importFrom utils read.delim
31-
#' @importFrom utils URLencode
32-
#' @importFrom utils tail
33-
#' @importFrom stats aggregate
34-
#' @importFrom stats lm
35-
#' @importFrom stats median
36-
#' @importFrom stats sd
37-
#' @importFrom stats reshape
38-
#' @importFrom stats filter
39-
#' @importFrom stats rnorm
40-
#' @importFrom stats na.omit
4129
#'
42-
#' @importFrom graphics abline
4330
#' @importFrom graphics axis
44-
#' @importFrom graphics box
45-
#' @importFrom graphics boxplot
46-
#' @importFrom graphics contour
47-
#' @importFrom graphics filled.contour
48-
#' @importFrom graphics grconvertX
49-
#' @importFrom graphics grconvertY
50-
#' @importFrom graphics legend
5131
#' @importFrom graphics lines
5232
#' @importFrom graphics mtext
5333
#' @importFrom graphics par
5434
#' @importFrom graphics points
5535
#' @importFrom graphics segments
5636
#' @importFrom graphics title
57-
#' @importFrom stats predict
58-
#' @importFrom stats quantile
59-
#' @importFrom grDevices colorRampPalette
6037
#' @author Robert M. Hirsch \email{rhirsch@@usgs.gov}, Laura De Cicco \email{ldecicco@@usgs.gov}
6138
#' @references Hirsch, R.M., and De Cicco, L.A., 2014, User guide to Exploration and Graphics for RivEr Trends
6239
#' (EGRET) and dataRetrieval: R packages for hydrologic data: U.S. Geological Survey Techniques and Methods book 4,
6340
#' chap. A10, 94 p., \doi{10.3133/tm4A10}
64-
#' @keywords water-quality graphics streamflow statistics
65-
NULL
41+
#' @keywords internal
42+
"_PACKAGE"
6643

6744
#' Example eList
6845
#'
@@ -85,10 +62,10 @@ NULL
8562

8663
#' Constants included with EGRET
8764
#'
88-
#'\itemize{
89-
#' \item{fluxConst}{Flux conversion object}
90-
#' \item{qConst}{Flow conversion object}
91-
#' \item{monthInfo}{Month object}
65+
#'\tabular{ll}{
66+
#' fluxConst \tab Flux conversion object\cr
67+
#' qConst \tab Flow conversion object\cr
68+
#' monthInfo \tab Month object\cr
9269
#'}
9370
#'
9471
#'@aliases fluxConst qConst monthInfo concConst

R/boxConcMonth.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#' @param tinyPlot logical variable, if TRUE plot is designed to be plotted small as part of a multi-plot figure, default is FALSE.
1818
#' @param logScale logical if TRUE y plotted in log axis
1919
#' @param customPar logical defaults to FALSE. If TRUE, par() should be set by user before calling this function
20-
#' @param las numeric in {0,1,2,3}; the style of axis labels, see ?par
20+
#' @param las numeric in c(0,1,2,3); the style of axis labels, see ?par
2121
#' @param showXLabels logical defaults to TRUE. If FALSE, the x axis label is not plotted
2222
#' @param showYLabels logical defaults to TRUE. If FALSE, the y axis label is not plotted
2323
#' @param showXAxis logical defaults to TRUE. If FALSE, the x axis is not plotted
@@ -124,7 +124,7 @@ boxConcMonth <- function(eList, printTitle = TRUE,
124124
units = localINFO$param.units)
125125
yTicksLab <- prettyNum(yInfo$ticks)
126126

127-
boxplot(tempDF$conc ~ tempDF$month,
127+
graphics::boxplot(tempDF$conc ~ tempDF$month,
128128
ylim = c(yInfo$bottom,yInfo$top),
129129
yaxs = "i",
130130
yTicks = yInfo$ticks,

R/boxConcThree.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ boxConcThree<-function (eList, tinyPlot=FALSE,
107107
yTicks <- yPretty(yMax)
108108
yTop <- yTicks[length(yTicks)]
109109

110-
boxplot(concV ~ index,varwidth=TRUE,
110+
graphics::boxplot(concV ~ index,varwidth=TRUE,
111111
names = groupNames,xlab = "", ylab = yLab,
112112
ylim = c(0,yTop), axes = FALSE,
113113
main = plotTitle, font.main = font.main, cex = cex,
@@ -119,7 +119,7 @@ boxConcThree<-function (eList, tinyPlot=FALSE,
119119
axis(2,tcl=0.5,las=1,at=yTicks,cex.axis=cex.axis)
120120
axis(3,tcl=0.5,at=c(1,2,3),labels=FALSE)
121121
axis(4,tcl=0.5,at=yTicks,labels=FALSE)
122-
box()
122+
graphics::box()
123123
if (!tinyPlot) mtext(title2,side=3,line=-1.5)
124124
invisible(eList)
125125
}

R/boxQTwice.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#' @param logScale logical if TRUE y plotted in log axis. Defaults to TRUE.
2828
#' @param tinyPlot logical variable, if TRUE plot is designed to be plotted small as part of a multi-plot figure, default is FALSE.
2929
#' @param customPar logical defaults to FALSE. If TRUE, par() should be set by user before calling this function
30-
#' @param las numeric in {0,1,2,3}; the style of axis labels, see ?par
30+
#' @param las numeric in c(0,1,2,3); the style of axis labels, see ?par
3131
#' @param usgsStyle logical option to use USGS style guidelines. Setting this option
3232
#' to TRUE does NOT guarantee USGS compliance. It will only change automatically
3333
#' generated labels.
@@ -111,7 +111,7 @@ boxQTwice<-function(eList,
111111
logScaleText <- ""
112112
}
113113

114-
boxplot(bigQ~index,varwidth=TRUE,
114+
graphics::boxplot(bigQ~index,varwidth=TRUE,
115115
names=groupNames,xlab="",
116116
ylim=c(yInfo$bottom,yInfo$top),
117117
main=plotTitle,cex=cex,ylab=yLabel,

R/boxResidMonth.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#' @param cex.main magnification to be used for main titles relative to the current setting of cex
2222
#' @param font.main font to be used for plot main titles
2323
#' @param customPar logical defaults to FALSE. If TRUE, par() should be set by user before calling this function
24-
#' @param las numeric in {0,1,2,3}; the style of axis labels
24+
#' @param las numeric in c(0,1,2,3); the style of axis labels
2525
#' @param randomCensored logical. Show censored residuals as randomized. Default = FALSE.
2626
#' @param monthLab object of monthLabel class, or numeric represented the short code,
2727
#' or character representing the descriptive name.
@@ -104,7 +104,7 @@ boxResidMonth <- function(eList,
104104
monthList <- singleMonthList[localSample$Month]
105105
monthList <- factor(monthList, namesListFactor)
106106

107-
boxplot(resid ~ monthList,
107+
graphics::boxplot(resid ~ monthList,
108108
varwidth = TRUE,
109109
xlab = "Month", ylab = yLab,
110110
main = plotTitle,
@@ -114,7 +114,7 @@ boxResidMonth <- function(eList,
114114
cex.axis = cex.axis,
115115
las = las,
116116
...)
117-
abline(h = 0)
117+
graphics::abline(h = 0)
118118
if (!tinyPlot) mtext(title2, side = 3, line = -1.5)
119119
invisible(eList)
120120
}

R/calculateMonthlyResults.R

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ calculateMonthlyResults <- function(eList){
1616

1717
localDaily <- getDaily(eList)
1818

19-
nDays <- aggregate(localDaily$ConcDay, by=list(localDaily$MonthSeq), function(x) sum(!is.na(x)))$x
19+
nDays <- stats::aggregate(localDaily$ConcDay, by=list(localDaily$MonthSeq), function(x) sum(!is.na(x)))$x
2020

21-
Q <- aggregate(localDaily$Q, by=list(localDaily$MonthSeq), mean)$x
22-
DecYear <- aggregate(localDaily$DecYear, by=list(localDaily$MonthSeq), mean)$x
21+
Q <- stats::aggregate(localDaily$Q, by=list(localDaily$MonthSeq), mean)$x
22+
DecYear <- stats::aggregate(localDaily$DecYear, by=list(localDaily$MonthSeq), mean)$x
2323
Year <- trunc(DecYear)
24-
Month <- aggregate(localDaily$Month, by=list(localDaily$MonthSeq), mean)$x
25-
Conc <- aggregate(localDaily$ConcDay, by=list(localDaily$MonthSeq), mean)$x
26-
Flux <- aggregate(localDaily$FluxDay, by=list(localDaily$MonthSeq), mean)$x
27-
FNConc <- aggregate(localDaily$FNConc, by=list(localDaily$MonthSeq), mean)$x
28-
FNFlux <- aggregate(localDaily$FNFlux, by=list(localDaily$MonthSeq), mean)$x
24+
Month <- stats::aggregate(localDaily$Month, by=list(localDaily$MonthSeq), mean)$x
25+
Conc <- stats::aggregate(localDaily$ConcDay, by=list(localDaily$MonthSeq), mean)$x
26+
Flux <- stats::aggregate(localDaily$FluxDay, by=list(localDaily$MonthSeq), mean)$x
27+
FNConc <- stats::aggregate(localDaily$FNConc, by=list(localDaily$MonthSeq), mean)$x
28+
FNFlux <- stats::aggregate(localDaily$FNFlux, by=list(localDaily$MonthSeq), mean)$x
2929

3030
kalman <- all(c("GenConc","GenFlux") %in% names(localDaily))
3131

3232
if(kalman){
33-
GenConc <- aggregate(localDaily$GenConc, by=list(localDaily$MonthSeq), mean)$x
34-
GenFlux <- aggregate(localDaily$GenFlux, by=list(localDaily$MonthSeq), mean)$x
33+
GenConc <- stats::aggregate(localDaily$GenConc, by=list(localDaily$MonthSeq), mean)$x
34+
GenFlux <- stats::aggregate(localDaily$GenFlux, by=list(localDaily$MonthSeq), mean)$x
3535

3636
MonthlyResults <- data.frame(Month, Year, nDays,
3737
DecYear, Q,

R/compressData.r

+16-13
Original file line numberDiff line numberDiff line change
@@ -51,24 +51,28 @@ compressData <- function(data, verbose = TRUE){
5151
i <- i + 1
5252
}
5353

54-
names(data) <- c('dateTime', 'code', 'value')
55-
returnDataFrame <- as.data.frame(matrix(ncol=3,nrow=nrow(data)))
56-
names(returnDataFrame) <- c('dateTime', 'ConcLow', 'ConcHigh')
54+
names(data)[1:3] <- c('dateTime', 'code', 'value')
5755

5856
data$dateTime <- as.character(data$dateTime)
5957
if(dateFormatCheck(data$dateTime)){
60-
returnDataFrame$dateTime <- as.Date(data$dateTime)
58+
data$dateTime <- as.Date(data$dateTime)
6159
} else {
6260
data$dateTime <- as.Date(data$dateTime,format="%m/%d/%Y")
63-
returnDataFrame$dateTime <- as.Date(data$dateTime,format="%m/%d/%Y")
6461
}
65-
returnDataFrame$ConcLow <- as.numeric(lowConcentration)
66-
returnDataFrame$ConcHigh <- as.numeric(highConcentration)
67-
Uncen1<-ifelse(returnDataFrame$ConcLow==returnDataFrame$ConcHigh,1,0)
68-
returnDataFrame$Uncen<-ifelse(is.na(returnDataFrame$ConcLow)|is.na(returnDataFrame$ConcHigh),0,Uncen1)
62+
63+
64+
data$ConcLow <- as.numeric(lowConcentration)
65+
data$ConcHigh <- as.numeric(highConcentration)
66+
Uncen1<-ifelse(data$ConcLow==data$ConcHigh,1,0)
67+
data$Uncen<-ifelse(is.na(data$ConcLow)|is.na(data$ConcHigh),0,Uncen1)
6968

70-
flaggedData1 <- returnDataFrame[(returnDataFrame$ConcLow == 0 & returnDataFrame$ConcHigh == 0),]
71-
returnDataFrame <- returnDataFrame[!(returnDataFrame$ConcLow == 0 & returnDataFrame$ConcHigh == 0),]
69+
return(data)
70+
}
71+
72+
73+
remove_zeros <- function(data, verbose){
74+
flaggedData1 <- data[(data$ConcLow == 0 & data$ConcHigh == 0),]
75+
data <- data[!(data$ConcLow == 0 & data$ConcHigh == 0),]
7276

7377
if (nrow(flaggedData1) > 0){
7478
WarningMessage <- paste("Deleted", nrow(flaggedData1), "rows of data because concentration was reported as 0.0, the program is unable to interpret that result and is therefore deleting it.")
@@ -78,6 +82,5 @@ compressData <- function(data, verbose = TRUE){
7882
print(flaggedData1)
7983
}
8084
}
81-
82-
return(returnDataFrame)
85+
return(data)
8386
}

R/cumQdate.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#' annualFlow <- cumQdate(eList)
2828
#' head(annualFlow)
2929
#' plot(annualFlow)
30-
#' mod1 <- lm(annualFlow[,2] ~ annualFlow[,1])
30+
#' mod1 <- stats::lm(annualFlow[,2] ~ annualFlow[,1])
3131
#' summary(mod1)
3232
cumQdate <- function(eList,
3333
paStart = 10, paLong = 12,
@@ -65,6 +65,6 @@ cumQdate <- function(eList,
6565
}
6666
}
6767

68-
annualSeries <- na.omit(annualSeries)
68+
annualSeries <- stats::na.omit(annualSeries)
6969
return(annualSeries)
7070
}

R/errorStats.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ errorStats <- function(eList) {
2222

2323
eListR <- makeAugmentedSample(eList)
2424
Sample <- eListR$Sample
25-
# n <- length(Sample$Date)
25+
2626
Sample$Pred <- log(Sample$rObserved) - Sample$rResid
2727
Sample$trueFlux <- Sample$rObserved * Sample$Q * 86.4
2828
Sample$trueLogF <- log(Sample$trueFlux)

R/estSurfaces.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ estSurfaces<-function(eList, surfaceStart=NA, surfaceEnd=NA, localSample=NA,
9292

9393
sliceIndex <- which(vectorYear >= decimalDate(as.Date(surfaceStart)) & vectorYear <=
9494
decimalDate(as.Date(surfaceEnd)))
95-
Year <- vectorYear[c(sliceIndex[1]-1, sliceIndex, tail(sliceIndex, n = 1)+1)]
95+
Year <- vectorYear[c(sliceIndex[1]-1, sliceIndex, utils::tail(sliceIndex, n = 1)+1)]
9696

9797
nVectorYear <- length(Year)
9898
estPtYear <- rep(Year,each=14)

R/genericEGRETplot.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ genericEGRETDotPlot <- function(x,y, xlim, ylim,
8484
ylim=ylim,yaxs=yaxs,ylab=if(showYLabels) ylab else "", main=plotTitle,col=col,lwd=lwd,
8585
pch=pch,cex=cex,cex.main=cex.main,font.main=font.main,cex.lab=cex.lab,...)
8686

87-
box()
88-
if (hLine) abline(h = 0)
89-
if (oneToOneLine) abline(a=0,b=1)
87+
graphics::box()
88+
if (hLine) graphics::abline(h = 0)
89+
if (oneToOneLine) graphics::abline(a=0,b=1)
9090

9191
if(rmSciX){
9292
xTicksLab <- prettyNum(xTicks)

R/kalman_functions.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ WRTDSKalman <- function(eList, rho = 0.90, niter = 200,
106106
endFill <- zends[iGap]+1
107107
nFill <- zz$length[iGap]+2
108108
if(i == 1 | i == numGap) {
109-
z <- rnorm(nFill - 2)
109+
z <- stats::rnorm(nFill - 2)
110110
xfill <- c(xxP[startFill], z, xxP[endFill])
111111
} else {
112112
xfill <- genmissing(xxP[startFill], xxP[endFill], rho, nFill)
@@ -385,7 +385,7 @@ plotWRTDSKalman <- function(eList, sideBySide = FALSE,
385385
ylab = ylab,
386386
cex.main = 0.9,
387387
plotTitle = title2)
388-
abline(a = 0, b = 1)
388+
graphics::abline(a = 0, b = 1)
389389

390390
if(sideBySide){
391391
mtext(mainTitle, line = -1, side = 3, outer = TRUE, cex= 1)

0 commit comments

Comments
 (0)