-
Notifications
You must be signed in to change notification settings - Fork 0
/
HowTo_get_survey_data.tex
813 lines (697 loc) · 58.9 KB
/
HowTo_get_survey_data.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
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{iftex}
\ifPDFTeX
\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}
\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{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
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\urlstyle{same} % disable monospaced font for URLs
\hypersetup{
pdftitle={Get and summarize AFSC survey data},
pdfauthor={Kirstin Holsman, Alaska Fisheries Science Center},
hidelinks,
pdfcreator={LaTeX via pandoc}}
\title{Get and summarize AFSC survey data}
\author{Kirstin Holsman, Alaska Fisheries Science Center}
\date{}
\begin{document}
\maketitle
{
\setcounter{tocdepth}{2}
\tableofcontents
}
\begin{verbatim}
## Warning: package 'svMisc' was built under R version 4.1.3
\end{verbatim}
\begin{verbatim}
## Warning: package 'reshape2' was built under R version 4.1.3
\end{verbatim}
\hypertarget{afsc-survey-cpue-data-github.comkholsmanafsc_cpue}{%
\paragraph{\texorpdfstring{\href{https://github.com/kholsman/AFSC_CPUE}{\textbf{AFSC
Survey CPUE data:
github.com/kholsman/AFSC\_CPUE}}}{AFSC Survey CPUE data: github.com/kholsman/AFSC\_CPUE}}\label{afsc-survey-cpue-data-github.comkholsmanafsc_cpue}}
Repo maintained by:\\
Kirstin Holsman\\
Alaska Fisheries Science Center\\
NOAA Fisheries, Seattle WA\\
\textbf{\url{[email protected]}}\strut \\
\emph{Last updated: Oct 04, 2024}
\hypertarget{overview}{%
\section{Overview}\label{overview}}
The below scripts return a list object cpue\_data saved as a compressed
Rdata file with the naming `reg.srvy\#.spp.cpue\_data.Rdata' such as
``ebs.srvy98.plk.cpue\_data.Rdata''. Each cpue\_data list contains 8
data.frames:
\begin{Shaded}
\begin{Highlighting}[]
\FunctionTok{load}\NormalTok{(}\FunctionTok{paste0}\NormalTok{(}\StringTok{"data/out/"}\NormalTok{,qrydate,}\StringTok{"/cpue/ebs/ebs.srvy98.plk.cpue\_data.Rdata"}\NormalTok{))}
\FunctionTok{names}\NormalTok{(cpue\_data)}
\end{Highlighting}
\end{Shaded}
There is a folder for each region ``ebs'', ``goa'', ``ai''. For the
``ebs'' (Bering Sea) there are two sets of cpue\_data, one that is
NEBS+SEBS combined (`ebs.srvy98.{[}sp{]}.cpue\_data.Rdata') and one that
is just SEBS survey areas (`sebs.srvy98.{[}sp{]}.cpue\_data.Rdata'). For
both the Gulf of Alaska (``goa'') and the Bering Sea, mean CPUE (Kg per
km2 or Number per km2) for each size bin at each strata was calculated
and then multiplied by the STRATA area to get total Biomass and
abundance. \textbf{Note:Since strata area estimates where not available
for the Aleutian Island (``ai'') or slope surveys (``slope'') these AREA
was set equal to 1 and the Total Biomass and abundance is actually the
sum of mean biomass. }
The data.frames within each cpue\_data object are:
\begin{enumerate}
\def\labelenumi{\arabic{enumi}.}
\tightlist
\item
\textbf{totalB\_N}: Total biomass (kg) or abundance (\# of fish) for
the species in each year\\
\item
\textbf{mnCPUE\_strata\_yr} : Average survey CPUE (kg per Km2) or
abundance (\# per Km2) for the species in each strata and year\\
\item
\textbf{total\_bin\_B\_N}: Total biomass (kg) or abundance (\# of
fish) for each bin (10 mm) for the species in each year\\
\item
\textbf{mnCPUE\_strata\_bin\_yr} : Average survey CPUE (kg per Km2) or
abundance (\# per Km2) for each size bin for the species in each
strata and year
\item
\textbf{CPUE\_station\_bin\_yr}: Station specific survey CPUE (kg per
Km2) or abundance (\# per Km2) for each size bin for the species in
each year\\
\item
\textbf{CPUE\_station\_yr}: Station specific survey CPUE (kg per Km2)
or abundance (\# per Km2) for the species in each year\\
\item
\textbf{propByBin}: proportion of biomass in each size bin per species
per year\\
\item
\textbf{propByStrata}: proportion of biomass in each strata per
species per year
\item
\textbf{propByStrataBin}: proportion of biomass in each bin and strata
per species per year
\end{enumerate}
\includegraphics{figs/Kearney_2023.jpg} To obtain population level
estimates of the biomass or abundance of fish by size bin \(l\), we used
a length weight regression to estimate the weight of each size fish
\(j\) measured (\(\hat{W}\)) to calculate the proportion by weight or
frequency at each station where \[\hat{W_j} = \alpha_s+L_j^{\beta_s} \]
where the species-specific (\(s\)) slope and intercept values
(\(\beta_s\) and \(\alpha_s\), respectively) were fit to all available
length and weight data from surveys from all years across the EBS, GOA,
and AI (rather than each basin separately).
The number and biomass (\(hat{W_j}\)) for each 1 (mm) length was summed
into 10 mm size bins \(l\) and expanded to include stations and bins
where CPUE = 0 (saved as the object
\texttt{cpue\_data\$CPUE\_station\_bin\_yr}). Bin-specific catch
\(\bar{CPUE}_{s,k,y,l}\) (kg per \(Km^2\) or number per \(Km^2\)) of all
stations \(i\) in strata \(k\) for size bin \(l\) (saved as the object
\texttt{cpue\_data\$mnCPUE\_strata\_bin\_yr})::
\[\bar{CPUE}^{B|N}_{s,k,y,l}=\frac{1}{n_k}\sum_{n_k}{CPUE^{B|N}_{s,k,y,l,i}}\]
and where \(CPUE^B_{s,k,y,l,i} = \sum_{n_l}\hat{W}_j\) and
\(CPUE^N_{s,k,y,l,i} = \sum_{n_l}1\) are the station specific CPUEs for
biomass and abundance of fish in size bin l (respectively). CPUE was
converted to total strata- and bin-specific biomass (\$B\_\{s,k,y,l\}
\$) by multiplying the strata average catch ( \(\bar{CPUE}_{s,k,y,l}\) )
for each species and bin by the strata area \(A_{k}\) ( \(Km2\); saved
as the object \texttt{cpue\_data\$total\_bin\_B\_N}):
\[B_{s,k,y,l} = \bar{CPUE}^{B}_{s,k,y,l} \dot{}A_{k}\] and
\[N_{s,k,y,l} = \bar{CPUE}^{N}_{s,k,y,l} \dot{}A_{k}\]
We then calculated the proportion of total annual abundance
(\(N_{s,y}= \sum_k{\sum_l{N_{s,k,y,l}}}\)) or biomass
(\(B_{s,y}= \sum_k{\sum_l{B_{s,k,y,l}}}\); saved as
\texttt{cpue\_data\$totalB\_N}) of each species and bin \(l\) in each
strata \(k\) as (saved as the object
\texttt{cpue\_data\$propByStrataBin}):
\[p^N_{s,k,y,l} = \frac{N_{s,k,y,l}}{ \sum_k{\sum_l{N_{s,k,y,l}}}}\] and
\[p^B_{s,k,y,l} = \frac{B_{s,k,y,l}}{ \sum_k{\sum_l{B_{s,k,y,l}}}}\] and
the proportion of total annual biomass (or abundance) of each species in
each strata as (saved as the object \texttt{cpue\_data\$propByStrata}):
\[p^B_{s,k,y} = \frac{\sum_l({B_{s,k,y,l}})}{ \sum_k{\sum_l{B_{s,k,y,l}}}}\]
and the proportion of total annual biomass of each species in each bin
l: (saved as the object \texttt{cpue\_data\$propByBin}):
\[p^B_{s,k,l} = \frac{\sum_k({B_{s,k,y,l}})}{ \sum_k{\sum_l{B_{s,k,y,l}}}}\]
\hypertarget{comparison-of-bering-sea-survey-biomass-indices}{%
\section{Comparison of Bering Sea survey biomass
indices}\label{comparison-of-bering-sea-survey-biomass-indices}}
\includegraphics{figs/plk_srvy.jpg}
\includegraphics{figs/pcod_srvy.jpg}
\begin{figure}
\centering
\includegraphics{figs/atf_srvy.jpg}
\caption{``arrowtooth''}
\end{figure}
\hypertarget{workflow-to-update-biomass-indices}{%
\section{Workflow to update biomass
indices}\label{workflow-to-update-biomass-indices}}
\hypertarget{step-1-2-set-up-the-r-workspace-update-lookups-and-lwa}{%
\subsection{Step 1 \& 2 : Set up the R workspace, update lookups and
LWA}\label{step-1-2-set-up-the-r-workspace-update-lookups-and-lwa}}
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# \#\# Step 0: Set up the R workspace}
\CommentTok{\# }
\CommentTok{\# The first step is to set up the switches for what files to update and create in the file \textasciigrave{}R/setup.R\textasciigrave{}. The code below then loads these settings as well as base data, functions, and packages. }
\CommentTok{\# }
\CommentTok{\# \#\# Step 1: Update SQL queries}
\CommentTok{\# This step must be run on a computer that has access to RACEBASE. The code below will generate the base files for steps 2 and 3 below,and will save them in the folder \textasciigrave{}r data.path \textasciigrave{} under subfolders for each region in \textasciigrave{}srvys$reg\textasciigrave{} and each species in \textasciigrave{}splist\textasciigrave{} (see \textasciigrave{}R/setup.R\textasciigrave{} to change these settings).}
\CommentTok{\# **IMPORTANT:** }
\CommentTok{\# }
\CommentTok{\# * **This step must be connected to the RACEBASE SQL database**}
\CommentTok{\# }
\CommentTok{\# * **The code will connect to the SQL database using your password and username. Remember to update the \textasciigrave{}username\_path\textasciigrave{} in the first line of the \textasciigrave{}R/setup.R \textasciigrave{} file and corresponding \textasciigrave{}username\textasciigrave{} and \textasciigrave{}password\textasciigrave{} under \textasciigrave{}username\_password.R\textasciigrave{}. A template is available under \textasciigrave{}R/\textasciigrave{}.**}
\CommentTok{\# }
\CommentTok{\# \textless{}!{-}{-} ![Header of \textasciigrave{}setup.R\textasciigrave{} where \textasciigrave{}username\_path\textasciigrave{} can be adjusted. This file also is where species, regions, and bins are specified.](figs/setup.jpg)\{width=80\%\} {-}{-}\textgreater{}}
\CommentTok{\# }
\CommentTok{\# get everything set up:}
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
\CommentTok{\# rm(list=ls())}
\CommentTok{\# this uses the password saved in R/password.R}
\NormalTok{ update\_qrydate }\OtherTok{\textless{}{-}} \ConstantTok{TRUE} \CommentTok{\# update the query date}
\NormalTok{ update\_LWdata }\OtherTok{\textless{}{-}} \ConstantTok{TRUE} \CommentTok{\# update LW regressions}
\NormalTok{ update\_lkups }\OtherTok{\textless{}{-}} \ConstantTok{TRUE} \CommentTok{\# update the lookuptables}
\FunctionTok{suppressMessages}\NormalTok{(}\FunctionTok{source}\NormalTok{(}\StringTok{"R/make.R"}\NormalTok{))}
\CommentTok{\# update the SQL queries for goa, ai, sebs and nebs}
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-} }
\FunctionTok{source}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(code.path,}\StringTok{"R/sub\_scripts/runRACE\_qrys.R"}\NormalTok{))}
\CommentTok{\# combine sebs and nebs into one region: ebs}
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-} }
\ControlFlowTok{if}\NormalTok{(}\FunctionTok{dir.exists}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(data.path,}\StringTok{"ebs"}\NormalTok{)))}
\FunctionTok{system}\NormalTok{(}\FunctionTok{paste}\NormalTok{(}\StringTok{"rm {-}r"}\NormalTok{,}\FunctionTok{file.path}\NormalTok{(data.path,}\StringTok{"ebs"}\NormalTok{)))}
\FunctionTok{dir.create}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(data.path,}\StringTok{"ebs"}\NormalTok{))}
\CommentTok{\# combine files and rename survey area to all of EBS}
\ControlFlowTok{for}\NormalTok{(sp }\ControlFlowTok{in} \FunctionTok{names}\NormalTok{(splist))\{}
\ControlFlowTok{if}\NormalTok{(}\FunctionTok{dir.exists}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(data.path,}\StringTok{"ebs"}\NormalTok{,sp)))}
\FunctionTok{system}\NormalTok{(}\FunctionTok{paste}\NormalTok{(}\StringTok{"rm {-}r"}\NormalTok{,}\FunctionTok{file.path}\NormalTok{(data.path,}\StringTok{"ebs"}\NormalTok{,sp)))}
\FunctionTok{dir.create}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(data.path,}\StringTok{"ebs"}\NormalTok{,sp))}
\CommentTok{\#"length.Rdata" }
\FunctionTok{load}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(data.path,}\StringTok{"nebs"}\NormalTok{,sp,}\StringTok{"length.Rdata"}\NormalTok{))}
\NormalTok{ length\_nebs }\OtherTok{\textless{}{-}}\NormalTok{ length;}\FunctionTok{rm}\NormalTok{(length)}
\FunctionTok{load}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(data.path,}\StringTok{"sebs"}\NormalTok{,sp,}\StringTok{"length.Rdata"}\NormalTok{))}
\NormalTok{ length\_sebs }\OtherTok{\textless{}{-}}\NormalTok{ length;}\FunctionTok{rm}\NormalTok{(length)}
\NormalTok{ length}\OtherTok{\textless{}{-}} \FunctionTok{rbind}\NormalTok{(length\_nebs}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{mutate}\NormalTok{(}\AttributeTok{SURVEY\_DEFINITION\_ID\_aka =}\NormalTok{SURVEY\_DEFINITION\_ID,}\AttributeTok{SURVEY\_DEFINITION\_ID =}\DecValTok{98}\NormalTok{),}
\NormalTok{ length\_sebs}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{mutate}\NormalTok{(}\AttributeTok{SURVEY\_DEFINITION\_ID\_aka =}\NormalTok{SURVEY\_DEFINITION\_ID,}\AttributeTok{SURVEY\_DEFINITION\_ID =}\DecValTok{98}\NormalTok{))}
\FunctionTok{save}\NormalTok{(length,}\AttributeTok{file =} \FunctionTok{file.path}\NormalTok{(data.path,}\StringTok{"ebs"}\NormalTok{,sp,}\StringTok{"length.Rdata"}\NormalTok{))}
\FunctionTok{rm}\NormalTok{(length)}
\CommentTok{\#"location.Rdata" }
\FunctionTok{load}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(data.path,}\StringTok{"nebs"}\NormalTok{,sp,}\StringTok{"location.Rdata"}\NormalTok{))}
\NormalTok{ location\_nebs }\OtherTok{\textless{}{-}}\NormalTok{ location;}\FunctionTok{rm}\NormalTok{(location)}
\FunctionTok{load}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(data.path,}\StringTok{"sebs"}\NormalTok{,sp,}\StringTok{"location.Rdata"}\NormalTok{))}
\NormalTok{ location\_sebs }\OtherTok{\textless{}{-}}\NormalTok{ location;}\FunctionTok{rm}\NormalTok{(location)}
\NormalTok{ location }\OtherTok{\textless{}{-}} \FunctionTok{rbind}\NormalTok{(location\_nebs, location\_sebs)}
\FunctionTok{save}\NormalTok{(location,}\AttributeTok{file =} \FunctionTok{file.path}\NormalTok{(data.path,}\StringTok{"ebs"}\NormalTok{,sp,}\StringTok{"location.Rdata"}\NormalTok{))}
\CommentTok{\#"location\_catch.Rdata"}
\FunctionTok{load}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(data.path,}\StringTok{"nebs"}\NormalTok{,sp,}\StringTok{"location\_catch.Rdata"}\NormalTok{))}
\NormalTok{ location\_catch\_nebs }\OtherTok{\textless{}{-}}\NormalTok{ location\_catch;}\FunctionTok{rm}\NormalTok{(location\_catch)}
\FunctionTok{load}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(data.path,}\StringTok{"sebs"}\NormalTok{,sp,}\StringTok{"location\_catch.Rdata"}\NormalTok{))}
\NormalTok{ location\_catch\_sebs }\OtherTok{\textless{}{-}}\NormalTok{ location\_catch;}\FunctionTok{rm}\NormalTok{(location\_catch)}
\NormalTok{ location\_catch }\OtherTok{\textless{}{-}} \FunctionTok{rbind}\NormalTok{(location\_catch\_nebs}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{mutate}\NormalTok{(}\AttributeTok{SURVEY\_DEFINITION\_ID\_aka =}\NormalTok{SURVEY\_DEFINITION\_ID,}\AttributeTok{SURVEY\_DEFINITION\_ID =}\DecValTok{98}\NormalTok{),}
\NormalTok{ location\_catch\_sebs}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{mutate}\NormalTok{(}\AttributeTok{SURVEY\_DEFINITION\_ID\_aka =}\NormalTok{SURVEY\_DEFINITION\_ID,}\AttributeTok{SURVEY\_DEFINITION\_ID =}\DecValTok{98}\NormalTok{))}
\FunctionTok{save}\NormalTok{(location\_catch,}\AttributeTok{file =} \FunctionTok{file.path}\NormalTok{(data.path,}\StringTok{"ebs"}\NormalTok{,sp,}\StringTok{"location\_catch.Rdata"}\NormalTok{))}
\NormalTok{ \}}
\CommentTok{\#\textasciigrave{}\textasciigrave{}\textasciigrave{}}
\DocumentationTok{\#\# Step 2: Update the LWA regressions}
\CommentTok{\# The default code for RACEBASE uses set LW relationships, however we prefer to update the LW regressions using glms. Depending on how many observations exist the LW relationships can be region specific or use data across all regions.The default below is all regions combined. This code generates two outputs in \textasciigrave{}r data.out\textasciigrave{}, \textasciigrave{}r LWname\textasciigrave{} and \textasciigrave{}LW\_SmryTable.Rdata\textasciigrave{}. It also updates the \textasciigrave{}species\_lkup$LW\_a\textasciigrave{} and species\_lkup$LW\_b\textasciigrave{} parms used in Step 3.}
\CommentTok{\# }
\CommentTok{\# \#\textasciigrave{}\textasciigrave{}\textasciigrave{}\{r updateLWglms, echo=TRUE, eval=FALSE\} }
\CommentTok{\# GAP\_PRODUCTS.AKFIN\_LENGTHS}
\CommentTok{\# update the LW regressions }
\CommentTok{\#{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-} }
\ControlFlowTok{if}\NormalTok{(update\_LWdata)\{ }
\FunctionTok{source}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(code.path,}\StringTok{"R/sub\_scripts/updateLW.R"}\NormalTok{))}
\CommentTok{\# reload with updated data:}
\FunctionTok{source}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(code.path,}\StringTok{"R/load\_data.R"}\NormalTok{))}
\NormalTok{ \}}
\NormalTok{ species\_lkup}
\end{Highlighting}
\end{Shaded}
\hypertarget{step-3-get-cpue-data-from-the-surveys}{%
\subsection{Step 3: Get CPUE data from the
surveys}\label{step-3-get-cpue-data-from-the-surveys}}
This code is the core script for generating the CPUE\_NUMKM2 and
CPUE\_BIOMKM2 values by size bin, region, and species.
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{ STRATA\_AREA}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{filter}\NormalTok{(REGION}\SpecialCharTok{==}\StringTok{"BS"}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR)}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{summarise}\NormalTok{(}\AttributeTok{mnAREA =} \FunctionTok{mean}\NormalTok{(AREA, }\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{sumAREA =} \FunctionTok{sum}\NormalTok{(AREA, }\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{cnt =} \FunctionTok{length}\NormalTok{(}\FunctionTok{unique}\NormalTok{(STRATUM)))}
\NormalTok{ STRATA\_AREA}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{filter}\NormalTok{(REGION}\SpecialCharTok{==}\StringTok{"GOA"}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR)}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{summarise}\NormalTok{(}\AttributeTok{mnAREA =} \FunctionTok{mean}\NormalTok{(AREA, }\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{sumAREA =} \FunctionTok{sum}\NormalTok{(AREA, }\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{cnt =} \FunctionTok{length}\NormalTok{(}\FunctionTok{unique}\NormalTok{(STRATUM)))}
\NormalTok{ STRATA\_AREA}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{filter}\NormalTok{(REGION}\SpecialCharTok{==}\StringTok{"BS"}\NormalTok{,YEAR}\SpecialCharTok{==}\DecValTok{2022}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{select}\NormalTok{(STRATUM)}
\CommentTok{\# overwrite the NEBS frame from setup for the next set of code (ebs = sebs+nebs now forward)}
\CommentTok{\# up above I combine the NEBS+SEBS into the ebs folder and rename the rest NEBS or SEBS accordingly }
\CommentTok{\# {-} so even though the survey number is 98 it;s actually 98 \& 143.}
\NormalTok{ srvys }\OtherTok{\textless{}{-}} \FunctionTok{data.frame}\NormalTok{(}\AttributeTok{reg=}\FunctionTok{c}\NormalTok{(}\StringTok{"ebs"}\NormalTok{,}\StringTok{"goa"}\NormalTok{,}\StringTok{"ai"}\NormalTok{,}\StringTok{"slope"}\NormalTok{),}\AttributeTok{RGN =} \FunctionTok{c}\NormalTok{(}\StringTok{"BS"}\NormalTok{,}\StringTok{"GOA"}\NormalTok{,}\StringTok{"AI"}\NormalTok{,}\StringTok{"SLOPE"}\NormalTok{), }\AttributeTok{num=}\FunctionTok{c}\NormalTok{(}\DecValTok{98}\NormalTok{,}\DecValTok{47}\NormalTok{,}\DecValTok{52}\NormalTok{,}\DecValTok{78}\NormalTok{) )}
\CommentTok{\# srvys \textless{}{-} data.frame(reg=c("ebs","goa","ai"),RGN = c("BS","GOA","AI"), num=c(98,47,52) )}
\NormalTok{ nreg }\OtherTok{\textless{}{-}} \FunctionTok{length}\NormalTok{(srvys}\SpecialCharTok{$}\NormalTok{reg)}
\NormalTok{ nspp }\OtherTok{\textless{}{-}} \FunctionTok{length}\NormalTok{(species\_lkup}\SpecialCharTok{$}\NormalTok{sp)}
\ControlFlowTok{for}\NormalTok{ (r }\ControlFlowTok{in} \DecValTok{1}\SpecialCharTok{:}\NormalTok{nreg)\{}
\ControlFlowTok{for}\NormalTok{(s }\ControlFlowTok{in} \DecValTok{1}\SpecialCharTok{:}\NormalTok{nspp)\{}
\ControlFlowTok{if}\NormalTok{(srvys[r,]}\SpecialCharTok{$}\NormalTok{reg }\SpecialCharTok{==}\StringTok{"ebs"}\NormalTok{)\{}
\CommentTok{\# first SEBS only:}
\CommentTok{\# {-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
\NormalTok{ STRATA\_AREAUSE }\OtherTok{\textless{}{-}}\NormalTok{ STRATA\_AREA}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{filter}\NormalTok{(REGION}\SpecialCharTok{==}\NormalTok{srvys}\SpecialCharTok{$}\NormalTok{RGN[r])}
\NormalTok{ maxyr }\OtherTok{\textless{}{-}} \FunctionTok{max}\NormalTok{(STRATA\_AREAUSE}\SpecialCharTok{$}\NormalTok{YEAR)}
\NormalTok{ STRATA\_AREAUSE }\OtherTok{\textless{}{-}}\NormalTok{ STRATA\_AREAUSE}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{filter}\NormalTok{(YEAR}\SpecialCharTok{==}\DecValTok{2022}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(REGION,STRATUM)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\AttributeTok{AREA =} \FunctionTok{mean}\NormalTok{(AREA, }\AttributeTok{na.rm=}\NormalTok{T))}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}
\CommentTok{\# label "sebs"}
\NormalTok{ flnm }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(}\StringTok{"s"}\NormalTok{,srvys[r,]}\SpecialCharTok{$}\NormalTok{reg,}\StringTok{".srvy"}\NormalTok{,}
\NormalTok{ srvys[r,]}\SpecialCharTok{$}\NormalTok{num,}\StringTok{"."}\NormalTok{,}
\NormalTok{ species\_lkup[s,]}\SpecialCharTok{$}\NormalTok{sp)}
\FunctionTok{cat}\NormalTok{(}\StringTok{"now getting data for: "}\NormalTok{,flnm,}\StringTok{"}\SpecialCharTok{\textbackslash{}n}\StringTok{"}\NormalTok{)}
\NormalTok{ cpue\_data }\OtherTok{\textless{}{-}} \FunctionTok{suppressMessages}\NormalTok{(}
\FunctionTok{get\_CPUE\_DATA}\NormalTok{(}
\AttributeTok{datapath =}\NormalTok{ data.path,}
\AttributeTok{out\_dir =} \FunctionTok{file.path}\NormalTok{(data.out),}
\AttributeTok{STRATA\_AREAIN =}\NormalTok{ STRATA\_AREAUSE,}
\AttributeTok{flnm =}\NormalTok{ flnm,}
\AttributeTok{species =}\NormalTok{ species\_lkup[s,]}\SpecialCharTok{$}\NormalTok{SPECIES\_CODE,}
\AttributeTok{survey =}\NormalTok{ srvys[r,]}\SpecialCharTok{$}\NormalTok{num,}
\AttributeTok{includeNBS =} \ConstantTok{FALSE}\NormalTok{,}
\AttributeTok{NEBSStrataIN =}\NormalTok{ NEBS\_strata ,}
\AttributeTok{saveit =}\NormalTok{ T,}
\AttributeTok{bins =}\NormalTok{ sp\_bins[[ species\_lkup[s,]}\SpecialCharTok{$}\NormalTok{sp ]]))}
\FunctionTok{rm}\NormalTok{(cpue\_data)}
\CommentTok{\# Now NESB + SEBS}
\CommentTok{\# {-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
\NormalTok{ flnm }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(srvys[r,]}\SpecialCharTok{$}\NormalTok{reg,}\StringTok{".srvy"}\NormalTok{,}
\NormalTok{ srvys[r,]}\SpecialCharTok{$}\NormalTok{num,}\StringTok{"."}\NormalTok{,}
\NormalTok{ species\_lkup[s,]}\SpecialCharTok{$}\NormalTok{sp)}
\FunctionTok{cat}\NormalTok{(}\StringTok{"now getting data for: "}\NormalTok{,flnm,}\StringTok{"}\SpecialCharTok{\textbackslash{}n}\StringTok{"}\NormalTok{)}
\NormalTok{ cpue\_data }\OtherTok{\textless{}{-}} \FunctionTok{suppressMessages}\NormalTok{(}
\FunctionTok{get\_CPUE\_DATA}\NormalTok{(}
\AttributeTok{datapath =}\NormalTok{ data.path,}
\AttributeTok{out\_dir =} \FunctionTok{file.path}\NormalTok{(data.out),}
\AttributeTok{STRATA\_AREAIN =}\NormalTok{ STRATA\_AREAUSE,}
\AttributeTok{flnm =}\NormalTok{ flnm,}
\AttributeTok{species =}\NormalTok{ species\_lkup[s,]}\SpecialCharTok{$}\NormalTok{SPECIES\_CODE,}
\AttributeTok{survey =}\NormalTok{ srvys[r,]}\SpecialCharTok{$}\NormalTok{num, }\CommentTok{\#? shouldn\textquotesingle{}t this be 98\&143? No, I see, up above I combine the NEBS+SEBS into the ebs folder and rename the rest NEBS or SEBS accordingly {-} so even though the survey number is 98 it;s actually 98 \& 143.}
\AttributeTok{includeNBS =} \ConstantTok{TRUE}\NormalTok{,}
\AttributeTok{NEBSStrataIN =}\NormalTok{ NEBS\_strata ,}
\AttributeTok{saveit =}\NormalTok{ T,}
\AttributeTok{bins =}\NormalTok{ sp\_bins[[ species\_lkup[s,]}\SpecialCharTok{$}\NormalTok{sp ]]))}
\NormalTok{ \}}
\ControlFlowTok{if}\NormalTok{(srvys[r,]}\SpecialCharTok{$}\NormalTok{reg }\SpecialCharTok{==}\StringTok{"goa"}\NormalTok{)\{}
\NormalTok{ STRATA\_AREAUSE }\OtherTok{\textless{}{-}}\NormalTok{ STRATA\_AREA}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{filter}\NormalTok{(REGION}\SpecialCharTok{==}\NormalTok{srvys}\SpecialCharTok{$}\NormalTok{RGN[r])}
\NormalTok{ maxyr }\OtherTok{\textless{}{-}} \FunctionTok{max}\NormalTok{(STRATA\_AREAUSE}\SpecialCharTok{$}\NormalTok{YEAR)}
\NormalTok{ STRATA\_AREAUSE }\OtherTok{\textless{}{-}}\NormalTok{ STRATA\_AREAUSE}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{filter}\NormalTok{(YEAR}\SpecialCharTok{==}\DecValTok{1993}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(REGION,STRATUM)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\AttributeTok{AREA =} \FunctionTok{mean}\NormalTok{(AREA, }\AttributeTok{na.rm=}\NormalTok{T))}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}
\NormalTok{ flnm }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(srvys[r,]}\SpecialCharTok{$}\NormalTok{reg,}\StringTok{".srvy"}\NormalTok{,}
\NormalTok{ srvys[r,]}\SpecialCharTok{$}\NormalTok{num,}\StringTok{"."}\NormalTok{,}
\NormalTok{ species\_lkup[s,]}\SpecialCharTok{$}\NormalTok{sp)}
\FunctionTok{cat}\NormalTok{(}\StringTok{"now getting data for: "}\NormalTok{,flnm,}\StringTok{"}\SpecialCharTok{\textbackslash{}n}\StringTok{"}\NormalTok{)}
\NormalTok{ cpue\_data }\OtherTok{\textless{}{-}} \FunctionTok{suppressMessages}\NormalTok{(}
\FunctionTok{get\_CPUE\_DATA}\NormalTok{(}
\AttributeTok{datapath =}\NormalTok{ data.path,}
\AttributeTok{out\_dir =} \FunctionTok{file.path}\NormalTok{(data.out),}
\AttributeTok{STRATA\_AREAIN =}\NormalTok{ STRATA\_AREAUSE,}
\AttributeTok{flnm =}\NormalTok{ flnm,}
\AttributeTok{species =}\NormalTok{ species\_lkup[s,]}\SpecialCharTok{$}\NormalTok{SPECIES\_CODE,}
\AttributeTok{survey =}\NormalTok{ srvys[r,]}\SpecialCharTok{$}\NormalTok{num,}
\AttributeTok{includeNBS =} \ConstantTok{FALSE}\NormalTok{,}
\AttributeTok{NEBSStrataIN =}\NormalTok{ NEBS\_strata ,}
\AttributeTok{saveit =}\NormalTok{ T,}
\AttributeTok{bins =}\NormalTok{ sp\_bins[[ species\_lkup[s,]}\SpecialCharTok{$}\NormalTok{sp ]]))}
\NormalTok{ \}}
\ControlFlowTok{if}\NormalTok{(}\SpecialCharTok{!}\NormalTok{srvys[r,]}\SpecialCharTok{$}\NormalTok{reg}\SpecialCharTok{\%in\%}\FunctionTok{c}\NormalTok{(}\StringTok{"ebs"}\NormalTok{,}\StringTok{"goa"}\NormalTok{))\{}
\ControlFlowTok{if}\NormalTok{(species\_lkup[s,]}\SpecialCharTok{$}\NormalTok{sp}\SpecialCharTok{==}\StringTok{"yfs"}\SpecialCharTok{\&}\NormalTok{srvys[r,]}\SpecialCharTok{$}\NormalTok{reg}\SpecialCharTok{==}\StringTok{"slope"}\NormalTok{)\{}
\CommentTok{\#skip}
\NormalTok{ \}}\ControlFlowTok{else}\NormalTok{\{}
\NormalTok{ flnm }\OtherTok{\textless{}{-}} \FunctionTok{paste0}\NormalTok{(srvys[r,]}\SpecialCharTok{$}\NormalTok{reg,}\StringTok{".srvy"}\NormalTok{,}
\NormalTok{ srvys[r,]}\SpecialCharTok{$}\NormalTok{num,}\StringTok{"."}\NormalTok{,}
\NormalTok{ species\_lkup[s,]}\SpecialCharTok{$}\NormalTok{sp)}
\FunctionTok{cat}\NormalTok{(}\StringTok{"now getting data for: "}\NormalTok{,flnm,}\StringTok{"}\SpecialCharTok{\textbackslash{}n}\StringTok{"}\NormalTok{)}
\NormalTok{ cpue\_data }\OtherTok{\textless{}{-}} \FunctionTok{suppressMessages}\NormalTok{(}
\FunctionTok{get\_CPUE\_DATA}\NormalTok{(}
\AttributeTok{datapath =}\NormalTok{ data.path,}
\AttributeTok{out\_dir =} \FunctionTok{file.path}\NormalTok{(data.out),}
\AttributeTok{STRATA\_AREAIN =} \ConstantTok{NULL}\NormalTok{,}
\AttributeTok{flnm =}\NormalTok{ flnm,}
\AttributeTok{species =}\NormalTok{ species\_lkup[s,]}\SpecialCharTok{$}\NormalTok{SPECIES\_CODE,}
\AttributeTok{survey =}\NormalTok{ srvys[r,]}\SpecialCharTok{$}\NormalTok{num,}
\AttributeTok{includeNBS =} \ConstantTok{FALSE}\NormalTok{,}
\AttributeTok{NEBSStrataIN =}\NormalTok{ NEBS\_strata ,}
\AttributeTok{saveit =}\NormalTok{ T,}
\AttributeTok{bins =}\NormalTok{ sp\_bins[[ species\_lkup[s,]}\SpecialCharTok{$}\NormalTok{sp ]]))}
\NormalTok{ \}}
\NormalTok{ \}}
\CommentTok{\# \# check the data :}
\ControlFlowTok{if}\NormalTok{(}\DecValTok{1}\SpecialCharTok{==}\DecValTok{10}\NormalTok{)\{}
\NormalTok{ tt }\OtherTok{\textless{}{-}}\NormalTok{ cpue\_data}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,REGION,STATIONID,SN)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{filter}\NormalTok{(BIN }\SpecialCharTok{==}\DecValTok{400}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\AttributeTok{cnt =}\FunctionTok{length}\NormalTok{(STATIONID))}
\FunctionTok{max}\NormalTok{(tt}\SpecialCharTok{$}\NormalTok{cnt) }\CommentTok{\#Should be 1}
\CommentTok{\#this looks to be a duplicate sampling...}
\CommentTok{\#mis{-}entry or code error ?}
\NormalTok{ cpue\_data}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{filter}\NormalTok{(YEAR}\SpecialCharTok{==}\DecValTok{1988}\NormalTok{,STATIONID}\SpecialCharTok{==}\StringTok{"J{-}13"}\NormalTok{)}
\NormalTok{ \}}
\FunctionTok{rm}\NormalTok{(cpue\_data)}
\NormalTok{ \}}
\NormalTok{ \}}
\CommentTok{\# Now make BT and SST files for strata, station and all basin}
\CommentTok{\# srvys \textless{}{-} data.frame(reg=c("ebs","goa","ai"),RGN = c("BS","GOA","AI"), num=c(98,47,52) )}
\NormalTok{ nreg }\OtherTok{\textless{}{-}} \FunctionTok{length}\NormalTok{(srvys}\SpecialCharTok{$}\NormalTok{reg)}
\NormalTok{ na.length }\OtherTok{\textless{}{-}} \ControlFlowTok{function}\NormalTok{(x,}\AttributeTok{na.rm=}\NormalTok{F)\{}
\ControlFlowTok{if}\NormalTok{(na.rm }\SpecialCharTok{==}\NormalTok{ T)}
\ControlFlowTok{if}\NormalTok{(}\FunctionTok{any}\NormalTok{(}\FunctionTok{is.na}\NormalTok{(x)))}
\NormalTok{ x }\OtherTok{\textless{}{-}}\NormalTok{ x[}\SpecialCharTok{!}\FunctionTok{is.na}\NormalTok{(x)]}
\FunctionTok{return}\NormalTok{( }\FunctionTok{length}\NormalTok{(x))}
\NormalTok{ \}}
\NormalTok{ i }\OtherTok{\textless{}{-}}\DecValTok{0}
\ControlFlowTok{for}\NormalTok{(regfl }\ControlFlowTok{in}\NormalTok{ srvys[,}\DecValTok{1}\NormalTok{] )\{}
\ControlFlowTok{if}\NormalTok{(regfl}\SpecialCharTok{!=}\StringTok{"slope"}\NormalTok{)\{}
\NormalTok{ i }\OtherTok{\textless{}{-}}\NormalTok{ i }\SpecialCharTok{+}\DecValTok{1}
\FunctionTok{load}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(data.path,regfl,}\StringTok{"plk/location.Rdata"}\NormalTok{))}
\NormalTok{ tmp}\OtherTok{\textless{}{-}}\NormalTok{location}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{group\_by}\NormalTok{(YEAR,STRATUM,STATIONID)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}
\AttributeTok{TEMP=}\FunctionTok{mean}\NormalTok{(TEMP,}\AttributeTok{na.rm=}\NormalTok{T),}
\CommentTok{\# sdTEMP = sd(TEMP,na.rm=T),}
\AttributeTok{num=} \FunctionTok{na.length}\NormalTok{(TEMP,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{SST =} \FunctionTok{mean}\NormalTok{(SST,}\AttributeTok{na.rm=}\NormalTok{T),}
\CommentTok{\# sdSST = sd(SST,na.rm=T),}
\AttributeTok{LAT=}\FunctionTok{mean}\NormalTok{(LAT,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{LON =} \FunctionTok{mean}\NormalTok{ (LON,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{MONTH =} \FunctionTok{mean}\NormalTok{(MONTH,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{DAY =} \FunctionTok{mean}\NormalTok{ (DAY,}\AttributeTok{na.rm=}\NormalTok{T))}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{mutate}\NormalTok{(}\AttributeTok{region =}\NormalTok{ regfl)}
\ControlFlowTok{if}\NormalTok{(i }\SpecialCharTok{==}\DecValTok{1}\NormalTok{)}
\NormalTok{ TEMP }\OtherTok{\textless{}{-}}\NormalTok{ tmp}
\ControlFlowTok{else}
\NormalTok{ TEMP }\OtherTok{\textless{}{-}} \FunctionTok{rbind}\NormalTok{(TEMP,tmp)}
\FunctionTok{rm}\NormalTok{(tmp)}
\NormalTok{\}}
\NormalTok{ \}}
\NormalTok{ TEMP\_station }\OtherTok{\textless{}{-}}\NormalTok{ TEMP}
\NormalTok{ TEMP\_yk }\OtherTok{\textless{}{-}}\NormalTok{ TEMP}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{group\_by}\NormalTok{(YEAR,STRATUM,region)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}
\AttributeTok{mnTEMP=}\FunctionTok{mean}\NormalTok{(TEMP,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{sdTEMP =} \FunctionTok{sd}\NormalTok{(TEMP,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{num=} \FunctionTok{na.length}\NormalTok{(TEMP,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{mnSST =} \FunctionTok{mean}\NormalTok{(SST,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{sdSST =} \FunctionTok{sd}\NormalTok{(SST,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{LAT=}\FunctionTok{mean}\NormalTok{(LAT,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{LON =} \FunctionTok{mean}\NormalTok{ (LON,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{MONTH =} \FunctionTok{mean}\NormalTok{(MONTH,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{DAY =} \FunctionTok{mean}\NormalTok{ (DAY,}\AttributeTok{na.rm=}\NormalTok{T))}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}
\CommentTok{\# Now just for EBS and GOA}
\CommentTok{\# {-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}{-}}
\NormalTok{ STRATA\_AREAUSE }\OtherTok{\textless{}{-}}\NormalTok{ STRATA\_AREA}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{filter}\NormalTok{(REGION}\SpecialCharTok{==}\StringTok{"BS"}\NormalTok{)}
\NormalTok{ STRATA\_AREAUSE }\OtherTok{\textless{}{-}}\NormalTok{ STRATA\_AREAUSE}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{filter}\NormalTok{(YEAR}\SpecialCharTok{==}\DecValTok{2022}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%} \CommentTok{\# updated with revised projection datum. Use 2022}
\FunctionTok{group\_by}\NormalTok{(REGION,STRATUM)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\AttributeTok{AREA =} \FunctionTok{mean}\NormalTok{(AREA, }\AttributeTok{na.rm=}\NormalTok{T))}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}
\NormalTok{ sub}\OtherTok{\textless{}{-}}\NormalTok{ TEMP\_yk}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,STRATUM,region)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{filter}\NormalTok{(region }\SpecialCharTok{\%in\%} \FunctionTok{c}\NormalTok{(}\StringTok{"nebs"}\NormalTok{,}\StringTok{"sebs"}\NormalTok{))}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{mutate}\NormalTok{(}\AttributeTok{REGION =} \StringTok{"BS"}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{left\_join}\NormalTok{(STRATA\_AREAUSE)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{ungroup}\NormalTok{()}
\NormalTok{ sub}\OtherTok{\textless{}{-}}\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{left\_join}\NormalTok{(}
\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{group\_by}\NormalTok{(YEAR,STRATUM,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\AttributeTok{AREA =} \FunctionTok{unique}\NormalTok{(AREA))}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\AttributeTok{sumAREA=}\FunctionTok{sum}\NormalTok{(AREA,}\AttributeTok{na.rm=}\NormalTok{T)))}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{mutate}\NormalTok{(}\AttributeTok{propA =}\NormalTok{ AREA}\SpecialCharTok{/}\NormalTok{sumAREA)}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}
\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{group\_by}\NormalTok{(YEAR,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\FunctionTok{sum}\NormalTok{(propA,}\AttributeTok{na.rm=}\NormalTok{T))}
\NormalTok{ SEBS\_NEBS\_TEMP\_y }\OtherTok{\textless{}{-}}\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}
\AttributeTok{mnTEMP =} \FunctionTok{sum}\NormalTok{(mnTEMP}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{sdTEMP =} \FunctionTok{sum}\NormalTok{(sdTEMP}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{mnSST =} \FunctionTok{sum}\NormalTok{(mnSST}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{sdSST =} \FunctionTok{sum}\NormalTok{(sdSST}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{num =} \FunctionTok{sum}\NormalTok{(num,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{MONTH =} \FunctionTok{sum}\NormalTok{(MONTH}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{DAY =} \FunctionTok{sum}\NormalTok{ (DAY}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T))}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}
\CommentTok{\# now just the NEBS:}
\NormalTok{ sub}\OtherTok{\textless{}{-}}\NormalTok{ TEMP\_yk}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,STRATUM,region)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{filter}\NormalTok{(region }\SpecialCharTok{\%in\%} \FunctionTok{c}\NormalTok{(}\StringTok{"nebs"}\NormalTok{))}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{mutate}\NormalTok{(}\AttributeTok{REGION =} \StringTok{"BS"}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{left\_join}\NormalTok{(STRATA\_AREAUSE)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{ungroup}\NormalTok{()}
\NormalTok{ sub}\OtherTok{\textless{}{-}}\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{left\_join}\NormalTok{(}
\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{group\_by}\NormalTok{(YEAR,STRATUM,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\AttributeTok{AREA =} \FunctionTok{unique}\NormalTok{(AREA))}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\AttributeTok{sumAREA=}\FunctionTok{sum}\NormalTok{(AREA,}\AttributeTok{na.rm=}\NormalTok{T)))}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{mutate}\NormalTok{(}\AttributeTok{propA =}\NormalTok{ AREA}\SpecialCharTok{/}\NormalTok{sumAREA)}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}
\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{group\_by}\NormalTok{(YEAR,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\FunctionTok{sum}\NormalTok{(propA,}\AttributeTok{na.rm=}\NormalTok{T))}
\NormalTok{ NEBS\_TEMP\_y }\OtherTok{\textless{}{-}}\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}
\AttributeTok{mnTEMP =} \FunctionTok{sum}\NormalTok{(mnTEMP}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{sdTEMP =} \FunctionTok{sum}\NormalTok{(sdTEMP}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{mnSST =} \FunctionTok{sum}\NormalTok{(mnSST}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{sdSST =} \FunctionTok{sum}\NormalTok{(sdSST}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{num =} \FunctionTok{sum}\NormalTok{(num,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{MONTH =} \FunctionTok{sum}\NormalTok{(MONTH}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{DAY =} \FunctionTok{sum}\NormalTok{ (DAY}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T))}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}
\CommentTok{\# now just the NEBS:}
\NormalTok{ sub}\OtherTok{\textless{}{-}}\NormalTok{ TEMP\_yk}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,STRATUM,region)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{filter}\NormalTok{(region }\SpecialCharTok{\%in\%} \FunctionTok{c}\NormalTok{(}\StringTok{"sebs"}\NormalTok{))}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{mutate}\NormalTok{(}\AttributeTok{REGION =} \StringTok{"BS"}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{left\_join}\NormalTok{(STRATA\_AREAUSE)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{ungroup}\NormalTok{()}
\NormalTok{ sub}\OtherTok{\textless{}{-}}\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{left\_join}\NormalTok{(}
\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{group\_by}\NormalTok{(YEAR,STRATUM,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\AttributeTok{AREA =} \FunctionTok{unique}\NormalTok{(AREA))}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\AttributeTok{sumAREA=}\FunctionTok{sum}\NormalTok{(AREA,}\AttributeTok{na.rm=}\NormalTok{T)))}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{mutate}\NormalTok{(}\AttributeTok{propA =}\NormalTok{ AREA}\SpecialCharTok{/}\NormalTok{sumAREA)}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}
\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{group\_by}\NormalTok{(YEAR,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\FunctionTok{sum}\NormalTok{(propA,}\AttributeTok{na.rm=}\NormalTok{T))}
\NormalTok{ SEBS\_TEMP\_y }\OtherTok{\textless{}{-}}\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}
\AttributeTok{mnTEMP =} \FunctionTok{sum}\NormalTok{(mnTEMP}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{sdTEMP =} \FunctionTok{sum}\NormalTok{(sdTEMP}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{mnSST =} \FunctionTok{sum}\NormalTok{(mnSST}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{sdSST =} \FunctionTok{sum}\NormalTok{(sdSST}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{num =} \FunctionTok{sum}\NormalTok{(num,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{MONTH =} \FunctionTok{sum}\NormalTok{(MONTH}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{DAY =} \FunctionTok{sum}\NormalTok{ (DAY}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T))}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}
\CommentTok{\# now for GOA}
\NormalTok{ STRATA\_AREAUSE }\OtherTok{\textless{}{-}}\NormalTok{ STRATA\_AREA}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{filter}\NormalTok{(REGION}\SpecialCharTok{==}\StringTok{"GOA"}\NormalTok{)}
\NormalTok{ STRATA\_AREAUSE }\OtherTok{\textless{}{-}}\NormalTok{ STRATA\_AREAUSE}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{filter}\NormalTok{(YEAR}\SpecialCharTok{==}\DecValTok{1993}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(REGION,STRATUM)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\AttributeTok{AREA =} \FunctionTok{mean}\NormalTok{(AREA, }\AttributeTok{na.rm=}\NormalTok{T))}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}
\NormalTok{ sub}\OtherTok{\textless{}{-}}\NormalTok{ TEMP\_yk}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,STRATUM,region)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{filter}\NormalTok{(region }\SpecialCharTok{\%in\%} \FunctionTok{c}\NormalTok{(}\StringTok{"goa"}\NormalTok{))}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{mutate}\NormalTok{(}\AttributeTok{REGION =} \StringTok{"GOA"}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{left\_join}\NormalTok{(STRATA\_AREAUSE)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{ungroup}\NormalTok{()}
\NormalTok{ sub}\OtherTok{\textless{}{-}}\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{left\_join}\NormalTok{(}
\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{group\_by}\NormalTok{(YEAR,STRATUM,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\AttributeTok{AREA =} \FunctionTok{unique}\NormalTok{(AREA))}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\AttributeTok{sumAREA=}\FunctionTok{sum}\NormalTok{(AREA,}\AttributeTok{na.rm=}\NormalTok{T)))}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{mutate}\NormalTok{(}\AttributeTok{propA =}\NormalTok{ AREA}\SpecialCharTok{/}\NormalTok{sumAREA)}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}
\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{group\_by}\NormalTok{(YEAR,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}\FunctionTok{sum}\NormalTok{(propA,}\AttributeTok{na.rm=}\NormalTok{T))}
\NormalTok{ GOA\_TEMP\_y }\OtherTok{\textless{}{-}}\NormalTok{ sub}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,REGION)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarize}\NormalTok{(}
\AttributeTok{mnTEMP =} \FunctionTok{sum}\NormalTok{(mnTEMP}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{sdTEMP =} \FunctionTok{sum}\NormalTok{(sdTEMP}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{mnSST =} \FunctionTok{sum}\NormalTok{(mnSST}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{sdSST =} \FunctionTok{sum}\NormalTok{(sdSST}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{num =} \FunctionTok{sum}\NormalTok{(num,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{MONTH =} \FunctionTok{sum}\NormalTok{(MONTH}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{DAY =} \FunctionTok{sum}\NormalTok{ (DAY}\SpecialCharTok{*}\NormalTok{propA,}\AttributeTok{na.rm=}\NormalTok{T))}\SpecialCharTok{\%\textgreater{}\%}\FunctionTok{ungroup}\NormalTok{()}
\ControlFlowTok{if}\NormalTok{(}\SpecialCharTok{!}\FunctionTok{dir.exists}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(data.out,}\StringTok{"Temp"}\NormalTok{)))}
\FunctionTok{dir.create}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(data.out,}\StringTok{"Temp"}\NormalTok{))}
\FunctionTok{save}\NormalTok{(GOA\_TEMP\_y,}\AttributeTok{file =} \FunctionTok{file.path}\NormalTok{(data.out,}\StringTok{"Temp/GOA\_TEMP\_y.Rdata"}\NormalTok{))}
\FunctionTok{save}\NormalTok{(SEBS\_TEMP\_y,}\AttributeTok{file =} \FunctionTok{file.path}\NormalTok{(data.out,}\StringTok{"Temp/SEBS\_TEMP\_y.Rdata"}\NormalTok{))}
\FunctionTok{save}\NormalTok{(NEBS\_TEMP\_y,}\AttributeTok{file =} \FunctionTok{file.path}\NormalTok{(data.out,}\StringTok{"Temp/NEBS\_TEMP\_y.Rdata"}\NormalTok{))}
\FunctionTok{save}\NormalTok{(SEBS\_NEBS\_TEMP\_y,}\AttributeTok{file =} \FunctionTok{file.path}\NormalTok{(data.out,}\StringTok{"Temp/SEBS\_NEBS\_TEMP\_y.Rdata"}\NormalTok{))}
\FunctionTok{save}\NormalTok{(TEMP\_station,}\AttributeTok{file =} \FunctionTok{file.path}\NormalTok{(data.out,}\StringTok{"Temp/TEMP\_station.Rdata"}\NormalTok{))}
\FunctionTok{save}\NormalTok{(TEMP\_yk,}\AttributeTok{file =} \FunctionTok{file.path}\NormalTok{(data.out,}\StringTok{"Temp/TEMP\_yk.Rdata"}\NormalTok{))}
\FunctionTok{cat}\NormalTok{(}\StringTok{"The cpue files are now saved in the directory "}\NormalTok{,}\FunctionTok{file.path}\NormalTok{(data.out,}\StringTok{"../"}\NormalTok{))}
\CommentTok{\#}
\CommentTok{\# \textasciigrave{}\textasciigrave{}\textasciigrave{}}
\CommentTok{\# }
\CommentTok{\# *The cpue files are now saved in the directory \textasciigrave{}r file.path(data.out,"../")\textasciigrave{}*}
\CommentTok{\# }
\CommentTok{\# \textasciigrave{}\textasciigrave{}\textasciigrave{}\{r viewcpue\_data, echo=TRUE, eval=FALSE\} }
\CommentTok{\# this uses the password saved in R/password.R}
\CommentTok{\# suppressMessages(source("R/make.R"))}
\FunctionTok{load}\NormalTok{(}\FunctionTok{file.path}\NormalTok{(data.out,}\StringTok{"cpue/ebs/ebs.srvy98.pcod.cpue\_data.Rdata"}\NormalTok{))}
\FunctionTok{names}\NormalTok{(cpue\_data)}
\FunctionTok{library}\NormalTok{(dplyr)}
\NormalTok{checkit }\OtherTok{\textless{}{-}}\ControlFlowTok{function}\NormalTok{(x)\{}
\ControlFlowTok{if}\NormalTok{(}\FunctionTok{round}\NormalTok{(}\FunctionTok{max}\NormalTok{(x ),}\DecValTok{1}\NormalTok{)}\SpecialCharTok{!=}\DecValTok{1}\NormalTok{) \{}
\FunctionTok{warning}\NormalTok{(}\StringTok{"ERROR! propB \textgreater{} 1 "}\NormalTok{)}
\FunctionTok{print}\NormalTok{(x)\}}
\NormalTok{\}}
\CommentTok{\#double check the results}
\NormalTok{ cnt\_ByStrataBin }\OtherTok{\textless{}{-}}\NormalTok{ cpue\_data}\SpecialCharTok{$}\NormalTok{propByStrataBin}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{select}\NormalTok{(}\StringTok{"REGION"}\NormalTok{,}\StringTok{"YEAR"}\NormalTok{,}\StringTok{"STRATUM"}\NormalTok{,BIN,BIN\_mm,}
\NormalTok{ SPECIES\_CODE,CN,SN,sp,num,}
\StringTok{"propB\_ykl"}\NormalTok{,}\StringTok{"propN\_ykl"}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,REGION,SN,CN)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarise}\NormalTok{(}\AttributeTok{sum\_propB\_ykl=}\FunctionTok{sum}\NormalTok{(propB\_ykl,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{sum\_propN\_ykl=}\FunctionTok{sum}\NormalTok{(propN\_ykl,}\AttributeTok{na.rm=}\NormalTok{T))}
\NormalTok{ cnt\_ByStrata }\OtherTok{\textless{}{-}}\NormalTok{ cpue\_data}\SpecialCharTok{$}\NormalTok{propByStrata}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{select}\NormalTok{(}\StringTok{"REGION"}\NormalTok{,}\StringTok{"YEAR"}\NormalTok{,}\StringTok{"STRATUM"}\NormalTok{,}
\NormalTok{ SPECIES\_CODE,CN,SN,sp,num,}
\StringTok{"propB\_yk"}\NormalTok{,}\StringTok{"propN\_yk"}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,REGION,SN,CN)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarise}\NormalTok{(}\AttributeTok{sum\_propB\_yk=}\FunctionTok{sum}\NormalTok{(propB\_yk,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{sum\_propN\_yk=}\FunctionTok{sum}\NormalTok{(propN\_yk,}\AttributeTok{na.rm=}\NormalTok{T))}
\NormalTok{ cnt\_ByBin }\OtherTok{\textless{}{-}}\NormalTok{ cpue\_data}\SpecialCharTok{$}\NormalTok{propByBin}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{select}\NormalTok{(}\StringTok{"REGION"}\NormalTok{,}\StringTok{"YEAR"}\NormalTok{,BIN,BIN\_mm,num,}
\NormalTok{ SPECIES\_CODE,CN,SN,sp,}
\StringTok{"propB\_yl"}\NormalTok{,}\StringTok{"propN\_yl"}\NormalTok{)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{group\_by}\NormalTok{(YEAR,REGION,SN,CN)}\SpecialCharTok{\%\textgreater{}\%}
\FunctionTok{summarise}\NormalTok{(}\AttributeTok{sum\_propB\_yl=}\FunctionTok{sum}\NormalTok{(propB\_yl ,}\AttributeTok{na.rm=}\NormalTok{T),}
\AttributeTok{sum\_propN\_yl=}\FunctionTok{sum}\NormalTok{(propN\_yl ,}\AttributeTok{na.rm=}\NormalTok{T))}
\FunctionTok{checkit}\NormalTok{(cnt\_ByStrataBin}\SpecialCharTok{$}\NormalTok{sum\_propB\_ykl)}
\FunctionTok{checkit}\NormalTok{(cnt\_ByStrata}\SpecialCharTok{$}\NormalTok{sum\_propB\_yk)}
\FunctionTok{checkit}\NormalTok{(cnt\_ByBin}\SpecialCharTok{$}\NormalTok{sum\_propB\_yl)}
\CommentTok{\# Step 4 Create Assessment files}
\ControlFlowTok{if}\NormalTok{(}\DecValTok{1}\SpecialCharTok{==}\DecValTok{10}\NormalTok{)\{}
\NormalTok{ thisYr }\OtherTok{\textless{}{-}} \FunctionTok{format}\NormalTok{(}\FunctionTok{Sys.time}\NormalTok{(), }\StringTok{"\%Y"}\NormalTok{)}
\NormalTok{ today }\OtherTok{\textless{}{-}} \FunctionTok{format}\NormalTok{(}\FunctionTok{Sys.time}\NormalTok{(), }\StringTok{"\%b \%d, \%Y)}
\StringTok{ source("}\NormalTok{R}\SpecialCharTok{/}\NormalTok{make.R}\StringTok{")}
\StringTok{ \}}
\StringTok{ }
\StringTok{ }
\StringTok{ source("}\NormalTok{R}\SpecialCharTok{/}\NormalTok{sub\_scripts}\SpecialCharTok{/}\NormalTok{make\_assessment\_files.R}\StringTok{")}
\StringTok{ }
\StringTok{\# }
\end{Highlighting}
\end{Shaded}
\hypertarget{step-4-make-some-plots}{%
\subsection{Step 4: make some plots}\label{step-4-make-some-plots}}
\hypertarget{appendix-1-rsetup.rprimary-setup-script}{%
\subsection{\texorpdfstring{Appendix 1: \texttt{R/setup.R}primary setup
script}{Appendix 1: R/setup.Rprimary setup script}}\label{appendix-1-rsetup.rprimary-setup-script}}
\end{document}