Skip to content

Commit ada4444

Browse files
authored
Merge pull request #12 from jfisher-usgs/master
Merge with upstream
2 parents ea06129 + 5c531e0 commit ada4444

File tree

10 files changed

+43
-43
lines changed

10 files changed

+43
-43
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: wrv
22
Title: Wood River Valley Groundwater-Flow Model
3-
Version: 1.1.1.9000
3+
Version: 1.1.2
44
Authors@R: person(given=c("Jason", "C."), family="Fisher", role=c("aut", "cre"), email="jfisher@usgs.gov")
55
Description: A processing program for the groundwater-flow model of the Wood
66
River Valley aquifer system, south-central Idaho. Included in the package is

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ build:
1717

1818
install: build
1919
cd ..;\
20-
R CMD INSTALL $(PKGNAME)_$(PKGVERS).tar.gz;\
20+
R CMD INSTALL --build $(PKGNAME)_$(PKGVERS).tar.gz;\
2121

2222
check:
2323
cd ..;\

NEWS.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
# wrv 1.1.1.9000
1+
# wrv 1.1.2
22

3-
- ...
3+
- In `RunWaterBalance` function, sum groundwater diversions for `div.gw` dataset records having an identical site location and stress period.
4+
5+
- Remove hard codding of irrigation years in appendix C, see `irr.lands` dataset creation.
6+
7+
- In `GetWellConfig` function, fixed error that occurred when a well was located outside the model grid.
8+
9+
- Specify `desc` argument in `inlmisc::SummariseBudget` function call, required for new version of **inlmisc** package.
410

511
# wrv 1.1.1
612

R/GetWellConfig.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@
5454
#' \dontrun{# see Appendix D. Uncalibrated Groundwater-Flow Model}
5555
#'
5656

