-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGettingStarted_Bering10K_ROMSNPZ.tex
executable file
·2570 lines (2135 loc) · 167 KB
/
GettingStarted_Bering10K_ROMSNPZ.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
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\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}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
pdftitle={Getting Started with Bering10K Level 2 \& 3 indices},
pdfauthor={K. Holsman and K. Aydin (Tutorial), A. Hermann, K. Kearney, W. Cheng, I. Ortiz (Bering10K)},
hidelinks,
pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage[margin=1in]{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}}}}
\usepackage{longtable,booktabs,array}
\usepackage{calc} % for calculating minipage widths
% Correct order of tables after \paragraph or \subparagraph
\usepackage{etoolbox}
\makeatletter
\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{}
\makeatother
% Allow footnotes in longtable head/foot
\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}}
\makesavenoteenv{longtable}
\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}{-\maxdimen} % remove section numbering
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{colortbl}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage{makecell}
\usepackage{xcolor}
\ifluatex
\usepackage{selnolig} % disable illegal ligatures
\fi
\title{Getting Started with Bering10K Level 2 \& 3 indices}
\author{K. Holsman and K. Aydin (Tutorial), A. Hermann, K. Kearney, W.
Cheng, I. Ortiz (Bering10K)}
\date{}
\begin{document}
\maketitle
{
\setcounter{tocdepth}{2}
\tableofcontents
}
\begin{figure}
\centering
\includegraphics[width=1\textwidth,height=\textheight]{Figs/logos2.jpg}
\caption{The ACLIM2 Repository
\href{https://github.com/kholsman/ACLIM2}{\textbf{github.com/kholsman/ACLIM2}}
is maintained by \textbf{\href{mailto:[email protected]}{Kirstin
Holsman}}, Alaska Fisheries Science Center, NOAA Fisheries, Seattle WA.
Multiple programs and projects have supported the production and sharing
of the suite of Bering10K hindcasts and projections. \emph{Last updated:
Apr 28, 2022}}
\end{figure}
\hypertarget{overview}{%
\section{1. Overview}\label{overview}}
This repository contains R code and Rdata files for working with
netcdf-format data generated from the
\href{https://beringnpz.github.io/roms-bering-sea}{\textbf{downscaled
ROMSNPZ modeling}} of the ROMSNPZ Bering Sea Ocean Modeling team; Drs.
Hermann, Cheng, Kearney, Pilcher,Ortiz, and Aydin. The code and R
resources described in this tutorial are publicly available through the
\href{https://github.com/kholsman/ACLIM2}{\textbf{ACLIM2 github
repository}} maintained by
\href{mailto:[email protected]}{Kirstin Holsman} as part of
NOAA's
\href{https://www.fisheries.noaa.gov/alaska/ecosystems/alaska-climate-integrated-modeling-project}{\textbf{ACLIM
project}} for the Bering Sea. \emph{See
\href{https://www.frontiersin.org/articles/10.3389/fmars.2019.00775/full}{Hollowed
et al.~2020} for more information about the ACLIM project.}
\hypertarget{resources}{%
\subsection{1.1. Resources}\label{resources}}
We \textbf{strongly recommend} reviewing the following documentation
before using the data in order to understand the origin of the indices
and their present level of skill and validation, which varies
considerably across indices and in space and time:
\begin{itemize}
\item
\href{https://zenodo.org/record/4586950/files/Bering10K_dataset_documentation.pdf}{\textbf{The
Bering10K Dataset documentation (pdf)}}: A pdf describing the dataset,
including full model descriptions, inputs for specific results, and a
tutorial for working directly with the ROMS native grid (Level 1
outputs).
\item
\href{https://zenodo.org/record/4586950/files/Bering10K_simulation_variables.xlsx?download=1}{\textbf{Bering10K
Simulaton Variables (xlsx)}}: A spreadsheet listing all simulations
and the archived output variables associated with each, updated
periodically as new simulations are run or new variables are made
available.
\item
A
\href{https://beringnpz.github.io/roms-bering-sea/B10K-dataset-docs/}{\textbf{collection}}
of Bering10K ROMSNPZ model documentation (including the above files)
is maintained by \href{mailto:[email protected]}{Kelly Kearney}
and will be regularly updated with new documentation and publications.
\end{itemize}
\hypertarget{guildlines-for-use-and-citation-of-the-data}{%
\subsection{1.2 Guildlines for use and citation of the
data}\label{guildlines-for-use-and-citation-of-the-data}}
The data described here are published and publicly available for use,
except as explicitly noted. However, for novel uses of the data, it is
\textbf{strongly recommended} that you consult with and consider
including at least one author from the ROMSNPZ team (Drs. Hermann,
Cheng, Kearney, Pilcher, Aydin, Ortiz). There are multiple spatial and
temporal caveats that are best described in discussions with the authors
of these data and inclusion as co-authors will facilitate appropriate
application and interpretation.
\hypertarget{the-bering-10k-model-v.-h16-with-10-depth-layers}{%
\subsubsection{1.2.1. The Bering 10K Model (v. H16) with 10 depth
layers}\label{the-bering-10k-model-v.-h16-with-10-depth-layers}}
The H16 model is the original BSIERP era 10 depth layer model with a 10
Km grid. This version was used in ACLIM1.0 to dynamically downscaled 3
global scale general circulation models (GCMs) under two CMIP
(\href{https://www.wcrp-climate.org/wgcm-cmip}{Coupled Model
Intercomparison Project}{]}) phase 5 representative carbon pathways
(RCP): RCP 4.5 or ``moderate global carbon mitigation'' and RCP 8.5
``high baseline global carbon emissions''. Details of the model and
projections can be found in:
\begin{itemize}
\item
\textbf{Hindcast (1979-2012; updated to 2018 during ACLIM 1.0):}
Hermann, A. J., G. A. Gibson, N. A. Bond, E. N. Curchitser, K.
Hedstrom, W. Cheng, M. Wang, E. D. Cokelet, P. J. Stabeno, and K.
Aydin. 2016. Projected future biophysical states of the Bering Sea.
Deep Sea Research Part II: Topical Studies in Oceanography 134:30--47.
\href{http://dx.doi.org/10.1016/j.dsr2.2015.11.001}{doi:10.1016/j.dsr2.2015.11.001}
\item
\textbf{Projections of the H16 10 layer model using CMIP5 scenarios:}
Hermann, A. J., G. A. Gibson, W. Cheng, I. Ortiz, K. Aydin, M. Wang,
A. B. Hollowed, K. K. Holsman, and S. Sathyendranath. 2019. Projected
biophysical conditions of the Bering Sea to 2100 under multiple
emission scenarios. ICES Journal of Marine Science 76:1280--1304.
\href{https://academic.oup.com/icesjms/article/76/5/1280/5477847?login=true}{doi:10.1093/icesjms/fsz043}
\end{itemize}
\hypertarget{the-bering-10k-model-v.-k20-with-30-depth-layers-and-other-advancements}{%
\subsubsection{1.2.2. The Bering 10K Model (v. K20) with 30 depth layers
and other
advancements}\label{the-bering-10k-model-v.-k20-with-30-depth-layers-and-other-advancements}}
The Bering10K model was subsequently updated by Kearney et al.~2020 (30
layer and other NPZ updates) and Pilcher et al .2019 (OA and O2
dynamics) and this version is used for the projections in ACLIM2.0 under
the most recent CMIP phase 6.
\begin{itemize}
\item
\textbf{Hindcast (1979-2020 hindcast with OA dynamics used in ACLIM
2.0):}
Kearney, K., A. Hermann, W. Cheng, I. Ortiz, and K. Aydin. 2020. A
coupled pelagic-benthic-sympagic biogeochemical model for the Bering
Sea: documentation and validation of the BESTNPZ model (v2019.08.23)
within a high-resolution regional ocean model. Geoscientific Model
Development 13:597--650.
\href{https://doi.org/10.5194/gmd-13-597-2020}{doi:10.5194/gmd-13-597-2020}
Pilcher, D. J., D. M. Naiman, J. N. Cross, A. J. Hermann, S. A.
Siedlecki, G. A. Gibson, and J. T. Mathis. 2019. Modeled Effect of
Coastal Biogeochemical Processes, Climate Variability, and Ocean
Acidification on Aragonite Saturation State in the Bering Sea.
Frontiers in Marine Science 5:1--18.
\href{https://www.frontiersin.org/articles/10.3389/fmars.2018.00508/full}{doi:
10.3389/fmars.2018.00508}
\end{itemize}
\hypertarget{installation}{%
\section{2. Installation}\label{installation}}
\hypertarget{minimal-install}{%
\subsection{2.1 Minimal Install}\label{minimal-install}}
A minimal R install (for Sections 3.2 and 4.1 only) requires installing
the \texttt{ncdf4}, \texttt{devtools} libraries (available on CRAN), and
\texttt{thredds} R library through its github site:
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{install.packages}\NormalTok{(}\StringTok{"devtools"}\NormalTok{)}
\FunctionTok{install.packages}\NormalTok{(}\StringTok{"ncdf4"}\NormalTok{)}
\NormalTok{ devtools}\SpecialCharTok{::}\FunctionTok{install\_github}\NormalTok{(}\StringTok{"bocinsky/thredds"}\NormalTok{)}
\end{Highlighting}
\end{Shaded}
Note that each of these has multiple sub-dependent libraries and may
take several minutes to install. \emph{The full install below includes
installation of these packages, so you don't need to perform this step
if you perform the full install.}
\hypertarget{full-install}{%
\subsection{2.2 Full install}\label{full-install}}
The full install consists of the full directory structure in the ACLIM2
Repo; this includes a substantial set of resource files including shape
files and data for performing Bering Sea spatial analysis in R. This
will eventually become a library package, but currently requires manual
downloading of the full directory structure from github. The full
install may take up to \textbf{1GB of disk space} (initial download
\textasciitilde12MB).
\hypertarget{option-1-clone-the-repository}{%
\subsubsection{Option 1: Clone the
repository}\label{option-1-clone-the-repository}}
If you have git installed and can work with it, this is the preferred
method as it preserves all directory structure and can aid in future
updating. Use this from a \textbf{terminal command line, not in R}, to
clone the full ACLIM2 directory and subdirectories:
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{git}\NormalTok{ clone https://github.com/kholsman/ACLIM2.git}
\end{Highlighting}
\end{Shaded}
\hypertarget{option-2-download-the-repository}{%
\subsubsection{Option 2: Download the
repository}\label{option-2-download-the-repository}}
Download the full zip archive directly from the
\href{https://github.com/kholsman/ACLIM2}{\textbf{ACLIM2 Repo}} using
this link:
\href{https://github.com/kholsman/ACLIM2/archive/main.zip}{\textbf{https://github.com/kholsman/ACLIM2/archive/main.zip}},
and unzip its contents while preserving directory structure.
\textbf{\emph{Important:}} if downloading from zip, please
\textbf{rename the root folder} from \texttt{ACLIM2-main} (in the
zipfile) to \texttt{ACLIM2} (name used in cloned copies) after
unzipping, for consistency in the following examples.
\hypertarget{option-3-use-r-to-download-the-repository}{%
\subsubsection{Option 3: Use R to download the
repository}\label{option-3-use-r-to-download-the-repository}}
This set of commands, run within R, downloads the ACLIM2 repository and
unpacks it, with the ACLIM2 directory structrue being located in the
specified \texttt{download\_path}. This also performs the folder
renaming mentioned in Option 2.
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# Specify the download directory}
\NormalTok{ main\_nm }\OtherTok{\textless{}{-}} \StringTok{"ACLIM2"}
\CommentTok{\# Note: Edit download\_path for preference}
\NormalTok{ download\_path }\OtherTok{\textless{}{-}} \FunctionTok{path.expand}\NormalTok{(}\StringTok{"\textasciitilde{}/desktop"}\NormalTok{)}
\NormalTok{ dest\_fldr }\OtherTok{\textless{}{-}} \FunctionTok{file.path}\NormalTok{(download\_path,main\_nm)}
\NormalTok{ url }\OtherTok{\textless{}{-}} \StringTok{"https://github.com/kholsman/ACLIM2/archive/main.zip"}
\NormalTok{ dest\_file }\OtherTok{\textless{}{-}} \FunctionTok{file.path}\NormalTok{(download\_path,}\FunctionTok{paste0}\NormalTok{(main\_nm,}\StringTok{".zip"}\NormalTok{))}
\FunctionTok{download.file}\NormalTok{(}\AttributeTok{url=}\NormalTok{url, }\AttributeTok{destfile=}\NormalTok{dest\_file)}
\CommentTok{\# unzip the .zip file}
\FunctionTok{setwd}\NormalTok{(download\_path)}
\FunctionTok{unzip}\NormalTok{ (dest\_file, }\AttributeTok{exdir =} \StringTok{"./"}\NormalTok{,}\AttributeTok{overwrite =}\NormalTok{ T)}
\CommentTok{\#rename the unzipped folder from ACLIM2{-}main to ACLIM2}
\FunctionTok{file.rename}\NormalTok{(}\FunctionTok{paste0}\NormalTok{(main\_nm,}\StringTok{"{-}main"}\NormalTok{), main\_nm)}
\FunctionTok{setwd}\NormalTok{(main\_nm)}
\end{Highlighting}
\end{Shaded}
\hypertarget{set-up-envionment-and-get-shapefiles-full-install}{%
\subsection{2.3 Set up envionment and get shapefiles (full
install)}\label{set-up-envionment-and-get-shapefiles-full-install}}
The remainder of this tutorial was tested in RStudio. This may work in
``plain'' R, but is untested. If you are using RStudio, open
\texttt{ACLIM2.Rproj} in Rstudio. If using R, use \texttt{setwd()} to
get to the main ACLIM2 directory. Then run:
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# {-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
\CommentTok{\# SETUP WORKSPACE}
\NormalTok{ tmstp }\OtherTok{\textless{}{-}} \FunctionTok{format}\NormalTok{(}\FunctionTok{Sys.time}\NormalTok{(), }\StringTok{"\%Y\_\%m\_\%d"}\NormalTok{)}
\NormalTok{ main }\OtherTok{\textless{}{-}} \FunctionTok{getwd}\NormalTok{() }\CommentTok{\#"\textasciitilde{}/GitHub\_new/ACLIM2}
\FunctionTok{suppressWarnings}\NormalTok{(}\FunctionTok{source}\NormalTok{(}\StringTok{"R/make.R"}\NormalTok{))}
\FunctionTok{suppressWarnings}\NormalTok{(}\FunctionTok{source}\NormalTok{(}\StringTok{"R/sub\_scripts/load\_maps.R"}\NormalTok{)) }\CommentTok{\# skip this for faster load}
\CommentTok{\# {-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
\end{Highlighting}
\end{Shaded}
The \texttt{R/make.R} command will install missing libraries (including
those listed under the minimal install) and download and process
multiple shapefiles for geographic analysis, it takes several minutes
depending on bandwidth.
\hypertarget{get-romsnpz-data}{%
\section{3. Get ROMSNPZ data}\label{get-romsnpz-data}}
The ROMSNPZ team has been working with
\href{mailto:[email protected]}{Roland Schweitzer} and
\href{mailto:[email protected]}{Peggy Sullivan} to develop the
ACLIM Live Access Server (LAS) to publicly host the published CMIP5
hindcasts and downscaled projections. This server is in beta testing
phase and can be accessed at the following links:
\begin{itemize}
\item
\href{https://data.pmel.noaa.gov/aclim/las/}{LAS custom ROMSNPZ data
exploration, query, mapping, and plotting tool}
\item
\href{https://data.pmel.noaa.gov/aclim/erddap/}{ERDAPP ACLIM data
access tool}
\item
\href{https://data.pmel.noaa.gov/aclim/thredds/}{THREDDS ACLIM direct
data access}
\end{itemize}
Currently, the public data includes hindcasts \& CMIP5 climate
projections.
\hypertarget{available-data}{%
\subsection{3.1 Available data}\label{available-data}}
\begin{itemize}
\tightlist
\item
\texttt{Level1} : (full grid, native ROMS coordinates, full suite of
variables).
\item
\texttt{Level2} : (full grid, rotated to lat lon from the native
ROMSNPZ grid, weekly averages)
\begin{itemize}
\tightlist
\item
\texttt{Bottom\ 5m} : subset of variables from the bottom 5 m of the
water column
\item
\texttt{Surface\ 5m} : subset of variables for the surface 5 m of
the water column
\item
\texttt{Integrated}: watercolumn integrated averages or totals for
various variables
\end{itemize}
\item
\texttt{Level3}: two post-processed datasets
\begin{itemize}
\tightlist
\item
\texttt{ACLIMsurveyrep-x.nc.}: Survey replicated (variables
``sampled'' at the average location and date that each groundfish
survey is sampled)\emph{(Note that the resampling stations need to
be removed before creating bottom temperature maps)}\\
\item
\texttt{ACLIMregion-xnc.}:weekly variables averaged for each survey
strata \emph{(Note that area (km2) weighting should be used to
combine values across multiple strata)}
\end{itemize}
\end{itemize}
For all files the general naming convention of the folders is:
\texttt{B10K-{[}ROMSNPZ\ version{]}\_{[}CMIP{]}\_{[}GCM{]}\_{[}carbon\ scenario{]}}.
For example, the CMIP5 set of indices was downscaled using the H16
(Hermann et al.~2016) version of the ROMSNPZ. Three models were used to
force boundary conditions( MIROC, CESM, and GFDL) under 2 carbon
scenarios RCP 8.5 and RCP 4.5. So to see an individual trajectory we
might look in the level3 (timeseries indices) folder under
\texttt{B10K-H16\_CMIP5\_CESM\_rcp45}, which would be the B10K version
H16 of the CMIP5 CESM model under RCP4.5.
\hypertarget{access-using-minimal-installation}{%
\subsection{3.2 Access using minimal
installation}\label{access-using-minimal-installation}}
The \href{https://data.pmel.noaa.gov/aclim/thredds/}{ACLIM Thredds
server} provides a directory structure and filenames/paths for
individual hindcasts and projections. The latest hindcast, using the
naming scheme described above, is \texttt{B10K-K20\_CORECFS}. Clicking
through the directory shows organization by Level (Levels 1-3), possibly
a subdirectory for variable type (depends on Level), then finally a
catalog page with metadata and the OPENDAP address.
\begin{figure}
\centering
\includegraphics[width=1\textwidth,height=\textheight]{Figs/catalog.jpg}
\caption{Thredds Catalog page.}
\end{figure}
The OPENDAP address (ending in .nc) is used to open a connection between
R and the nc files associated with that data:
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# Only required libraries for direct extraction {-} works in plain R}
\FunctionTok{library}\NormalTok{(ncdf4)}
\FunctionTok{library}\NormalTok{(thredds) }
\CommentTok{\# Note: Still ironing out inconsistencies in naming scheme for datasets {-}}
\CommentTok{\# browse to metadata on thredds server to check current names.}
\CommentTok{\# PMEL thredds server (for all available data)}
\NormalTok{ url\_base }\OtherTok{\textless{}{-}} \StringTok{"https://data.pmel.noaa.gov/aclim/thredds/"}
\CommentTok{\# List available runs for whole server}
\FunctionTok{tds\_list\_datasets}\NormalTok{(url\_base)}
\CommentTok{\# Dataset address for hindcast Level2 data}
\NormalTok{ dataset }\OtherTok{\textless{}{-}} \StringTok{"B10K{-}K20\_CORECFS/Level2.html"}
\CommentTok{\# List available data for Level2 hindcast}
\FunctionTok{tds\_list\_datasets}\NormalTok{(}\FunctionTok{paste}\NormalTok{(url\_base,dataset,}\AttributeTok{sep=}\StringTok{""}\NormalTok{))}
\CommentTok{\# Opendap address for bottom 5 meter layer}
\NormalTok{ opendap }\OtherTok{\textless{}{-}} \StringTok{"dodsC/Level2/B10K{-}K20\_CORECFS\_bottom5m.nc"}
\CommentTok{\# Open ncdf4 connection with dataset}
\NormalTok{ nc\_handle }\OtherTok{\textless{}{-}} \FunctionTok{nc\_open}\NormalTok{(}\FunctionTok{paste}\NormalTok{(url\_base,opendap,}\AttributeTok{sep=}\StringTok{""}\NormalTok{)) }
\CommentTok{\# Show metadata from this dataset}
\NormalTok{ nc\_handle}
\CommentTok{\# Close the connection}
\FunctionTok{nc\_close}\NormalTok{(nc\_handle)}
\end{Highlighting}
\end{Shaded}
\hypertarget{access-using-aclim-package}{%
\subsection{3.3 Access using ACLIM
package}\label{access-using-aclim-package}}
The below code will extract variables from the Level 2 and Level 3
netcdf files (\texttt{.nc}) and save them as compressed \texttt{.Rdata}
files on your local Data/in/Newest/Rdata folder.
\hypertarget{setup-up-the-r-worksace}{%
\subsubsection{3.3.1 Setup up the R
worksace}\label{setup-up-the-r-worksace}}
First let's get the workspace set up, will we step through an example
downloading the hindcast and a single projection (CMIP5 MIROC rcp8.5)
but you can loop the code below to download the full set of CMIP5
projections.
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# {-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
\CommentTok{\# SETUP WORKSPACE}
\CommentTok{\# rm(list=ls())}
\NormalTok{ tmstp }\OtherTok{\textless{}{-}} \FunctionTok{format}\NormalTok{(}\FunctionTok{Sys.time}\NormalTok{(), }\StringTok{"\%Y\_\%m\_\%d"}\NormalTok{)}
\NormalTok{ main }\OtherTok{\textless{}{-}} \FunctionTok{getwd}\NormalTok{() }\CommentTok{\#"\textasciitilde{}/GitHub\_new/ACLIM2}
\FunctionTok{source}\NormalTok{(}\StringTok{"R/make.R"}\NormalTok{)}
\CommentTok{\# {-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
\end{Highlighting}
\end{Shaded}
Let's take a look at the available online datasets:
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# preview the datasets on the server:}
\NormalTok{ url\_list }\OtherTok{\textless{}{-}} \FunctionTok{tds\_list\_datasets}\NormalTok{(}\AttributeTok{thredds\_url =}\NormalTok{ ACLIM\_data\_url)}
\CommentTok{\#display the full set of datasets:}
\FunctionTok{cat}\NormalTok{(}\FunctionTok{paste}\NormalTok{(url\_list}\SpecialCharTok{$}\NormalTok{dataset,}\StringTok{"}\SpecialCharTok{\textbackslash{}n}\StringTok{"}\NormalTok{))}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## Constants/
## B10K-H16_CMIP5_CESM_BIO_rcp85/
## B10K-H16_CMIP5_CESM_rcp45/
## B10K-H16_CMIP5_CESM_rcp85/
## B10K-H16_CMIP5_GFDL_BIO_rcp85/
## B10K-H16_CMIP5_GFDL_rcp45/
## B10K-H16_CMIP5_GFDL_rcp85/
## B10K-H16_CMIP5_MIROC_rcp45/
## B10K-H16_CMIP5_MIROC_rcp85/
## B10K-H16_CORECFS/
## B10K-K20_CORECFS/
## files/
\end{verbatim}
\hypertarget{download-level-2-data}{%
\subsubsection{3.3.2 Download Level 2
data}\label{download-level-2-data}}
First we will explore the Level 2 bottom temperature data on the
\href{https://data.pmel.noaa.gov/aclim/thredds/}{ACLIM Thredds server}
using the H16 hindcast and the H16 (CMIP5) projection for MIROC under
rcp8.5. The first step is to get the data urls:
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# define the simulation to download:}
\NormalTok{ cmip }\OtherTok{\textless{}{-}} \StringTok{"CMIP5"} \CommentTok{\# Coupled Model Intercomparison Phase}
\NormalTok{ GCM }\OtherTok{\textless{}{-}} \StringTok{"MIROC"} \CommentTok{\# Global Circulation Model}
\NormalTok{ rcp }\OtherTok{\textless{}{-}} \StringTok{"rcp85"} \CommentTok{\# future carbon scenario}
\NormalTok{ mod }\OtherTok{\textless{}{-}} \StringTok{"B10K{-}H16"} \CommentTok{\# ROMSNPZ model}
\NormalTok{ hind }\OtherTok{\textless{}{-}} \StringTok{"CORECFS"} \CommentTok{\# Hindcast}
\CommentTok{\# define the projection simulation:}
\NormalTok{ proj }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(mod,}\StringTok{"\_"}\NormalTok{,cmip,}\StringTok{"\_"}\NormalTok{,GCM,}\StringTok{"\_"}\NormalTok{,rcp)}
\NormalTok{ hind }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(mod,}\StringTok{"\_"}\NormalTok{,hind)}
\CommentTok{\# get the url for the projection and hindcast datasets:}
\NormalTok{ proj\_url }\OtherTok{\textless{}{-}}\NormalTok{ url\_list[url\_list}\SpecialCharTok{$}\NormalTok{dataset }\SpecialCharTok{==} \FunctionTok{paste0}\NormalTok{(proj,}\StringTok{"/"}\NormalTok{),]}\SpecialCharTok{$}\NormalTok{path}
\NormalTok{ hind\_url }\OtherTok{\textless{}{-}}\NormalTok{ url\_list[url\_list}\SpecialCharTok{$}\NormalTok{dataset }\SpecialCharTok{==} \FunctionTok{paste0}\NormalTok{(hind,}\StringTok{"/"}\NormalTok{),]}\SpecialCharTok{$}\NormalTok{path}
\CommentTok{\# preview the projection and hindcast data and data catalogs (Level 1, 2, and 3):}
\NormalTok{ proj\_datasets }\OtherTok{\textless{}{-}} \FunctionTok{tds\_list\_datasets}\NormalTok{(}\AttributeTok{thredds\_url =}\NormalTok{ proj\_url)}
\NormalTok{ hind\_datasets }\OtherTok{\textless{}{-}} \FunctionTok{tds\_list\_datasets}\NormalTok{(}\AttributeTok{thredds\_url =}\NormalTok{ hind\_url)}
\CommentTok{\# get url for the projection and hindcast Level 2 and Level 3 catalogs}
\NormalTok{ proj\_l2\_cat }\OtherTok{\textless{}{-}}\NormalTok{ proj\_datasets[proj\_datasets}\SpecialCharTok{$}\NormalTok{dataset }\SpecialCharTok{==} \StringTok{"Level 2/"}\NormalTok{,]}\SpecialCharTok{$}\NormalTok{path}
\NormalTok{ proj\_l3\_cat }\OtherTok{\textless{}{-}}\NormalTok{ proj\_datasets[proj\_datasets}\SpecialCharTok{$}\NormalTok{dataset }\SpecialCharTok{==} \StringTok{"Level 3/"}\NormalTok{,]}\SpecialCharTok{$}\NormalTok{path}
\NormalTok{ hind\_l2\_cat }\OtherTok{\textless{}{-}}\NormalTok{ hind\_datasets[hind\_datasets}\SpecialCharTok{$}\NormalTok{dataset }\SpecialCharTok{==} \StringTok{"Level 2/"}\NormalTok{,]}\SpecialCharTok{$}\NormalTok{path}
\NormalTok{ hind\_l3\_cat }\OtherTok{\textless{}{-}}\NormalTok{ hind\_datasets[hind\_datasets}\SpecialCharTok{$}\NormalTok{dataset }\SpecialCharTok{==} \StringTok{"Level 3/"}\NormalTok{,]}\SpecialCharTok{$}\NormalTok{path}
\NormalTok{ hind\_l2\_cat}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## [1] "https://data.pmel.noaa.gov/aclim/thredds/B10K-H16_CORECFS/Level2.html"
\end{verbatim}
Now that we have the URLs let's take a look at the available Level2
datasets:
\begin{itemize}
\tightlist
\item
\texttt{Bottom\ 5m} : bottom water temperature at 5 meters
\item
\texttt{Surface\ 5m} : surface water temperature in the first 5 meters
\item
\texttt{Integrated} : Integrated water column averages for various NPZ
variables
\end{itemize}
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# preview the projection and hindcast Level 2 datasets:}
\NormalTok{ proj\_l2\_datasets }\OtherTok{\textless{}{-}} \FunctionTok{tds\_list\_datasets}\NormalTok{(proj\_l2\_cat)}
\NormalTok{ hind\_l2\_datasets }\OtherTok{\textless{}{-}} \FunctionTok{tds\_list\_datasets}\NormalTok{(hind\_l2\_cat)}
\NormalTok{ proj\_l2\_datasets}\SpecialCharTok{$}\NormalTok{dataset}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## [1] "Bottom 5m" "Surface 5m" "Integrated"
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# get url for bottom temperature:}
\NormalTok{ proj\_l2\_BT\_url }\OtherTok{\textless{}{-}}\NormalTok{ proj\_l2\_datasets[proj\_l2\_datasets}\SpecialCharTok{$}\NormalTok{dataset }\SpecialCharTok{==} \StringTok{"Bottom 5m"}\NormalTok{,]}\SpecialCharTok{$}\NormalTok{path}
\NormalTok{ hind\_l2\_BT\_url }\OtherTok{\textless{}{-}}\NormalTok{ hind\_l2\_datasets[hind\_l2\_datasets}\SpecialCharTok{$}\NormalTok{dataset }\SpecialCharTok{==} \StringTok{"Bottom 5m"}\NormalTok{,]}\SpecialCharTok{$}\NormalTok{path}
\NormalTok{ proj\_l2\_BT\_url}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
## [1] "https://data.pmel.noaa.gov/aclim/thredds/B10K-H16_CMIP5_MIROC_rcp85/Level2.html?dataset=B10K-H16_CMIP5_MIROC_rcp85_Level2_bottom5m"
\end{verbatim}
We can't preview the Level 3 datasets in the same way but they are
identical to those in the google drive and include two datasets
\begin{itemize}
\tightlist
\item
\texttt{ACLIMsurveyrep\_B10K-H16\_CMIP5\_CESM\_BIO\_rcp85.nc} : NMFS
Groundfish summer NBS and EBS survey replicated values for 60+
variables
\item
\texttt{ACLIMregion\_B10K-H16\_CMIP5\_CESM\_BIO\_rcp85.nc} : weekly
strata averages for 60+ variables
\end{itemize}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{ weekly\_vars }\CommentTok{\# list of possible variables in the ACLIMregion\_ files }
\end{Highlighting}
\end{Shaded}
Now we can download a subset of the Level2 data (full 10KM Lat Lon
re-gridded data), here with an example of sampling on Aug 1 of each
year:
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# Currently available Level 2 variables}
\NormalTok{ dl }\OtherTok{\textless{}{-}}\NormalTok{ proj\_l2\_datasets}\SpecialCharTok{$}\NormalTok{dataset }\CommentTok{\# datasets}
\CommentTok{\# variable list}
\NormalTok{ svl }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}
\StringTok{\textquotesingle{}Bottom 5m\textquotesingle{}} \OtherTok{=} \StringTok{"temp"}\NormalTok{,}
\StringTok{\textquotesingle{}Surface 5m\textquotesingle{}} \OtherTok{=} \StringTok{"temp"}\NormalTok{,}
\StringTok{\textquotesingle{}Integrated\textquotesingle{}} \OtherTok{=} \FunctionTok{c}\NormalTok{(}\StringTok{"EupS"}\NormalTok{,}\StringTok{"Cop"}\NormalTok{,}\StringTok{"NCaS"}\NormalTok{) ) }
\CommentTok{\# preview the variables, timesteps, and lat lon in each dataset:}
\NormalTok{ l2\_info }\OtherTok{\textless{}{-}} \FunctionTok{scan\_l2}\NormalTok{(}\AttributeTok{ds\_list =}\NormalTok{ dl,}\AttributeTok{sim\_list =} \StringTok{"B10K{-}H16\_CORECFS"}\NormalTok{ )}
\FunctionTok{names}\NormalTok{(l2\_info)}
\NormalTok{ l2\_info[[}\StringTok{"Bottom 5m"}\NormalTok{]]}\SpecialCharTok{$}\NormalTok{vars}
\NormalTok{ l2\_info[[}\StringTok{"Surface 5m"}\NormalTok{]]}\SpecialCharTok{$}\NormalTok{vars}
\NormalTok{ l2\_info[[}\StringTok{"Integrated"}\NormalTok{]]}\SpecialCharTok{$}\NormalTok{vars}
\FunctionTok{max}\NormalTok{(l2\_info[[}\StringTok{"Integrated"}\NormalTok{]]}\SpecialCharTok{$}\NormalTok{time\_steps)}
\NormalTok{ l2\_info[[}\StringTok{"Integrated"}\NormalTok{]]}\SpecialCharTok{$}\NormalTok{years}
\CommentTok{\# Simulation list:}
\CommentTok{\# {-}{-}\textgreater{} {-}{-}\textgreater{} Tinker:add additional projection scenarios here}
\NormalTok{ sl }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(hind, proj)}
\CommentTok{\# Currently available Level 2 variables}
\NormalTok{ dl }\OtherTok{\textless{}{-}}\NormalTok{ proj\_l2\_datasets}\SpecialCharTok{$}\NormalTok{dataset }\CommentTok{\# datasets}
\CommentTok{\# variables to pull from each data set}
\CommentTok{\# {-}{-}\textgreater{} {-}{-}\textgreater{} Tinker: try subbing in other Integrated variables }
\CommentTok{\# (l2\_info[["Integrated"]]$vars) into the third list vector }
\NormalTok{ svl }\OtherTok{\textless{}{-}} \FunctionTok{list}\NormalTok{(}
\StringTok{\textquotesingle{}Bottom 5m\textquotesingle{}} \OtherTok{=} \StringTok{"temp"}\NormalTok{,}
\StringTok{\textquotesingle{}Surface 5m\textquotesingle{}} \OtherTok{=} \StringTok{"temp"}\NormalTok{,}
\StringTok{\textquotesingle{}Integrated\textquotesingle{}} \OtherTok{=} \FunctionTok{c}\NormalTok{(}\StringTok{"EupS"}\NormalTok{,}\StringTok{"Cop"}\NormalTok{,}\StringTok{"NCaS"}\NormalTok{) ) }
\CommentTok{\# Let\textquotesingle{}s sample the model years as close to Aug 1 as the model timesteps run:}
\CommentTok{\# {-}{-}\textgreater{} {-}{-}\textgreater{} Tinker {-} try a different date}
\NormalTok{ tr }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}\StringTok{"{-}08{-}1 12:00:00 GMT"}\NormalTok{) }
\CommentTok{\# grab nc files from the aclim server and convert to rdatafiles with the ID Aug1}
\FunctionTok{get\_l2}\NormalTok{(}
\AttributeTok{ID =} \StringTok{"\_Aug1"}\NormalTok{,}
\AttributeTok{overwrite =}\NormalTok{ T,}
\AttributeTok{ds\_list =}\NormalTok{ dl,}
\AttributeTok{trIN =}\NormalTok{ tr,}
\AttributeTok{sub\_varlist =}\NormalTok{ svl, }
\AttributeTok{sim\_list =}\NormalTok{ sl )}
\end{Highlighting}
\end{Shaded}
\hypertarget{download-level-3-data}{%
\subsubsection{3.3.3 Download Level 3
data}\label{download-level-3-data}}
Now let's grab some of the Level 3 data and store it in the
Data/in/Newest/Rdata folder. This is comparatively faster because Level
3 files are already post-processed to be in the ACLIM indices format and
are relatively small:
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# Simulation list:}
\CommentTok{\# {-}{-}\textgreater{} {-}{-}\textgreater{} Tinker:add additional projection scenarios here}
\NormalTok{ sl }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(hind, proj)}
\CommentTok{\# variable list}
\CommentTok{\# {-}{-}\textgreater{} {-}{-}\textgreater{} Tinker:add additional variables to varlist}
\NormalTok{ vl }\OtherTok{\textless{}{-}} \FunctionTok{c}\NormalTok{(}
\StringTok{"temp\_bottom5m"}\NormalTok{, }\CommentTok{\# bottom temperature,}
\StringTok{"NCaS\_integrated"}\NormalTok{, }\CommentTok{\# Large Cop}
\StringTok{"Cop\_integrated"}\NormalTok{, }\CommentTok{\# Small Cop}
\StringTok{"EupS\_integrated"}\NormalTok{) }\CommentTok{\# Shelf euphausiids}
\CommentTok{\# convert nc files into a long data.frame for each variable}
\CommentTok{\# three options are:}
\CommentTok{\# {-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
\CommentTok{\# opt 1: access nc files remotely (fast, less local storage needed)}
\FunctionTok{get\_l3}\NormalTok{(}\AttributeTok{web\_nc =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{download\_nc =}\NormalTok{ F,}
\AttributeTok{varlist =}\NormalTok{ vl,}\AttributeTok{sim\_list =}\NormalTok{ sl)}
\CommentTok{\# opt 2: download nc files then access locallly:}
\FunctionTok{get\_l3}\NormalTok{(}\AttributeTok{web\_nc =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{download\_nc =}\NormalTok{ T,}
\AttributeTok{local\_path =} \FunctionTok{file.path}\NormalTok{(local\_fl,}\StringTok{"aclim\_thredds"}\NormalTok{),}
\AttributeTok{varlist =}\NormalTok{ vl,}\AttributeTok{sim\_list =}\NormalTok{ sl)}
\CommentTok{\# opt 3: access existing nc files locally:}
\FunctionTok{get\_l3}\NormalTok{(}\AttributeTok{web\_nc =}\NormalTok{ F, }\AttributeTok{download\_nc =}\NormalTok{ F,}
\AttributeTok{local\_path =} \FunctionTok{file.path}\NormalTok{(local\_fl,}\StringTok{"aclim\_thredds"}\NormalTok{),}
\AttributeTok{varlist =}\NormalTok{ vl,}\AttributeTok{sim\_list =}\NormalTok{ sl)}
\end{Highlighting}
\end{Shaded}
\hypertarget{download-level-3-cmip6-aclim-only-for-now}{%
\subsubsection{3.3.4 Download Level 3 CMIP6 (ACLIM only for
now)}\label{download-level-3-cmip6-aclim-only-for-now}}
Go to the shared google drive and dowload the CMIP6 data into your
ACLIM2 local folder:
\href{https://drive.google.com/drive/folders/1ljACM6cgMD7M14lzvozZyTP4tMBnf_S4}{00\_ACLIM\_shared\textgreater02\_Data\textgreater Newest\textgreater roms\_for\_aclim}
and put in your local folder under: \texttt{Data/in/roms\_for\_aclim}
\includegraphics{Figs/filestructure2.jpg}
\hypertarget{explore-indices-plot-the-data}{%
\section{4. Explore indices \& plot the
data}\label{explore-indices-plot-the-data}}
\hypertarget{data-exploration-with-the-minimal-installation}{%
\subsection{4.1. Data exploration with the minimal
installation}\label{data-exploration-with-the-minimal-installation}}
Let's look at some data from the Level 2 bottom temperature records,
using the threadds and ncdf4 libraries:
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{library}\NormalTok{(ncdf4)}
\FunctionTok{library}\NormalTok{(thredds) }
\CommentTok{\# Open connection to Level 2 bottom 5 meter layer}
\NormalTok{ url\_base }\OtherTok{\textless{}{-}} \StringTok{"https://data.pmel.noaa.gov/aclim/thredds/"}
\NormalTok{ opendap }\OtherTok{\textless{}{-}} \StringTok{"dodsC/Level2/B10K{-}K20\_CORECFS\_bottom5m.nc"}
\NormalTok{ nc }\OtherTok{\textless{}{-}} \FunctionTok{nc\_open}\NormalTok{(}\FunctionTok{paste}\NormalTok{(url\_base,opendap,}\AttributeTok{sep=}\StringTok{""}\NormalTok{))}
\CommentTok{\# Examination of the nc object shows variables such as temperature (temp)}
\CommentTok{\# float temp[xi\_rho,eta\_rho,ocean\_time] }
\CommentTok{\# long\_name: time{-}averaged potential temperature, bottom 5m mean}
\CommentTok{\# units: Celsius}
\CommentTok{\# time: ocean\_time}
\CommentTok{\# coordinates: lon\_rho lat\_rho ocean\_time}
\CommentTok{\# field: temperature, scalar, series}
\CommentTok{\# \_FillValue: 9.99999993381581e+36}
\CommentTok{\# cell\_methods: s\_rho: mean}
\CommentTok{\# temp has three dimensions {-} xi\_rho, eta\_rho, and ocean\_time}
\CommentTok{\# Now we make vectors of each axis.}
\NormalTok{ xi\_axis }\OtherTok{\textless{}{-}} \FunctionTok{seq}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{182}\NormalTok{) }\CommentTok{\# Hardcoded axis length}
\NormalTok{ eta\_axis }\OtherTok{\textless{}{-}} \FunctionTok{seq}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{258}\NormalTok{) }\CommentTok{\# Hardcoded axis length}
\CommentTok{\# time units in GMT: seconds since 1900{-}01{-}01 00:00:00}
\NormalTok{ t\_axis }\OtherTok{\textless{}{-}} \FunctionTok{ncvar\_get}\NormalTok{(nc,}\StringTok{"ocean\_time"}\NormalTok{)}
\NormalTok{ time\_axis }\OtherTok{\textless{}{-}} \FunctionTok{as.POSIXct}\NormalTok{(t\_axis, }\AttributeTok{origin =} \StringTok{"1900{-}01{-}01"}\NormalTok{, }\AttributeTok{tz =} \StringTok{"GMT"}\NormalTok{)}
\CommentTok{\# Make two dates to find in the data}
\NormalTok{ date1 }\OtherTok{\textless{}{-}} \FunctionTok{ISOdate}\NormalTok{(}\AttributeTok{year=}\DecValTok{2010}\NormalTok{, }\AttributeTok{month=}\DecValTok{7}\NormalTok{, }\AttributeTok{day=}\DecValTok{1}\NormalTok{, }\AttributeTok{hour =} \DecValTok{12}\NormalTok{, }\AttributeTok{tz =} \StringTok{"GMT"}\NormalTok{)}
\NormalTok{ date2 }\OtherTok{\textless{}{-}} \FunctionTok{ISOdate}\NormalTok{(}\AttributeTok{year=}\DecValTok{2019}\NormalTok{, }\AttributeTok{month=}\DecValTok{7}\NormalTok{, }\AttributeTok{day=}\DecValTok{1}\NormalTok{, }\AttributeTok{hour =} \DecValTok{12}\NormalTok{, }\AttributeTok{tz =} \StringTok{"GMT"}\NormalTok{)}
\CommentTok{\# Which time index is closest to those dates?}
\NormalTok{ timerec1 }\OtherTok{\textless{}{-}} \FunctionTok{which.min}\NormalTok{(}\FunctionTok{abs}\NormalTok{(time\_axis }\SpecialCharTok{{-}}\NormalTok{ date1))}
\NormalTok{ timerec2 }\OtherTok{\textless{}{-}} \FunctionTok{which.min}\NormalTok{(}\FunctionTok{abs}\NormalTok{(time\_axis }\SpecialCharTok{{-}}\NormalTok{ date2))}
\CommentTok{\# Center time of the closest weekly average}
\NormalTok{ time\_axis[timerec1]}
\NormalTok{ time\_axis[timerec2]}
\CommentTok{\# Get full xi, eta grid (count={-}1) for two time slices}
\CommentTok{\# Get one record starting at desired timerec. }
\CommentTok{\# Careful (easy to grab too much data, if count and start are missing}
\CommentTok{\# it will grab all the data).}
\NormalTok{ temp1 }\OtherTok{\textless{}{-}} \FunctionTok{ncvar\_get}\NormalTok{(nc, }\StringTok{"temp"}\NormalTok{, }\AttributeTok{start=}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{1}\NormalTok{,timerec1), }\AttributeTok{count=}\FunctionTok{c}\NormalTok{(}\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{,}\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{,}\DecValTok{1}\NormalTok{))}
\NormalTok{ temp2 }\OtherTok{\textless{}{-}} \FunctionTok{ncvar\_get}\NormalTok{(nc, }\StringTok{"temp"}\NormalTok{, }\AttributeTok{start=}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{1}\NormalTok{,timerec2), }\AttributeTok{count=}\FunctionTok{c}\NormalTok{(}\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{,}\SpecialCharTok{{-}}\DecValTok{1}\NormalTok{,}\DecValTok{1}\NormalTok{))}
\CommentTok{\# Plot comparison (not checking scale here)}
\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow=}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))}
\FunctionTok{image}\NormalTok{(temp1)}
\FunctionTok{image}\NormalTok{(temp2)}
\CommentTok{\# Get lat/lon for better mapping {-} getting whole variable }
\NormalTok{ lats }\OtherTok{\textless{}{-}} \FunctionTok{ncvar\_get}\NormalTok{(nc,}\StringTok{"lat\_rho"}\NormalTok{)}
\NormalTok{ lons }\OtherTok{\textless{}{-}} \FunctionTok{ncvar\_get}\NormalTok{(nc,}\StringTok{"lon\_rho"}\NormalTok{)}
\CommentTok{\# Visualizing the coordinate transformation }
\FunctionTok{plot}\NormalTok{(lons,lats)}
\CommentTok{\# Let\textquotesingle{}s flag water \textless{}2 degrees C}
\FunctionTok{par}\NormalTok{(}\AttributeTok{mfrow=}\FunctionTok{c}\NormalTok{(}\DecValTok{1}\NormalTok{,}\DecValTok{2}\NormalTok{))}
\FunctionTok{plot}\NormalTok{(lons,lats,}\AttributeTok{col=}\FunctionTok{ifelse}\NormalTok{(temp1}\SpecialCharTok{\textless{}}\DecValTok{2}\NormalTok{,}\StringTok{"blue"}\NormalTok{,}\StringTok{"green"}\NormalTok{),}\AttributeTok{main=}\StringTok{"2010"}\NormalTok{)}
\FunctionTok{plot}\NormalTok{(lons,lats,}\AttributeTok{col=}\FunctionTok{ifelse}\NormalTok{(temp2}\SpecialCharTok{\textless{}}\DecValTok{2}\NormalTok{,}\StringTok{"blue"}\NormalTok{,}\StringTok{"green"}\NormalTok{),}\AttributeTok{main=}\StringTok{"2019"}\NormalTok{)}
\CommentTok{\# Close the connection}
\FunctionTok{nc\_close}\NormalTok{(nc)}
\end{Highlighting}
\end{Shaded}
\begin{figure}
\centering
\includegraphics[width=1\textwidth,height=\textheight]{Figs/minimal_coldpool.jpg}
\caption{Bottom temperature \textless2 degrees C (blue) and
\textgreater=2 degrees C (green).}
\end{figure}
\hypertarget{level-3-indices}{%
\subsection{4.2. Level 3 indices}\label{level-3-indices}}
Level 3 indices can be used to generate seasonal, monthly, and annual
indices (like those reported in
\href{https://www.frontiersin.org/articles/10.3389/fmars.2020.00124/full}{Reum
et al.~2020)},
\href{http://dx.doi.org/10.1038/s41467-020-18300-3}{Holsman et
al.~2020)}. In the section below we explore these indices in more detail
using R, including using (2) above to generate weekly, monthly, and
seasonal indices (e.g.~Fall Zooplankton) for use in biological models.
In section 3 below we explore these indices in more detail using R,
including using (2) above to generate weekly, monthly, and seasonal
indices (e.g.~Fall Zooplankton) for use in biological models. The
following examples show how to analyze and plot the ACLIM indices from
the .Rdata files created in the previous step 3. Please be sure to
coordinate with ROMSNPZ modeling team members to ensure data is applied
appropriately.
\hypertarget{explore-level-3-data-catalog}{%
\subsubsection{4.2.1 Explore Level 3 data
catalog}\label{explore-level-3-data-catalog}}
Once the base files and setup are loaded you can explore the index
types. Recall that in each scenario folder there are two indices saved
within the \texttt{Level3} subfolders:
\begin{enumerate}
\def\labelenumi{\arabic{enumi})}
\tightlist
\item
\texttt{ACLIMsurveyrep\_B10K-x.nc} contains summer groundfish trawl
``survey replicated'' indices (using mean date and lat lon)
\emph{(Note that the resampling stations need to be removed before
creating bottom temperature maps)}\\
\item
\texttt{ACLIMregion\_B10K-x.nc}: contains weekly ``strata'' values
\emph{(Note that area weighting should be used to combine values
across multiple strata)}
\end{enumerate}
First run the below set of code to set up the workspace:
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# {-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
\CommentTok{\# SETUP WORKSPACE}
\NormalTok{ tmstp }\OtherTok{\textless{}{-}} \FunctionTok{format}\NormalTok{(}\FunctionTok{Sys.time}\NormalTok{(), }\StringTok{"\%Y\_\%m\_\%d"}\NormalTok{)}
\NormalTok{ main }\OtherTok{\textless{}{-}} \FunctionTok{getwd}\NormalTok{() }\CommentTok{\#"\textasciitilde{}/GitHub\_new/ACLIM2}
\FunctionTok{source}\NormalTok{(}\StringTok{"R/make.R"}\NormalTok{)}
\CommentTok{\# {-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
\CommentTok{\# list of the scenario x GCM downscaled ACLIM indices}
\ControlFlowTok{for}\NormalTok{(k }\ControlFlowTok{in}\NormalTok{ aclim)}
\FunctionTok{cat}\NormalTok{(}\FunctionTok{paste}\NormalTok{(k,}\StringTok{"}\SpecialCharTok{\textbackslash{}n}\StringTok{"}\NormalTok{))}
\NormalTok{ embargoed }\CommentTok{\# not yet public or published}
\NormalTok{ public }\CommentTok{\# published runs (CMIP5)}
\CommentTok{\# get some info about a scenario:}
\NormalTok{ all\_info1}
\NormalTok{ all\_info2}
\CommentTok{\# variables in each of the two files:}
\NormalTok{ srvy\_vars}
\NormalTok{ weekly\_vars}
\CommentTok{\#summary tables for variables}
\NormalTok{ srvy\_var\_def}
\NormalTok{ weekly\_var\_def}
\CommentTok{\# explore stations in the survey replicated data:}
\FunctionTok{head}\NormalTok{(station\_info)}
\end{Highlighting}
\end{Shaded}
\hypertarget{level-3-spatial-indices-survey-replicated}{%
\subsubsection{4.2.2 Level 3: Spatial indices (survey
replicated)}\label{level-3-spatial-indices-survey-replicated}}
Let's start b exploring the survey replicated values for each variable.
Previous steps generated the Rdata files that are stored in the
\texttt{ACLIMsurveyrep\_B10K-{[}version\_CMIPx\_GCM\_RCP{]}.Rdata} in
each corresponding simulation folder.
\includegraphics[width=0.5\textwidth,height=\textheight]{Figs/stations_NS.jpg}
\includegraphics[width=0.5\textwidth,height=\textheight]{Figs/stations.jpg}
The code segment below will recreate the above figures.\emph{Note that
if this is the first time through it may take 3-5 mins to load the
spatial packages and download the files from the web (first time through
only).}
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# if load\_gis is set to FALSE in R/setup.R (default) }
\CommentTok{\# we will need to load the gis layers and packages}
\CommentTok{\# if this is the first time through this would be a good time}
\CommentTok{\# to grab a coffee...}
\FunctionTok{source}\NormalTok{(}\StringTok{"R/sub\_scripts/load\_maps.R"}\NormalTok{)}
\CommentTok{\# first convert the station\_info object into a shapefile for mapping:}
\NormalTok{ station\_sf }\OtherTok{\textless{}{-}} \FunctionTok{convert2shp}\NormalTok{(station\_info)}
\NormalTok{ station\_sf}\SpecialCharTok{$}\NormalTok{stratum }\OtherTok{\textless{}{-}} \FunctionTok{factor}\NormalTok{(station\_sf}\SpecialCharTok{$}\NormalTok{stratum)}
\CommentTok{\# plot the stations:}
\NormalTok{ p }\OtherTok{\textless{}{-}} \FunctionTok{plot\_stations\_basemap}\NormalTok{(}\AttributeTok{sfIN =}\NormalTok{ station\_sf,}
\AttributeTok{fillIN =} \StringTok{"subregion"}\NormalTok{,}
\AttributeTok{colorIN =} \StringTok{"subregion"}\NormalTok{) }\SpecialCharTok{+}
\FunctionTok{scale\_color\_viridis\_d}\NormalTok{(}\AttributeTok{begin =}\NormalTok{ .}\DecValTok{2}\NormalTok{,}\AttributeTok{end=}\NormalTok{.}\DecValTok{6}\NormalTok{) }\SpecialCharTok{+}