-
Notifications
You must be signed in to change notification settings - Fork 1
/
Haskell.tex
2175 lines (1837 loc) · 109 KB
/
Haskell.tex
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
%%
% Copyright (c) 2017 - 2021, Pascal Wagler;
% Copyright (c) 2014 - 2021, John MacFarlane
%
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions
% are met:
%
% - Redistributions of source code must retain the above copyright
% notice, this list of conditions and the following disclaimer.
%
% - Redistributions in binary form must reproduce the above copyright
% notice, this list of conditions and the following disclaimer in the
% documentation and/or other materials provided with the distribution.
%
% - Neither the name of John MacFarlane nor the names of other
% contributors may be used to endorse or promote products derived
% from this software without specific prior written permission.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
% "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
% FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
% COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
% INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
% BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
% LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
% ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%%
%%
% This is the Eisvogel pandoc LaTeX template.
%
% For usage information and examples visit the official GitHub page:
% https://github.com/Wandmalfarbe/pandoc-latex-template
%%
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
\PassOptionsToPackage{dvipsnames,svgnames*,x11names*,table}{xcolor}
%
\documentclass[
paper=a4,
,captions=tableheading
]{scrartcl}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{setspace}
\setstretch{1.2}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\definecolor{default-linkcolor}{HTML}{A50000}
\definecolor{default-filecolor}{HTML}{A50000}
\definecolor{default-citecolor}{HTML}{4077C0}
\definecolor{default-urlcolor}{HTML}{4077C0}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
pdftitle={Sensing the Earth: CFT tutorial},
hidelinks,
breaklinks=true,
pdfcreator={LaTeX via pandoc with the Eisvogel template}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[margin=2.5cm,includehead=true,includefoot=true,centering,]{geometry}
\usepackage{color}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\usepackage{framed}
\definecolor{shadecolor}{RGB}{248,248,248}
\newenvironment{Shaded}{\begin{snugshade}}{\end{snugshade}}
\newcommand{\AlertTok}[1]{\textcolor[rgb]{0.94,0.16,0.16}{#1}}
\newcommand{\AnnotationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\AttributeTok}[1]{\textcolor[rgb]{0.77,0.63,0.00}{#1}}
\newcommand{\BaseNTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\BuiltInTok}[1]{#1}
\newcommand{\CharTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\CommentTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\CommentVarTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ConstantTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ControlFlowTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\DataTypeTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{#1}}
\newcommand{\DecValTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\DocumentationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\ErrorTok}[1]{\textcolor[rgb]{0.64,0.00,0.00}{\textbf{#1}}}
\newcommand{\ExtensionTok}[1]{#1}
\newcommand{\FloatTok}[1]{\textcolor[rgb]{0.00,0.00,0.81}{#1}}
\newcommand{\FunctionTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\ImportTok}[1]{#1}
\newcommand{\InformationTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
\newcommand{\KeywordTok}[1]{\textcolor[rgb]{0.13,0.29,0.53}{\textbf{#1}}}
\newcommand{\NormalTok}[1]{#1}
\newcommand{\OperatorTok}[1]{\textcolor[rgb]{0.81,0.36,0.00}{\textbf{#1}}}
\newcommand{\OtherTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{#1}}
\newcommand{\PreprocessorTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textit{#1}}}
\newcommand{\RegionMarkerTok}[1]{#1}
\newcommand{\SpecialCharTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\SpecialStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\StringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\VariableTok}[1]{\textcolor[rgb]{0.00,0.00,0.00}{#1}}
\newcommand{\VerbatimStringTok}[1]{\textcolor[rgb]{0.31,0.60,0.02}{#1}}
\newcommand{\WarningTok}[1]{\textcolor[rgb]{0.56,0.35,0.01}{\textbf{\textit{#1}}}}
% Workaround/bugfix from jannick0.
% See https://github.com/jgm/pandoc/issues/4302#issuecomment-360669013)
% or https://github.com/Wandmalfarbe/pandoc-latex-template/issues/2
%
% Redefine the verbatim environment 'Highlighting' to break long lines (with
% the help of fvextra). Redefinition is necessary because it is unlikely that
% pandoc includes fvextra in the default template.
\usepackage{fvextra}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,fontsize=\small,commandchars=\\\{\}}
% add backlinks to footnote references, cf. https://tex.stackexchange.com/questions/302266/make-footnote-clickable-both-ways
\usepackage{footnotebackref}
\usepackage{graphicx}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother
% Scale images if necessary, so that they will not overflow the page
% margins by default, and it is still possible to overwrite the defaults
% using explicit options in \includegraphics[width, height, ...]{}
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
% Set default figure placement to htbp
\makeatletter
\def\fps@figure{htbp}
\makeatother
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{5}
% Make use of float-package and set default placement for figures to H.
% The option H means 'PUT IT HERE' (as opposed to the standard h option which means 'You may put it here if you like').
\usepackage{float}
\floatplacement{figure}{H}
\ifluatex
\usepackage{selnolig} % disable illegal ligatures
\fi
\title{Sensing the Earth: CFT tutorial}
\author{}
\date{}
%%
%% added
%%
%
% language specification
%
% If no language is specified, use English as the default main document language.
%
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[shorthands=off,main=english]{babel}
\else
% Workaround for bug in Polyglossia that breaks `\familydefault` when `\setmainlanguage` is used.
% See https://github.com/Wandmalfarbe/pandoc-latex-template/issues/8
% See https://github.com/reutenauer/polyglossia/issues/186
% See https://github.com/reutenauer/polyglossia/issues/127
\renewcommand*\familydefault{\sfdefault}
% load polyglossia as late as possible as it *could* call bidi if RTL lang (e.g. Hebrew or Arabic)
\usepackage{polyglossia}
\setmainlanguage[]{english}
\fi
%
% for the background color of the title page
%
%
% break urls
%
\PassOptionsToPackage{hyphens}{url}
%
% When using babel or polyglossia with biblatex, loading csquotes is recommended
% to ensure that quoted texts are typeset according to the rules of your main language.
%
\usepackage{csquotes}
%
% captions
%
\definecolor{caption-color}{HTML}{777777}
\usepackage[font={stretch=1.2}, textfont={color=caption-color}, position=top, skip=4mm, labelfont=bf, singlelinecheck=false, justification=raggedright]{caption}
\setcapindent{0em}
%
% blockquote
%
\definecolor{blockquote-border}{RGB}{221,221,221}
\definecolor{blockquote-text}{RGB}{119,119,119}
\usepackage{mdframed}
\newmdenv[rightline=false,bottomline=false,topline=false,linewidth=3pt,linecolor=blockquote-border,skipabove=\parskip]{customblockquote}
\renewenvironment{quote}{\begin{customblockquote}\list{}{\rightmargin=0em\leftmargin=0em}%
\item\relax\color{blockquote-text}\ignorespaces}{\unskip\unskip\endlist\end{customblockquote}}
%
% Source Sans Pro as the default font family
% Source Code Pro for monospace text
%
% 'default' option sets the default
% font family to Source Sans Pro, not \sfdefault.
%
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[default]{sourcesanspro}
\usepackage{sourcecodepro}
\else % if not pdftex
\usepackage[default]{sourcesanspro}
\usepackage{sourcecodepro}
% XeLaTeX specific adjustments for straight quotes: https://tex.stackexchange.com/a/354887
% This issue is already fixed (see https://github.com/silkeh/latex-sourcecodepro/pull/5) but the
% fix is still unreleased.
% TODO: Remove this workaround when the new version of sourcecodepro is released on CTAN.
\ifxetex
\makeatletter
\defaultfontfeatures[\ttfamily]
{ Numbers = \sourcecodepro@figurestyle,
Scale = \SourceCodePro@scale,
Extension = .otf }
\setmonofont
[ UprightFont = *-\sourcecodepro@regstyle,
ItalicFont = *-\sourcecodepro@regstyle It,
BoldFont = *-\sourcecodepro@boldstyle,
BoldItalicFont = *-\sourcecodepro@boldstyle It ]
{SourceCodePro}
\makeatother
\fi
\fi
%
% heading color
%
\definecolor{heading-color}{RGB}{40,40,40}
\addtokomafont{section}{\color{heading-color}}
% When using the classes report, scrreprt, book,
% scrbook or memoir, uncomment the following line.
%\addtokomafont{chapter}{\color{heading-color}}
%
% variables for title, author and date
%
\usepackage{titling}
\title{Sensing the Earth: CFT tutorial}
\author{}
\date{}
%
% tables
%
%
% remove paragraph indention
%
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em} % prevent overfull lines
%
%
% Listings
%
%
%
% header and footer
%
\usepackage{fancyhdr}
\fancypagestyle{eisvogel-header-footer}{
\fancyhead{}
\fancyfoot{}
\lhead[]{Sensing the Earth: CFT tutorial}
\chead[]{}
\rhead[Sensing the Earth: CFT tutorial]{}
\lfoot[\thepage]{}
\cfoot[]{}
\rfoot[]{\thepage}
\renewcommand{\headrulewidth}{0.4pt}
\renewcommand{\footrulewidth}{0.4pt}
}
\pagestyle{eisvogel-header-footer}
%%
%% end added
%%
\begin{document}
%%
%% begin titlepage
%%
%%
%% end titlepage
%%
{
\setcounter{tocdepth}{2}
\tableofcontents
}
\let\oldsection\section
\renewcommand\section{\clearpage\oldsection}
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{options}\NormalTok{(}\AttributeTok{knitr.kable.NA =} \StringTok{\textquotesingle{}\textquotesingle{}}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\hypertarget{climate-futures-for-haskell-indian-nations-university}{%
\section{\texorpdfstring{Climate futures for
\href{https://www.haskell.edu}{Haskell Indian Nations
University}}{Climate futures for Haskell Indian Nations University}}\label{climate-futures-for-haskell-indian-nations-university}}
\hypertarget{prepare-your-environment}{%
\subsection{Prepare your environment}\label{prepare-your-environment}}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
Install Climate Futures Toolbox
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{install.packages}\NormalTok{(}\StringTok{"cft"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{1}
\tightlist
\item
Load other packages
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{library}\NormalTok{(tidyverse)}
\FunctionTok{library}\NormalTok{(tidync)}
\FunctionTok{library}\NormalTok{(cft)}
\FunctionTok{library}\NormalTok{(sf)}
\FunctionTok{library}\NormalTok{(ggplot2)}
\FunctionTok{library}\NormalTok{(ggthemes)}
\FunctionTok{library}\NormalTok{(ggpattern)}
\FunctionTok{library}\NormalTok{(magick)}
\FunctionTok{library}\NormalTok{(future)}
\FunctionTok{library}\NormalTok{(forecast)}
\FunctionTok{library}\NormalTok{(tidytable)}
\FunctionTok{library}\NormalTok{(janitor)}
\FunctionTok{options}\NormalTok{(}\AttributeTok{timeout =} \DecValTok{600}\NormalTok{)}
\FunctionTok{library}\NormalTok{(ggfortify)}
\FunctionTok{library}\NormalTok{(reticulate)}
\FunctionTok{library}\NormalTok{(osmdata)}
\FunctionTok{library}\NormalTok{(osmextract)}
\FunctionTok{library}\NormalTok{(changepoint)}
\FunctionTok{library}\NormalTok{(weathermetrics)}
\end{Highlighting}
\end{Shaded}
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{conda\_update}\NormalTok{(}\AttributeTok{conda =} \StringTok{"auto"}\NormalTok{)}
\FunctionTok{py\_install}\NormalTok{(}\StringTok{"numpy"}\NormalTok{)}
\FunctionTok{py\_install}\NormalTok{(}\StringTok{"matplotlib"}\NormalTok{)}
\FunctionTok{py\_install}\NormalTok{(}\StringTok{"pandas"}\NormalTok{)}
\FunctionTok{py\_install}\NormalTok{(}\StringTok{"statsmodels"}\NormalTok{)}
\FunctionTok{py\_install}\NormalTok{(}\StringTok{"osmnx"}\NormalTok{)}
\FunctionTok{py\_install}\NormalTok{(}\StringTok{"geopandas"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\hypertarget{set-your-color-palette}{%
\subsubsection{Set your color palette}\label{set-your-color-palette}}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
Download the Haskell university logo
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{seamless\_image\_filenames }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}
\StringTok{\textquotesingle{}Haskell\_logo.png\textquotesingle{}}
\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\includegraphics[width=0.5\textwidth,height=\textheight]{Haskell_logo.png}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{1}
\tightlist
\item
Sample the colors on that logo to make a custom color palette for our
basemap
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{our\_blue }\OtherTok{\textless{}{-}} \StringTok{"\#3A4E8B"}
\NormalTok{our\_yellow }\OtherTok{\textless{}{-}} \StringTok{"\#FFD60F"}
\NormalTok{our\_beige }\OtherTok{\textless{}{-}} \StringTok{"\#EDEDF0"}
\NormalTok{our\_purple }\OtherTok{\textless{}{-}} \StringTok{"\#3E1471"}
\end{Highlighting}
\end{Shaded}
\hypertarget{finding-basic-layers-in-openstreetmap}{%
\subsection{Finding basic layers in
OpenStreetMap}\label{finding-basic-layers-in-openstreetmap}}
Explain the basics of APIs and the premise of fast downloads.
\hypertarget{use-plain-lnaguage-to-request-a-bounding-box}{%
\subsubsection{Use plain lnaguage to request a bounding
box}\label{use-plain-lnaguage-to-request-a-bounding-box}}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
Find the general area on Open Street Map We use a function from the
osmdata package to find a bounding box for our area of interest. This
is a nice function for this purpose because it can use plan language
declarations (e.g.~``Lawrence, Kansas'' or ``Boulder, Colorado'') for
the location. You do not need to use this function to define a
bounding box. You can define your bounding box from any source. The
benefit of this method is that is it is rather easy and reliable.
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{bb }\OtherTok{\textless{}{-}} \FunctionTok{getbb}\NormalTok{(}\StringTok{"Lawrence, Kansas"}\NormalTok{)}
\NormalTok{bb}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## min max
## x -95.34454 -95.16662
## y 38.90447 39.03350
\end{verbatim}
If you format your request a little differently, then it will return the
more complex polygon for the bounding box.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{bb\_sf }\OtherTok{\textless{}{-}} \FunctionTok{getbb}\NormalTok{(}\StringTok{"Lawrence, Kansas"}\NormalTok{, }\AttributeTok{format\_out =} \StringTok{"sf\_polygon"}\NormalTok{)}
\FunctionTok{ggplot}\NormalTok{(}\AttributeTok{data=}\NormalTok{bb\_sf}\SpecialCharTok{$}\NormalTok{multipolygon) }\SpecialCharTok{+} \FunctionTok{geom\_sf}\NormalTok{(}\AttributeTok{fill=}\NormalTok{our\_beige, }\AttributeTok{color=}\NormalTok{our\_purple) }\SpecialCharTok{+} \FunctionTok{theme\_tufte}\NormalTok{()}
\end{Highlighting}
\end{Shaded}
\includegraphics{Haskell_files/figure-latex/unnamed-chunk-8-1.pdf}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{1}
\tightlist
\item
Find any buildings associated with any University in our ``Lawrence,
Kansas'' bounding box.
\end{enumerate}
\hypertarget{using-the-package-osmdata}{%
\paragraph{Using the package osmdata}\label{using-the-package-osmdata}}
This request first calls the opq() function, which mounts to the
OpenStreetMap database and then queries the ``building'' key (i.e.~all
the building footprints) for any building types matching the value
``university''. This is a representation of the ``key'' and ``value''
system that OSM uses to query data. The final step is to convert the OSM
output into a spatial format that works well in R, called sf.
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{library}\NormalTok{(osmdata)}
\NormalTok{University\_buildings }\OtherTok{\textless{}{-}}
\FunctionTok{opq}\NormalTok{(bb) }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{add\_osm\_feature}\NormalTok{(}\AttributeTok{key =} \StringTok{"building"}\NormalTok{, }\AttributeTok{value =} \StringTok{"university"}\NormalTok{) }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{osmdata\_sf}\NormalTok{()}
\end{Highlighting}
\end{Shaded}
The output from this request shows a list of multipolygons, polygons,
linestrings, and points. Each of these data types have a different
storage structure, so we can't look at them all at the same time.
Instead, lets start with polygons, which likely represent a single
building footprint. Printing `my\_boundary\$osm\_polygons' shows that
there are two Universities in Lawrence and we need to filter those
results down to only include Haskell building.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{University\_buildings }\OtherTok{\textless{}{-}}\NormalTok{ University\_buildings}\SpecialCharTok{$}\NormalTok{osm\_polygons}
\end{Highlighting}
\end{Shaded}
\hypertarget{using-the-package-osmextract}{%
\paragraph{Using the package
osmextract}\label{using-the-package-osmextract}}
The package OSMextract is calling the same OSM API, but it does it in a
slightly different way that can make if faster but also requires a
little better understanding of what you're looking for. For example, by
default OSM extract only downloads the first 25 columns as their own
column and clumps the rest into a list that is difficult to read. You
can add columns to the api call as I did here (e.g.~extra\_tags =
c(``operator)) and it will return that column as a column instead of in
the list. You can also parse the list yourself or use osmdata() to
download a sample and then use osmextract to execute larger downloads.
This package usually clumps polygons and multipolygons by default so,
you just ask for multipolygons and get both back.
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{library}\NormalTok{(osmextract)}
\NormalTok{University\_buildings }\OtherTok{\textless{}{-}} \FunctionTok{oe\_get}\NormalTok{(}
\AttributeTok{place =} \StringTok{"Lawrence, Kansas"}\NormalTok{, }
\AttributeTok{layer =} \StringTok{"multipolygons"}\NormalTok{,}
\AttributeTok{query =} \StringTok{"SELECT * FROM multipolygons WHERE building IN (\textquotesingle{}university\textquotesingle{})"}\NormalTok{,}
\AttributeTok{quiet =} \ConstantTok{TRUE}\NormalTok{,}
\AttributeTok{extra\_tags =} \FunctionTok{c}\NormalTok{(}\StringTok{"operator"}\NormalTok{)}
\NormalTok{)}
\FunctionTok{colnames}\NormalTok{(University\_buildings)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## [1] "osm_id" "osm_way_id" "name" "type" "aeroway"
## [6] "amenity" "admin_level" "barrier" "boundary" "building"
## [11] "craft" "geological" "historic" "land_area" "landuse"
## [16] "leisure" "man_made" "military" "natural" "office"
## [21] "place" "shop" "sport" "tourism" "operator"
## [26] "other_tags" "geometry"
\end{verbatim}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{2}
\tightlist
\item
Use the `operator' column to identify the owner of those buildings and
filter down to building operated by Haskell Indian Nations University.
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{Haskell\_university\_buildings }\OtherTok{\textless{}{-}}\NormalTok{ University\_buildings }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{filter}\NormalTok{(operator }\SpecialCharTok{==} \StringTok{"Haskell Indian Nations University"}\NormalTok{) }
\NormalTok{Haskell\_university\_buildings1 }\OtherTok{\textless{}{-}}\NormalTok{ Haskell\_university\_buildings[}\DecValTok{1}\NormalTok{,] }\CommentTok{\#take the first building (e.g. first row) of the returns}
\FunctionTok{head}\NormalTok{(Haskell\_university\_buildings1)}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## # A tidytable: 1 x 27
## osm_id osm_way_id name type aeroway amenity admin~1 barrier bound~2 build~3
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 <NA> 172577406 Winon~ <NA> <NA> <NA> <NA> <NA> <NA> univer~
## # ... with 17 more variables: craft <chr>, geological <chr>, historic <chr>,
## # land_area <chr>, landuse <chr>, leisure <chr>, man_made <chr>,
## # military <chr>, natural <chr>, office <chr>, place <chr>, shop <chr>,
## # sport <chr>, tourism <chr>, operator <chr>, other_tags <chr>,
## # geometry <MULTIPOLYGON [°]>, and abbreviated variable names 1: admin_level,
## # 2: boundary, 3: building
\end{verbatim}
The janitor package is useful for performing automated cleaning tasks on
your data. Here we remove all of the columns that contain no data to
make our dataframe much smaller and easier to read.
\begin{verbatim}
## osm_way_id name building operator
## 1 172577406 Winona Hall university Haskell Indian Nations University
## other_tags
## 1 "gnis:county_id"=>"045","gnis:created"=>"12/08/2008","gnis:feature_id"=>"2510678","gnis:state_id"=>"20"
## geometry
## 1 MULTIPOLYGON (((-95.23447 3...
\end{verbatim}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{3}
\tightlist
\item
Plot our discovered footprint to visually confirm It looks like we
found \href{https://www.kansasmemory.org/item/449914}{Winona Hall} in
the OpenStreetMap database. This is how we plot the perimeters
associated with it. \includegraphics{winona hall haskell.png}
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{basemap }\OtherTok{\textless{}{-}} \FunctionTok{ggplot}\NormalTok{(}\AttributeTok{data =} \FunctionTok{st\_as\_sf}\NormalTok{(boundaries1)) }\SpecialCharTok{+}
\FunctionTok{geom\_sf}\NormalTok{(}\AttributeTok{fill =}\NormalTok{ our\_purple, }\AttributeTok{color=}\NormalTok{our\_yellow) }\SpecialCharTok{+}
\FunctionTok{geom\_sf\_text}\NormalTok{(}\FunctionTok{aes}\NormalTok{(}\AttributeTok{label =}\NormalTok{ name), }\AttributeTok{size=}\DecValTok{10}\NormalTok{, }\AttributeTok{color=}\NormalTok{our\_yellow) }\SpecialCharTok{+}
\FunctionTok{theme\_tufte}\NormalTok{()}
\NormalTok{basemap}
\end{Highlighting}
\end{Shaded}
\includegraphics{Haskell_files/figure-latex/unnamed-chunk-14-1.pdf}
\#\#\#\# OSM in python using osmnx The python interface for OSM uses a
slightly different syntax to write the requests, but it's calling the
same OSM api that the R packages call. You still submit a plain-language
area-of-interest, a value, and a key. Those three inputs will return a
list of points, lines, and polygons for you to use and manipulate.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{place\_name }\OperatorTok{=} \StringTok{"Lawrence, Kansas"}
\CommentTok{\# import osmnx}
\ImportTok{import}\NormalTok{ osmnx }\ImportTok{as}\NormalTok{ ox}
\ImportTok{import}\NormalTok{ geopandas }\ImportTok{as}\NormalTok{ gpd}
\ImportTok{import}\NormalTok{ matplotlib.pyplot }\ImportTok{as}\NormalTok{ plt}
\CommentTok{\# Get place boundary related to the place name as a geodataframe}
\NormalTok{area }\OperatorTok{=}\NormalTok{ ox.geocode\_to\_gdf(place\_name)}
\BuiltInTok{type}\NormalTok{(area)}
\CommentTok{\# List key{-}value pairs for tags}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## <class 'geopandas.geodataframe.GeoDataFrame'>
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{tags }\OperatorTok{=}\NormalTok{ \{}\StringTok{\textquotesingle{}building\textquotesingle{}}\NormalTok{: }\StringTok{\textquotesingle{}university\textquotesingle{}}\NormalTok{\} }
\NormalTok{buildings }\OperatorTok{=}\NormalTok{ ox.geometries\_from\_place(place\_name, tags)}
\NormalTok{buildings.plot()}
\NormalTok{plt.show()}
\end{Highlighting}
\end{Shaded}
\includegraphics{Haskell_files/figure-latex/unnamed-chunk-15-1.pdf}
\hypertarget{build-a-basemap-from-openstreetmap}{%
\subsection{Build a basemap from
OpenStreetMap}\label{build-a-basemap-from-openstreetmap}}
\hypertarget{download-all-the-layers-you-want-to-include-in-your-basemap}{%
\subsubsection{Download all the layers you want to include in your
basemap}\label{download-all-the-layers-you-want-to-include-in-your-basemap}}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
Download the Haskell University footprint
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{amenity\_poly }\OtherTok{\textless{}{-}} \FunctionTok{oe\_get}\NormalTok{(}
\AttributeTok{place =} \StringTok{"Lawrence, Kansas"}\NormalTok{, }
\AttributeTok{layer =} \StringTok{"multipolygons"}\NormalTok{,}
\AttributeTok{query =} \StringTok{"SELECT * FROM multipolygons WHERE amenity IN (\textquotesingle{}university\textquotesingle{})"}\NormalTok{,}
\AttributeTok{quiet =} \ConstantTok{TRUE}\NormalTok{,}
\AttributeTok{extra\_tags =} \FunctionTok{c}\NormalTok{(}\StringTok{"operator"}\NormalTok{)}
\NormalTok{)}
\NormalTok{haskell\_poly }\OtherTok{\textless{}{-}}\NormalTok{ amenity\_poly }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{filter}\NormalTok{(name }\SpecialCharTok{==}\StringTok{\textquotesingle{}Haskell Indian Nations University\textquotesingle{}}\NormalTok{) }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{st\_as\_sf}\NormalTok{()}
\end{Highlighting}
\end{Shaded}
\includegraphics{Haskell_files/figure-latex/unnamed-chunk-17-1.pdf}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{1}
\tightlist
\item
Download street vector layers The street vector is divided into two
different downloads in order to create two different objects for
coloring in the final figure. This first download will be in the
foreground. It includes the larger and faster roadways.
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# the big streets}
\NormalTok{big\_streets\_lines }\OtherTok{\textless{}{-}} \FunctionTok{oe\_get}\NormalTok{(}
\AttributeTok{place =} \StringTok{"Lawrence, Kansas"}\NormalTok{, }
\AttributeTok{layer =} \StringTok{"lines"}\NormalTok{,}
\AttributeTok{query =} \StringTok{"SELECT * FROM lines WHERE highway IN (\textquotesingle{}motorway\textquotesingle{}, \textquotesingle{}trunk\textquotesingle{}, \textquotesingle{}primary\textquotesingle{}, \textquotesingle{}secondary\textquotesingle{}, \textquotesingle{}tertiary\textquotesingle{})"}\NormalTok{,}
\AttributeTok{quiet =} \ConstantTok{TRUE}
\NormalTok{)}
\NormalTok{streets\_crop }\OtherTok{\textless{}{-}}\NormalTok{ big\_streets\_lines }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{st\_crop}\NormalTok{(}\AttributeTok{y =} \FunctionTok{c}\NormalTok{(}\AttributeTok{ymin =}\NormalTok{ bb[}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{], }\AttributeTok{ymax =}\NormalTok{ bb[}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{], }\AttributeTok{xmin =}\NormalTok{ bb[}\DecValTok{1}\NormalTok{,}\DecValTok{1}\NormalTok{], }\AttributeTok{xmax =}\NormalTok{ bb[}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{]))}
\end{Highlighting}
\end{Shaded}
\includegraphics{Haskell_files/figure-latex/unnamed-chunk-19-1.pdf}
The second street download is for the small side streets and footpaths.
These lines will be more faint and in the background.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{small\_streets }\OtherTok{\textless{}{-}} \FunctionTok{oe\_get}\NormalTok{(}
\AttributeTok{place =} \StringTok{"Lawrence, Kansas"}\NormalTok{, }
\AttributeTok{layer =} \StringTok{"lines"}\NormalTok{,}
\AttributeTok{query =} \StringTok{"SELECT * FROM lines WHERE highway IN (\textquotesingle{}residential\textquotesingle{}, \textquotesingle{}living\textquotesingle{}, \textquotesingle{}unclassified\textquotesingle{}, \textquotesingle{}service\textquotesingle{}, \textquotesingle{}footway\textquotesingle{})"}\NormalTok{,}
\AttributeTok{quiet =} \ConstantTok{TRUE}
\NormalTok{)}
\NormalTok{small\_streets\_crop }\OtherTok{\textless{}{-}}\NormalTok{ small\_streets }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{st\_crop}\NormalTok{(}\AttributeTok{y =} \FunctionTok{c}\NormalTok{(}\AttributeTok{ymin =}\NormalTok{ bb[}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{], }\AttributeTok{ymax =}\NormalTok{ bb[}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{], }\AttributeTok{xmin =}\NormalTok{ bb[}\DecValTok{1}\NormalTok{,}\DecValTok{1}\NormalTok{], }\AttributeTok{xmax =}\NormalTok{ bb[}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{]))}
\end{Highlighting}
\end{Shaded}
\includegraphics{Haskell_files/figure-latex/unnamed-chunk-21-1.pdf}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{2}
\tightlist
\item
Download water features. The water features are first divided into
moving and stationary water. We will download the river layer from the
waterway key.
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{water }\OtherTok{\textless{}{-}} \FunctionTok{oe\_get}\NormalTok{(}
\AttributeTok{place =} \StringTok{"Lawrence, Kansas"}\NormalTok{, }
\AttributeTok{layer =} \StringTok{"lines"}\NormalTok{,}
\AttributeTok{query =} \StringTok{"SELECT * FROM lines WHERE waterway IN (\textquotesingle{}river\textquotesingle{})"}\NormalTok{,}
\AttributeTok{quiet =} \ConstantTok{TRUE}
\NormalTok{)}
\end{Highlighting}
\end{Shaded}
We divide the water into large and small waterways in the same way we
did with the road. We are interested in making the main river much
larger and the remaining waterways collectively smaller. The Kansas
river is the large feature in this map so, we pull it out first.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{Kansas\_river\_multi }\OtherTok{\textless{}{-}}\NormalTok{ water }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{filter}\NormalTok{(name }\SpecialCharTok{==} \StringTok{"Kansas River"}\NormalTok{) }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{st\_as\_sf}\NormalTok{() }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{st\_crop}\NormalTok{(}\AttributeTok{y =} \FunctionTok{c}\NormalTok{(}\AttributeTok{ymin =}\NormalTok{ bb[}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{], }\AttributeTok{ymax =}\NormalTok{ bb[}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{], }\AttributeTok{xmin =}\NormalTok{ bb[}\DecValTok{1}\NormalTok{,}\DecValTok{1}\NormalTok{], }\AttributeTok{xmax =}\NormalTok{ bb[}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{]))}
\end{Highlighting}
\end{Shaded}
\includegraphics{Haskell_files/figure-latex/unnamed-chunk-24-1.pdf}
After removing the Kansas river, we are left with a number of remaining
waterways that are stored as both linestrings and multilinestrings. We
need to download each of those data types individually.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{small\_water\_lines }\OtherTok{\textless{}{-}}\NormalTok{ water }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{filter}\NormalTok{(name }\SpecialCharTok{!=} \StringTok{"Kansas River"}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{st\_as\_sf}\NormalTok{() }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{st\_crop}\NormalTok{(}\AttributeTok{y =} \FunctionTok{c}\NormalTok{(}\AttributeTok{ymin =}\NormalTok{ bb[}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{], }\AttributeTok{ymax =}\NormalTok{ bb[}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{], }\AttributeTok{xmin =}\NormalTok{ bb[}\DecValTok{1}\NormalTok{,}\DecValTok{1}\NormalTok{], }\AttributeTok{xmax =}\NormalTok{ bb[}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{]))}
\end{Highlighting}
\end{Shaded}
\includegraphics{Haskell_files/figure-latex/unnamed-chunk-26-1.pdf}
The stationary water bodies are a subcategory under the key=natural and
the value=water. We ask for the extra column named water to be include
in our returned sf table. We can use that column to filter our the lakes
and reservours as local water bodies.
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# Request all water features using natural:water but also request the water tag be given it\textquotesingle{}s own column. }
\NormalTok{water\_body }\OtherTok{\textless{}{-}} \FunctionTok{oe\_get}\NormalTok{(}
\AttributeTok{place =} \StringTok{"Lawrence, Kansas"}\NormalTok{, }
\AttributeTok{layer =} \StringTok{"multipolygons"}\NormalTok{,}
\AttributeTok{query =} \StringTok{"SELECT * FROM multipolygons WHERE natural IN (\textquotesingle{}water\textquotesingle{})"}\NormalTok{,}
\AttributeTok{quiet =} \ConstantTok{TRUE}\NormalTok{,}
\AttributeTok{extra\_tags =} \FunctionTok{c}\NormalTok{(}\StringTok{"water"}\NormalTok{) }\CommentTok{\#give water it\textquotesingle{}s own column instead of clumping in supplimentary list}
\NormalTok{)}
\NormalTok{water\_body\_crop }\OtherTok{\textless{}{-}}\NormalTok{ water\_body }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{filter}\NormalTok{(water }\SpecialCharTok{==} \StringTok{\textquotesingle{}lake\textquotesingle{}} \SpecialCharTok{|}\NormalTok{ water }\SpecialCharTok{==} \StringTok{"reservoir"}\NormalTok{) }\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{st\_as\_sf}\NormalTok{() }
\end{Highlighting}
\end{Shaded}
\includegraphics{Haskell_files/figure-latex/unnamed-chunk-28-1.pdf}
\hypertarget{stack-downloaded-osm-layers-into-a-final-basemap.}{%
\subsubsection{Stack downloaded OSM layers into a final
basemap.}\label{stack-downloaded-osm-layers-into-a-final-basemap.}}
This is a special edit to manually shift the bounding box so that it
better centered Haskell University in the basemap. Most people will not
need this adjustment but may enjoy the ability to microadjust their
basemap.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{bbb }\OtherTok{\textless{}{-}}\NormalTok{ bb}
\NormalTok{bbb[}\DecValTok{1}\NormalTok{,}\DecValTok{1}\NormalTok{] }\OtherTok{\textless{}{-}}\NormalTok{ bbb[}\DecValTok{1}\NormalTok{,}\DecValTok{1}\NormalTok{] }\SpecialCharTok{{-}} \FloatTok{0.001}
\NormalTok{bbb[}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{] }\OtherTok{\textless{}{-}}\NormalTok{ bbb[}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{] }\SpecialCharTok{+} \FloatTok{0.001}
\NormalTok{bbb[}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{] }\OtherTok{\textless{}{-}}\NormalTok{ bbb[}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{] }\SpecialCharTok{{-}} \FloatTok{0.03}
\NormalTok{bbb[}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{] }\OtherTok{\textless{}{-}}\NormalTok{ bbb[}\DecValTok{2}\NormalTok{,}\DecValTok{2}\NormalTok{] }\SpecialCharTok{+} \FloatTok{0.001}
\NormalTok{xlimit }\OtherTok{\textless{}{-}}\NormalTok{ bbb[}\DecValTok{1}\NormalTok{,]}
\NormalTok{ylimit }\OtherTok{\textless{}{-}}\NormalTok{ bbb[}\DecValTok{2}\NormalTok{,] }
\NormalTok{xmid }\OtherTok{\textless{}{-}}\NormalTok{ xlimit[}\DecValTok{1}\NormalTok{] }\SpecialCharTok{+} \FunctionTok{diff}\NormalTok{(xlimit) }\SpecialCharTok{/} \DecValTok{2}
\NormalTok{ratio }\OtherTok{\textless{}{-}} \FunctionTok{diff}\NormalTok{(xlimit) }\SpecialCharTok{/} \FunctionTok{diff}\NormalTok{(ylimit)}
\end{Highlighting}
\end{Shaded}
This is a long plot that calls each of the plot layers in order from the
back to the front. There is a section at the end that crop, format, and
append the basemap.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{haskel\_basemap }\OtherTok{\textless{}{-}} \FunctionTok{ggplot}\NormalTok{() }\SpecialCharTok{+}
\CommentTok{\# plot moving water layers first}
\FunctionTok{geom\_sf}\NormalTok{(}\AttributeTok{data =}\NormalTok{ Kansas\_river\_multi, }\AttributeTok{alpha =}\NormalTok{ .}\DecValTok{8}\NormalTok{,}
\AttributeTok{size =} \DecValTok{3}\NormalTok{, }\AttributeTok{colour =}\NormalTok{ our\_blue) }\SpecialCharTok{+}
\FunctionTok{geom\_sf}\NormalTok{(}\AttributeTok{data =}\NormalTok{ small\_water\_lines, }\AttributeTok{alpha =}\NormalTok{ .}\DecValTok{8}\NormalTok{,}
\AttributeTok{size =} \FloatTok{0.5}\NormalTok{, }\AttributeTok{colour =}\NormalTok{ our\_blue) }\SpecialCharTok{+}
\CommentTok{\# Layer bodies of water over the moving water layers}
\FunctionTok{geom\_sf}\NormalTok{(}\AttributeTok{data =}\NormalTok{ water\_body\_crop, }\AttributeTok{alpha =} \DecValTok{1}\NormalTok{, }\AttributeTok{fill =}\NormalTok{ our\_blue, }\AttributeTok{size=}\DecValTok{0}\NormalTok{) }\SpecialCharTok{+}
\CommentTok{\# Plot small streets in the background with a light fade}
\FunctionTok{geom\_sf}\NormalTok{(}\AttributeTok{data =}\NormalTok{ small\_streets\_crop, }\AttributeTok{alpha =}\NormalTok{ .}\DecValTok{6}\NormalTok{, }
\AttributeTok{size =}\NormalTok{ .}\DecValTok{1}\NormalTok{, }\AttributeTok{colour =}\NormalTok{ our\_beige) }\SpecialCharTok{+}
\CommentTok{\# Layer large streets over the top of the small streets with a bold color.}
\FunctionTok{geom\_sf}\NormalTok{(}\AttributeTok{data =}\NormalTok{ streets\_crop, }\AttributeTok{alpha =}\NormalTok{ .}\DecValTok{8}\NormalTok{, }
\AttributeTok{size =}\NormalTok{ .}\DecValTok{4}\NormalTok{, }\AttributeTok{colour =}\NormalTok{ our\_yellow ) }\SpecialCharTok{+}
\CommentTok{\# Layer Haskell university property polygon in the foreground}
\FunctionTok{geom\_sf}\NormalTok{( }\AttributeTok{data=}\NormalTok{haskell\_poly, }\AttributeTok{color=}\NormalTok{our\_yellow, }\AttributeTok{size=}\DecValTok{1}\NormalTok{) }\SpecialCharTok{+}
\CommentTok{\# Fill Haskell property polygon with Haskell logo}
\FunctionTok{geom\_sf\_pattern}\NormalTok{( }
\AttributeTok{data =}\NormalTok{ haskell\_poly,}
\AttributeTok{size=}\DecValTok{0}\NormalTok{,}
\AttributeTok{pattern =} \StringTok{\textquotesingle{}image\textquotesingle{}}\NormalTok{,}
\AttributeTok{pattern\_type =} \StringTok{\textquotesingle{}tile\textquotesingle{}}\NormalTok{,}
\AttributeTok{pattern\_scale =} \FloatTok{0.06}\NormalTok{,}
\AttributeTok{pattern\_filename =}\NormalTok{ seamless\_image\_filenames}
\NormalTok{ ) }\SpecialCharTok{+}
\CommentTok{\# set limits on final figure }
\FunctionTok{coord\_sf}\NormalTok{(}\AttributeTok{ylim =}\NormalTok{ ylimit, }\AttributeTok{xlim =}\NormalTok{ xlimit, }\AttributeTok{expand =} \ConstantTok{TRUE}\NormalTok{) }\SpecialCharTok{+}
\CommentTok{\# adding labels}
\FunctionTok{annotate}\NormalTok{(}\AttributeTok{geom =} \StringTok{"text"}\NormalTok{, }\AttributeTok{y =}\NormalTok{ bbb[}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{]}\SpecialCharTok{+} \FloatTok{0.013}\NormalTok{, }\AttributeTok{x =}\NormalTok{ xmid, }
\AttributeTok{label =} \StringTok{"Haskell Indian Nations University"}\NormalTok{, }\AttributeTok{size =} \DecValTok{12}\NormalTok{, }\AttributeTok{colour =}\NormalTok{ our\_beige}
\NormalTok{ ) }\SpecialCharTok{+}
\FunctionTok{annotate}\NormalTok{(}\AttributeTok{geom =} \StringTok{"errorbarh"}\NormalTok{, }\AttributeTok{xmin =}\NormalTok{ xlimit[}\DecValTok{1}\NormalTok{], }\AttributeTok{xmax =}\NormalTok{ xlimit[}\DecValTok{2}\NormalTok{], }\AttributeTok{y =}\NormalTok{ bbb[}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{]}\SpecialCharTok{+} \FloatTok{0.005}\NormalTok{, }
\AttributeTok{height =} \DecValTok{0}\NormalTok{, }\AttributeTok{size =} \FloatTok{0.5}\NormalTok{, }\AttributeTok{colour =}\NormalTok{ our\_beige) }\SpecialCharTok{+}
\FunctionTok{annotate}\NormalTok{(}\AttributeTok{geom =} \StringTok{"text"}\NormalTok{, }\AttributeTok{y =}\NormalTok{ bbb[}\DecValTok{2}\NormalTok{,}\DecValTok{1}\NormalTok{]}\SpecialCharTok{+} \FloatTok{0.0001}\NormalTok{, }\AttributeTok{x =}\NormalTok{ xmid,}
\AttributeTok{label =} \StringTok{"38°93\textquotesingle{}88}\SpecialCharTok{\textbackslash{}"}\StringTok{N 95°23\textquotesingle{}29}\SpecialCharTok{\textbackslash{}"}\StringTok{W"}\NormalTok{, }\AttributeTok{size =} \DecValTok{6}\NormalTok{,}
\AttributeTok{colour =}\NormalTok{ our\_beige) }\SpecialCharTok{+}
\CommentTok{\# clean out unused elements and set background color}
\FunctionTok{theme\_void}\NormalTok{() }\SpecialCharTok{+}
\FunctionTok{theme}\NormalTok{(}\AttributeTok{panel.background =} \FunctionTok{element\_rect}\NormalTok{(}\AttributeTok{fill =}\NormalTok{ our\_purple),}
\AttributeTok{plot.background =} \FunctionTok{element\_rect}\NormalTok{(}\AttributeTok{fill =} \ConstantTok{NA}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
\includegraphics{All_roads_lead_to_Haskell.png}
\hypertarget{save-the-basemap-in-high-resolution-print}{%
\subsubsection{Save the basemap in high resolution
print}\label{save-the-basemap-in-high-resolution-print}}
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{ggsave}\NormalTok{(haskel\_basemap, }\AttributeTok{filename =} \StringTok{"All\_roads\_lead\_to\_Haskell.png"}\NormalTok{, }\AttributeTok{height =} \DecValTok{11}\NormalTok{, }\AttributeTok{width=}\FloatTok{8.5}\NormalTok{, }
\AttributeTok{units=}\StringTok{"in"}\NormalTok{, }\AttributeTok{dpi=}\DecValTok{600}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\hypertarget{mount-the-climate-dataset}{%
\subsection{Mount the climate dataset}\label{mount-the-climate-dataset}}
This dataset is way too big to download to a particular machine.
Instead, you mount to the analysis ready data cube (i.e.~netCDF) and
only download the subsetted data that you want to pull.
\includegraphics{climate_grid.png} 1. We calculate the center point for
measuring to the nearest climate data point.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{haskel\_centroid }\OtherTok{\textless{}{-}} \FunctionTok{st\_coordinates}\NormalTok{(}\FunctionTok{st\_centroid}\NormalTok{(haskell\_poly))}
\NormalTok{lat\_pt }\OtherTok{\textless{}{-}}\NormalTok{ haskel\_centroid[}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{]}
\NormalTok{lon\_pt }\OtherTok{\textless{}{-}}\NormalTok{ haskel\_centroid[}\DecValTok{1}\NormalTok{,}\DecValTok{1}\NormalTok{]}
\end{Highlighting}
\end{Shaded}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{1}
\tightlist
\item
Connect to the web server and activate the proper data dimensions.
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{web\_link }\OtherTok{=} \StringTok{"https://cida.usgs.gov/thredds/dodsC/macav2metdata\_daily\_future"}
\CommentTok{\# Change to "https://cida.usgs.gov/thredds/catalog.html?dataset=cida.usgs.gov/macav2metdata\_daily\_historical" for historical data. }
\NormalTok{src }\OtherTok{\textless{}{-}}\NormalTok{ tidync}\SpecialCharTok{::}\FunctionTok{tidync}\NormalTok{(web\_link)}
\NormalTok{lons }\OtherTok{\textless{}{-}}\NormalTok{ src }\SpecialCharTok{\%\textgreater{}\%} \FunctionTok{activate}\NormalTok{(}\StringTok{"D2"}\NormalTok{) }\SpecialCharTok{\%\textgreater{}\%} \FunctionTok{hyper\_tibble}\NormalTok{()}
\NormalTok{lats }\OtherTok{\textless{}{-}}\NormalTok{ src }\SpecialCharTok{\%\textgreater{}\%} \FunctionTok{activate}\NormalTok{(}\StringTok{"D1"}\NormalTok{) }\SpecialCharTok{\%\textgreater{}\%} \FunctionTok{hyper\_tibble}\NormalTok{()}
\end{Highlighting}
\end{Shaded}
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\setcounter{enumi}{2}
\tightlist
\item
Search through the database of climate prediction points to find which
one is closest to our centroid. We then spatially project that chosen
pt into an sf object.
\end{enumerate}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{known\_lon }\OtherTok{\textless{}{-}}\NormalTok{ lons[}\FunctionTok{which}\NormalTok{(}\FunctionTok{abs}\NormalTok{(lons}\SpecialCharTok{{-}}\NormalTok{lon\_pt)}\SpecialCharTok{==}\FunctionTok{min}\NormalTok{(}\FunctionTok{abs}\NormalTok{(lons}\SpecialCharTok{{-}}\NormalTok{lon\_pt))),]}
\NormalTok{known\_lat }\OtherTok{\textless{}{-}}\NormalTok{ lats[}\FunctionTok{which}\NormalTok{(}\FunctionTok{abs}\NormalTok{(lats}\SpecialCharTok{{-}}\NormalTok{lat\_pt)}\SpecialCharTok{==}\FunctionTok{min}\NormalTok{(}\FunctionTok{abs}\NormalTok{(lats}\SpecialCharTok{{-}}\NormalTok{lat\_pt))),]}
\NormalTok{chosen\_pt }\OtherTok{\textless{}{-}} \FunctionTok{st\_as\_sf}\NormalTok{(}\FunctionTok{cbind}\NormalTok{(known\_lon,known\_lat), }\AttributeTok{coords =} \FunctionTok{c}\NormalTok{(}\StringTok{"lon"}\NormalTok{, }\StringTok{"lat"}\NormalTok{), }\AttributeTok{crs =} \StringTok{"WGS84"}\NormalTok{, }\AttributeTok{agr =} \StringTok{"constant"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
\includegraphics{grid_match.png}
\hypertarget{find-and-transfer-climate-data-from-an-api}{%