57-
GetWellConfig <- function(rs.model, wells, well.col, rate.col=NULL,
58-
lay2.hk.tol=1e-02) {
57+
GetWellConfig <- function(rs.model, wells, well.col, rate.col=NULL, lay2.hk.tol=1e-02) {
5958

6059
wells@data$cell <- sp::over(wells, methods::as(rs.model, "SpatialGrid"))
61-
is.in.model <- as.logical(!is.na(rs.model[["lay1.top"]])[wells@data$cell])
60+
is.in.grid <- !is.na(wells@data$cell)
61+
wells <- wells[is.in.grid, , drop=FALSE]
62+
is.in.model <- !is.na(rs.model[["lay1.top"]][wells@data$cell])
6263
wells <- wells[is.in.model, , drop=FALSE]
6364

6465
d <- wells@data

R/RunWaterBalance.R

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,7 @@ RunWaterBalance <- function(r.grid, tr.stress.periods,
269269

270270
comp <- entity.components[[i]]@data
271271
comp <- comp[comp$Source == "Mixed", cols]
272-
names(comp) <- c("EntityName", "area.mix", "et.mix", "precip.mix",
273-
"cir.mix")
272+
names(comp) <- c("EntityName", "area.mix", "et.mix", "precip.mix", "cir.mix")
274273
d <- suppressWarnings(dplyr::left_join(d, comp, by="EntityName"))
275274
d$cir.mix[is.na(d$cir.mix)] <- 0
276275

@@ -312,8 +311,7 @@ RunWaterBalance <- function(r.grid, tr.stress.periods,
312311
d$hg.mix[is.src] <- d$SWDel[is.src]
313312
d$gw.dem.mix[is.src] <- d$cir.mix[is.src] / d$Eff[is.src] - d$hg.mix[is.src]
314313
d$gw.dem.mix[is.src & d$cir.mix <= 0] <- 0
315-
d$gw.div.est[is.src] <- d$WWDiv[is.src] - d$gw.dem.mix[is.src] -
316-
d$GWDiv[is.src]
314+
d$gw.div.est[is.src] <- d$WWDiv[is.src] - d$gw.dem.mix[is.src] - d$GWDiv[is.src]
317315
is.pos <- is.src & d$gw.div.est >= 0
318316
d$gw.div.est[is.pos] <- 0
319317
d$rech.mix[is.src] <- d$hg.mix[is.src] - d$GWDiv[is.src] + d$WWDiv[is.src] -
@@ -346,8 +344,7 @@ RunWaterBalance <- function(r.grid, tr.stress.periods,
346344
d$gw.dem.gw[is.src & d$cir.gw <= 0] <- 0
347345
d$gw.div.est[is.src] <- -d$gw.dem.gw[is.src] - d$GWDiv[is.src]
348346
d$gw.div.est[is.src & d$gw.div.est > 0] <- 0
349-
d$rech.gw[is.src] <- -d$GWDiv[is.src] - d$gw.div.est[is.src] -
350-
d$cir.gw[is.src]
347+
d$rech.gw[is.src] <- -d$GWDiv[is.src] - d$gw.div.est[is.src] - d$cir.gw[is.src]
351348

352349
return(d)
353350
}
@@ -357,18 +354,13 @@ RunWaterBalance <- function(r.grid, tr.stress.periods,
357354
cols <- names(div.by.entity[[1]])
358355
FUN <- function(i) {
359356
d <- data.frame(EntityName=levels(irr.entities@data$EntityName))
360-
361357
d <- suppressWarnings(dplyr::left_join(d, sw.div.by.entity[[i]], by="EntityName"))
362358
d$SWDiv[is.na(d$SWDiv)] <- 0
363-
364359
d <- suppressWarnings(dplyr::left_join(d, gw.div.by.entity[[i]], by="EntityName"))
365360
d$GWDiv[is.na(d$GWDiv)] <- 0
366-
367361
d <- suppressWarnings(dplyr::left_join(d, ww.div.by.entity[[i]], by="EntityName"))
368362
d$WWDiv[is.na(d$WWDiv)] <- 0
369-
370363
d$rech.gw <- d$SWDiv - d$GWDiv + d$WWDiv
371-
372364
d[, cols[!cols %in% names(d)]] <- NA
373365
return(d[, cols])
374366
}
@@ -383,8 +375,7 @@ RunWaterBalance <- function(r.grid, tr.stress.periods,
383375

384376
cols <- names(div.by.entity[[1]])
385377
d <- dplyr::bind_rows(lapply(div.by.entity, function(i) i[, cols]))
386-
year.month <- rep(names(div.by.entity),
387-
times=vapply(div.by.entity, nrow, 0L))
378+
year.month <- rep(names(div.by.entity), times=vapply(div.by.entity, nrow, 0L))
388379
d <- cbind(YearMonth=year.month, d)
389380
rownames(d) <- NULL
390381
d <- d[order(d$EntityName), c(2, 1, 3:ncol(d))]
@@ -464,12 +455,10 @@ RunWaterBalance <- function(r.grid, tr.stress.periods,
464455
FUN <- function(i) {
465456
d <- comb.sw.irr
466457
d$sw.rate <- 0
467-
priority.cut <- priority.cuts[priority.cuts$YearMonth == i,
468-
"Pdate_BWR"]
458+
priority.cut <- priority.cuts[priority.cuts$YearMonth == i, "Pdate_BWR"]
469459
is.lt <- !is.sc.src & (!is.na(priority.cut) & d$Pdate < priority.cut)
470460
d$sw.rate[is.lt] <- d$MaxDivRate[is.lt]
471-
priority.cut <- priority.cuts[priority.cuts$YearMonth == i,
472-
"Pdate_SC"]
461+
priority.cut <- priority.cuts[priority.cuts$YearMonth == i, "Pdate_SC"]
473462
is.lt <- is.sc.src & (!is.na(priority.cut) & d$Pdate < priority.cut)
474463
d$sw.rate[is.lt] <- d$MaxDivRate[is.lt]
475464
d <- dplyr::summarise_(dplyr::group_by_(d, "WaterRight"),
@@ -486,8 +475,7 @@ RunWaterBalance <- function(r.grid, tr.stress.periods,
486475
d <- d[is.est, ]
487476
d.agg <- dplyr::summarise_(dplyr::group_by_(d, "EntityName"),
488477
gw.rate="sum(gw.rate, na.rm=TRUE)")
489-
d$fraction <- d$gw.rate /
490-
d.agg$gw.rate[match(d$EntityName, d.agg$EntityName)]
478+
d$fraction <- d$gw.rate / d.agg$gw.rate[match(d$EntityName, d.agg$EntityName)]
491479
d$gw.div <- 0
492480
div <- div.by.entity[[i]][, c("EntityName", "gw.div.est")]
493481
idxs <- match(d$EntityName, div$EntityName)
@@ -499,8 +487,7 @@ RunWaterBalance <- function(r.grid, tr.stress.periods,
499487
names(rech.by.pod) <- yr.mo.irr
500488

501489
FUN <- function(i) {
502-
rec <- gw.div.by.wmis.no[gw.div.by.wmis.no$YearMonth == i,
503-
c("WMISNumber", "GWDiv")]
490+
rec <- gw.div.by.wmis.no[gw.div.by.wmis.no$YearMonth == i, c("WMISNumber", "GWDiv")]
504491
est <- rech.by.pod[[i]][, c("WMISNumber", "gw.div")]
505492
est <- dplyr::summarise_(dplyr::group_by_(est, "WMISNumber"),
506493
gw.div="sum(gw.div, na.rm=TRUE)")
@@ -517,7 +504,8 @@ RunWaterBalance <- function(r.grid, tr.stress.periods,
517504

518505
is.non.irr <- div.gw$YearMonth %in% yr.mo.non.irr
519506
d <- div.gw[is.non.irr, c("WMISNumber", "YearMonth", "GWDiv")]
520-
507+
d <- aggregate(d$GWDiv, by=list(paste(d[, 1], d[, 2])), sum)
508+
d <- data.frame(do.call(rbind, strsplit(d[, 1], split=" ")), d[, 2])
521509
rows <- match(d[, 1], rownames(pod.rech))
522510
cols <- match(d[, 2], colnames(pod.rech))
523511
pod.rech[cbind(rows, cols)] <- d[, 3]

inst/doc/sir20165080_AppendixC.R

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,9 @@ CheckStatus("irr.entities")
906906

907907
## ----irr_lands_1---------------------------------------------------------
908908
path <- file.path(dir.in, "irr")
909-
yr <- c(1996, 2000, 2002, 2006, 2008, 2009, 2010)
910-
files <- paste0("irr.lands.", yr)
909+
files <- grep("^irr.lands.\\d{4}.shp$", list.files(path), value = TRUE)
910+
files <- tools::file_path_sans_ext(files)
911+
yr <- sub("irr.lands.", "", files)
911912
irr.lands <- list()
912913
for (i in seq_along(files)) {
913914
p <- readOGR(path, files[i], verbose = FALSE)
@@ -919,7 +920,7 @@ for (i in seq_along(files)) {
919920
p@data <- droplevels(p@data)
920921
irr.lands[[i]] <- p
921922
}
922-
names(irr.lands) <- as.character(yr)
923+
names(irr.lands) <- yr
923924
save(irr.lands, file = file.path(dir.out, "irr.lands.rda"), compress = "xz")
924925

925926
## ----echo=FALSE----------------------------------------------------------

inst/doc/sir20165080_AppendixC.Rnw

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,8 +1543,9 @@ Irrigated and semi-irrigated lands of the WRV.
15431543

15441544
<<irr_lands_1>>=
15451545
path <- file.path(dir.in, "irr")
1546-
yr <- c(1996, 2000, 2002, 2006, 2008, 2009, 2010)
1547-
files <- paste0("irr.lands.", yr)
1546+
files <- grep("^irr.lands.\\d{4}.shp$", list.files(path), value = TRUE)
1547+
files <- tools::file_path_sans_ext(files)
1548+
yr <- sub("irr.lands.", "", files)
15481549
irr.lands <- list()
15491550
for (i in seq_along(files)) {
15501551
p <- readOGR(path, files[i], verbose = FALSE)
@@ -1556,7 +1557,7 @@ for (i in seq_along(files)) {
15561557
p@data <- droplevels(p@data)
15571558
irr.lands[[i]] <- p
15581559
}
1559-
names(irr.lands) <- as.character(yr)
1560+
names(irr.lands) <- yr
15601561
save(irr.lands, file = file.path(dir.out, "irr.lands.rda"), compress = "xz")
15611562
@
15621563

inst/extdata/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,18 @@ The only unprocessed dataset used during model construction and not included und
6363
| +-- irr.lands.2008.zip (location of irrigated lands during 2008)
6464
| +-- irr.lands.2009.zip (location of irrigated lands during 2009)
6565
| +-- irr.lands.2010.zip (location of irrigated lands during 2010)
66+
| +-- irr.lands.2011.zip (location of irrigated lands during 2011)
6667
| +-- irr.lands.year.csv (substitute years for missing years of irrigated lands)
6768
+-- opt (parameter estimation)
6869
| +-- div.ret.exch.zip (diversions, returns, and exchange wells)
6970
| +-- kriging.zones.zip (kriging zones)
7071
| +-- obs.wells.head.csv (groundwater-level measurements)
7172
| +-- obs.wells.zip (observation wells)
7273
| +-- pilot.points.zip (location of pilot points)
73-
| +-- reach.recharge.csv (recharge from stream-aquifer flow exchange)
74-
| +-- sensitivity.csv (sensitivity analysis)
74+
| +-- reach.recharge.csv (recharge from stream-aquifer flow exchange on major river reaches)
7575
| +-- seepage.study.zip (stream seepage study)
76+
| +-- sensitivity.csv (sensitivity analysis)
77+
| +-- subreach.recharge.csv (recharge from stream-aquifer flow exchange sub-reaches)
7678
+-- precip
7779
| +-- precip.csv (precipitation recorded at weather stations)
7880
| +-- swe.choco.csv (snow water equivalent recorded at the Chocolate Gulch weather station)
@@ -85,11 +87,11 @@ The only unprocessed dataset used during model construction and not included und
8587
+-- drains.kml (location of outlet boundaries represented as drains)
8688
+-- misc.seepage.csv (recharge rates at miscellaneous recharge sources)
8789
+-- perennial.reaches.csv (perennial river reaches)
88-
+-- precipitation.csv (mean monthly precipitation depth)
8990
+-- public.parcels.zip (location of public land parcels)
9091
+-- README.md
9192
+-- river.reaches.zip (location of major river reaches)
92-
+-- soils.zip (location of surficial soil units and their maximum seepage rates)
93+
+-- soils.csv (maximum seepage rates on surficial soil units)
94+
+-- soils.zip (location of surficial soil units)
9395
+-- tributaries.csv (flow properties in the tributaries)
9496
+-- tributaries.kml (location of groundwater inflow boundaries in the tributary canyons)
9597
+-- wetlands.zip (location of wetlands)

inst/misc/Rd2.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ \chapter*{}
1414
\raggedright{}
1515
\inputencoding{utf8}
1616
\item[Title]\AsIs{Wood River Valley Groundwater-Flow Model}
17-
\item[Version]\AsIs{1.1.1.9000}
17+
\item[Version]\AsIs{1.1.2}
1818
\item[Description]\AsIs{A processing program for the groundwater-flow model of the Wood
1919
River Valley aquifer system, south-central Idaho. Included in the package is
2020
MODFLOW-USG version 1.3, a U.S. Geological Survey groundwater-flow model.}

vignettes/sir20165080_AppendixC.Rnw

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,8 +1543,9 @@ Irrigated and semi-irrigated lands of the WRV.
15431543

15441544
<<irr_lands_1>>=
15451545
path <- file.path(dir.in, "irr")
1546-
yr <- c(1996, 2000, 2002, 2006, 2008, 2009, 2010)
1547-
files <- paste0("irr.lands.", yr)
1546+
files <- grep("^irr.lands.\\d{4}.shp$", list.files(path), value = TRUE)
1547+
files <- tools::file_path_sans_ext(files)
1548+
yr <- sub("irr.lands.", "", files)
15481549
irr.lands <- list()
15491550
for (i in seq_along(files)) {
15501551
p <- readOGR(path, files[i], verbose = FALSE)
@@ -1556,7 +1557,7 @@ for (i in seq_along(files)) {
15561557
p@data <- droplevels(p@data)
15571558
irr.lands[[i]] <- p
15581559
}
1559-
names(irr.lands) <- as.character(yr)
1560+
names(irr.lands) <- yr
15601561
save(irr.lands, file = file.path(dir.out, "irr.lands.rda"), compress = "xz")
15611562
@
15621563

0 commit comments

Comments
 (0)