forked from AdamWilsonLabEDU/SpatialDataScience
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPS_09_weather.html
More file actions
1644 lines (1539 loc) · 92.3 KB
/
PS_09_weather.html
File metadata and controls
1644 lines (1539 loc) · 92.3 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>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<title>APIs, time-series, and weather Data</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="externals/reveal.js-3.3.0.1/css/reveal.css"/>
<style type="text/css">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; position: absolute; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
{ position: relative; }
pre.numberSource a.sourceLine:empty
{ position: absolute; }
pre.numberSource a.sourceLine::before
{ content: attr(data-line-number);
position: absolute; left: -5em; text-align: right; vertical-align: baseline;
border: none; pointer-events: all;
-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
{ background-color: #f8f8f8; }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ef2929; } /* Alert */
code span.an { color: #8f5902; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #c4a000; } /* Attribute */
code span.bn { color: #0000cf; } /* BaseN */
code span.cf { color: #204a87; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4e9a06; } /* Char */
code span.cn { color: #000000; } /* Constant */
code span.co { color: #8f5902; font-style: italic; } /* Comment */
code span.cv { color: #8f5902; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #8f5902; font-weight: bold; font-style: italic; } /* Documentation */
code span.dt { color: #204a87; } /* DataType */
code span.dv { color: #0000cf; } /* DecVal */
code span.er { color: #a40000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #0000cf; } /* Float */
code span.fu { color: #000000; } /* Function */
code span.im { } /* Import */
code span.in { color: #8f5902; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #204a87; font-weight: bold; } /* Keyword */
code span.op { color: #ce5c00; font-weight: bold; } /* Operator */
code span.ot { color: #8f5902; } /* Other */
code span.pp { color: #8f5902; font-style: italic; } /* Preprocessor */
code span.sc { color: #000000; } /* SpecialChar */
code span.ss { color: #4e9a06; } /* SpecialString */
code span.st { color: #4e9a06; } /* String */
code span.va { color: #000000; } /* Variable */
code span.vs { color: #4e9a06; } /* VerbatimString */
code span.wa { color: #8f5902; font-weight: bold; font-style: italic; } /* Warning */
</style>
<link rel="stylesheet" href="externals/reveal.js-3.3.0.1/css/theme/white.css" id="theme">
<!-- some tweaks to reveal css -->
<style type="text/css">
.reveal h1 { font-size: 2.0em; }
.reveal h2 { font-size: 1.5em; }
.reveal h3 { font-size: 1.25em; }
.reveal h4 { font-size: 1em; }
.reveal .slides>section,
.reveal .slides>section>section {
padding: 0px 0px;
}
.reveal table {
border-width: 1px;
border-spacing: 2px;
border-style: dotted;
border-color: gray;
border-collapse: collapse;
font-size: 0.7em;
}
.reveal table th {
border-width: 1px;
padding-left: 10px;
padding-right: 25px;
font-weight: bold;
border-style: dotted;
border-color: gray;
}
.reveal table td {
border-width: 1px;
padding-left: 10px;
padding-right: 25px;
border-style: dotted;
border-color: gray;
}
</style>
<style type="text/css">code{white-space: pre;}</style>
<link rel="stylesheet" href="reveal.css"/>
<!-- Printing and PDF exports -->
<script id="paper-css" type="application/dynamic-css">
/* Default Print Stylesheet Template
by Rob Glazebrook of CSSnewbie.com
Last Updated: June 4, 2008
Feel free (nay, compelled) to edit, append, and
manipulate this file as you see fit. */
@media print {
/* SECTION 1: Set default width, margin, float, and
background. This prevents elements from extending
beyond the edge of the printed page, and prevents
unnecessary background images from printing */
html {
background: #fff;
width: auto;
height: auto;
overflow: visible;
}
body {
background: #fff;
font-size: 20pt;
width: auto;
height: auto;
border: 0;
margin: 0 5%;
padding: 0;
overflow: visible;
float: none !important;
}
/* SECTION 2: Remove any elements not needed in print.
This would include navigation, ads, sidebars, etc. */
.nestedarrow,
.controls,
.fork-reveal,
.share-reveal,
.state-background,
.reveal .progress,
.reveal .backgrounds {
display: none !important;
}
/* SECTION 3: Set body font face, size, and color.
Consider using a serif font for readability. */
body, p, td, li, div {
font-size: 20pt!important;
font-family: Georgia, "Times New Roman", Times, serif !important;
color: #000;
}
/* SECTION 4: Set heading font face, sizes, and color.
Differentiate your headings from your body text.
Perhaps use a large sans-serif for distinction. */
h1,h2,h3,h4,h5,h6 {
color: #000!important;
height: auto;
line-height: normal;
font-family: Georgia, "Times New Roman", Times, serif !important;
text-shadow: 0 0 0 #000 !important;
text-align: left;
letter-spacing: normal;
}
/* Need to reduce the size of the fonts for printing */
h1 { font-size: 28pt !important; }
h2 { font-size: 24pt !important; }
h3 { font-size: 22pt !important; }
h4 { font-size: 22pt !important; font-variant: small-caps; }
h5 { font-size: 21pt !important; }
h6 { font-size: 20pt !important; font-style: italic; }
/* SECTION 5: Make hyperlinks more usable.
Ensure links are underlined, and consider appending
the URL to the end of the link for usability. */
a:link,
a:visited {
color: #000 !important;
font-weight: bold;
text-decoration: underline;
}
/*
.reveal a:link:after,
.reveal a:visited:after {
content: " (" attr(href) ") ";
color: #222 !important;
font-size: 90%;
}
*/
/* SECTION 6: more reveal.js specific additions by @skypanther */
ul, ol, div, p {
visibility: visible;
position: static;
width: auto;
height: auto;
display: block;
overflow: visible;
margin: 0;
text-align: left !important;
}
.reveal pre,
.reveal table {
margin-left: 0;
margin-right: 0;
}
.reveal pre code {
padding: 20px;
border: 1px solid #ddd;
}
.reveal blockquote {
margin: 20px 0;
}
.reveal .slides {
position: static !important;
width: auto !important;
height: auto !important;
left: 0 !important;
top: 0 !important;
margin-left: 0 !important;
margin-top: 0 !important;
padding: 0 !important;
zoom: 1 !important;
overflow: visible !important;
display: block !important;
text-align: left !important;
-webkit-perspective: none;
-moz-perspective: none;
-ms-perspective: none;
perspective: none;
-webkit-perspective-origin: 50% 50%;
-moz-perspective-origin: 50% 50%;
-ms-perspective-origin: 50% 50%;
perspective-origin: 50% 50%;
}
.reveal .slides section {
visibility: visible !important;
position: static !important;
width: auto !important;
height: auto !important;
display: block !important;
overflow: visible !important;
left: 0 !important;
top: 0 !important;
margin-left: 0 !important;
margin-top: 0 !important;
padding: 60px 20px !important;
z-index: auto !important;
opacity: 1 !important;
page-break-after: always !important;
-webkit-transform-style: flat !important;
-moz-transform-style: flat !important;
-ms-transform-style: flat !important;
transform-style: flat !important;
-webkit-transform: none !important;
-moz-transform: none !important;
-ms-transform: none !important;
transform: none !important;
-webkit-transition: none !important;
-moz-transition: none !important;
-ms-transition: none !important;
transition: none !important;
}
.reveal .slides section.stack {
padding: 0 !important;
}
.reveal section:last-of-type {
page-break-after: avoid !important;
}
.reveal section .fragment {
opacity: 1 !important;
visibility: visible !important;
-webkit-transform: none !important;
-moz-transform: none !important;
-ms-transform: none !important;
transform: none !important;
}
.reveal section img {
display: block;
margin: 15px 0px;
background: rgba(255,255,255,1);
border: 1px solid #666;
box-shadow: none;
}
.reveal section small {
font-size: 0.8em;
}
}
</script>
<script id="pdf-css" type="application/dynamic-css">
/**
* This stylesheet is used to print reveal.js
* presentations to PDF.
*
* https://github.com/hakimel/reveal.js#pdf-export
*/
* {
-webkit-print-color-adjust: exact;
}
body {
margin: 0 auto !important;
border: 0;
padding: 0;
float: none !important;
overflow: visible;
}
html {
width: 100%;
height: 100%;
overflow: visible;
}
/* Remove any elements not needed in print. */
.nestedarrow,
.reveal .controls,
.reveal .progress,
.reveal .playback,
.reveal.overview,
.fork-reveal,
.share-reveal,
.state-background {
display: none !important;
}
h1, h2, h3, h4, h5, h6 {
text-shadow: 0 0 0 #000 !important;
}
.reveal pre code {
overflow: hidden !important;
font-family: Courier, 'Courier New', monospace !important;
}
ul, ol, div, p {
visibility: visible;
position: static;
width: auto;
height: auto;
display: block;
overflow: visible;
margin: auto;
}
.reveal {
width: auto !important;
height: auto !important;
overflow: hidden !important;
}
.reveal .slides {
position: static;
width: 100%;
height: auto;
left: auto;
top: auto;
margin: 0 !important;
padding: 0 !important;
overflow: visible;
display: block;
-webkit-perspective: none;
-moz-perspective: none;
-ms-perspective: none;
perspective: none;
-webkit-perspective-origin: 50% 50%; /* there isn't a none/auto value but 50-50 is the default */
-moz-perspective-origin: 50% 50%;
-ms-perspective-origin: 50% 50%;
perspective-origin: 50% 50%;
}
.reveal .slides section {
page-break-after: always !important;
visibility: visible !important;
position: relative !important;
display: block !important;
position: relative !important;
margin: 0 !important;
padding: 0 !important;
box-sizing: border-box !important;
min-height: 1px;
opacity: 1 !important;
-webkit-transform-style: flat !important;
-moz-transform-style: flat !important;
-ms-transform-style: flat !important;
transform-style: flat !important;
-webkit-transform: none !important;
-moz-transform: none !important;
-ms-transform: none !important;
transform: none !important;
}
.reveal section.stack {
margin: 0 !important;
padding: 0 !important;
page-break-after: avoid !important;
height: auto !important;
min-height: auto !important;
}
.reveal img {
box-shadow: none;
}
.reveal .roll {
overflow: visible;
line-height: 1em;
}
/* Slide backgrounds are placed inside of their slide when exporting to PDF */
.reveal section .slide-background {
display: block !important;
position: absolute;
top: 0;
left: 0;
width: 100%;
z-index: -1;
}
/* All elements should be above the slide-background */
.reveal section>* {
position: relative;
z-index: 1;
}
/* Display slide speaker notes when 'showNotes' is enabled */
.reveal .speaker-notes-pdf {
display: block;
width: 100%;
max-height: none;
left: auto;
top: auto;
z-index: 100;
}
/* Display slide numbers when 'slideNumber' is enabled */
.reveal .slide-number-pdf {
display: block;
position: absolute;
font-size: 14px;
}
</script>
<script>
var style = document.createElement( 'style' );
style.type = 'text/css';
var style_script_id = window.location.search.match( /print-pdf/gi ) ? 'pdf-css' : 'paper-css';
var style_script = document.getElementById(style_script_id).text;
style.innerHTML = style_script;
document.getElementsByTagName('head')[0].appendChild(style);
</script>
<link href="externals/font-awesome-5.0.13/css/fa-svg-with-js.css" rel="stylesheet" />
<script src="externals/font-awesome-5.0.13/js/fontawesome-all.min.js"></script>
<script src="externals/font-awesome-5.0.13/js/fa-v4-shims.min.js"></script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1 class="title">APIs, time-series, and weather Data</h1>
</section>
<section><section id="api" class="title-slide slide level1"><h1>API</h1></section><section id="application-programming-interface" class="slide level2">
<h2>Application Programming Interface</h2>
<iframe src="https://en.wikipedia.org/wiki/Application_programming_interface" width="100%" height="400px">
</iframe>
<ul>
<li class="fragment">Imagine I wanted to work with Wikipedia content…</li>
</ul>
</section><section id="manually-processing-information-from-the-web" class="slide level2">
<h2>Manually processing information from the web</h2>
<ul>
<li>Browse to page, <code>File->Save As</code>, repeat.</li>
<li>Deal with ugly html stuff…</li>
</ul>
<pre><code><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<title>APIs, time-series, and weather Data</title>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="externals/reveal.js-3.3.0.1/css/reveal.css"/></code></pre>
</section><section class="slide level2">
<div class="sourceCode" id="cb2"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb2-1" data-line-number="1"><span class="kw">library</span>(WikipediR)</a>
<a class="sourceLine" id="cb2-2" data-line-number="2"><span class="kw">library</span>(tidyverse)</a>
<a class="sourceLine" id="cb2-3" data-line-number="3"></a>
<a class="sourceLine" id="cb2-4" data-line-number="4">content=<span class="kw">page_content</span>(</a>
<a class="sourceLine" id="cb2-5" data-line-number="5"> <span class="dt">page_name =</span> <span class="st">"Application_programming_interface"</span>,</a>
<a class="sourceLine" id="cb2-6" data-line-number="6"> <span class="dt">project=</span><span class="st">"Wikipedia"</span>,</a>
<a class="sourceLine" id="cb2-7" data-line-number="7"> <span class="dt">language=</span><span class="st">"en"</span>,</a>
<a class="sourceLine" id="cb2-8" data-line-number="8"> <span class="dt">as_wikitext=</span>T)</a></code></pre></div>
</section><section id="apis-allow-direct-and-often-custom-sharing-of-data" class="slide level2">
<h2>APIs allow direct (and often custom) sharing of data</h2>
<div class="sourceCode" id="cb3"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb3-1" data-line-number="1">c1=content<span class="op">$</span>parse<span class="op">$</span>wikitext<span class="op">%>%</span></a>
<a class="sourceLine" id="cb3-2" data-line-number="2"><span class="st"> </span><span class="kw">str_split</span>(<span class="kw">boundary</span>(<span class="st">"sentence"</span>),<span class="dt">simplify =</span> T)<span class="op">%>%</span></a>
<a class="sourceLine" id="cb3-3" data-line-number="3"><span class="st"> </span><span class="kw">str_replace_all</span>(<span class="st">"'"</span>,<span class="st">""</span>)<span class="op">%>%</span></a>
<a class="sourceLine" id="cb3-4" data-line-number="4"><span class="st"> </span><span class="kw">str_replace_all</span>(<span class="st">"</span><span class="ch">\\</span><span class="st">[|</span><span class="ch">\\</span><span class="st">]"</span>,<span class="st">""</span>)</a>
<a class="sourceLine" id="cb3-5" data-line-number="5"><span class="co"># results:</span></a>
<a class="sourceLine" id="cb3-6" data-line-number="6"><span class="kw">cat</span>(c1[<span class="dv">3</span><span class="op">:</span><span class="dv">4</span>])</a></code></pre></div>
<p>In Programming language|computer programming, an application programming interface (API) is a set of subroutine definitions, communication protocols, and tools for building software. In general terms, it is a set of clearly defined methods of communication among various components.</p>
</section><section id="many-data-providers-now-have-apis" class="slide level2">
<h2>Many data providers now have APIs</h2>
<ul>
<li>Government Demographic data (census, etc.)</li>
<li>Government Environmental data</li>
<li>Google, Twitter, etc.</li>
</ul>
</section><section id="pros-cons" class="slide level2">
<h2>Pros & Cons</h2>
<h3 id="pros">Pros</h3>
<ul>
<li>Get the data you want, when you want it</li>
<li>Automatic updates - just re-run the request</li>
</ul>
<h3 id="cons">Cons</h3>
<ul>
<li>Dependent on real-time access</li>
<li>APIs, permissions, etc. can change and break code</li>
</ul>
</section><section id="generic-api-access" class="slide level2">
<h2>Generic API Access</h2>
<ol type="1">
<li>Provide R with a URL to request information</li>
<li>The API sends you back a response
<ul>
<li>JavaScript Object Notation (JSON)</li>
<li>Extensible Markup Language (XML).</li>
</ul></li>
</ol>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb4-1" data-line-number="1"><span class="kw">library</span>(tidyverse)</a>
<a class="sourceLine" id="cb4-2" data-line-number="2"><span class="kw">library</span>(httr)</a>
<a class="sourceLine" id="cb4-3" data-line-number="3"><span class="kw">library</span>(jsonlite)</a></code></pre></div>
</section><section id="endpoints" class="slide level2">
<h2>Endpoints</h2>
<p>The URL you will request information from.</p>
<ul>
<li>Data.gov API: <a href="https://www.data.gov/developers/apis" class="uri">https://www.data.gov/developers/apis</a></li>
<li>Github API: <a href="https://api.github.com" class="uri">https://api.github.com</a></li>
</ul>
</section><section id="some-r-packages-for-specific-apis" class="slide level2">
<h2>Some R Packages for specific APIs</h2>
<h3 id="feddata-package"><code>FedData</code> package</h3>
<ul>
<li>National Elevation Dataset digital elevation models (1 and 1/3 arc-second; USGS)</li>
<li>National Hydrography Dataset (USGS)</li>
<li>Soil Survey Geographic (SSURGO) database</li>
<li>International Tree Ring Data Bank.</li>
<li>Global Historical Climatology Network (GHCN)</li>
<li>Others</li>
</ul>
</section><section id="noaa-apiv2" class="slide level2">
<h2>NOAA APIv2</h2>
<iframe src="https://www.ncdc.noaa.gov/cdo-web/webservices/v2" width="100%" height="400px">
</iframe>
<p><a href="http://www.ncdc.noaa.gov/cdo-web/webservices/v2">National Climatic Data Center application programming interface (API)</a>.</p>
</section><section id="rnoaa-package" class="slide level2">
<h2><code>rNOAA</code> package</h2>
<p>Handles downloading data directly from NOAA APIv2.</p>
<ul>
<li><code>buoy_*</code> NOAA Buoy data from the National Buoy Data Center</li>
<li><code>ghcnd_*</code> GHCND daily data from NOAA</li>
<li><code>isd_*</code> ISD/ISH data from NOAA</li>
<li><code>homr_*</code> Historical Observing Metadata Repository</li>
<li><code>ncdc_*</code> NOAA National Climatic Data Center (NCDC)</li>
<li><code>seaice</code> Sea ice</li>
<li><code>storm_</code> Storms (IBTrACS)</li>
<li><code>swdi</code> Severe Weather Data Inventory (SWDI)</li>
<li><code>tornadoes</code> From the NOAA Storm Prediction Center</li>
</ul>
</section></section>
<section><section id="global-historical-climatology-network-ghcn" class="title-slide slide level1"><h1>Global Historical Climatology Network (GHCN)</h1></section><section id="ghcn" class="slide level2">
<h2>GHCN</h2>
<iframe src="https://www.ncdc.noaa.gov/ghcn-daily-description" width="100%" height="400px">
</iframe>
</section><section id="libraries" class="slide level2">
<h2>Libraries</h2>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb5-1" data-line-number="1"><span class="kw">library</span>(sf)</a>
<a class="sourceLine" id="cb5-2" data-line-number="2"><span class="kw">library</span>(broom)</a>
<a class="sourceLine" id="cb5-3" data-line-number="3"><span class="kw">library</span>(tidyverse)</a>
<a class="sourceLine" id="cb5-4" data-line-number="4"><span class="kw">library</span>(ggmap)</a>
<a class="sourceLine" id="cb5-5" data-line-number="5"><span class="kw">library</span>(scales)</a>
<a class="sourceLine" id="cb5-6" data-line-number="6"><span class="co"># New Packages</span></a>
<a class="sourceLine" id="cb5-7" data-line-number="7"><span class="kw">library</span>(rnoaa)</a>
<a class="sourceLine" id="cb5-8" data-line-number="8"><span class="kw">library</span>(climdex.pcic)</a>
<a class="sourceLine" id="cb5-9" data-line-number="9"><span class="kw">library</span>(zoo)</a></code></pre></div>
</section><section id="station-locations" class="slide level2">
<h2>Station locations</h2>
<p>Download the GHCN station inventory with <code>ghcnd_stations()</code> and convert to <code>sf</code> object. The download can take a minute or two.</p>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb6-1" data-line-number="1">st =<span class="st"> </span><span class="kw">ghcnd_stations</span>()<span class="op">%>%</span></a>
<a class="sourceLine" id="cb6-2" data-line-number="2"><span class="st"> </span><span class="kw">na.omit</span>()<span class="op">%>%</span><span class="st"> </span><span class="co"># remove records with missing values</span></a>
<a class="sourceLine" id="cb6-3" data-line-number="3"><span class="st"> </span><span class="kw">st_as_sf</span>(<span class="dt">coords=</span><span class="kw">c</span>(<span class="st">"longitude"</span>,<span class="st">"latitude"</span>))<span class="op">%>%</span><span class="st"> </span><span class="co">#convert to sf</span></a>
<a class="sourceLine" id="cb6-4" data-line-number="4"><span class="st"> </span><span class="kw">st_set_crs</span>(<span class="st">"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"</span>)</a>
<a class="sourceLine" id="cb6-5" data-line-number="5"> <span class="kw">head</span>(st)<span class="op">%>%</span><span class="kw">kable</span>()</a></code></pre></div>
<table>
<thead>
<tr class="header">
<th style="text-align: left;">id</th>
<th style="text-align: right;">elevation</th>
<th style="text-align: left;">state</th>
<th style="text-align: left;">name</th>
<th style="text-align: left;">gsn_flag</th>
<th style="text-align: left;">wmo_id</th>
<th style="text-align: left;">element</th>
<th style="text-align: right;">first_year</th>
<th style="text-align: right;">last_year</th>
<th style="text-align: left;">geometry</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">ACW00011604</td>
<td style="text-align: right;">10.1</td>
<td style="text-align: left;"></td>
<td style="text-align: left;">ST JOHNS COOLIDGE FLD</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">TMAX</td>
<td style="text-align: right;">1949</td>
<td style="text-align: right;">1949</td>
<td style="text-align: left;">c(-61.7833, 17.1167)</td>
</tr>
<tr class="even">
<td style="text-align: left;">ACW00011604</td>
<td style="text-align: right;">10.1</td>
<td style="text-align: left;"></td>
<td style="text-align: left;">ST JOHNS COOLIDGE FLD</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">TMIN</td>
<td style="text-align: right;">1949</td>
<td style="text-align: right;">1949</td>
<td style="text-align: left;">c(-61.7833, 17.1167)</td>
</tr>
<tr class="odd">
<td style="text-align: left;">ACW00011604</td>
<td style="text-align: right;">10.1</td>
<td style="text-align: left;"></td>
<td style="text-align: left;">ST JOHNS COOLIDGE FLD</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">PRCP</td>
<td style="text-align: right;">1949</td>
<td style="text-align: right;">1949</td>
<td style="text-align: left;">c(-61.7833, 17.1167)</td>
</tr>
<tr class="even">
<td style="text-align: left;">ACW00011604</td>
<td style="text-align: right;">10.1</td>
<td style="text-align: left;"></td>
<td style="text-align: left;">ST JOHNS COOLIDGE FLD</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">SNOW</td>
<td style="text-align: right;">1949</td>
<td style="text-align: right;">1949</td>
<td style="text-align: left;">c(-61.7833, 17.1167)</td>
</tr>
<tr class="odd">
<td style="text-align: left;">ACW00011604</td>
<td style="text-align: right;">10.1</td>
<td style="text-align: left;"></td>
<td style="text-align: left;">ST JOHNS COOLIDGE FLD</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">SNWD</td>
<td style="text-align: right;">1949</td>
<td style="text-align: right;">1949</td>
<td style="text-align: left;">c(-61.7833, 17.1167)</td>
</tr>
<tr class="even">
<td style="text-align: left;">ACW00011604</td>
<td style="text-align: right;">10.1</td>
<td style="text-align: left;"></td>
<td style="text-align: left;">ST JOHNS COOLIDGE FLD</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">PGTM</td>
<td style="text-align: right;">1949</td>
<td style="text-align: right;">1949</td>
<td style="text-align: left;">c(-61.7833, 17.1167)</td>
</tr>
</tbody>
</table>
</section><section id="ghcnd-variables-5-core-values" class="slide level2">
<h2>GHCND Variables: 5 core values</h2>
<ul>
<li><strong>PRCP</strong> Precipitation (tenths of mm)</li>
<li><strong>SNOW</strong> Snowfall (mm)</li>
<li><strong>SNWD</strong> Snow depth (mm)</li>
<li><strong>TMAX</strong> Maximum temperature</li>
<li><strong>TMIN</strong> Minimum temperature</li>
</ul>
</section><section class="slide level2">
<h3 id="and-50-others-for-example">And ~50 others! For example:</h3>
<ul>
<li><strong>ACMC</strong> Average cloudiness midnight to midnight from 30-second ceilometer</li>
<li><strong>AWND</strong> Average daily wind speed</li>
<li><strong>FMTM</strong> Time of fastest mile or fastest 1-minute wind</li>
<li><strong>MDSF</strong> Multiday snowfall total</li>
</ul>
</section><section id="filter-to-temperature-and-precipitation" class="slide level2">
<h2><code>filter()</code> to temperature and precipitation</h2>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb7-1" data-line-number="1">st_filtered=dplyr<span class="op">::</span><span class="kw">filter</span>(st,element<span class="op">%in%</span><span class="kw">c</span>(<span class="st">"TMAX"</span>,<span class="st">"TMIN"</span>,<span class="st">"PRCP"</span>))</a></code></pre></div>
</section><section id="map-ghcnd-stations" class="slide level2">
<h2>Map GHCND stations</h2>
<p>First, get a global country polygon</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb8-1" data-line-number="1"><span class="kw">library</span>(spData)</a>
<a class="sourceLine" id="cb8-2" data-line-number="2"><span class="kw">data</span>(world)</a></code></pre></div>
</section><section id="station-locations-1" class="slide level2">
<h2>Station locations</h2>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb9-1" data-line-number="1">map1=<span class="kw">ggplot</span>() <span class="op">+</span></a>
<a class="sourceLine" id="cb9-2" data-line-number="2"><span class="st"> </span><span class="kw">geom_sf</span>(<span class="dt">data=</span>world,<span class="dt">inherit.aes =</span> F,<span class="dt">size=</span>.<span class="dv">1</span>,<span class="dt">fill=</span><span class="st">"grey"</span>,<span class="dt">colour=</span><span class="st">"black"</span>)<span class="op">+</span></a>
<a class="sourceLine" id="cb9-3" data-line-number="3"><span class="st"> </span><span class="kw">facet_wrap</span>(<span class="op">~</span>element)<span class="op">+</span></a>
<a class="sourceLine" id="cb9-4" data-line-number="4"><span class="st"> </span><span class="kw">stat_bin2d</span>(<span class="dt">data=</span>st_filtered,</a>
<a class="sourceLine" id="cb9-5" data-line-number="5"> <span class="kw">aes</span>(<span class="dt">y=</span><span class="kw">st_coordinates</span>(st_filtered)[,<span class="dv">2</span>],</a>
<a class="sourceLine" id="cb9-6" data-line-number="6"> <span class="dt">x=</span><span class="kw">st_coordinates</span>(st_filtered)[,<span class="dv">1</span>]),<span class="dt">bins=</span><span class="dv">100</span>)<span class="op">+</span></a>
<a class="sourceLine" id="cb9-7" data-line-number="7"><span class="st"> </span><span class="kw">scale_fill_distiller</span>(<span class="dt">palette=</span><span class="st">"YlOrRd"</span>,<span class="dt">trans=</span><span class="st">"log"</span>,<span class="dt">direction=</span><span class="op">-</span><span class="dv">1</span>,</a>
<a class="sourceLine" id="cb9-8" data-line-number="8"> <span class="dt">breaks =</span> <span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">10</span>,<span class="dv">100</span>,<span class="dv">1000</span>))<span class="op">+</span></a>
<a class="sourceLine" id="cb9-9" data-line-number="9"><span class="st"> </span><span class="kw">coord_sf</span>()<span class="op">+</span></a>
<a class="sourceLine" id="cb9-10" data-line-number="10"><span class="st"> </span><span class="kw">labs</span>(<span class="dt">x=</span><span class="st">""</span>,<span class="dt">y=</span><span class="st">""</span>)</a></code></pre></div>
</section><section class="slide level2">
<p><img data-src="PS_09_weather_files/figure-revealjs/unnamed-chunk-11-1.png" /></p>
</section><section id="download-daily-data-from-ghcn" class="slide level2">
<h2>Download daily data from GHCN</h2>
<p><code>ghcnd()</code> will download a <code>.dly</code> text file for a particular station. But how to choose?</p>
</section><section id="geocode-in-ggmap-package-useful-for-geocoding-place-names" class="slide level2">
<h2><code>geocode</code> in ggmap package useful for geocoding place names</h2>
<p>Geocodes a location (find latitude and longitude) using either (1) the Data Science Toolkit (<a href="http://www.datasciencetoolkit.org/about" class="uri">http://www.datasciencetoolkit.org/about</a>) or (2) Google Maps.</p>
<div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb10-1" data-line-number="1"><span class="kw">geocode</span>(<span class="st">"University at Buffalo, NY"</span>,<span class="dt">source =</span> <span class="st">"dsk"</span>)</a></code></pre></div>
<pre><code>## lon lat
## 1 -78.80388 42.95973</code></pre>
</section><section class="slide level2">
<p>However, you have to be careful:</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb12-1" data-line-number="1"><span class="kw">geocode</span>(<span class="st">"Washington"</span>,<span class="dt">source =</span> <span class="st">"dsk"</span>)</a></code></pre></div>
<pre><code>## lon lat
## 1 -120.5015 47.50012</code></pre>
<div class="sourceCode" id="cb14"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb14-1" data-line-number="1"><span class="kw">geocode</span>(<span class="st">"Washington D.C."</span>,<span class="dt">source =</span> <span class="st">"dsk"</span>)</a></code></pre></div>
<pre><code>## lon lat
## 1 -77.03637 38.89511</code></pre>
</section><section class="slide level2">
<p>But this is pretty safe for well known and well-defined places.</p>
<div class="sourceCode" id="cb16"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb16-1" data-line-number="1">buffalo_c=<span class="kw">geocode</span>(<span class="st">"Buffalo International Airport, NY"</span>,<span class="dt">source =</span> <span class="st">"dsk"</span>)</a>
<a class="sourceLine" id="cb16-2" data-line-number="2">buffalo_c</a></code></pre></div>
<pre><code>## lon lat
## 1 -78.73153 42.97851</code></pre>
<div class="sourceCode" id="cb18"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb18-1" data-line-number="1">buffalo=buffalo_c<span class="op">%>%</span></a>
<a class="sourceLine" id="cb18-2" data-line-number="2"><span class="st"> </span><span class="kw">st_as_sf</span>(<span class="dt">coords=</span><span class="kw">c</span>(<span class="dv">1</span>,<span class="dv">2</span>))<span class="op">%>%</span><span class="st"> </span><span class="co">#convert to sf</span></a>
<a class="sourceLine" id="cb18-3" data-line-number="3"><span class="st"> </span><span class="kw">st_set_crs</span>(<span class="st">"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"</span>)</a></code></pre></div>
</section><section class="slide level2">
<p>Now use that location to spatially filter stations.</p>
<div class="sourceCode" id="cb19"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb19-1" data-line-number="1">buffalo_b=<span class="kw">st_buffer</span>(buffalo, <span class="fl">0.05</span>) <span class="co">#radius of buffer in decimal degrees</span></a>
<a class="sourceLine" id="cb19-2" data-line-number="2">st1=<span class="kw">st_within</span>(st_filtered,buffalo_b)<span class="op">%>%</span><span class="st"> </span><span class="co">#find stations in the buffered polygon</span></a>
<a class="sourceLine" id="cb19-3" data-line-number="3"><span class="st"> </span><span class="kw">apply</span>(<span class="dv">1</span>, any) </a>
<a class="sourceLine" id="cb19-4" data-line-number="4"><span class="kw">str</span>(st1)</a></code></pre></div>
<pre><code>## logi [1:175510] FALSE FALSE FALSE FALSE FALSE FALSE ...</code></pre>
<div class="sourceCode" id="cb21"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb21-1" data-line-number="1"><span class="kw">kable</span>(st_filtered[st1,])</a></code></pre></div>
<table>
<thead>
<tr class="header">
<th style="text-align: left;">id</th>
<th style="text-align: right;">elevation</th>
<th style="text-align: left;">state</th>
<th style="text-align: left;">name</th>
<th style="text-align: left;">gsn_flag</th>
<th style="text-align: left;">wmo_id</th>
<th style="text-align: left;">element</th>
<th style="text-align: right;">first_year</th>
<th style="text-align: right;">last_year</th>
<th style="text-align: left;">geometry</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;">US1NYER0004</td>
<td style="text-align: right;">184.1</td>
<td style="text-align: left;">NY</td>
<td style="text-align: left;">WILLIAMSVILLE 4.1 N</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">PRCP</td>
<td style="text-align: right;">2009</td>
<td style="text-align: right;">2011</td>
<td style="text-align: left;">c(-78.7432, 43.0216)</td>
</tr>
<tr class="even">
<td style="text-align: left;">US1NYER0007</td>
<td style="text-align: right;">214.0</td>
<td style="text-align: left;">NY</td>
<td style="text-align: left;">WILLIAMSVILLE 2.7 E</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">PRCP</td>
<td style="text-align: right;">2008</td>
<td style="text-align: right;">2018</td>
<td style="text-align: left;">c(-78.6879, 42.9693)</td>
</tr>
<tr class="odd">
<td style="text-align: left;">US1NYER0054</td>
<td style="text-align: right;">178.0</td>
<td style="text-align: left;">NY</td>
<td style="text-align: left;">EAST AMHERST 1.2 WNW</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">PRCP</td>
<td style="text-align: right;">2009</td>
<td style="text-align: right;">2018</td>
<td style="text-align: left;">c(-78.719, 43.0225)</td>
</tr>
<tr class="even">
<td style="text-align: left;">US1NYER0083</td>
<td style="text-align: right;">96.9</td>
<td style="text-align: left;">NY</td>
<td style="text-align: left;">WILLIAMSVILLE 1 NW</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">PRCP</td>
<td style="text-align: right;">2010</td>
<td style="text-align: right;">2014</td>
<td style="text-align: left;">c(-78.7663, 42.9698)</td>
</tr>
<tr class="odd">
<td style="text-align: left;">US1NYER0102</td>
<td style="text-align: right;">214.3</td>
<td style="text-align: left;">NY</td>
<td style="text-align: left;">CHEEKTOWAGA 2.7 NE</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">PRCP</td>
<td style="text-align: right;">2013</td>
<td style="text-align: right;">2018</td>
<td style="text-align: left;">c(-78.7193, 42.9412)</td>
</tr>
<tr class="even">
<td style="text-align: left;">US1NYER0104</td>
<td style="text-align: right;">179.5</td>
<td style="text-align: left;">NY</td>
<td style="text-align: left;">WILLIAMSVILLE 2.2 NNW</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">PRCP</td>
<td style="text-align: right;">2013</td>
<td style="text-align: right;">2018</td>
<td style="text-align: left;">c(-78.7526, 42.9942)</td>
</tr>
<tr class="odd">
<td style="text-align: left;">US1NYER0107</td>
<td style="text-align: right;">186.2</td>
<td style="text-align: left;">NY</td>
<td style="text-align: left;">AMHERST 3.3 ENE</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">PRCP</td>
<td style="text-align: right;">2014</td>
<td style="text-align: right;">2018</td>
<td style="text-align: left;">c(-78.7269, 42.9855)</td>
</tr>
<tr class="even">
<td style="text-align: left;">US1NYER0147</td>
<td style="text-align: right;">180.7</td>
<td style="text-align: left;">NY</td>
<td style="text-align: left;">WILLIAMSVILLE 2.4 N</td>
<td style="text-align: left;"></td>
<td style="text-align: left;"></td>
<td style="text-align: left;">PRCP</td>
<td style="text-align: right;">1998</td>
<td style="text-align: right;">2018</td>
<td style="text-align: left;">c(-78.7403, 42.9974)</td>
</tr>
<tr class="odd">
<td style="text-align: left;">USW00014733</td>
<td style="text-align: right;">211.2</td>
<td style="text-align: left;">NY</td>
<td style="text-align: left;">BUFFALO</td>
<td style="text-align: left;"></td>
<td style="text-align: left;">HCN 72528</td>
<td style="text-align: left;">TMAX</td>
<td style="text-align: right;">1938</td>
<td style="text-align: right;">2018</td>
<td style="text-align: left;">c(-78.7369, 42.9486)</td>
</tr>
<tr class="even">
<td style="text-align: left;">USW00014733</td>
<td style="text-align: right;">211.2</td>
<td style="text-align: left;">NY</td>
<td style="text-align: left;">BUFFALO</td>
<td style="text-align: left;"></td>
<td style="text-align: left;">HCN 72528</td>
<td style="text-align: left;">TMIN</td>
<td style="text-align: right;">1938</td>
<td style="text-align: right;">2018</td>
<td style="text-align: left;">c(-78.7369, 42.9486)</td>
</tr>
<tr class="odd">
<td style="text-align: left;">USW00014733</td>
<td style="text-align: right;">211.2</td>
<td style="text-align: left;">NY</td>
<td style="text-align: left;">BUFFALO</td>
<td style="text-align: left;"></td>
<td style="text-align: left;">HCN 72528</td>
<td style="text-align: left;">PRCP</td>
<td style="text-align: right;">1938</td>
<td style="text-align: right;">2018</td>
<td style="text-align: left;">c(-78.7369, 42.9486)</td>
</tr>
</tbody>
</table>
</section><section class="slide level2">
<p>With the station ID, we can download daily data from NOAA.</p>
<div class="sourceCode" id="cb22"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb22-1" data-line-number="1">d=<span class="kw">meteo_pull_monitors</span>(<span class="dt">monitors=</span><span class="kw">c</span>(<span class="st">"USW00014733"</span>),</a>
<a class="sourceLine" id="cb22-2" data-line-number="2"> <span class="dt">var =</span> <span class="kw">c</span>(<span class="st">"TMAX"</span>,<span class="st">"TMIN"</span>,<span class="st">"PRCP"</span>),</a>
<a class="sourceLine" id="cb22-3" data-line-number="3"> <span class="dt">keep_flags =</span> T)</a>
<a class="sourceLine" id="cb22-4" data-line-number="4"><span class="kw">head</span>(d)<span class="op">%>%</span><span class="kw">kable</span>()</a></code></pre></div>
<table>
<colgroup>
<col style="width: 8%" />
<col style="width: 8%" />
<col style="width: 8%" />
<col style="width: 8%" />
<col style="width: 8%" />
<col style="width: 3%" />
<col style="width: 8%" />
<col style="width: 8%" />
<col style="width: 8%" />
<col style="width: 8%" />
<col style="width: 8%" />
<col style="width: 8%" />
<col style="width: 3%" />
<col style="width: 3%" />
</colgroup>
<thead>
<tr class="header">