-
Notifications
You must be signed in to change notification settings - Fork 6
/
sir20165080_AppendixC.Rnw
1979 lines (1526 loc) · 68.9 KB
/
sir20165080_AppendixC.Rnw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% \VignetteIndexEntry{Appendix C. Package Dataset Creation}
% \VignetteEngine{knitr::knitr}
% \VignetteDepends{wrv}
\documentclass[twoside]{article}
\input{\Sexpr{shQuote(system.file("misc", "preamble.tex", package="inlmisc"))}}
\fancyhead[LE]{\normalfont\bfseries\sffamily \thepage \quad Groundwater-Flow Model for the Wood River Valley Aquifer System, South-Central Idaho}
\renewcommand{\thefigure}{C\arabic{figure}}
\renewcommand{\thetable}{C\arabic{table}}
\renewcommand{\thepage}{C\arabic{page}}
\setcounter{page}{1}
% =========================================================================
\begin{document}
<<setup, include=FALSE>>=
t0 <- Sys.time()
try(knitr::opts_chunk$set(tidy=FALSE, comment="#", fig.align="center"), silent=TRUE)
grDevices::pdf.options(useDingbats=FALSE)
# Device dimension in inches (width, height)
fin.graph <- c(7.17, 7.17)
fin.graph.short <- c(7.17, 3.50)
fig.graph.small <- c(3.50, 3.50)
fin.map <- c(7.17, 9.31)
fin.map.0 <- c(7.17, 8.77)
fin.map.s <- c(7.17, 5.22)
fin.map.s.0 <- c(7.17, 4.68)
fin.map.n <- c(7.17, 6.97)
fin.map.n.small <- c(3.50, 3.60)
fin.map.n.small.0 <- c(3.50, 3.30)
fin.cs <- c(7.17, 5.26)
fin.cs.0 <- c(7.17, 4.68)
# Extreme coordinates of plotting region (x1, x2, y1, y2)
usr.map <- c(2451504, 2497815, 1342484, 1402354)
# Map credit
credit <- paste("Base derived from U.S. Geological Survey National Elevation Dataset 10-meter digital elevation model.",
"Idaho Transverse Mercator projection; North American Datum of 1983.", sep="\n")
CheckStatus <- function(s) {
if (interactive()) {
if (!isTRUE(all.equal(get(s), eval(parse(text=paste0("wrv::", s))), showwarning=FALSE, tolerance=1e-5))) {
warning(paste0("dataset '", s, "' has changed"), call.=FALSE)
}
}
}
@
\title{Appendix C. Creating Datasets for the R-Package `wrv'}
\author{}
\maketitle
\tableofcontents
\newpage
\renewcommand*\listfigurename{Figures}
\listoffigures
\clearpage
\RaggedRight
% =========================================================================
\section{Introduction}
This vignette explains the processing steps for creating \R{} datasets in the \textbf{wrv} package.
Datasets are processed at two levels: \emph{level~1} is unprocessed data mapped on a uniform space-time grid scale; and \emph{level~2} results from analyses of level~1 data.
Considerable effort was placed on minimizing the number and complexity of processing steps required for dataset creation.
However, some datasets (such as the level~2 datasets) are necessary for parameter estimation, and computationally too expensive to recreate during each iteration of model calibration;
including these datasets in the \textbf{wrv} package avoids these long run times.
It is assumed that the reader of this vignette is familiar with the \R{}-programming language and has read help documentation for functions and datasets in the \textbf{wrv} package (appendix B).
% =========================================================================
\section{R Environment}
Load the following packages into the current \R{} session:
<<warning=FALSE, message=FALSE, results="hide">>=
library("rgdal") # bindings for the geospatial data abstraction library
library("raster") # gridded spatial data toolkit
@
\noindent Set a \textbf{raster} package option to prevent the standardization of raster names:
<<>>=
rasterOptions(standardnames = FALSE)
@
\noindent The memory requirement for running R code in this vignette is about 10 gigabytes.
% =========================================================================
\section{Input/Output Paths}
Package datasets are primarily created from unprocessed data files located on \href{https://github.com/USGS-R/wrv}{GitHub},
a web-based distributed revision control system.
Download these files to a temporary directory and uncompress the ZIP files.
<<download_git, message=FALSE, results="hide">>=
url <- "https://github.com/USGS-R/wrv.git"
path <- file.path(tempdir(), basename(tools::file_path_sans_ext(url)))
git2r::clone(url, path, progress = FALSE)
dir.in <- file.path(path, "inst/extdata")
files <- list.files(dir.in, pattern = "*.zip$", full.names = TRUE, recursive = TRUE)
for (i in files) unzip(i, exdir = dirname(i))
@
\noindent The data file containing land-surface elevations was deemed too large in file size (about 500 megabytes) to be placed in the package repository.
These elevations are part of The National Map (\href{https://nationalmap.gov/elevation.html}{TNM}) $\sfrac{1}{3}$-arc-second raster and available in a ArcGRID file format.
Download the ZIP file to a temporary directory and uncompress.
<<download_ned, message=FALSE>>=
ftp <- "ftp://rockyftp.cr.usgs.gov/vdelivery/Datasets/Staged/NED/13/ArcGrid/n44w115.zip"
file <- file.path(tempdir(), basename(ftp))
download.file(ftp, file, method = "curl", quiet = TRUE)
unzip(file, exdir = dir.in)
@
\noindent Output from this vignette is placed in the current working directory.
<<create_data_dir>>=
dir.create(dir.out <- "data", showWarnings = FALSE)
@
\newpage
% =========================================================================
\section{Space-Time Grid Scale}
The length and time dimensions for datasets are in units of meters and days, respectively.
Conversion factors are listed with an explanation of how they are used:
<<unit_conversions>>=
in.to.m <- 0.0254 # inches to meters
ft.to.m <- 0.3048 # feet to meters
mm.to.m <- 0.001 # millimeters to meters
mi2.to.m2 <- 2589990 # square miles to square meters
af.to.m3 <- 1233.48185532 # acre-feet to cubic meters
in.per.y.to.m.per.d <- 6.95429e-05 # inches per year to meters per day
af.per.y.to.m3.per.d <- 3.377 # acre-feet per year to cubic meters per day
cfs.to.m3.per.d <- 2446.57555 # cubic feet per second to cubic meters per day
@
\noindent The common coordinate reference system (CRS) applied to all spatial datasets is the
Idaho Transverse Mercator projection (\href{https://www.idwr.idaho.gov/GIS/IDTM/}{IDTM83}).
\href{http://proj4.org/}{PROJ.4} projection arguments are used to specify a CRS in R.
The CRS that all unprocessed data are converted into is specified as:
<<crs>>=
crs <- CRS(paste("+proj=tmerc +lat_0=42 +lon_0=-114 +k=0.9996 +x_0=2500000 +y_0=1200000",
"+datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0"))
@
\noindent The common spatial grid applied to all gridded datasets is composed of 565 rows and 429 columns, and has a constant cell size of 100 meters by 100 meters.
<<spatial>>=
ext <- extent(2453200, 2496100, 1344139, 1400639) # xmin, xmax, ymin, ymax in IDTM
spatial.grid <- raster(crs = crs, ext = ext, resolution = 100)
@
\noindent Gridded data are available at a higher resolution (smaller cells) than the resolution of the model grid.
Projecting the higher resolution data into the model grid first requires the projection of this data into a high resolution spatial grid of comparable cell size.
The high resolution spatial grid is defined using a constant cell size of 20 meters by 20 meters.
<<high_res_spatial>>=
high.res.spatial.grid <- disaggregate(spatial.grid, fact = 5L)
@
\noindent The transient model simulates groundwater flow from 1995 through 2010, using monthly stress periods.
<<temporal>>=
tr.interval <- as.Date(c("1995-01-01", "2011-01-01"), tz = "MST")
tr.stress.periods <- seq(tr.interval[1] , tr.interval[2], "1 month")
yr.mo <- format(head(tr.stress.periods, -1), "%Y%m")
yr.mo.irr <- yr.mo[months(head(tr.stress.periods, -1), abbreviate = TRUE) %in%
c("Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct")]
@
\newpage
% =========================================================================
\section{Level 1 Data}
Datasets processed at level~1 are described as unprocessed data (that is, data read from files or specified in this vignette) mapped on a uniform space-time grid scale.
Unprocessed data that is redundant, or deemed unnecessary for model processing or quality assurance, is removed.
A few of the level~1 datasets require supplemental processing steps; descriptions of these steps are included alongside the relevant `code chunks'.
Variable names, for the most part, are maintained between unprocessed and processed data.
% =========================================================================
\subsection{Tables}
% =========================================================================
\subsubsection{Canal seepage (canal.seep)}
Canal seepage as a fraction of diversions for irrigation entities in the Wood River Valley (WRV).
<<canal_seep_1>>=
file <- file.path(dir.in, "canal/canal.seep.csv")
canal.seep <- read.csv(file, strip.white = TRUE)
save(canal.seep, file = file.path(dir.out, "canal.seep.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("canal.seep")
@
% =========================================================================
\subsubsection{Combined surface-water irrigation diversions (comb.sw.irr)}
Supplemental groundwater rights and associated surface-water rights.
<<comb_sw_irr_1>>=
file <- file.path(dir.in, "div/comb.sw.irr.csv")
comb.sw.irr <- read.csv(file, strip.white = TRUE)
comb.sw.irr$Pdate <- as.Date(comb.sw.irr$Pdate, format = "%m/%d/%Y")
comb.sw.irr$MaxDivRate <- comb.sw.irr$MaxDivRate * cfs.to.m3.per.d
save(comb.sw.irr, file = file.path(dir.out, "comb.sw.irr.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("comb.sw.irr")
@
% =========================================================================
\subsubsection{Evapotranspiration methods (et.method)}
Methods used to calculate monthly distributions of evapotranspiration rate.
<<et_method_1>>=
file <- file.path(dir.in, "et/et.method.csv")
et.method <- read.csv(file, strip.white = TRUE)
et.method$YearMonth <- as.character(et.method$YearMonth)
save(et.method, file = file.path(dir.out, "et.method.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("et.method")
@
% =========================================================================
\subsubsection{Groundwater diversions (div.gw)}
Groundwater diversions recorded by Water District 37 or municipal water providers.
Groundwater is diverted from the aquifer by means of either pumping wells or flowing artesian wells.
<<div_gw_1>>=
file <- file.path(dir.in, "div/div.gw.csv")
div.gw <- read.csv(file, strip.white = TRUE)
div.gw$YearMonth <- as.factor(div.gw$YearMonth)
div.gw$GWDiv <- div.gw$GWDiv_af * af.to.m3
div.gw$GWDiv_af <- NULL
div.gw[is.na(div.gw$GWDiv), "GWDiv"] <- 0
save(div.gw, file = file.path(dir.out, "div.gw.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("div.gw")
@
% =========================================================================
\subsubsection{Irrigation efficiency (efficiency)}
Irrigation efficiency for irrigation entities.
<<efficiency_1>>=
file <- file.path(dir.in, "irr/efficiency.csv")
efficiency <- read.csv(file, strip.white = TRUE)
save(efficiency, file = file.path(dir.out, "efficiency.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("efficiency")
@
% =========================================================================
\subsubsection{Irrigation lands for a given year (irr.lands.year)}
The annual land classification for irrigation practices is only available for select years.
For missing years, this dataset provides substitute years when land-classification was available.
<<irr_lands_year_1>>=
file <- file.path(dir.in, "irr/irr.lands.year.csv")
irr.lands.year <- read.csv(file, strip.white = TRUE, colClasses = "character")
save(irr.lands.year, file = file.path(dir.out, "irr.lands.year.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("irr.lands.year")
@
% =========================================================================
\subsubsection{Snow Water Equivalent (swe)}
Average daily snow water equivalent (SWE) at weather stations in the WRV and surrounding areas.
<<swe_1>>=
file <- file.path(dir.in, "precip/swe.choco.csv")
swe.choco <- read.csv(file, strip.white = TRUE)
swe.choco$MonthDay <- format(as.Date(swe.choco$Date, "%m/%d/%Y"), "%m%d")
swe.choco$SWE <- swe.choco$SWE_in * in.to.m
file <- file.path(dir.in, "precip/swe.hailey.csv")
swe.hailey <- read.csv(file, strip.white = TRUE)
swe.hailey$MonthDay <- format(as.Date(swe.hailey$Date, "%m/%d/%Y"), "%m%d")
swe.hailey$SWE <- swe.hailey$SWE_in * in.to.m
file <- file.path(dir.in, "precip/swe.picabo.csv")
swe.picabo <- read.csv(file, strip.white = TRUE)
swe.picabo$MonthDay <- format(as.Date(swe.picabo$Date, "%m/%d/%Y"), "%m%d")
swe.picabo$SWE <- swe.picabo$SWE_in * in.to.m
@
\noindent Aggregate SWE data by day in a year:
<<swe_2>>=
swe.choco <- aggregate(swe.choco$SWE, list(swe.choco$MonthDay), mean)
swe.hailey <- aggregate(swe.hailey$SWE, list(swe.hailey$MonthDay), mean)
swe.picabo <- aggregate(swe.picabo$SWE, list(swe.picabo$MonthDay), mean)
@
\noindent Combine datasets and write to disk:
<<swe_3>>=
swe <- swe.choco[order(swe.choco[[1]]), ]
swe <- dplyr::left_join(swe, swe.hailey, by = "Group.1")
swe <- dplyr::left_join(swe, swe.picabo, by = "Group.1")
names(swe) <- c("MonthDay", "Choco", "Hailey", "Picabo")
save(swe, file = file.path(dir.out, "swe.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("swe")
@
\newpage
% =========================================================================
\subsubsection{Precipitation Rate (precipitation)}
Precipitation rates in the WRV and surrounding areas.
Combine precipitation records into a single data table:
<<precipitation_1>>=
file <- file.path(dir.in, "precip/precip.csv")
d <- read.csv(file, strip.white = TRUE)
d$Ketchum <- d$Ketchum_ft * ft.to.m
d$Hailey <- d$Hailey_ft * ft.to.m
d$Picabo <- d$Picabo_ft * ft.to.m
d$Ketchum_ft <- NULL
d$Hailey_ft <- NULL
d$Picabo_ft <- NULL
@
\noindent Create a linear regression model between the average of the precipitation depth recorded at the Picabo and Ketchum weather stations,
and the precipitation depth recorded at the Hailey weather station:
<<precipitation_2>>=
x <- apply(d[, c("Picabo", "Ketchum")], 1, mean)
y <- d$Hailey
LM <- lm(y ~ x)
@
\noindent A strong positive correlation (R-squared of \Sexpr{format(summary(LM)$r.squared, digits=3)})
indicates that the regression model may be used to estimate missing data at the Hailey weather station (\hyperref[fig:graph_precip_hailey]{fig.~\ref{fig:graph_precip_hailey}}).
<<precipitation_3>>=
is.na.hailey <- is.na(y)
d$Hailey[is.na.hailey] <- predict(LM, data.frame(x))[is.na.hailey]
precipitation <- d
@
<<include=FALSE>>=
v <- "Monthly precipitation depth at the Hailey HADS weather station in the Wood River Valley aquifer system, south-central Idaho."
v <- c(paste("Graph showing", paste0(tolower(substr(v, 1, 1)), substr(v, 2, nchar(v)))), v)
@
<<graph_precip_hailey, echo=FALSE, fig.width=fin.graph.short[1], fig.height=fin.graph.short[2], fig.scap=sprintf("{%s}", v[1]), fig.cap=sprintf("{%s}", v[2])>>=
d <- precipitation
d <- data.frame(Date=as.Date(paste0(d$YearMonth, "01"), format="%Y%m%d"),
Precip=d$Hailey)
d1 <- d[!is.na.hailey, ]
d2 <- d[ is.na.hailey, ]
cols <- "#327CCB"
ylab <- paste("Monthly precipitation, in", c("meters", "feet"))
ltys <- c(1, 2)
inlmisc::PlotGraph(d, xlim=tr.interval, ylab=ylab, col=cols, lty=0,
conversion.factor=1 / ft.to.m, center.date.labels=TRUE, seq.date.by="year")
lines(d1, lty=ltys[1], col=cols, type="s")
lines(d2, lty=ltys[2], col=cols, type="s")
legend("topright", c("Measured", "Estimated"), col=cols, lty=ltys, inset=0.02,
cex=0.7, box.lty=1, box.lwd=0.5, bg="#FFFFFFE7")
@
\newpage
\noindent Use a monthly precipitation redistribution model to account for frozen precipitation (snow):
<<precipitation_4>>=
d <- precipitation
mo <- month.abb[as.integer(substr(precipitation$YearMonth, 5, 6))]
for (i in seq_along(mo)) {
if (mo[i] == "Nov") {
precipitation$Ketchum[i] <- d$Ketchum[i] * 0.25
precipitation$Hailey[i] <- d$Hailey[i] * 0.75
precipitation$Picabo[i] <- d$Picabo[i] * 0.75
} else if (mo[i] %in% c("Dec", "Jan")) {
precipitation$Ketchum[i] <- d$Ketchum[i] * 0.25
precipitation$Hailey[i] <- d$Hailey[i] * 0.25
precipitation$Picabo[i] <- d$Picabo[i] * 0.25
} else if (mo[i] == "Feb") {
precipitation$Ketchum[i] <- d$Ketchum[i] * 0.25
precipitation$Hailey[i] <- d$Hailey[i] * 0.50
precipitation$Picabo[i] <- d$Picabo[i] * 0.75
} else if (mo[i] == "Mar") {
precipitation$Ketchum[i] <- d$Ketchum[i] * 0.25
precipitation$Hailey[i] <- sum(d$Hailey[(i - 4L):i] * c(0.25, 0.75, 0.75, 0.50, 1))
precipitation$Picabo[i] <- sum(d$Picabo[(i - 4L):i] * c(0.25, 0.75, 0.75, 0.25, 1))
} else if (mo[i] == "Apr") {
precipitation$Ketchum[i] <- sum(d$Ketchum[(i - 5L):i] * c(rep(0.75, 5), 1))
}
}
precipitation <- dplyr::left_join(d, precipitation, by = "YearMonth")
sites <- c("Ketchum", "Hailey", "Picabo")
names(precipitation) <- c("YearMonth", paste0(sites, ".raw"), sites)
@
\noindent Remove precipitation records that occurred outside the model simulation period:
<<precipitation_5>>=
date.time <- as.Date(paste0(precipitation[, "YearMonth"], "01"), "%Y%m%d")
precipitation <- precipitation[date.time >= tr.interval[1] & date.time < tr.interval[2], ]
@
\noindent Add precipitation zone meta data:
<<precipitation_6>>=
d <- data.frame(YearMonth = as.factor(rep(as.character(precipitation$YearMonth), 3)),
PrecipZone = rep(sites, each = nrow(precipitation)),
Precip = NA, Precip.raw = NA)
d[d$PrecipZone == "Ketchum", 3:4] <- precipitation[, c("Ketchum", "Ketchum.raw")]
d[d$PrecipZone == "Hailey", 3:4] <- precipitation[, c("Hailey", "Hailey.raw")]
d[d$PrecipZone == "Picabo", 3:4] <- precipitation[, c("Picabo", "Picabo.raw")]
@
\noindent Save the dataset to disk:
<<precipitation_7>>=
precipitation <- d
save(precipitation, file = file.path(dir.out, "precipitation.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("precipitation")
@
% =========================================================================
\subsubsection{Priority cuts (priority.cuts)}
Priority cut dates applied to Big Wood River above Magic Reservoir and Silver Creek by Water District 37 and 37M at the end of each month.
<<priority_cuts_1>>=
file <- file.path(dir.in, "div/priority.cuts.csv")
priority.cuts <- read.csv(file, strip.white = TRUE)
priority.cuts$YearMonth <- as.factor(priority.cuts$YearMonth)
priority.cuts$Pdate_BWR <- as.Date(priority.cuts$Pdate_BWR, format = "%m/%d/%Y")
priority.cuts$Pdate_SC <- as.Date(priority.cuts$Pdate_SC, format = "%m/%d/%Y")
save(priority.cuts, file = file.path(dir.out, "priority.cuts.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("priority.cuts")
@
% =========================================================================
\subsubsection{Surface-water diversions (div.sw)}
Surface-water diversions recorded by Water District 37 or municipal water providers.
<<div_sw_1>>=
file <- file.path(dir.in, "div/div.sw.csv")
div.sw <- read.csv(file, strip.white = TRUE)
div.sw$YearMonth <- as.factor(div.sw$YearMonth)
div.sw$SWDiv <- div.sw$SWDiv_af * af.to.m3
div.sw$SWDiv_af <- NULL
div.sw[is.na(div.sw$SWDiv), "SWDiv"] <- 0
save(div.sw, file = file.path(dir.out, "div.sw.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("div.sw")
@
% =========================================================================
\subsubsection{Wastewater treatment plant diversions (div.ww)}
Discharge from wastewater treatment plants.
<<div_ww_1>>=
file <- file.path(dir.in, "div/div.ww.csv")
div.ww <- read.csv(file, strip.white = TRUE)
div.ww$YearMonth <- as.factor(div.ww$YearMonth)
div.ww$WWDiv <- div.ww$WWTP_af * af.to.m3
div.ww$WWTP_af <- NULL
div.ww[is.na(div.ww$WWDiv), "WWDiv"] <- 0
save(div.ww, file = file.path(dir.out, "div.ww.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("div.ww")
@
% =========================================================================
\subsubsection{Daily mean discharge at streamgages (gage.disch)}
Daily mean discharge at streamgages in the WRV:
Big Wood River near Ketchum, Idaho (13135500);
Big Wood River at Hailey, Idaho (13139510); and
Big Wood River at Stanton Crossing near Bellevue, Idaho (13140800).
<<gage_disch_1>>=
FUN <- function(i) {
file <- file.path(dir.in, "gage", i)
d <- read.csv(file, colClasses = "character", strip.white = TRUE)
d$Date <- as.Date(d$Date, format = "%Y-%m-%d")
d$Disch <- suppressWarnings(as.numeric(d$Disch_cfs)) * cfs.to.m3.per.d
return(d[substr(d$Code, 1, 1) == "A" & !is.na(d$Disch), c("Date", "Disch")])
}
gage.13135500.disch <- FUN("gage.13135500.disch.csv")
gage.13139510.disch <- FUN("gage.13139510.disch.csv")
gage.13140800.disch <- FUN("gage.13140800.disch.csv")
@
\noindent Combine discharge records into a single data table:
<<gage_disch_2>>=
dlim <- range(c(gage.13135500.disch$Date, gage.13139510.disch$Date,
gage.13140800.disch$Date))
d <- data.frame(Date=seq(dlim[1], dlim[2], by = "day"))
d <- dplyr::left_join(d, gage.13135500.disch, by = "Date")
d <- dplyr::left_join(d, gage.13139510.disch, by = "Date")
d <- dplyr::left_join(d, gage.13140800.disch, by = "Date")
colnames(d) <- c("Date", "13135500", "13139510", "13140800")
gage.disch <- d
save(gage.disch, file = file.path(dir.out, "gage.disch.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("gage.disch")
@
\newpage
% =========================================================================
\subsubsection{Daily mean gage height at streamgages (gage.height)}
Daily mean gage height at streamgages in the WRV:
Big Wood River near Ketchum, Idaho (13135500);
Big Wood River at Hailey, Idaho (13139510); and
Big Wood River at Stanton Crossing near Bellevue, Idaho (13140800) (\hyperref[fig:graph_gage_height]{fig.~\ref{fig:graph_gage_height}}).
<<gage_height_1>>=
FUN <- function(i) {
file <- file.path(dir.in, "gage", i)
d <- read.csv(file, colClasses = "character", strip.white = TRUE)
d$DateTime <- strptime(d$DateTime, "%Y-%m-%d %H:%M", tz = "MST")
d$Date <- as.Date(d$DateTime)
d$Height <- suppressWarnings(as.numeric(d$Height_ft)) * ft.to.m
d <- d[substr(d$Code, 1, 1) %in% c("W", "R", "A") & !is.na(d$Height), ]
d <- aggregate(d$Height, list(d$Date), mean, na.rm = TRUE)
names(d) <- c("Date", "Height")
return(d)
}
gage.13135500.height <- FUN("gage.13135500.height.csv")
gage.13139510.height <- FUN("gage.13139510.height.csv")
gage.13140800.height <- FUN("gage.13140800.height.csv")
@
\noindent Combine gage-height records into a single data table:
<<gage_height_2>>=
dlim <- range(c(gage.13135500.height$Date, gage.13139510.height$Date,
gage.13140800.height$Date))
d <- data.frame(Date=seq(dlim[1], dlim[2], by = "day"))
d <- dplyr::left_join(d, gage.13135500.height, by = "Date")
d <- dplyr::left_join(d, gage.13139510.height, by = "Date")
d <- dplyr::left_join(d, gage.13140800.height, by = "Date")
colnames(d) <- c("Date", "13135500", "13139510", "13140800")
@
\noindent Remove negative values of gage height (n = \Sexpr{length(which(d < 0))}):
<<gage_height_3>>=
d[d < 0] <- NA
@
\noindent Create a linear regression model between gage-height data recorded at the Hailey gage and Near Ketchum gage:
<<gage_height_4>>=
x <- d[["13139510"]]
y <- d[["13135500"]]
LM <- lm(y ~ x)
@
\noindent A strong positive correlation (R-squared of \Sexpr{format(summary(LM)$r.squared, digits=3)})
indicates that the regression model may be used to estimate missing data at the Near Ketchum gage.
<<gage_height_5>>=
is.na.13135500 <- is.na(y)
d[["13135500"]][is.na.13135500] <- predict(LM, data.frame(x))[is.na.13135500]
@
\noindent Missing data at the Stanton Crossing near Bellevue gage are replaced with average gage-height values recorded at this gage.
Substantial seepage losses and surface-water diversions between the Hailey gage and Stanton Crossing near Bellevue gage make regression inappropriate.
<<gage_height_6>>=
jday <- as.integer(julian(as.Date(paste0("1900-", format(d$Date, "%m-%d"))),
origin = as.Date("1899-12-31")))
m <- cbind(jday, height = d[["13140800"]])
m <- m[rowSums(is.na(m)) == 0, ]
m0 <- m[m[, "jday"] > 300, ]
m1 <- m[m[, "jday"] < 66, ]
m0[, "jday"] <- m0[, "jday"] - 365
m1[, "jday"] <- m1[, "jday"] + 365
LPM <- loess(height ~ jday, data.frame(rbind(m0, m, m1)), span = 1 / 35)
ave.heights <- predict(LPM, newdata = 1:365)[jday]
is.na.13140800 <- is.na(d[["13140800"]])
d[["13140800"]][is.na.13140800] <- ave.heights[is.na.13140800]
@
\noindent Save the dataset to disk:
<<gage_height_7>>=
gage.height <- d
save(gage.height, file = file.path(dir.out, "gage.height.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("gage.height")
@
<<include=FALSE>>=
v <- "Gage heights recorded at streamgages along the Big Wood River."
v <- c(paste("Graph showing", paste0(tolower(substr(v, 1, 1)), substr(v, 2, nchar(v)))), v)
@
<<graph_gage_height, echo=FALSE, fig.width=fin.graph.short[1], fig.height=fin.graph.short[2], fig.scap=sprintf("{%s}", v[1]), fig.cap=sprintf("{%s}", v[2])>>=
d1 <- gage.height
d2 <- gage.height
d1[ is.na.13135500, "13135500"] <- NA
d2[!is.na.13135500, "13135500"] <- NA
d1[ is.na.13140800, "13140800"] <- NA
d2[!is.na.13140800, "13140800"] <- NA
x <- merge(d1, d2, by = "Date")[d$Date >= tr.interval[1] & d$Date < tr.interval[2], ]
cols <- rep(c("#1B9E77", "#D95F02", "#7570B3"), 2)
ltys <- c(rep(1, 3), rep(3, 3))
ylab <- paste("Gage height, in", c("meters", "feet"))
inlmisc::PlotGraph(x, ylab=ylab, col=cols, lty=ltys, conversion.factor=1 / ft.to.m,
center.date.labels=TRUE, seq.date.by="year")
leg <- c(sprintf("%s measured", names(d)[-1]),
sprintf("%s estimated", names(d)[-1]))
legend("topright", leg, col=cols, lty=ltys, inset=0.02, cex=0.7, box.lty=1,
box.lwd=0.5, bg="#FFFFFFE7")
@
% =========================================================================
\subsubsection{Points of diversion for groundwater (pod.gw)}
Points of diversion for groundwater.
<<pod_gw_1>>=
file <- file.path(dir.in, "div/pod.gw.csv")
d <- read.csv(file, strip.white = TRUE, stringsAsFactors = FALSE)
d$Pdate <- as.Date(d$PriorityDa, format = "%m/%d/%Y")
d$IrrRate <- d$IRRcfs * cfs.to.m3.per.d
columns <- c("WMISNumber", "WaterRight", "EntityName", "EntitySrce", "Pdate", "IrrRate")
pod.gw <- d[, columns]
save(pod.gw, file = file.path(dir.out, "pod.gw.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("pod.gw")
@
% =========================================================================
\subsubsection{Recharge at miscellaneous seepage sites (misc.seepage)}
Recharge from miscellaneous seepage sites.
<<misc_seepage_1>>=
file <- file.path(dir.in, "misc.seepage.csv")
d <- read.csv(file, strip.white = TRUE)
d$Rech <- d$Rech_af * af.to.m3
FUN <- function(i) {
x <- d[d$YearMonth == i, c("RechSite", "Rech")]
colnames(x) <- c("RechSite", i)
return(x)
}
l <- lapply(yr.mo, FUN)
misc.seepage <- Reduce(function(x, y) merge(x, y, all = TRUE, by = "RechSite"), l)
save(misc.seepage, file = file.path(dir.out, "misc.seepage.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("misc.seepage")
@
% =========================================================================
\subsubsection{Hydraulic properties of hydrogeologic zones (zone.properties)}
Hydraulic properties for each hydrogeologic zone.
<<zone_properties_1>>=
file <- file.path(dir.in, "zone.properties.csv")
d <- read.csv(file, strip.white = TRUE, stringsAsFactors = FALSE)
d$hk <- d$hk_ft.per.d * ft.to.m
d$hk_ft.per.d <- NULL
d$ss <- d$ss_per.ft / ft.to.m
d$ss_per.ft <- NULL
zone.properties <- d
save(zone.properties, file = file.path(dir.out, "zone.properties.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("zone.properties")
@
% =========================================================================
\subsubsection{Dry river bed and stream fed creek conditions (drybed)}
Spring fed creek conditions are specified for select stream reaches.
The mathematical representation of spring fed creeks using the MODFLOW river package is identical to the mathematical representation for a dry stream bed.
<<drybed_1>>=
file <- file.path(dir.in, "perennial.reaches.csv")
perennial.reaches <- read.csv(file, colClasses = "character", strip.white = TRUE)[, 1]
drybed <- as.data.frame(matrix(NA, nrow = length(perennial.reaches), ncol = length(yr.mo)))
colnames(drybed) <- yr.mo
rownames(drybed) <- perennial.reaches
drybed[perennial.reaches, ] <- TRUE
@
\noindent Stream reaches on the Big Wood River between Glendale and Wood River Ranch are episodically dry;
dry bed conditions are specified each year beginning in the first month when the entire flow of the Big Wood River is diverted into the Bypass Canal before
the $16\textsuperscript{th}$ of the month and ending at the end of October.
Between Wood River Ranch and Stanton Crossing, the Big Wood River gains water from springs and seeps,
thus this reach acts as a spring fed creek when dry bed conditions are specified between Glendale and Wood River Ranch and
there is no return flow from the Bypass Canal to the Big Wood River.
<<drybed_2>>=
file <- file.path(dir.in, "canal/bypass.canal.op.csv")
d <- read.csv(file, colClasses = "character", strip.white = TRUE)
date1 <- as.Date(d$StartDate, tz = "MST")
date2 <- as.Date(d$EndDate, tz = "MST")
FUN <- function(i) {
d <- as.integer(format(i, format = "%d"))
m <- format(i, format = "%m")
while (format(i, format = "%m") == m) i <- i + 1L
return(d / as.integer(format(i - 1L, format = "%d")))
}
frac1 <- vapply(date1, FUN, 0)
frac2 <- vapply(date2, FUN, 0)
date1[frac1 > 0.5] <- date1[frac1 > 0.5] + 16L
date2[frac2 < 0.5] <- date2[frac2 < 0.5] - 16L
date1 <- as.Date(paste0(format(date1, format = "%Y-%m"), "-01"))
date2 <- as.Date(paste0(format(date2, format = "%Y-%m"), "-01"))
FUN <- function(i) format(seq(date1[i], date2[i], by = "month"), format = "%Y%m")
is.drybed <- yr.mo %in% unlist(lapply(seq_along(date1), FUN))
episodic.reaches <- c("Big Wood, Glendale to Sluder",
"Big Wood, Sluder to Wood River Ranch",
"Big Wood, Wood River Ranch to Stanton Crossing")
for (i in episodic.reaches) drybed[i, ] <- is.drybed
@
\noindent During the month of October the water district stops monitoring diversions and much of the water diverted into the Bypass Canal is returned to the Big Wood River at Wood River Ranch.
Therefore, flows in the Big Wood, Wood River Ranch to Stanton Crossing reach are accounted for in the model.
<<drybed_3>>=
drybed["Big Wood, Wood River Ranch to Stanton Crossing",
substr(colnames(drybed), 5, 6) == "10"] <- FALSE
@
\noindent Save the dataset to disk:
<<drybed_4>>=
drybed <- data.frame(Reach = rownames(drybed), drybed, check.names = FALSE,
row.names = NULL, stringsAsFactors = FALSE)
save(drybed, file = file.path(dir.out, "drybed.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("drybed")
@
% =========================================================================
\subsubsection{Groundwater-level measurements (obs.wells.head)}
Groundwater-level measurements recorded in observation wells in the WRV.
Values used as observations in parameter estimation.
<<obs_wells_head_1>>=
file <- file.path(dir.in, "opt/obs.wells.head.csv")
d <- read.csv(file, strip.white = TRUE, stringsAsFactors = FALSE)
d$DateTime <- as.POSIXct(d$DateTime, tz = "MST", format = "%Y-%m-%d %H:%M:%S")
d$Head <- as.numeric(d$Head_m)
d$Head_m <- NULL
obs.wells.head <- d
save(obs.wells.head, file = file.path(dir.out, "obs.wells.head.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("obs.wells.head")
@
% =========================================================================
\subsubsection{Stream-aquifer flow exchange along river reaches (reach.recharge)}
Stream-aquifer flow exchange along river reaches specified as aquifer recharge.
Values used as observations in parameter estimation.
<<reach_recharge_1>>=
file <- file.path(dir.in, "opt/reach.recharge.csv")
d <- read.csv(file, strip.white = TRUE, stringsAsFactors = FALSE)
d$YearMonth <- as.character(d$YearMonth)
d$nKet_Hai <- d$nKet_Hai_cfs * cfs.to.m3.per.d
d$nKet_Hai_cfs <- NULL
d$Hai_StC <- d$Hai_StC_cfs * cfs.to.m3.per.d
d$Hai_StC_cfs <- NULL
d$WillowCr <- d$WillowCr_cfs * cfs.to.m3.per.d
d$WillowCr_cfs <- NULL
d$SilverAbv <- d$SilverAbv_cfs * cfs.to.m3.per.d
d$SilverAbv_cfs <- NULL
d$SilverBlw <- d$SilverBlw_cfs * cfs.to.m3.per.d
d$SilverBlw_cfs <- NULL
reach.recharge <- d
save(reach.recharge, file = file.path(dir.out, "reach.recharge.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("reach.recharge")
@
% =========================================================================
\subsubsection{Stream-aquifer flow exchange along river subreaches (subreach.recharge)}
Stream-aquifer flow exchange along river subreaches specified as aquifer recharge.
Values used as observations in parameter estimation.
<<subreach_recharge_1>>=
file <- file.path(dir.in, "opt/subreach.recharge.csv")
d <- read.csv(file, strip.white = TRUE, stringsAsFactors = FALSE)
d[, c("Aug", "Oct", "Mar")] <- d[, c("Aug_cfs", "Oct_cfs", "Mar_cfs")] * cfs.to.m3.per.d
d$Aug_cfs <- NULL
d$Oct_cfs <- NULL
d$Mar_cfs <- NULL
subreach.recharge <- d
save(subreach.recharge, file = file.path(dir.out, "subreach.recharge.rda"),
compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("subreach.recharge")
@
% =========================================================================
\subsubsection{PEST sensitivity analysis (sensitivity)}
Calibrated parameter values and composite sensitivities generated by PEST during its last iteration.
<<sensitivity_1>>=
file <- file.path(dir.in, "opt/sensitivity.csv")
sensitivity <- read.csv(file, strip.white = TRUE)
sensitivity$parameter.name <- as.character(sensitivity$parameter.name)
rel <- with(sensitivity, comp.sens * abs(value)) # Realtive Composite Sensitivity
is.log <- sensitivity$parameter.desc %in% c("Horizontal hydraulic conductivity",
"Storage coefficient",
"Riverbed conductance",
"Drain conductance")
rel[is.log] <- with(sensitivity, comp.sens * abs(log10(value)))[is.log]
sensitivity$rel.comp.sens <- rel
save(sensitivity, file = file.path(dir.out, "sensitivity.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("sensitivity")
@
% =========================================================================
\subsection{Points}
% =========================================================================
\subsubsection{Cities and towns (cities)}
Cities and towns in the WRV and surrounding areas.
<<cities_1>>=
path <- file.path(dir.in, "decorative")
cities <- readOGR(path, "cities", verbose = FALSE, integer64 = "allow.loss")
cities <- spTransform(cities, crs)
cities <- cities[cities@data$FEATURE_NA != "Elkhorn Village", ]
save(cities, file = file.path(dir.out, "cities.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("cities")
@
% =========================================================================
\subsubsection{Map labels (map.labels)}
Map labels in the WRV and surrounding areas.
<<map_labels_1>>=
file <- file.path(dir.in, "decorative/map.labels.csv")
map.labels <- read.csv(file, strip.white = TRUE, stringsAsFactors = FALSE)
map.labels$label <- sub("\\\\n", "\\\n", map.labels$label)
coordinates(map.labels) <- 1:2
colnames(map.labels@coords) <- c("x", "y")
proj4string(map.labels) <- CRS("+init=epsg:4326")
map.labels <- spTransform(map.labels, crs)
save(map.labels, file = file.path(dir.out, "map.labels.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("map.labels")
@
% =========================================================================
\subsubsection{Miscellaneous Locations (misc.locations)}
Miscellaneous locations in the Bellevue triangle area.
<<misc_locations_1>>=
file <- file.path(dir.in, "decorative/misc.locations.csv")
misc.locations <- read.csv(file, strip.white = TRUE, stringsAsFactors = FALSE)
misc.locations$label <- sub("\\\\n", "\\\n", misc.locations$label)
coordinates(misc.locations) <- 1:2
colnames(misc.locations@coords) <- c("x", "y")
proj4string(misc.locations) <- CRS("+init=epsg:4326")
misc.locations <- spTransform(misc.locations, crs)
save(misc.locations, file = file.path(dir.out, "misc.locations.rda"), compress = "xz")
@
<<echo=FALSE>>=
CheckStatus("misc.locations")
@
\newpage
% =========================================================================
\subsubsection{Weather Stations (weather.stations)}
Weather stations in the WRV and surrounding areas.
<<weather_stations_1>>=
file <- file.path(dir.in, "precip/weather.stations.csv")
weather.stations <- read.csv(file, strip.white = TRUE, stringsAsFactors = FALSE)
weather.stations$elevation <- weather.stations$elevation_ft * ft.to.m
weather.stations$elevation_ft <- NULL
weather.stations$url <- NULL
coordinates(weather.stations) <- 1:2
colnames(weather.stations@coords) <- c("x", "y")
proj4string(weather.stations) <- CRS("+init=epsg:4326")
weather.stations <- spTransform(weather.stations, crs)
save(weather.stations, file = file.path(dir.out, "weather.stations.rda"), compress = "xz")