-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetdata.html
More file actions
1195 lines (1107 loc) · 99.4 KB
/
getdata.html
File metadata and controls
1195 lines (1107 loc) · 99.4 KB
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
<!DOCTYPE html>
<html lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>Chapter 7 Joins, Pivots, and USGS dataRetrieval | Hydroinformatics at VT</title>
<meta name="description" content="This bookdown contains notes and exercises for a course in hydroinformatics at Virginia Tech." />
<meta name="generator" content="bookdown 0.27 and GitBook 2.6.7" />
<meta property="og:title" content="Chapter 7 Joins, Pivots, and USGS dataRetrieval | Hydroinformatics at VT" />
<meta property="og:type" content="book" />
<meta property="og:description" content="This bookdown contains notes and exercises for a course in hydroinformatics at Virginia Tech." />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="Chapter 7 Joins, Pivots, and USGS dataRetrieval | Hydroinformatics at VT" />
<meta name="twitter:description" content="This bookdown contains notes and exercises for a course in hydroinformatics at Virginia Tech." />
<meta name="author" content="JP Gannon" />
<meta name="date" content="2023-02-09" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<link rel="prev" href="statsactivity.html"/>
<link rel="next" href="joinpivotDR.html"/>
<script src="libs/jquery-3.6.0/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js@6.4.6/dist/fuse.min.js"></script>
<link href="libs/gitbook-2.6.7/css/style.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-table.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-fontsettings.css" rel="stylesheet" />
<link href="libs/gitbook-2.6.7/css/plugin-clipboard.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.1.0/anchor-sections.css" rel="stylesheet" />
<link href="libs/anchor-sections-1.1.0/anchor-sections-hash.css" rel="stylesheet" />
<script src="libs/anchor-sections-1.1.0/anchor-sections.js"></script>
<script src="libs/htmlwidgets-1.5.4/htmlwidgets.js"></script>
<link href="libs/leaflet-1.3.1/leaflet.css" rel="stylesheet" />
<script src="libs/leaflet-1.3.1/leaflet.js"></script>
<link href="libs/leafletfix-1.0.0/leafletfix.css" rel="stylesheet" />
<script src="libs/proj4-2.6.2/proj4.min.js"></script>
<script src="libs/Proj4Leaflet-1.0.1/proj4leaflet.js"></script>
<link href="libs/rstudio_leaflet-1.3.1/rstudio_leaflet.css" rel="stylesheet" />
<script src="libs/leaflet-binding-2.1.1/leaflet.js"></script>
<script src="libs/leaflet-providers-1.9.0/leaflet-providers_1.9.0.js"></script>
<script src="libs/leaflet-providers-plugin-2.1.1/leaflet-providers-plugin.js"></script>
<script src="libs/rglWebGL-binding-0.109.6/rglWebGL.js"></script>
<link href="libs/rglwidgetClass-0.109.6/rgl.css" rel="stylesheet" />
<script src="libs/rglwidgetClass-0.109.6/rglClass.min.js"></script>
<script type = "text/plain" id = "rgl-vertex-shader">
#line 2 1
// File 1 is the vertex shader
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
attribute vec3 aPos;
attribute vec4 aCol;
uniform mat4 mvMatrix;
uniform mat4 prMatrix;
varying vec4 vCol;
varying vec4 vPosition;
#ifdef NEEDS_VNORMAL
attribute vec3 aNorm;
uniform mat4 normMatrix;
varying vec4 vNormal;
#endif
#if defined(HAS_TEXTURE) || defined (IS_TEXT)
attribute vec2 aTexcoord;
varying vec2 vTexcoord;
#endif
#ifdef FIXED_SIZE
uniform vec3 textScale;
#endif
#ifdef FIXED_QUADS
attribute vec3 aOfs;
#endif
#ifdef IS_TWOSIDED
#ifdef HAS_NORMALS
varying float normz;
uniform mat4 invPrMatrix;
#else
attribute vec3 aPos1;
attribute vec3 aPos2;
varying float normz;
#endif
#endif // IS_TWOSIDED
#ifdef FAT_LINES
attribute vec3 aNext;
attribute vec2 aPoint;
varying vec2 vPoint;
varying float vLength;
uniform float uAspect;
uniform float uLwd;
#endif
void main(void) {
#ifndef IS_BRUSH
#if defined(NCLIPPLANES) || !defined(FIXED_QUADS) || defined(HAS_FOG)
vPosition = mvMatrix * vec4(aPos, 1.);
#endif
#ifndef FIXED_QUADS
gl_Position = prMatrix * vPosition;
#endif
#endif // !IS_BRUSH
#ifdef IS_POINTS
gl_PointSize = POINTSIZE;
#endif
vCol = aCol;
#ifdef NEEDS_VNORMAL
vNormal = normMatrix * vec4(-aNorm, dot(aNorm, aPos));
#endif
#ifdef IS_TWOSIDED
#ifdef HAS_NORMALS
/* normz should be calculated *after* projection */
normz = (invPrMatrix*vNormal).z;
#else
vec4 pos1 = prMatrix*(mvMatrix*vec4(aPos1, 1.));
pos1 = pos1/pos1.w - gl_Position/gl_Position.w;
vec4 pos2 = prMatrix*(mvMatrix*vec4(aPos2, 1.));
pos2 = pos2/pos2.w - gl_Position/gl_Position.w;
normz = pos1.x*pos2.y - pos1.y*pos2.x;
#endif
#endif // IS_TWOSIDED
#ifdef NEEDS_VNORMAL
vNormal = vec4(normalize(vNormal.xyz/vNormal.w), 1);
#endif
#if defined(HAS_TEXTURE) || defined(IS_TEXT)
vTexcoord = aTexcoord;
#endif
#if defined(FIXED_SIZE) && !defined(ROTATING)
vec4 pos = prMatrix * mvMatrix * vec4(aPos, 1.);
pos = pos/pos.w;
gl_Position = pos + vec4(aOfs*textScale, 0.);
#endif
#if defined(IS_SPRITES) && !defined(FIXED_SIZE)
vec4 pos = mvMatrix * vec4(aPos, 1.);
pos = pos/pos.w + vec4(aOfs, 0.);
gl_Position = prMatrix*pos;
#endif
#ifdef FAT_LINES
/* This code was inspired by Matt Deslauriers' code in
https://mattdesl.svbtle.com/drawing-lines-is-hard */
vec2 aspectVec = vec2(uAspect, 1.0);
mat4 projViewModel = prMatrix * mvMatrix;
vec4 currentProjected = projViewModel * vec4(aPos, 1.0);
currentProjected = currentProjected/currentProjected.w;
vec4 nextProjected = projViewModel * vec4(aNext, 1.0);
vec2 currentScreen = currentProjected.xy * aspectVec;
vec2 nextScreen = (nextProjected.xy / nextProjected.w) * aspectVec;
float len = uLwd;
vec2 dir = vec2(1.0, 0.0);
vPoint = aPoint;
vLength = length(nextScreen - currentScreen)/2.0;
vLength = vLength/(vLength + len);
if (vLength > 0.0) {
dir = normalize(nextScreen - currentScreen);
}
vec2 normal = vec2(-dir.y, dir.x);
dir.x /= uAspect;
normal.x /= uAspect;
vec4 offset = vec4(len*(normal*aPoint.x*aPoint.y - dir), 0.0, 0.0);
gl_Position = currentProjected + offset;
#endif
#ifdef IS_BRUSH
gl_Position = vec4(aPos, 1.);
#endif
}
</script>
<script type = "text/plain" id = "rgl-fragment-shader">
#line 2 2
// File 2 is the fragment shader
#ifdef GL_ES
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
#endif
varying vec4 vCol; // carries alpha
varying vec4 vPosition;
#if defined(HAS_TEXTURE) || defined (IS_TEXT)
varying vec2 vTexcoord;
uniform sampler2D uSampler;
#endif
#ifdef HAS_FOG
uniform int uFogMode;
uniform vec3 uFogColor;
uniform vec4 uFogParms;
#endif
#if defined(IS_LIT) && !defined(FIXED_QUADS)
varying vec4 vNormal;
#endif
#if NCLIPPLANES > 0
uniform vec4 vClipplane[NCLIPPLANES];
#endif
#if NLIGHTS > 0
uniform mat4 mvMatrix;
#endif
#ifdef IS_LIT
uniform vec3 emission;
uniform float shininess;
#if NLIGHTS > 0
uniform vec3 ambient[NLIGHTS];
uniform vec3 specular[NLIGHTS]; // light*material
uniform vec3 diffuse[NLIGHTS];
uniform vec3 lightDir[NLIGHTS];
uniform bool viewpoint[NLIGHTS];
uniform bool finite[NLIGHTS];
#endif
#endif // IS_LIT
#ifdef IS_TWOSIDED
uniform bool front;
varying float normz;
#endif
#ifdef FAT_LINES
varying vec2 vPoint;
varying float vLength;
#endif
void main(void) {
vec4 fragColor;
#ifdef FAT_LINES
vec2 point = vPoint;
bool neg = point.y < 0.0;
point.y = neg ? (point.y + vLength)/(1.0 - vLength) :
-(point.y - vLength)/(1.0 - vLength);
#if defined(IS_TRANSPARENT) && defined(IS_LINESTRIP)
if (neg && length(point) <= 1.0) discard;
#endif
point.y = min(point.y, 0.0);
if (length(point) > 1.0) discard;
#endif // FAT_LINES
#ifdef ROUND_POINTS
vec2 coord = gl_PointCoord - vec2(0.5);
if (length(coord) > 0.5) discard;
#endif
#if NCLIPPLANES > 0
for (int i = 0; i < NCLIPPLANES; i++)
if (dot(vPosition, vClipplane[i]) < 0.0) discard;
#endif
#ifdef FIXED_QUADS
vec3 n = vec3(0., 0., 1.);
#elif defined(IS_LIT)
vec3 n = normalize(vNormal.xyz);
#endif
#ifdef IS_TWOSIDED
if ((normz <= 0.) != front) discard;
#endif
#ifdef IS_LIT
vec3 eye = normalize(-vPosition.xyz/vPosition.w);
vec3 lightdir;
vec4 colDiff;
vec3 halfVec;
vec4 lighteffect = vec4(emission, 0.);
vec3 col;
float nDotL;
#ifdef FIXED_QUADS
n = -faceforward(n, n, eye);
#endif
#if NLIGHTS > 0
for (int i=0;i<NLIGHTS;i++) {
colDiff = vec4(vCol.rgb * diffuse[i], vCol.a);
lightdir = lightDir[i];
if (!viewpoint[i])
lightdir = (mvMatrix * vec4(lightdir, 1.)).xyz;
if (!finite[i]) {
halfVec = normalize(lightdir + eye);
} else {
lightdir = normalize(lightdir - vPosition.xyz/vPosition.w);
halfVec = normalize(lightdir + eye);
}
col = ambient[i];
nDotL = dot(n, lightdir);
col = col + max(nDotL, 0.) * colDiff.rgb;
col = col + pow(max(dot(halfVec, n), 0.), shininess) * specular[i];
lighteffect = lighteffect + vec4(col, colDiff.a);
}
#endif
#else // not IS_LIT
vec4 colDiff = vCol;
vec4 lighteffect = colDiff;
#endif
#ifdef IS_TEXT
vec4 textureColor = lighteffect*texture2D(uSampler, vTexcoord);
#endif
#ifdef HAS_TEXTURE
#ifdef TEXTURE_rgb
vec4 textureColor = lighteffect*vec4(texture2D(uSampler, vTexcoord).rgb, 1.);
#endif
#ifdef TEXTURE_rgba
vec4 textureColor = lighteffect*texture2D(uSampler, vTexcoord);
#endif
#ifdef TEXTURE_alpha
vec4 textureColor = texture2D(uSampler, vTexcoord);
float luminance = dot(vec3(1.,1.,1.), textureColor.rgb)/3.;
textureColor = vec4(lighteffect.rgb, lighteffect.a*luminance);
#endif
#ifdef TEXTURE_luminance
vec4 textureColor = vec4(lighteffect.rgb*dot(texture2D(uSampler, vTexcoord).rgb, vec3(1.,1.,1.))/3., lighteffect.a);
#endif
#ifdef TEXTURE_luminance_alpha
vec4 textureColor = texture2D(uSampler, vTexcoord);
float luminance = dot(vec3(1.,1.,1.),textureColor.rgb)/3.;
textureColor = vec4(lighteffect.rgb*luminance, lighteffect.a*textureColor.a);
#endif
fragColor = textureColor;
#elif defined(IS_TEXT)
if (textureColor.a < 0.1)
discard;
else
fragColor = textureColor;
#else
fragColor = lighteffect;
#endif // HAS_TEXTURE
#ifdef HAS_FOG
// uFogParms elements: x = near, y = far, z = fogscale, w = (1-sin(FOV/2))/(1+sin(FOV/2))
// In Exp and Exp2: use density = density/far
// fogF will be the proportion of fog
// Initialize it to the linear value
float fogF;
if (uFogMode > 0) {
fogF = (uFogParms.y - vPosition.z/vPosition.w)/(uFogParms.y - uFogParms.x);
if (uFogMode > 1)
fogF = mix(uFogParms.w, 1.0, fogF);
fogF = fogF*uFogParms.z;
if (uFogMode == 2)
fogF = 1.0 - exp(-fogF);
// Docs are wrong: use (density*c)^2, not density*c^2
// https://gitlab.freedesktop.org/mesa/mesa/-/blob/master/src/mesa/swrast/s_fog.c#L58
else if (uFogMode == 3)
fogF = 1.0 - exp(-fogF*fogF);
fogF = clamp(fogF, 0.0, 1.0);
gl_FragColor = vec4(mix(fragColor.rgb, uFogColor, fogF), fragColor.a);
} else gl_FragColor = fragColor;
#else
gl_FragColor = fragColor;
#endif // HAS_FOG
}
</script>
<script src="libs/CanvasMatrix4-0.109.6/CanvasMatrix.min.js"></script>
<script src="libs/plotly-binding-4.10.0/plotly.js"></script>
<script src="libs/typedarray-0.1/typedarray.min.js"></script>
<link href="libs/crosstalk-1.2.0/css/crosstalk.min.css" rel="stylesheet" />
<script src="libs/crosstalk-1.2.0/js/crosstalk.min.js"></script>
<link href="libs/plotly-htmlwidgets-css-2.5.1/plotly-htmlwidgets.css" rel="stylesheet" />
<script src="libs/plotly-main-2.5.1/plotly-latest.min.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-GBDXSZFFSR"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-GBDXSZFFSR');
</script>
<style type="text/css">
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
color: #aaaaaa;
}
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { color: #008000; } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { color: #008000; font-weight: bold; } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">
<div class="book-summary">
<nav role="navigation">
<ul class="summary">
<li><a href="./">Hydroinformatics</a></li>
<li class="divider"></li>
<li class="chapter" data-level="1" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i><b>1</b> Introduction</a>
<ul>
<li class="chapter" data-level="1.0.1" data-path="index.html"><a href="index.html#to-help-me-keep-get-an-idea-of-who-is-using-this-resource-so-i-can-improve-it-in-the-future-please-consider-filling-out-any-or-all-of-this-survey-httpsforms.gle6zcntzvr1wzzuh6s7-thanks"><i class="fa fa-check"></i><b>1.0.1</b> To help me keep get an idea of who is using this resource so I can improve it in the future, please consider filling out any or all of this survey: https://forms.gle/6Zcntzvr1wZZUh6S7 Thanks!</a></li>
<li class="chapter" data-level="1.1" data-path="index.html"><a href="index.html#how-to-use-these-materials"><i class="fa fa-check"></i><b>1.1</b> How to use these materials</a></li>
<li class="chapter" data-level="1.2" data-path="index.html"><a href="index.html#table-of-contents"><i class="fa fa-check"></i><b>1.2</b> Table of contents:</a></li>
</ul></li>
<li class="chapter" data-level="2" data-path="Plotting.html"><a href="Plotting.html"><i class="fa fa-check"></i><b>2</b> Intro to Plotting</a>
<ul>
<li class="chapter" data-level="2.1" data-path="Plotting.html"><a href="Plotting.html#download-and-install-tidyverse-library"><i class="fa fa-check"></i><b>2.1</b> Download and install tidyverse library</a></li>
<li class="chapter" data-level="2.2" data-path="Plotting.html"><a href="Plotting.html#reading-data"><i class="fa fa-check"></i><b>2.2</b> Reading data</a></li>
<li class="chapter" data-level="2.3" data-path="Plotting.html"><a href="Plotting.html#our-first-ggplot"><i class="fa fa-check"></i><b>2.3</b> Our first ggplot</a></li>
<li class="chapter" data-level="2.4" data-path="Plotting.html"><a href="Plotting.html#change-point-type"><i class="fa fa-check"></i><b>2.4</b> Change point type</a></li>
<li class="chapter" data-level="2.5" data-path="Plotting.html"><a href="Plotting.html#set-colors"><i class="fa fa-check"></i><b>2.5</b> Set colors</a></li>
<li class="chapter" data-level="2.6" data-path="Plotting.html"><a href="Plotting.html#controlling-color-with-a-third-variable-and-other-functions"><i class="fa fa-check"></i><b>2.6</b> Controlling color with a third variable and other functions</a></li>
<li class="chapter" data-level="2.7" data-path="Plotting.html"><a href="Plotting.html#plotting-multiple-groups"><i class="fa fa-check"></i><b>2.7</b> Plotting multiple groups</a></li>
<li class="chapter" data-level="2.8" data-path="Plotting.html"><a href="Plotting.html#facets"><i class="fa fa-check"></i><b>2.8</b> Facets</a></li>
<li class="chapter" data-level="2.9" data-path="Plotting.html"><a href="Plotting.html#two-variable-faceting"><i class="fa fa-check"></i><b>2.9</b> Two variable faceting</a></li>
<li class="chapter" data-level="2.10" data-path="Plotting.html"><a href="Plotting.html#boxplots"><i class="fa fa-check"></i><b>2.10</b> Boxplots</a></li>
<li class="chapter" data-level="2.11" data-path="Plotting.html"><a href="Plotting.html#more-about-color-size-etc"><i class="fa fa-check"></i><b>2.11</b> More about color, size, etc</a></li>
<li class="chapter" data-level="2.12" data-path="Plotting.html"><a href="Plotting.html#multiple-geoms"><i class="fa fa-check"></i><b>2.12</b> Multiple geoms</a></li>
</ul></li>
<li class="chapter" data-level="3" data-path="Programming.html"><a href="Programming.html"><i class="fa fa-check"></i><b>3</b> R Tidyverse Programming Basics</a>
<ul>
<li class="chapter" data-level="3.1" data-path="Programming.html"><a href="Programming.html#introduction-1"><i class="fa fa-check"></i><b>3.1</b> Introduction</a></li>
<li class="chapter" data-level="3.2" data-path="Programming.html"><a href="Programming.html#you-can-use-r-as-a-calculator"><i class="fa fa-check"></i><b>3.2</b> You can use R as a calculator</a></li>
<li class="chapter" data-level="3.3" data-path="Programming.html"><a href="Programming.html#you-can-create-new-objects-using--"><i class="fa fa-check"></i><b>3.3</b> You can create new objects using <-</a></li>
<li class="chapter" data-level="3.4" data-path="Programming.html"><a href="Programming.html#using-functions"><i class="fa fa-check"></i><b>3.4</b> Using functions</a></li>
<li class="chapter" data-level="3.5" data-path="Programming.html"><a href="Programming.html#read-in-some-data."><i class="fa fa-check"></i><b>3.5</b> Read in some data.</a></li>
<li class="chapter" data-level="3.6" data-path="Programming.html"><a href="Programming.html#wait-hold-up.-what-is-a-tibble"><i class="fa fa-check"></i><b>3.6</b> Wait, hold up. What is a tibble?</a></li>
<li class="chapter" data-level="3.7" data-path="Programming.html"><a href="Programming.html#data-wrangling-in-dplyr"><i class="fa fa-check"></i><b>3.7</b> Data wrangling in dplyr</a></li>
<li class="chapter" data-level="3.8" data-path="Programming.html"><a href="Programming.html#filter"><i class="fa fa-check"></i><b>3.8</b> Filter</a>
<ul>
<li class="chapter" data-level="3.8.1" data-path="Programming.html"><a href="Programming.html#multiple-conditions"><i class="fa fa-check"></i><b>3.8.1</b> Multiple conditions</a></li>
</ul></li>
<li class="chapter" data-level="3.9" data-path="Programming.html"><a href="Programming.html#arrange"><i class="fa fa-check"></i><b>3.9</b> Arrange</a></li>
<li class="chapter" data-level="3.10" data-path="Programming.html"><a href="Programming.html#select"><i class="fa fa-check"></i><b>3.10</b> Select</a></li>
<li class="chapter" data-level="3.11" data-path="Programming.html"><a href="Programming.html#mutate"><i class="fa fa-check"></i><b>3.11</b> Mutate</a></li>
<li class="chapter" data-level="3.12" data-path="Programming.html"><a href="Programming.html#summarize"><i class="fa fa-check"></i><b>3.12</b> Summarize</a></li>
<li class="chapter" data-level="3.13" data-path="Programming.html"><a href="Programming.html#multiple-operations-with-pipes"><i class="fa fa-check"></i><b>3.13</b> Multiple operations with pipes</a>
<ul>
<li class="chapter" data-level="3.13.1" data-path="Programming.html"><a href="Programming.html#lets-say-we-want-to-tell-r-to-make-a-pbj-sandwich-by-using-the-pbbread-jbread-and-joinslices-functions-and-the-data-ingredients.-if-we-do-this-saving-each-step-if-would-look-like-this"><i class="fa fa-check"></i><b>3.13.1</b> Let’s say we want to tell R to make a PB&J sandwich by using the pbbread(), jbread(), and joinslices() functions and the data “ingredients”. If we do this saving each step if would look like this:</a></li>
<li class="chapter" data-level="3.13.2" data-path="Programming.html"><a href="Programming.html#if-we-nest-the-functions-together-we-get-this"><i class="fa fa-check"></i><b>3.13.2</b> If we nest the functions together we get this</a></li>
<li class="chapter" data-level="3.13.3" data-path="Programming.html"><a href="Programming.html#using-the-pipe-it-would-look-like-this"><i class="fa fa-check"></i><b>3.13.3</b> Using the pipe it would look like this</a></li>
<li class="chapter" data-level="3.13.4" data-path="Programming.html"><a href="Programming.html#when-you-use-the-pipe-it-basically-takes-whatever-came-out-of-the-first-function-and-puts-it-into-the-data-argument-for-the-next-one"><i class="fa fa-check"></i><b>3.13.4</b> When you use the pipe, it basically takes whatever came out of the first function and puts it into the data argument for the next one</a></li>
</ul></li>
<li class="chapter" data-level="3.14" data-path="Programming.html"><a href="Programming.html#save-your-results-to-a-new-tibble"><i class="fa fa-check"></i><b>3.14</b> Save your results to a new tibble</a></li>
<li class="chapter" data-level="3.15" data-path="Programming.html"><a href="Programming.html#what-about-nas"><i class="fa fa-check"></i><b>3.15</b> What about NAs?</a></li>
<li class="chapter" data-level="3.16" data-path="Programming.html"><a href="Programming.html#what-are-some-things-you-think-ill-ask-you-to-do-for-the-activity-next-class"><i class="fa fa-check"></i><b>3.16</b> What are some things you think I’ll ask you to do for the activity next class?</a></li>
</ul></li>
<li class="chapter" data-level="4" data-path="introactivity.html"><a href="introactivity.html"><i class="fa fa-check"></i><b>4</b> ACTIVITY Intro Skills</a>
<ul>
<li class="chapter" data-level="4.1" data-path="introactivity.html"><a href="introactivity.html#problem-1"><i class="fa fa-check"></i><b>4.1</b> Problem 1</a></li>
<li class="chapter" data-level="4.2" data-path="introactivity.html"><a href="introactivity.html#problem-2"><i class="fa fa-check"></i><b>4.2</b> Problem 2</a></li>
<li class="chapter" data-level="4.3" data-path="introactivity.html"><a href="introactivity.html#problem-3"><i class="fa fa-check"></i><b>4.3</b> Problem 3</a></li>
<li class="chapter" data-level="4.4" data-path="introactivity.html"><a href="introactivity.html#problem-4"><i class="fa fa-check"></i><b>4.4</b> Problem 4</a></li>
<li class="chapter" data-level="4.5" data-path="introactivity.html"><a href="introactivity.html#problem-5"><i class="fa fa-check"></i><b>4.5</b> Problem 5</a></li>
<li class="chapter" data-level="4.6" data-path="introactivity.html"><a href="introactivity.html#problem-6"><i class="fa fa-check"></i><b>4.6</b> Problem 6</a></li>
</ul></li>
<li class="chapter" data-level="5" data-path="stats.html"><a href="stats.html"><i class="fa fa-check"></i><b>5</b> Introduction to Basic Statistics</a>
<ul>
<li class="chapter" data-level="5.1" data-path="stats.html"><a href="stats.html#reading-for-this-section-statistical-methods-in-water-resources-chapter-1"><i class="fa fa-check"></i><b>5.1</b> Reading for this section: Statistical Methods in Water Resources: Chapter 1</a></li>
<li class="chapter" data-level="5.2" data-path="stats.html"><a href="stats.html#questions-for-today"><i class="fa fa-check"></i><b>5.2</b> Questions for today:</a>
<ul>
<li class="chapter" data-level="5.2.1" data-path="stats.html"><a href="stats.html#stack-plots-to-compare-histogram-and-pdf"><i class="fa fa-check"></i><b>5.2.1</b> Stack plots to compare histogram and pdf</a></li>
</ul></li>
<li class="chapter" data-level="5.3" data-path="stats.html"><a href="stats.html#what-is-the-difference-between-a-sample-and-a-population."><i class="fa fa-check"></i><b>5.3</b> What is the difference between a sample and a population.</a></li>
<li class="chapter" data-level="5.4" data-path="stats.html"><a href="stats.html#measuring-our-sample-distribution-central-tendency."><i class="fa fa-check"></i><b>5.4</b> Measuring our sample distribution: central tendency.</a>
<ul>
<li class="chapter" data-level="5.4.1" data-path="stats.html"><a href="stats.html#so-whats-a-weighted-average"><i class="fa fa-check"></i><b>5.4.1</b> So what’s a weighted average?</a></li>
</ul></li>
<li class="chapter" data-level="5.5" data-path="stats.html"><a href="stats.html#measures-of-variability"><i class="fa fa-check"></i><b>5.5</b> Measures of variability</a></li>
<li class="chapter" data-level="5.6" data-path="stats.html"><a href="stats.html#what-is-a-normal-distribution-and-how-can-we-determine-if-we-have-one"><i class="fa fa-check"></i><b>5.6</b> What is a normal distribution and how can we determine if we have one?</a></li>
</ul></li>
<li class="chapter" data-level="6" data-path="statsactivity.html"><a href="statsactivity.html"><i class="fa fa-check"></i><b>6</b> ACTIVITY Intro Stats</a>
<ul>
<li class="chapter" data-level="6.1" data-path="statsactivity.html"><a href="statsactivity.html#problem-1-1"><i class="fa fa-check"></i><b>6.1</b> Problem 1</a></li>
<li class="chapter" data-level="6.2" data-path="statsactivity.html"><a href="statsactivity.html#problem-2-1"><i class="fa fa-check"></i><b>6.2</b> Problem 2</a></li>
<li class="chapter" data-level="6.3" data-path="statsactivity.html"><a href="statsactivity.html#problem-3-1"><i class="fa fa-check"></i><b>6.3</b> Problem 3</a></li>
<li class="chapter" data-level="6.4" data-path="statsactivity.html"><a href="statsactivity.html#problem-4-1"><i class="fa fa-check"></i><b>6.4</b> Problem 4</a></li>
<li class="chapter" data-level="6.5" data-path="statsactivity.html"><a href="statsactivity.html#problem-5-1"><i class="fa fa-check"></i><b>6.5</b> Problem 5</a></li>
<li class="chapter" data-level="6.6" data-path="statsactivity.html"><a href="statsactivity.html#problem-6-1"><i class="fa fa-check"></i><b>6.6</b> Problem 6</a></li>
</ul></li>
<li class="chapter" data-level="7" data-path="getdata.html"><a href="getdata.html"><i class="fa fa-check"></i><b>7</b> Joins, Pivots, and USGS dataRetrieval</a>
<ul>
<li class="chapter" data-level="7.1" data-path="getdata.html"><a href="getdata.html#goals-for-today"><i class="fa fa-check"></i><b>7.1</b> Goals for today</a></li>
<li class="chapter" data-level="7.2" data-path="getdata.html"><a href="getdata.html#exploring-what-dataretrieval-can-do."><i class="fa fa-check"></i><b>7.2</b> Exploring what dataRetrieval can do.</a></li>
<li class="chapter" data-level="7.3" data-path="getdata.html"><a href="getdata.html#joins"><i class="fa fa-check"></i><b>7.3</b> Joins</a></li>
<li class="chapter" data-level="7.4" data-path="getdata.html"><a href="getdata.html#join-example"><i class="fa fa-check"></i><b>7.4</b> Join example</a></li>
<li class="chapter" data-level="7.5" data-path="getdata.html"><a href="getdata.html#finding-ids-to-download-usgs-data"><i class="fa fa-check"></i><b>7.5</b> Finding IDs to download USGS data</a></li>
<li class="chapter" data-level="7.6" data-path="getdata.html"><a href="getdata.html#ok-lets-download-some-data"><i class="fa fa-check"></i><b>7.6</b> OK let’s download some data!</a></li>
<li class="chapter" data-level="7.7" data-path="getdata.html"><a href="getdata.html#pivoting-wide-and-long-data"><i class="fa fa-check"></i><b>7.7</b> Pivoting: wide and long data</a></li>
<li class="chapter" data-level="7.8" data-path="getdata.html"><a href="getdata.html#pivot-examples"><i class="fa fa-check"></i><b>7.8</b> Pivot Examples</a></li>
</ul></li>
<li class="chapter" data-level="8" data-path="joinpivotDR.html"><a href="joinpivotDR.html"><i class="fa fa-check"></i><b>8</b> ACTIVITY: Joins Pivots dataRetrieval</a>
<ul>
<li class="chapter" data-level="8.1" data-path="joinpivotDR.html"><a href="joinpivotDR.html#load-the-tidyverse-dataretrieval-and-patchwork-packages."><i class="fa fa-check"></i><b>8.1</b> Load the tidyverse, dataRetrieval, and patchwork packages.</a></li>
<li class="chapter" data-level="8.2" data-path="joinpivotDR.html"><a href="joinpivotDR.html#problem-1-2"><i class="fa fa-check"></i><b>8.2</b> Problem 1</a></li>
<li class="chapter" data-level="8.3" data-path="joinpivotDR.html"><a href="joinpivotDR.html#problem-2-2"><i class="fa fa-check"></i><b>8.3</b> Problem 2</a></li>
<li class="chapter" data-level="8.4" data-path="joinpivotDR.html"><a href="joinpivotDR.html#problem-3-2"><i class="fa fa-check"></i><b>8.4</b> Problem 3</a></li>
<li class="chapter" data-level="8.5" data-path="joinpivotDR.html"><a href="joinpivotDR.html#problem-4-2"><i class="fa fa-check"></i><b>8.5</b> Problem 4</a></li>
<li class="chapter" data-level="8.6" data-path="joinpivotDR.html"><a href="joinpivotDR.html#problem-5-2"><i class="fa fa-check"></i><b>8.6</b> Problem 5</a></li>
<li class="chapter" data-level="8.7" data-path="joinpivotDR.html"><a href="joinpivotDR.html#problem-6-2"><i class="fa fa-check"></i><b>8.7</b> Problem 6</a></li>
<li class="chapter" data-level="8.8" data-path="joinpivotDR.html"><a href="joinpivotDR.html#problem-7"><i class="fa fa-check"></i><b>8.8</b> Problem 7</a></li>
</ul></li>
<li class="chapter" data-level="9" data-path="Summative1.html"><a href="Summative1.html"><i class="fa fa-check"></i><b>9</b> ACTIVITY Summative 1</a>
<ul>
<li class="chapter" data-level="9.0.1" data-path="Summative1.html"><a href="Summative1.html#instructions"><i class="fa fa-check"></i><b>9.0.1</b> Instructions</a></li>
<li class="chapter" data-level="9.1" data-path="Summative1.html"><a href="Summative1.html#problem-1-3"><i class="fa fa-check"></i><b>9.1</b> Problem 1</a></li>
<li class="chapter" data-level="9.2" data-path="Summative1.html"><a href="Summative1.html#problem-2-3"><i class="fa fa-check"></i><b>9.2</b> Problem 2</a></li>
<li class="chapter" data-level="9.3" data-path="Summative1.html"><a href="Summative1.html#problem-3-3"><i class="fa fa-check"></i><b>9.3</b> Problem 3</a></li>
<li class="chapter" data-level="9.4" data-path="Summative1.html"><a href="Summative1.html#problem-4-3"><i class="fa fa-check"></i><b>9.4</b> Problem 4</a></li>
<li class="chapter" data-level="9.5" data-path="Summative1.html"><a href="Summative1.html#problem-5-3"><i class="fa fa-check"></i><b>9.5</b> Problem 5</a></li>
<li class="chapter" data-level="9.6" data-path="Summative1.html"><a href="Summative1.html#problem-6-3"><i class="fa fa-check"></i><b>9.6</b> Problem 6</a></li>
<li class="chapter" data-level="9.7" data-path="Summative1.html"><a href="Summative1.html#problem-7-1"><i class="fa fa-check"></i><b>9.7</b> Problem 7</a></li>
<li class="chapter" data-level="9.8" data-path="Summative1.html"><a href="Summative1.html#problem-8"><i class="fa fa-check"></i><b>9.8</b> Problem 8</a></li>
<li class="chapter" data-level="9.9" data-path="Summative1.html"><a href="Summative1.html#problem-9"><i class="fa fa-check"></i><b>9.9</b> Problem 9</a></li>
<li class="chapter" data-level="9.10" data-path="Summative1.html"><a href="Summative1.html#problem-10"><i class="fa fa-check"></i><b>9.10</b> Problem 10</a></li>
</ul></li>
<li class="chapter" data-level="10" data-path="fdcs.html"><a href="fdcs.html"><i class="fa fa-check"></i><b>10</b> Flow Duration Curves</a>
<ul>
<li class="chapter" data-level="10.1" data-path="fdcs.html"><a href="fdcs.html#get-data"><i class="fa fa-check"></i><b>10.1</b> Get data</a></li>
<li class="chapter" data-level="10.2" data-path="fdcs.html"><a href="fdcs.html#review-describe-the-distribution"><i class="fa fa-check"></i><b>10.2</b> Review: describe the distribution</a></li>
<li class="chapter" data-level="10.3" data-path="fdcs.html"><a href="fdcs.html#ecdfs"><i class="fa fa-check"></i><b>10.3</b> ECDFs</a></li>
<li class="chapter" data-level="10.4" data-path="fdcs.html"><a href="fdcs.html#calculate-flow-exceedence-probabilities"><i class="fa fa-check"></i><b>10.4</b> Calculate flow exceedence probabilities</a></li>
<li class="chapter" data-level="10.5" data-path="fdcs.html"><a href="fdcs.html#plot-a-flow-duration-curve-using-the-probabilities"><i class="fa fa-check"></i><b>10.5</b> Plot a Flow Duration Curve using the probabilities</a></li>
<li class="chapter" data-level="10.6" data-path="fdcs.html"><a href="fdcs.html#make-an-almost-fdc-with-stat_ecdf"><i class="fa fa-check"></i><b>10.6</b> Make an almost FDC with stat_ecdf</a></li>
<li class="chapter" data-level="10.7" data-path="fdcs.html"><a href="fdcs.html#example-use-of-an-fdc"><i class="fa fa-check"></i><b>10.7</b> Example use of an FDC</a></li>
<li class="chapter" data-level="10.8" data-path="fdcs.html"><a href="fdcs.html#compare-to-a-boxplot-of-the-same-data"><i class="fa fa-check"></i><b>10.8</b> Compare to a boxplot of the same data</a></li>
<li class="chapter" data-level="10.9" data-path="fdcs.html"><a href="fdcs.html#challenge-examining-flow-regime-change-at-the-grand-canyon"><i class="fa fa-check"></i><b>10.9</b> Challenge: Examining flow regime change at the Grand Canyon</a></li>
</ul></li>
<li class="chapter" data-level="11" data-path="lfas.html"><a href="lfas.html"><i class="fa fa-check"></i><b>11</b> Low Flow Analysis</a>
<ul>
<li class="chapter" data-level="11.1" data-path="lfas.html"><a href="lfas.html#what-are-low-flow-statistics"><i class="fa fa-check"></i><b>11.1</b> What are low flow statistics?</a></li>
<li class="chapter" data-level="11.2" data-path="lfas.html"><a href="lfas.html#get-data-1"><i class="fa fa-check"></i><b>11.2</b> Get data</a></li>
<li class="chapter" data-level="11.3" data-path="lfas.html"><a href="lfas.html#create-the-x-days-average-flow-record"><i class="fa fa-check"></i><b>11.3</b> Create the X days average flow record</a></li>
<li class="chapter" data-level="11.4" data-path="lfas.html"><a href="lfas.html#look-at-what-a-rolling-mean-does."><i class="fa fa-check"></i><b>11.4</b> Look at what a rolling mean does.</a></li>
<li class="chapter" data-level="11.5" data-path="lfas.html"><a href="lfas.html#calculate-yearly-minimums"><i class="fa fa-check"></i><b>11.5</b> Calculate yearly minimums</a></li>
<li class="chapter" data-level="11.6" data-path="lfas.html"><a href="lfas.html#calculate-return-interval"><i class="fa fa-check"></i><b>11.6</b> Calculate return interval</a></li>
<li class="chapter" data-level="11.7" data-path="lfas.html"><a href="lfas.html#fit-to-pearson-type-iii-distribution"><i class="fa fa-check"></i><b>11.7</b> Fit to Pearson Type III distribution</a></li>
<li class="chapter" data-level="11.8" data-path="lfas.html"><a href="lfas.html#distribution-free-method"><i class="fa fa-check"></i><b>11.8</b> Distribution-free method</a></li>
</ul></li>
<li class="chapter" data-level="12" data-path="floods.html"><a href="floods.html"><i class="fa fa-check"></i><b>12</b> Flood Frequency Analysis and Creating Functions</a>
<ul>
<li class="chapter" data-level="12.1" data-path="floods.html"><a href="floods.html#template-repository"><i class="fa fa-check"></i><b>12.1</b> Template Repository</a></li>
<li class="chapter" data-level="12.2" data-path="floods.html"><a href="floods.html#intro"><i class="fa fa-check"></i><b>12.2</b> Intro</a></li>
<li class="chapter" data-level="12.3" data-path="floods.html"><a href="floods.html#challenge-create-a-function"><i class="fa fa-check"></i><b>12.3</b> Challenge: Create a function</a></li>
</ul></li>
<li class="chapter" data-level="13" data-path="rgeospatial.html"><a href="rgeospatial.html"><i class="fa fa-check"></i><b>13</b> Geospatial data in R - Vector</a>
<ul>
<li class="chapter" data-level="13.1" data-path="rgeospatial.html"><a href="rgeospatial.html#goals"><i class="fa fa-check"></i><b>13.1</b> Goals</a></li>
<li class="chapter" data-level="13.2" data-path="rgeospatial.html"><a href="rgeospatial.html#intro-to-tmap"><i class="fa fa-check"></i><b>13.2</b> Intro to tmap</a></li>
<li class="chapter" data-level="13.3" data-path="rgeospatial.html"><a href="rgeospatial.html#data-wrangling-with-tidyverse-principles"><i class="fa fa-check"></i><b>13.3</b> Data wrangling with tidyverse principles</a></li>
<li class="chapter" data-level="13.4" data-path="rgeospatial.html"><a href="rgeospatial.html#plot-maps-side-by-side"><i class="fa fa-check"></i><b>13.4</b> Plot maps side by side</a></li>
<li class="chapter" data-level="13.5" data-path="rgeospatial.html"><a href="rgeospatial.html#built-in-styles-like-themes-in-ggplot"><i class="fa fa-check"></i><b>13.5</b> Built in styles, like themes in ggplot</a></li>
<li class="chapter" data-level="13.6" data-path="rgeospatial.html"><a href="rgeospatial.html#interactive-maps"><i class="fa fa-check"></i><b>13.6</b> Interactive Maps</a>
<ul>
<li class="chapter" data-level="13.6.1" data-path="rgeospatial.html"><a href="rgeospatial.html#tmap"><i class="fa fa-check"></i><b>13.6.1</b> tmap</a></li>
<li class="chapter" data-level="13.6.2" data-path="rgeospatial.html"><a href="rgeospatial.html#leaflet"><i class="fa fa-check"></i><b>13.6.2</b> Leaflet</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="14" data-path="summative2.html"><a href="summative2.html"><i class="fa fa-check"></i><b>14</b> Summative Assessment 2</a>
<ul>
<li class="chapter" data-level="14.1" data-path="summative2.html"><a href="summative2.html#info-for-assessment"><i class="fa fa-check"></i><b>14.1</b> Info for assessment</a></li>
</ul></li>
<li class="chapter" data-level="15" data-path="rgeoraster.html"><a href="rgeoraster.html"><i class="fa fa-check"></i><b>15</b> Geospatial R Raster - Hydro Analyses</a>
<ul>
<li class="chapter" data-level="15.1" data-path="rgeoraster.html"><a href="rgeoraster.html#introduction-2"><i class="fa fa-check"></i><b>15.1</b> Introduction</a></li>
<li class="chapter" data-level="15.2" data-path="rgeoraster.html"><a href="rgeoraster.html#read-in-dem"><i class="fa fa-check"></i><b>15.2</b> Read in DEM</a></li>
<li class="chapter" data-level="15.3" data-path="rgeoraster.html"><a href="rgeoraster.html#plot-dem"><i class="fa fa-check"></i><b>15.3</b> Plot DEM</a></li>
<li class="chapter" data-level="15.4" data-path="rgeoraster.html"><a href="rgeoraster.html#generate-a-hillshade"><i class="fa fa-check"></i><b>15.4</b> Generate a hillshade</a>
<ul>
<li class="chapter" data-level="15.4.1" data-path="rgeoraster.html"><a href="rgeoraster.html#how-whitebox-tools-functions-work"><i class="fa fa-check"></i><b>15.4.1</b> How whitebox tools functions work</a></li>
</ul></li>
<li class="chapter" data-level="15.5" data-path="rgeoraster.html"><a href="rgeoraster.html#prepare-dem-for-hydrology-analyses"><i class="fa fa-check"></i><b>15.5</b> Prepare DEM for Hydrology Analyses</a></li>
<li class="chapter" data-level="15.6" data-path="rgeoraster.html"><a href="rgeoraster.html#visualize-filled-sinks-and-breached-depressions"><i class="fa fa-check"></i><b>15.6</b> Visualize filled sinks and breached depressions</a></li>
<li class="chapter" data-level="15.7" data-path="rgeoraster.html"><a href="rgeoraster.html#d8-flow-accumulation"><i class="fa fa-check"></i><b>15.7</b> D8 Flow Accumulation</a></li>
<li class="chapter" data-level="15.8" data-path="rgeoraster.html"><a href="rgeoraster.html#d-infinity-flow-accumulation"><i class="fa fa-check"></i><b>15.8</b> D infinity flow accumulation</a></li>
<li class="chapter" data-level="15.9" data-path="rgeoraster.html"><a href="rgeoraster.html#topographic-wetness-index"><i class="fa fa-check"></i><b>15.9</b> Topographic Wetness Index</a></li>
<li class="chapter" data-level="15.10" data-path="rgeoraster.html"><a href="rgeoraster.html#downslope-twi"><i class="fa fa-check"></i><b>15.10</b> Downslope TWI</a></li>
<li class="chapter" data-level="15.11" data-path="rgeoraster.html"><a href="rgeoraster.html#map-stream-network"><i class="fa fa-check"></i><b>15.11</b> Map Stream Network</a></li>
<li class="chapter" data-level="15.12" data-path="rgeoraster.html"><a href="rgeoraster.html#extract-raster-values-to-point-locations"><i class="fa fa-check"></i><b>15.12</b> Extract raster values to point locations</a>
<ul>
<li class="chapter" data-level="15.12.1" data-path="rgeoraster.html"><a href="rgeoraster.html#import-and-plot-points"><i class="fa fa-check"></i><b>15.12.1</b> Import and plot points</a></li>
<li class="chapter" data-level="15.12.2" data-path="rgeoraster.html"><a href="rgeoraster.html#extract-values-from-multiple-rasters-at-once"><i class="fa fa-check"></i><b>15.12.2</b> Extract values from multiple rasters at once</a></li>
</ul></li>
<li class="chapter" data-level="15.13" data-path="rgeoraster.html"><a href="rgeoraster.html#view-raster-data-as-a-pdf-or-histogram"><i class="fa fa-check"></i><b>15.13</b> View raster data as a PDF or histogram</a></li>
<li class="chapter" data-level="15.14" data-path="rgeoraster.html"><a href="rgeoraster.html#subsetting-a-raster-for-visualization"><i class="fa fa-check"></i><b>15.14</b> Subsetting a raster for visualization</a></li>
<li class="chapter" data-level="15.15" data-path="rgeoraster.html"><a href="rgeoraster.html#raster-math"><i class="fa fa-check"></i><b>15.15</b> Raster Math</a></li>
<li class="chapter" data-level="15.16" data-path="rgeoraster.html"><a href="rgeoraster.html#extra-plot-topo-characteristics-against-one-another"><i class="fa fa-check"></i><b>15.16</b> Extra: plot topo characteristics against one another</a></li>
</ul></li>
<li class="chapter" data-level="16" data-path="rgeowatersheds.html"><a href="rgeowatersheds.html"><i class="fa fa-check"></i><b>16</b> Geospatial R Raster - Watershed Delineation</a>
<ul>
<li class="chapter" data-level="16.1" data-path="rgeowatersheds.html"><a href="rgeowatersheds.html#introduction-3"><i class="fa fa-check"></i><b>16.1</b> Introduction</a></li>
<li class="chapter" data-level="16.2" data-path="rgeowatersheds.html"><a href="rgeowatersheds.html#the-watershed-delineation-toolprocess"><i class="fa fa-check"></i><b>16.2</b> The watershed delineation tool/process</a></li>
<li class="chapter" data-level="16.3" data-path="rgeowatersheds.html"><a href="rgeowatersheds.html#read-in-dem-1"><i class="fa fa-check"></i><b>16.3</b> Read in DEM</a></li>
<li class="chapter" data-level="16.4" data-path="rgeowatersheds.html"><a href="rgeowatersheds.html#generate-a-hillshade-1"><i class="fa fa-check"></i><b>16.4</b> Generate a hillshade</a></li>
<li class="chapter" data-level="16.5" data-path="rgeowatersheds.html"><a href="rgeowatersheds.html#prepare-dem-for-hydrology-analyses-1"><i class="fa fa-check"></i><b>16.5</b> Prepare DEM for Hydrology Analyses</a></li>
<li class="chapter" data-level="16.6" data-path="rgeowatersheds.html"><a href="rgeowatersheds.html#create-flow-accumulation-and-pointer-grids"><i class="fa fa-check"></i><b>16.6</b> Create flow accumulation and pointer grids</a></li>
<li class="chapter" data-level="16.7" data-path="rgeowatersheds.html"><a href="rgeowatersheds.html#setting-pour-points"><i class="fa fa-check"></i><b>16.7</b> Setting pour points</a></li>
<li class="chapter" data-level="16.8" data-path="rgeowatersheds.html"><a href="rgeowatersheds.html#delineate-watersheds"><i class="fa fa-check"></i><b>16.8</b> Delineate watersheds</a></li>
<li class="chapter" data-level="16.9" data-path="rgeowatersheds.html"><a href="rgeowatersheds.html#convert-watersheds-to-shapefiles"><i class="fa fa-check"></i><b>16.9</b> Convert watersheds to shapefiles</a></li>
<li class="chapter" data-level="16.10" data-path="rgeowatersheds.html"><a href="rgeowatersheds.html#extract-data-based-on-watershed-outline"><i class="fa fa-check"></i><b>16.10</b> Extract data based on watershed outline</a></li>
<li class="chapter" data-level="16.11" data-path="rgeowatersheds.html"><a href="rgeowatersheds.html#bonus-make-a-3d-map-of-your-watershed-with-rayshader"><i class="fa fa-check"></i><b>16.11</b> BONUS: Make a 3d map of your watershed with rayshader</a></li>
</ul></li>
<li class="chapter" data-level="17" data-path="modelingintro.html"><a href="modelingintro.html"><i class="fa fa-check"></i><b>17</b> Intro to Modeling - Getting Started with HBV</a>
<ul>
<li class="chapter" data-level="17.1" data-path="modelingintro.html"><a href="modelingintro.html#introduction-4"><i class="fa fa-check"></i><b>17.1</b> Introduction</a></li>
<li class="chapter" data-level="17.2" data-path="modelingintro.html"><a href="modelingintro.html#creating-the-hbv-model-function"><i class="fa fa-check"></i><b>17.2</b> Creating the HBV model function</a></li>
<li class="chapter" data-level="17.3" data-path="modelingintro.html"><a href="modelingintro.html#read-in-precip-and-temp"><i class="fa fa-check"></i><b>17.3</b> Read in Precip and Temp</a></li>
<li class="chapter" data-level="17.4" data-path="modelingintro.html"><a href="modelingintro.html#calculate-pet"><i class="fa fa-check"></i><b>17.4</b> Calculate PET</a></li>
<li class="chapter" data-level="17.5" data-path="modelingintro.html"><a href="modelingintro.html#hbv-parameters"><i class="fa fa-check"></i><b>17.5</b> HBV Parameters</a></li>
<li class="chapter" data-level="17.6" data-path="modelingintro.html"><a href="modelingintro.html#first-model-run"><i class="fa fa-check"></i><b>17.6</b> First model run</a></li>
<li class="chapter" data-level="17.7" data-path="modelingintro.html"><a href="modelingintro.html#import-observed-streamflow-data"><i class="fa fa-check"></i><b>17.7</b> Import observed streamflow data</a></li>
<li class="chapter" data-level="17.8" data-path="modelingintro.html"><a href="modelingintro.html#compare-observed-and-modeled-discharge-graphically"><i class="fa fa-check"></i><b>17.8</b> Compare observed and modeled discharge graphically</a></li>
<li class="chapter" data-level="17.9" data-path="modelingintro.html"><a href="modelingintro.html#compare-observed-and-modelled-discharge-with-interactive-graph"><i class="fa fa-check"></i><b>17.9</b> Compare observed and modelled discharge with interactive graph</a></li>
<li class="chapter" data-level="17.10" data-path="modelingintro.html"><a href="modelingintro.html#measure-how-well-the-model-fits-with-nse"><i class="fa fa-check"></i><b>17.10</b> Measure how well the model fits with NSE</a></li>
<li class="chapter" data-level="17.11" data-path="modelingintro.html"><a href="modelingintro.html#assess-model-fit-with-a-different-measure-snow"><i class="fa fa-check"></i><b>17.11</b> Assess model fit with a different measure: Snow</a></li>
<li class="chapter" data-level="17.12" data-path="modelingintro.html"><a href="modelingintro.html#calibrate-hbv-manually"><i class="fa fa-check"></i><b>17.12</b> Calibrate HBV manually</a></li>
</ul></li>
<li class="chapter" data-level="18" data-path="modelingcalibration.html"><a href="modelingcalibration.html"><i class="fa fa-check"></i><b>18</b> Intro to Modeling - Calibrate HBV</a>
<ul>
<li class="chapter" data-level="18.1" data-path="modelingcalibration.html"><a href="modelingcalibration.html#introduction-5"><i class="fa fa-check"></i><b>18.1</b> Introduction</a></li>
<li class="chapter" data-level="18.2" data-path="modelingcalibration.html"><a href="modelingcalibration.html#challenge-write-a-for-loop"><i class="fa fa-check"></i><b>18.2</b> Challenge: Write a for loop</a></li>
<li class="chapter" data-level="18.3" data-path="modelingcalibration.html"><a href="modelingcalibration.html#prep-data-for-hbv"><i class="fa fa-check"></i><b>18.3</b> Prep data for HBV</a></li>
<li class="chapter" data-level="18.4" data-path="modelingcalibration.html"><a href="modelingcalibration.html#calculate-pet-1"><i class="fa fa-check"></i><b>18.4</b> Calculate PET</a></li>
<li class="chapter" data-level="18.5" data-path="modelingcalibration.html"><a href="modelingcalibration.html#monte-carlo-step-1-generate-random-parameter-sets"><i class="fa fa-check"></i><b>18.5</b> Monte Carlo step 1: generate random parameter sets</a></li>
<li class="chapter" data-level="18.6" data-path="modelingcalibration.html"><a href="modelingcalibration.html#run-the-model-for-each-parameter-set"><i class="fa fa-check"></i><b>18.6</b> Run the model for each parameter set</a></li>
<li class="chapter" data-level="18.7" data-path="modelingcalibration.html"><a href="modelingcalibration.html#find-the-best-parameter-set"><i class="fa fa-check"></i><b>18.7</b> Find the best parameter set</a></li>
<li class="chapter" data-level="18.8" data-path="modelingcalibration.html"><a href="modelingcalibration.html#investigating-a-much-bigger-monte-carlo"><i class="fa fa-check"></i><b>18.8</b> Investigating a much bigger Monte Carlo</a></li>
</ul></li>
<li class="divider"></li>
<li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i><a href="./">Hydroinformatics at VT</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<section class="normal" id="section-">
<div id="getdata" class="section level1 hasAnchor" number="7">
<h1><span class="header-section-number">Chapter 7</span> Joins, Pivots, and USGS dataRetrieval<a href="getdata.html#getdata" class="anchor-section" aria-label="Anchor link to header"></a></h1>
<p>Use Template Repository from github:</p>
<p>Readings: Introduction to the dataRetrieval package <a href="https://cran.r-project.org/web/packages/dataRetrieval/vignettes/dataRetrieval.html" class="uri">https://cran.r-project.org/web/packages/dataRetrieval/vignettes/dataRetrieval.html</a></p>
<p>Chapter 12 & 13 of R for Data Science <a href="https://r4ds.had.co.nz/tidy-data.html" class="uri">https://r4ds.had.co.nz/tidy-data.html</a></p>
<div id="goals-for-today" class="section level2 hasAnchor" number="7.1">
<h2><span class="header-section-number">7.1</span> Goals for today<a href="getdata.html#goals-for-today" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<ul>
<li>Get familiar with the dataRetrieval package</li>
<li>Intro to joins</li>
<li>Learn about long vs. wide data and how to change between them</li>
</ul>
<p>Prep question: How would you get data from the USGS NWIS (non-R)?</p>
<p>Install the dataRetrieval package. Load it and the tidyverse.</p>
<div class="sourceCode" id="cb111"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb111-1"><a href="getdata.html#cb111-1" aria-hidden="true" tabindex="-1"></a><span class="co">#install.packages("dataRetrieval")</span></span>
<span id="cb111-2"><a href="getdata.html#cb111-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(dataRetrieval)</span></code></pre></div>
<pre><code>## Warning: package 'dataRetrieval' was built under R version 4.1.2</code></pre>
<div class="sourceCode" id="cb113"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb113-1"><a href="getdata.html#cb113-1" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(tidyverse)</span>
<span id="cb113-2"><a href="getdata.html#cb113-2" aria-hidden="true" tabindex="-1"></a><span class="fu">library</span>(lubridate)</span></code></pre></div>
</div>
<div id="exploring-what-dataretrieval-can-do." class="section level2 hasAnchor" number="7.2">
<h2><span class="header-section-number">7.2</span> Exploring what dataRetrieval can do.<a href="getdata.html#exploring-what-dataretrieval-can-do." class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>Think about the dataRetrieval as a way to interact with same public data you can access through waterdata.usgs.gov but without having to click on buttons and search around. It makes getting data or doing analyses with USGS data much more reproducible and fast!</p>
<p>To explore a few of the capabilities (NOT ALL!!) we will start with the USGS gage on the New River at Radford. The gage number is 03171000.</p>
<p>The documentation for the package is extremely helpful: <a href="https://cran.r-project.org/web/packages/dataRetrieval/vignettes/dataRetrieval.html" class="uri">https://cran.r-project.org/web/packages/dataRetrieval/vignettes/dataRetrieval.html</a></p>
<p>I always have to look up how to do things because the package is very specialized! This is the case with most website APIs, in my experience. It’s a good argument for getting good at navigating package documentation! Basically you just look through and try to piece together the recipe for what you want to do using the examples they give in the document.</p>
<p>First, let’s get information about the site using the readNWISsite() and whatNWISdata() functions. Try each out and see what they tell you.</p>
<p>Remember, all the parameter codes and site names get passed to dataRetrieval functions as characters, so they must be in quotes.</p>
<div class="sourceCode" id="cb114"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb114-1"><a href="getdata.html#cb114-1" aria-hidden="true" tabindex="-1"></a><span class="co">#important: note the site number gets input as a character</span></span>
<span id="cb114-2"><a href="getdata.html#cb114-2" aria-hidden="true" tabindex="-1"></a>site <span class="ot"><-</span> <span class="st">"03171000"</span></span>
<span id="cb114-3"><a href="getdata.html#cb114-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb114-4"><a href="getdata.html#cb114-4" aria-hidden="true" tabindex="-1"></a><span class="co">#Information about the site</span></span>
<span id="cb114-5"><a href="getdata.html#cb114-5" aria-hidden="true" tabindex="-1"></a>siteinfo <span class="ot"><-</span> <span class="fu">readNWISsite</span>(site)</span>
<span id="cb114-6"><a href="getdata.html#cb114-6" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb114-7"><a href="getdata.html#cb114-7" aria-hidden="true" tabindex="-1"></a><span class="co">#What data is available for the site?</span></span>
<span id="cb114-8"><a href="getdata.html#cb114-8" aria-hidden="true" tabindex="-1"></a><span class="co">#Daily values, mean values</span></span>
<span id="cb114-9"><a href="getdata.html#cb114-9" aria-hidden="true" tabindex="-1"></a>dataAvailable <span class="ot"><-</span> <span class="fu">whatNWISdata</span>(<span class="at">siteNumber =</span> site, <span class="at">service =</span> <span class="st">"dv"</span>, <span class="at">statCd =</span> <span class="st">"00003"</span>)</span>
<span id="cb114-10"><a href="getdata.html#cb114-10" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb114-11"><a href="getdata.html#cb114-11" aria-hidden="true" tabindex="-1"></a>dataAvailable</span></code></pre></div>
<pre><code>## agency_cd site_no station_nm site_tp_cd dec_lat_va dec_long_va
## 2 USGS 03171000 NEW RIVER AT RADFORD, VA ST 37.14179 -80.56922
## 3 USGS 03171000 NEW RIVER AT RADFORD, VA ST 37.14179 -80.56922
## 4 USGS 03171000 NEW RIVER AT RADFORD, VA ST 37.14179 -80.56922
## coord_acy_cd dec_coord_datum_cd alt_va alt_acy_va alt_datum_cd huc_cd
## 2 U NAD83 1711.99 0.13 NAVD88 05050001
## 3 U NAD83 1711.99 0.13 NAVD88 05050001
## 4 U NAD83 1711.99 0.13 NAVD88 05050001
## data_type_cd parm_cd stat_cd ts_id loc_web_ds medium_grp_cd parm_grp_cd
## 2 dv 00010 00003 241564 NA wat <NA>
## 3 dv 00060 00003 145684 NA wat <NA>
## 4 dv 00095 00003 145685 NA wat <NA>
## srs_id access_cd begin_date end_date count_nu
## 2 1645597 0 2006-12-20 2009-03-18 704
## 3 1645423 0 1907-10-01 2023-02-08 33368
## 4 1646694 0 2006-12-20 2008-09-29 534</code></pre>
</div>
<div id="joins" class="section level2 hasAnchor" number="7.3">
<h2><span class="header-section-number">7.3</span> Joins<a href="getdata.html#joins" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>When we look at what whatNWISdata returns, we see it gives us parameter codes, but doesn’t tell us what they mean. This is a common attribute of databases: you use a common identifier but then have the full information in a lookup file. In this case, the look-up information telling us what the parameter codes mean is in “parameterCdFile” which loads with the dataRetrieval package.</p>
<p>So, you could look at that and see what the parameters mean.</p>
<p>OR We could have R do it and add a column that tells us what the parameters mean. Enter JOINS!</p>
<p>Joins allow us to combine the data from two different data sets that have a column in common. At its most basic, a join looks for a matching row with the same key in both datasets (for example, a USGS gage number) and then combines the rows. So now you have all the data from both sets, matched on the key.</p>
<p>But you have to make some decisions: what if a key value exists in one set but not the other? Do you just drop that observation? Do you add an NA? Let’s look at the different options.</p>
<p>Take for example the two data sets, FlowTable and SizeTable. The SiteName values are the key values and the MeanFlow and WSsize values are the data.</p>
<div class="figure">
<img src="images/joinsetup.png" title="Join setup" width="400" alt="" />
<p class="caption">Join Setup</p>
</div>
<p>Note River1 and River2 match up, but River3 and River5 only exist in one data set or the other.</p>
<p>The first way to deal with this is an <strong>INNER JOIN: inner_join()</strong> In an inner join, you only keep records that match. So the rows for River3 and River5 will be dropped because there is no corresponding data in the other set. See below:</p>
<div class="figure">
<img src="images/innerjoin.png" title="Inner Join" alt="" />
<p class="caption">Inner Join</p>
</div>
<p>But what if you don’t want to lose the values in one or the other or both?!</p>
<p>For instance, let’s say you have a bunch of discharge data for a stream, and then chemistry grab samples. You want to join the chemistry to the discharge based on the dates and times they were taken. But when you do this, you don’t want to delete all the discharge data where there is no chemistry! We need another option. Enter OUTER JOINS</p>
<p><strong>LEFT JOIN, left_join():</strong> Preserves all values from the LEFT data set, and pastes on the matching ones from the right. This creates NAs where there is a value on the left but not the right. (this is what you’d want to do in the discharge - chemistry example above)</p>
<div class="figure">
<img src="images/leftjoin1.png" title="Left Join" alt="" />
<p class="caption">Left Join</p>
</div>
<p><strong>RIGHT JOIN, right_join():</strong> Preserves all values from the RIGHT data set, and pastes on the matching ones from the left. This creates NAs where there is a value on the right but not the left.</p>
<div class="figure">
<img src="images/rightjoin.png" title="Right Join" alt="" />
<p class="caption">Right Join</p>
</div>
<p><strong>FULL JOIN, full_join():</strong> KEEP EVERYTHING! The hoarder of the joins. No matching record on the left? create an NA on the right! No matching value on the right? Create an NA on the left! NAs for everyone!</p>
<div class="figure">
<img src="images/fulljoin.png" title="Full Join" alt="" />
<p class="caption">Full Join</p>
</div>
<p>When you do this in R, you use the functions identified in the descriptions with the following syntax (see example below):</p>
<p><strong>if the column is named the same in both data sets</strong>
> xxx_join(left_tibble, right_tibble, by = “key_column”)**</p>
<p><strong>if the column is named differently in both data sets</strong>
> xxx_join(left_tibble, right_tibble, by = c(“left_key” = “right_key”)</p>
<div class="figure">
<img src="images/leftjoin2.png" title="Left Join with differing column names" alt="" />
<p class="caption">Left Join Differing Col Names</p>
</div>
<p>Note in both of the above, when you specify which column to use as “by” you have to put it in quotes.</p>
</div>
<div id="join-example" class="section level2 hasAnchor" number="7.4">
<h2><span class="header-section-number">7.4</span> Join example<a href="getdata.html#join-example" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>So in the chunk below let’s get add information about the parameters in dataAvailable by joining it with the key file: parameterCdFile. The column with the parameter codes is called parm_cd in dataAvailable and parameter_cd in parameterCdFile</p>
<div class="sourceCode" id="cb116"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb116-1"><a href="getdata.html#cb116-1" aria-hidden="true" tabindex="-1"></a>dataAvailable <span class="ot"><-</span> <span class="fu">left_join</span>(dataAvailable, parameterCdFile, </span>
<span id="cb116-2"><a href="getdata.html#cb116-2" aria-hidden="true" tabindex="-1"></a> <span class="at">by =</span> <span class="fu">c</span>(<span class="st">"parm_cd"</span> <span class="ot">=</span> <span class="st">"parameter_cd"</span>))</span>
<span id="cb116-3"><a href="getdata.html#cb116-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb116-4"><a href="getdata.html#cb116-4" aria-hidden="true" tabindex="-1"></a>dataAvailable</span></code></pre></div>
<pre><code>## agency_cd site_no station_nm site_tp_cd dec_lat_va dec_long_va
## 1 USGS 03171000 NEW RIVER AT RADFORD, VA ST 37.14179 -80.56922
## 2 USGS 03171000 NEW RIVER AT RADFORD, VA ST 37.14179 -80.56922
## 3 USGS 03171000 NEW RIVER AT RADFORD, VA ST 37.14179 -80.56922
## coord_acy_cd dec_coord_datum_cd alt_va alt_acy_va alt_datum_cd huc_cd
## 1 U NAD83 1711.99 0.13 NAVD88 05050001
## 2 U NAD83 1711.99 0.13 NAVD88 05050001
## 3 U NAD83 1711.99 0.13 NAVD88 05050001
## data_type_cd parm_cd stat_cd ts_id loc_web_ds medium_grp_cd parm_grp_cd
## 1 dv 00010 00003 241564 NA wat <NA>
## 2 dv 00060 00003 145684 NA wat <NA>
## 3 dv 00095 00003 145685 NA wat <NA>
## srs_id access_cd begin_date end_date count_nu parameter_group_nm
## 1 1645597 0 2006-12-20 2009-03-18 704 Physical
## 2 1645423 0 1907-10-01 2023-02-08 33368 Physical
## 3 1646694 0 2006-12-20 2008-09-29 534 Physical
## parameter_nm
## 1 Temperature, water, degrees Celsius
## 2 Discharge, cubic feet per second
## 3 Specific conductance, water, unfiltered, microsiemens per centimeter at 25 degrees Celsius
## casrn srsname parameter_units
## 1 Temperature, water deg C
## 2 Stream flow, mean. daily ft3/s
## 3 Specific conductance uS/cm @25C</code></pre>
<div class="sourceCode" id="cb118"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb118-1"><a href="getdata.html#cb118-1" aria-hidden="true" tabindex="-1"></a><span class="co">#that made a lot of columns, let's clean it up</span></span>
<span id="cb118-2"><a href="getdata.html#cb118-2" aria-hidden="true" tabindex="-1"></a>dataAvailClean <span class="ot"><-</span> dataAvailable <span class="sc">%>%</span> <span class="fu">select</span>(site_no, </span>
<span id="cb118-3"><a href="getdata.html#cb118-3" aria-hidden="true" tabindex="-1"></a> station_nm,</span>
<span id="cb118-4"><a href="getdata.html#cb118-4" aria-hidden="true" tabindex="-1"></a> parm_cd, </span>
<span id="cb118-5"><a href="getdata.html#cb118-5" aria-hidden="true" tabindex="-1"></a> srsname, </span>
<span id="cb118-6"><a href="getdata.html#cb118-6" aria-hidden="true" tabindex="-1"></a> parameter_units,</span>
<span id="cb118-7"><a href="getdata.html#cb118-7" aria-hidden="true" tabindex="-1"></a> begin_date, </span>
<span id="cb118-8"><a href="getdata.html#cb118-8" aria-hidden="true" tabindex="-1"></a> end_date)</span>
<span id="cb118-9"><a href="getdata.html#cb118-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb118-10"><a href="getdata.html#cb118-10" aria-hidden="true" tabindex="-1"></a>dataAvailClean</span></code></pre></div>
<pre><code>## site_no station_nm parm_cd srsname
## 1 03171000 NEW RIVER AT RADFORD, VA 00010 Temperature, water
## 2 03171000 NEW RIVER AT RADFORD, VA 00060 Stream flow, mean. daily
## 3 03171000 NEW RIVER AT RADFORD, VA 00095 Specific conductance
## parameter_units begin_date end_date
## 1 deg C 2006-12-20 2009-03-18
## 2 ft3/s 1907-10-01 2023-02-08
## 3 uS/cm @25C 2006-12-20 2008-09-29</code></pre>
</div>
<div id="finding-ids-to-download-usgs-data" class="section level2 hasAnchor" number="7.5">
<h2><span class="header-section-number">7.5</span> Finding IDs to download USGS data<a href="getdata.html#finding-ids-to-download-usgs-data" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>You can find sites via map and just enter the id like we did in the chunks above: <a href="https://maps.waterdata.usgs.gov/mapper/index.html" class="uri">https://maps.waterdata.usgs.gov/mapper/index.html</a></p>
<p>Below we will look at two other ways to get sites: using a bounding box of a geographic region, or search terms like State and drainage area</p>
<div class="sourceCode" id="cb120"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb120-1"><a href="getdata.html#cb120-1" aria-hidden="true" tabindex="-1"></a><span class="co">#find sites in a bounding box</span></span>
<span id="cb120-2"><a href="getdata.html#cb120-2" aria-hidden="true" tabindex="-1"></a><span class="co">#coords of bottom left, top right</span></span>
<span id="cb120-3"><a href="getdata.html#cb120-3" aria-hidden="true" tabindex="-1"></a>swva <span class="ot"><-</span> <span class="fu">c</span>(<span class="sc">-</span><span class="fl">81.36</span>, <span class="fl">36.72</span>, <span class="sc">-</span><span class="fl">80.27</span>, <span class="fl">37.32</span>)</span>
<span id="cb120-4"><a href="getdata.html#cb120-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb120-5"><a href="getdata.html#cb120-5" aria-hidden="true" tabindex="-1"></a><span class="co">#get sites in this bounding box that have daily water temperature and discharge</span></span>
<span id="cb120-6"><a href="getdata.html#cb120-6" aria-hidden="true" tabindex="-1"></a>swva_sites <span class="ot"><-</span> <span class="fu">whatNWISsites</span>(<span class="at">bBox =</span> swva, </span>
<span id="cb120-7"><a href="getdata.html#cb120-7" aria-hidden="true" tabindex="-1"></a> <span class="at">parameterCd =</span> <span class="fu">c</span>(<span class="st">"00060"</span>, <span class="st">"00010"</span>), </span>
<span id="cb120-8"><a href="getdata.html#cb120-8" aria-hidden="true" tabindex="-1"></a> <span class="at">hasDataTypeCd =</span> <span class="st">"dv"</span>)</span>
<span id="cb120-9"><a href="getdata.html#cb120-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb120-10"><a href="getdata.html#cb120-10" aria-hidden="true" tabindex="-1"></a>swva_sites</span></code></pre></div>
<pre><code>## agency_cd site_no station_nm
## 1 USGS 03473500 M F HOLSTON RIVER AT GROSECLOSE, VA
## 2 USGS 03175140 WEST FORK COVE CREEK NEAR BLUEFIELD, VA
## 3 USGS 03177710 BLUESTONE RIVER AT FALLS MILLS, VA
## 4 USGS 03177700 BLUESTONE RIVER AT BLUEFIELD, VA
## 5 USGS 03166000 CRIPPLE CREEK NEAR IVANHOE, VA
## 6 USGS 03164500 NEW RIVER NEAR GRAYSON, VA
## 7 USGS 03165500 NEW RIVER AT IVANHOE, VA
## 8 USGS 03166880 WEST SP AT NAT FISH HAT NEAR GRAHAMS FORGE, VA
## 9 USGS 03166800 GLADE CREEK AT GRAHAMS FORGE, VA
## 10 USGS 03166900 BOILING SP AT NAT FISH HAT NR GRAHAMS FORGE, VA
## 11 USGS 03167000 REED CREEK AT GRAHAMS FORGE, VA
## 12 USGS 03175500 WOLF CREEK NEAR NARROWS, VA
## 13 USGS 03168500 PEAK CREEK AT PULASKI, VA
## 14 USGS 03168000 NEW RIVER AT ALLISONIA, VA
## 15 USGS 03167500 BIG REED ISLAND CREEK NEAR ALLISONIA, VA
## 16 USGS 03172500 WALKER CREEK AT STAFFORDSVILLE, VA
## 17 USGS 03173000 WALKER CREEK AT BANE, VA
## 18 USGS 03171500 NEW RIVER AT EGGLESTON, VA
## 19 USGS 03171000 NEW RIVER AT RADFORD, VA
## 20 USGS 03170000 LITTLE RIVER AT GRAYSONTOWN, VA
## 21 USGS 03169500 LITTLE RIVER NEAR COPPER VALLEY, VA
## site_tp_cd dec_lat_va dec_long_va colocated queryTime
## 1 ST 36.88873 -81.34733 FALSE 2023-02-09 11:20:29
## 2 ST 37.18428 -81.32982 FALSE 2023-02-09 11:20:29
## 3 ST 37.27151 -81.30482 FALSE 2023-02-09 11:20:29
## 4 ST 37.25595 -81.28177 FALSE 2023-02-09 11:20:29
## 5 ST 36.85984 -80.98036 FALSE 2023-02-09 11:20:29
## 6 ST 36.75985 -80.95619 FALSE 2023-02-09 11:20:29
## 7 ST 36.83485 -80.95258 FALSE 2023-02-09 11:20:29
## 8 SP 36.93429 -80.90313 FALSE 2023-02-09 11:20:29
## 9 ST 36.93095 -80.90036 FALSE 2023-02-09 11:20:29
## 10 SP 36.93068 -80.89619 FALSE 2023-02-09 11:20:29
## 11 ST 36.93901 -80.88730 FALSE 2023-02-09 11:20:29
## 12 ST 37.30568 -80.84980 FALSE 2023-02-09 11:20:29
## 13 ST 37.04721 -80.78472 FALSE 2023-02-09 11:20:29
## 14 ST 36.93762 -80.74563 FALSE 2023-02-09 11:20:29
## 15 ST 36.88901 -80.72757 FALSE 2023-02-09 11:20:29
## 16 ST 37.24179 -80.71090 FALSE 2023-02-09 11:20:29
## 17 ST 37.26818 -80.70951 FALSE 2023-02-09 11:20:29
## 18 ST 37.28957 -80.61673 FALSE 2023-02-09 11:20:29
## 19 ST 37.14179 -80.56922 FALSE 2023-02-09 11:20:29
## 20 ST 37.03763 -80.55672 FALSE 2023-02-09 11:20:29
## 21 ST 36.99652 -80.52144 FALSE 2023-02-09 11:20:29</code></pre>
<div class="sourceCode" id="cb122"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb122-1"><a href="getdata.html#cb122-1" aria-hidden="true" tabindex="-1"></a><span class="co">#find sites with other criteria, VA, less than 20 sqmi, other criteria can be used..</span></span>
<span id="cb122-2"><a href="getdata.html#cb122-2" aria-hidden="true" tabindex="-1"></a><span class="co">#check out the CRAN documentation</span></span>
<span id="cb122-3"><a href="getdata.html#cb122-3" aria-hidden="true" tabindex="-1"></a>smallVA <span class="ot"><-</span> <span class="fu">readNWISdata</span>(<span class="at">service =</span> <span class="st">"dv"</span>,</span>
<span id="cb122-4"><a href="getdata.html#cb122-4" aria-hidden="true" tabindex="-1"></a> <span class="at">stateCd =</span> <span class="st">"VA"</span>,</span>
<span id="cb122-5"><a href="getdata.html#cb122-5" aria-hidden="true" tabindex="-1"></a> <span class="at">parameterCd =</span> <span class="st">"00060"</span>,</span>
<span id="cb122-6"><a href="getdata.html#cb122-6" aria-hidden="true" tabindex="-1"></a> <span class="at">drainAreaMax =</span> <span class="st">"20"</span>,</span>
<span id="cb122-7"><a href="getdata.html#cb122-7" aria-hidden="true" tabindex="-1"></a> <span class="at">statCd =</span> <span class="st">"00003"</span>)</span></code></pre></div>
</div>
<div id="ok-lets-download-some-data" class="section level2 hasAnchor" number="7.6">
<h2><span class="header-section-number">7.6</span> OK let’s download some data!<a href="getdata.html#ok-lets-download-some-data" class="anchor-section" aria-label="Anchor link to header"></a></h2>
<p>We are going to use readNWISdv(), which downloads daily values.</p>
<p>We will tell it which sites to download, which parameters to download, and then what time period to download.</p>
<p>siteNumber gets the sites we want to download, USGS site numbers, as a character. We will use the swva_sites data we generated (yep, you can download multiple sites at once!)</p>
<p>startDate and endDate get the…. start and end dates. IMPORTANT: These must be in YYY-MM-DD format, but you don’t have to tell R they are dates before you give them to the function, it’ll do that for you.</p>
<p>parameterCd is the parameters you want to download. We want water temperature and discharge, which are “00060” and “00010”, respectively.</p>
<p>Once we have the data, the column names correspond to the keys that identify them, for example, discharge will be 00060 something something. Fortunately the dataRetrieval package also provides “renameNWISColumns()” which translates these into words, making them more easily understood by humans. We can pipe the results of our download to that function after we get the data to make the column names easier to understand.</p>
<div class="sourceCode" id="cb123"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb123-1"><a href="getdata.html#cb123-1" aria-hidden="true" tabindex="-1"></a>start <span class="ot"><-</span> <span class="st">"2006-10-01"</span></span>
<span id="cb123-2"><a href="getdata.html#cb123-2" aria-hidden="true" tabindex="-1"></a>end <span class="ot"><-</span> <span class="st">"2008-09-30"</span></span>
<span id="cb123-3"><a href="getdata.html#cb123-3" aria-hidden="true" tabindex="-1"></a>params <span class="ot"><-</span> <span class="fu">c</span>(<span class="st">"00010"</span>, <span class="st">"00060"</span>)</span>
<span id="cb123-4"><a href="getdata.html#cb123-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb123-5"><a href="getdata.html#cb123-5" aria-hidden="true" tabindex="-1"></a>swva_dat <span class="ot"><-</span> <span class="fu">readNWISdv</span>(<span class="at">siteNumber =</span> swva_sites<span class="sc">$</span>site_no, </span>
<span id="cb123-6"><a href="getdata.html#cb123-6" aria-hidden="true" tabindex="-1"></a> <span class="at">parameterCd =</span> params, </span>
<span id="cb123-7"><a href="getdata.html#cb123-7" aria-hidden="true" tabindex="-1"></a> <span class="at">startDate =</span> start, </span>
<span id="cb123-8"><a href="getdata.html#cb123-8" aria-hidden="true" tabindex="-1"></a> <span class="at">endDate =</span> end) <span class="sc">%>%</span> </span>
<span id="cb123-9"><a href="getdata.html#cb123-9" aria-hidden="true" tabindex="-1"></a> <span class="fu">renameNWISColumns</span>()</span></code></pre></div>
<p>Let’s plot the water temperature data as a line and control the color of the lines with the different sites.</p>
<p>What could be better about this plot?</p>
<div class="sourceCode" id="cb124"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb124-1"><a href="getdata.html#cb124-1" aria-hidden="true" tabindex="-1"></a>swva_dat <span class="sc">%>%</span> <span class="fu">ggplot</span>(<span class="fu">aes</span>(<span class="at">x =</span> Date, <span class="at">y =</span> Wtemp, <span class="at">color =</span> site_no)) <span class="sc">+</span></span>
<span id="cb124-2"><a href="getdata.html#cb124-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">geom_line</span>()</span></code></pre></div>
<pre><code>## Warning: Removed 2218 row(s) containing missing values (geom_path).</code></pre>
<p><img src="Hydroinformatics_Bookdown_files/figure-html/unnamed-chunk-62-1.png" width="672" /></p>
<p>We can add site names with….More joins! Our swva_sites data has the names of the sites in human-friendly language. The column in the downloaded data and in the swva_sites data is called “site_no” so we just give that to the “by” argument. Perform a left join to add the names of the sites to the data.</p>
<p>Then use select to remove some of the unnecessary columns.</p>
<p>Then make the plot and then snazz it up with labels and a non-junky theme.</p>
<div class="sourceCode" id="cb126"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb126-1"><a href="getdata.html#cb126-1" aria-hidden="true" tabindex="-1"></a>swva_dat_clean <span class="ot"><-</span> <span class="fu">left_join</span>(swva_dat, swva_sites, <span class="at">by =</span> <span class="st">"site_no"</span>) <span class="sc">%>%</span></span>