-
Notifications
You must be signed in to change notification settings - Fork 0
/
Run_CEATTLE_2024.Rmd
959 lines (785 loc) · 42.7 KB
/
Run_CEATTLE_2024.Rmd
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
---
output:
html_document: default
pdf_document: default
---
# Update the EBS Multi-species Stock Assessment
#### Kirstin Holsman
#### kirstin.holsman@noaa.gov
```{r, echo = F}
#knitr::opts_chunk$set(echo = TRUE)
tmpdir <- getwd()
setwd("../../CEATTLE")
source("R/make.R") # loads packages, data, setup, etc.
setwd(tmpdir)
thisYr <- as.numeric(format(Sys.time(), "%Y"))
today <- format(Sys.time(), "%b %d, %Y")
```
*Last updated: `r today`*
**This code runs the Assessment update loop for CEATTLE.**This document steps through the process of fitting the CEATTLE model to EBS data and projecting to get multispecies reference points. To ensure that the model runs correctly, it is best to run all steps on the same machine otherwise some errors may arise (still debugging the tmpfile.txt and paths in a few r-scripts, but they run correctly if started at step 1).
_The code below assumed a model run name of **assmnt_2020** (designated using -m) and various sub-run names (designated using -f)._
## A note on updating data:
The following minimal updates are needed:
### The following variables are needed in order to update the input files with the latest year of data:
main assessment data file (main.dat): assmnt_2020_2.dat
variable Filename
[2021] nyrs ceattle.ctl
[2021] nyrs_est ceattle.ctl
[2021] nTyrs retro_data2018_asssmnt.dat
[2021] BTempC_retro retro_data2018_asssmnt.dat (,1,nTyrs)
[2021] SSTempC_retro retro_data2018_asssmnt.dat (,1,nTyrs)
[2021] rs_cov retro_data2018_asssmnt.dat rs_cov(1,ncov,1,nTyrs)
[2021] nyrs_tc_biom main.dat
[2021] tcb_biom_obs main.dat
[2021] nyrs_fsh_comp main.dat
[2021] yrs_fsh_comp main.dat
[2021] obs_catch main.dat (note this is numbers by age/size)
[2021] nyrs_wt_at_age main.dat
[2021] yrs_wt_at_age main.dat
[2021] wt main.dat
[2021] nyrs_srv_biom main.dat
[2021] srv_biom main.dat
[2021] nyrs_srv_age main.dat
[2021] yrs_srv_age main.dat
[2021] srv_age_n main.dat
[2021] srv_age_obs main.dat (note this is numbers by age/size)
**_Additional files that should be updated:**_
[2016] n_eit main.dat
[2016] yrs_eit main.dat
[2016] obs_eit_age main.dat
[2016] eit_age_n main.dat
[2016] nyrs_eit_sel main.dat
[2016] yrs_eit_sel main.dat
[2016] eit_sel main.dat
[2021] nTyrs_obs stomach2019.dat
[2021] Tyrs_obs stomach2019.dat
[2021] nPyrs stomach2019.dat Pby_yr(1,nspp,1,nyrs+1,1,nages)
[2021] Pyrs stomach2019.dat Not used = nyrs
[2021] Pby_yr stomach2019.dat and
## Step 1: Estimate parameters conditioned on historical data
**_-o overwrites folders with the same name_**
* Note that for 2021 I used the observed SST and bottom temperatures but interpolated 1979-1981 and 2020 from the ROMSNPZ bottom and SST using the bias correction methods where the mean was calculate for 1982-2012. Tobsmn+ ((SDobs/SDmod)(Tmod_y-Tmodmn)).
This is based on ACLIM methodology (Holsman et al. 2020) that sets a universal B0 for all climate scenarios in the projection mode. The universal B0 is specific to single- or multi-species modes and is not yet fully automated.
# The general approach is:
# 1. estimate / fit the model
# 2. project with F = 0 to get B0 under climate naive (persistence)
# 3. input B0 into model and project with F to get to 40% B0 under climate naive (persistence) - can be climate informed
# 4. step three give Ftarget and ABC2100 from 3 (take average of last 5 years to get max ABC)
# 5. Calculate F_abc in y+1 given catch_y+1 = ABC_y+1 = ABC_2100 (that F is now Fabc)
# 6. Use Fabc to get ABC_y+1 and ABC_y+2 This can be climate informed
```{r getTemp, eval=FALSE, include = T}
# flhd <- "KKHfut_ACLIM2_CMIP6_delta_bc.dat"
# #"KKHhind_operat_ACLIM2_CMIP5n6_operational_short_bcs.dat"
# flft <- "KKHhind_ACLIM2_CMIP6_delta_bc.dat"
# # "KKHfut_operat_ACLIM2_CMIP5n6_operational_short_bcs.dat"
# from_fldr <- "../../ACLIM2/Data/out"
# to_fldr <- "data/in/dat_input_files"
#
source("docs/Assessment_setup.R")
setwd(run_fl)
if(1==10) source("R/get_EBSTemp.R")
update_romsindices <- FALSE
# make the ROMSNPZ indices
tmpdir <- getwd()
setwd("../../ACLIM2")
suppressMessages( suppressWarnings(source("R/make.R")))
if(update_romsindices){
source("R/sub_scripts/make_ceattle_indices.R")
}else{
load(file="Data/out/CEATTLE_indices/ceattle_vars_op.Rdata")
load(file="Data/out/CEATTLE_indices/ceattle_vars_wide_op.Rdata")
}
# now create .dat files
varlist <- unique(ceattle_vars_op$var)
aa <- sapply(strsplit(varlist,"_"),"[",2:3)
tmpV <- data.frame(apply(aa,1,paste0))%>%mutate(var = paste0(X1,"_",X2))
varset_list <- tmpV$var; rm(tmpV)
# switches
thisYr <- as.numeric(format(Sys.time(), "%Y"))
today <- format(Sys.time(), "%b %d, %Y")
lastyr_hind <- thisYr-1 #as.numeric(thisYr) #2021
hind_yrs <- 1979:thisYr # define the years of your estimation model
fut_yrs <- (thisYr+1):2099 # define the years of your projections
stitchDate <- "2019-12-30" # last date of the ACLIM hindcast
stitchDate_op <- "2022-05-16" #last operational hindcast date
log_adj <- 1e-4
zscore_years <- 1980:2010 # years to recenter z score on
plotbasin <- "SEBS"
# Define the name for the .dat file
fn <- paste0("ACLIM2_CMIP6_short_delta_bc_",thisYr,".dat")
fn_long <- paste0("ACLIM2_CMIP6_delta_bc_",thisYr,".dat")
archive_old <- T # Archive the older version of the .dat file?
normlist <- read.csv(file=file.path(Rdata_path,"../../../out/normlist.csv"))
CMIPS <- c("K20P19_CMIP6","K20P19_CMIP5")
# create dat files:
source("R/sub_scripts/make_CEATTLE_dat_files.R")
topath <- file.path(run_fl,"data/in/dat_input_files")
# copy files over:
file.copy(from = fndat_hind, to = file.path(topath), overwrite = T)
file.copy(from = fndat_fut, to = file.path(topath), overwrite = T)
file.copy(from = fndat_hind_long, to = file.path(topath), overwrite = T)
file.copy(from = fndat_fut_long, to = file.path(topath), overwrite = T)
# file.copy(from = fndat_hind2, to = file.path(topath), overwrite = T)
# file.copy(from = fndat_fut2, to = file.path(topath), overwrite = T)
#
# also copy to a folder for this year:
thisyr_fl <- file.path(run_fl,"data/in",paste0(thisYr,"_data"))
if(!dir.exists(thisyr_fl))
dir.create(thisyr_fl)
fnn <- file.path(thisyr_fl,"..","Bering10K_simulation_variables.xlsx")
if(!file.exists(fnn))
download.file(url ="https://zenodo.org/record/4586950/files/Bering10K_simulation_variables.xlsx?download=1",
destfile=fnn)
var_def <- readxl::read_xlsx(fnn, col_names = TRUE,skip=2)
oxygen_thresh <- data.frame(mg_l = "<3",category = "Hypoxia")
O2mmol_m3_to_O2mg_L <- function(mmol_m3){
# Oxygen (O2)
# https://www.ices.dk/data/tools/Pages/Unit-conversions.aspx
# Molar volume at STP = 22.391 l
# Molar weight of oxygen = 31.998 g
# Atomic Mass of oxygen = 15.994 g/mol
# 1 µmol O2= 0.022391 ml
# 1 ml/l = 1000/22.391 = 44.661 µmol/l
# 1 mg/l = 22.391 ml/31.998 = 0.700 ml/l
# 1 mg-at/l = 15.994x22.391/31.998 = 11.192 ml
# 1 m3 of seawater = 1000 L 1m3 = 1000L
ATmg_mmol <- 15.994*(1/1000)*(1000/1) #g/mol * mol/1000 mmol 1000 mg/g = mg/mmol
ATmg_m3 <- mmol_m3*ATmg_mmol # mg/mmol* mmol/m3 = mg/m3
ATmg_L <- ATmg_m3/1000 # mg/m3 *m3/1000L = mg/L
return((c(O2mg_L=ATmg_L)))
}
# 62.5 mmol m-3 = hypoxia Zhang 2022 Water research v 225
O2mg_L_to_O2mmol_m3<- function(mg_L){
ATmg_mmol <- 15.994*(1/1000)*(1000/1) #g/mol * mol/1000 mmol 1000 mg/g = mg/mmol
ATmg_m3 <- mg_L*1000
mmol_m3 <- ATmg_m3/ATmg_mmol
return((c(O2mmol_m3 = mmol_m3)))
}
normoxic = O2mg_L_to_O2mmol_m3(6) # cold water fish
lowoxygen = O2mg_L_to_O2mmol_m3(4) # eg crabs
hypoxic_cat1 = O2mg_L_to_O2mmol_m3(3) # eg crabs
hypoxic_cat2 = O2mg_L_to_O2mmol_m3(2) # eg crabs
anoxic = O2mg_L_to_O2mmol_m3(1) # eg crabs
file.copy(from = "Data/out/CEATTLE_indices", to = thisyr_fl, recursive = T)
save(fut, file=file.path(thisyr_fl,paste0("fut.Rdata")))
save(hind, file=file.path(thisyr_fl,paste0("hind.Rdata")))
# make some variable plots for the assessment:
scen_lvls <- sort(unique(ceattle_vars_op$scen))
scen_lvls <- scen_lvls[c( grep("126",scen_lvls),
grep("45",scen_lvls),
grep("85",scen_lvls))]
GCM_scen_lvls <- sort(unique(ceattle_vars_op$GCM_scen))
GCM_scen_lvls <- c("A: Hindcast",GCM_scen_lvls[c( grep("126",GCM_scen_lvls),
grep("45",GCM_scen_lvls),
grep("85",GCM_scen_lvls))])
tt <- ceattle_vars_op%>%
ungroup()%>%rowwise()%>%
mutate(GCM_scen = factor(GCM_scen,levels = GCM_scen_lvls),
scen = factor(scen,levels = scen_lvls),
season_lab = sapply(strsplit(var,"_"),"[",1) )
tta <- tt%>%
select(basin,year,var,val_use,mn_val,mnDate, GCM_scen,GCM,type,scen,season)%>%ungroup()
ttb <- tta%>%
filter(year<thisYr,GCM == "hind")%>%
unique()%>%
mutate(GCM_scen =factor("A: Hindcast",levels = GCM_scen_lvls))%>%ungroup()
tt_use <- rbind(tta,ttb)
tt_use <- tt_use%>%rowwise()%>%mutate(var2=
strsplit(var,split=paste0(season,"_"))[[1]][2]
)
tt_use$var2 <- gsub("temp_bottom5m","BT",tt_use$var2)
tt_use$var2 <- gsub("temp_surface5m","SST",tt_use$var2)
tt_use$var2 <- gsub("oxygen_bottom5m","O2",tt_use$var2)
tt_use$var2 <- gsub("fracbelow2","Coldpool",tt_use$var2)
tt_use$var2 <- gsub("fracbelow1","BT < 1 ",tt_use$var2)
tt_use$var2 <- gsub("_integrated","",tt_use$var2)
tt_use$var2 <- gsub("_surface5m","",tt_use$var2)
unique(tt_use$var2)
ceattle_covars <- tt_use
save(ceattle_covars, file = file.path(tmpdir,"Figs/ceattle_covars.Rdata"))
colIT <- c("gray30", col4(length(GCM_scen_lvls)-1))
names(colIT) <- c(GCM_scen_lvls)
save(colIT, file = file.path(tmpdir,"Figs/colIT.Rdata"))
# plot the full set in one panel:
seasonIN <- "Spring"
plot_all <- list()
for(seasonIN in unique(tt_use$season)){
plot_all[[seasonIN]] <- ggplot(tt_use%>% filter(var%in%varlist,season==seasonIN))+
geom_line(aes(x=mnDate,y=mn_val,color= GCM_scen, linetype = basin))+
labs(title="CEATTLE Indices, delta corrected to the operational hindcast")+
geom_line(data = tt_use%>%
filter(GCM_scen=="A: Hindcast",var%in%varlist,season==seasonIN) ,
aes(x=mnDate,y=mn_val,color= GCM_scen, linetype = basin),
inherit.aes = FALSE,
show.legend = TRUE) +theme_minimal()+
scale_color_manual(values=colIT,name="Scenario")+
scale_fill_manual(values=colIT,name="Scenario")+
facet_grid(var2~scen,scales="free_y")+
labs(subtitle = seasonIN) +
# theme(legend.position="bottom",
# strip.text = element_text(size = 8))+
#guides(color=guide_legend(nrow=1, byrow=TRUE))+
ylab("")
sclr <- 1
jpeg(filename = file.path(tmpdir,"Figs",paste0(seasonIN,"_all.jpg")),
width=8*sclr,height=10*sclr,units="in",res=250)
print(plot_all[[seasonIN]])
dev.off()
}
plot_all[["Spring"]]
plot_varset <- list()
if(!dir.exists(file.path(tmpdir,"Figs/varset/")))
dir.create(file.path(tmpdir,"Figs/varset/"))
sclr <- 1
# plot actual values
for(varset in varset_list){
cat("plotting(",varset,")\n")
plot_varset[[varset]] <-
plotTS(tt_use%>%filter(var%in%varlist[grep(varset,varlist)]),
plotvalIN = "mn_val")+
labs(title="CEATTLE Indices, delta corrected to the operational hindcast")+
geom_line(data = tt_use%>%
filter(GCM_scen=="A: Hindcast",var%in%varlist[grep(varset,varlist)]) ,
aes(x=mnDate,y=mn_val,color= GCM_scen, linetype = basin),
fill=NA,inherit.aes = FALSE,
show.legend = TRUE) +
scale_color_manual(values=colIT,name="Scenario")+
scale_fill_manual(values=colIT,name="Scenario")+
facet_grid(season ~ scen,scales="free_y")+
labs(subtitle = varset)+
ylab(varset)
if(length(grep("oxygen",varset)>0)){
plot_varset[[varset]] <- plot_varset[[varset]]+
geom_hline(aes(yintercept = lowoxygen, linetype="low oxygen"),
alpha = .6, color="orange3",size=1)+
geom_hline(aes(yintercept = hypoxic_cat1, linetype="hypoxic (cat1)"),
alpha = .6, color="red4",size=1.2)+
scale_linetype_manual(name="",
values = c("SEBS" = 1,"low oxygen" = 2,"hypoxic (cat1)" =3))
# coord_cartesian(ylim=c(0,400))
}
plot_varset[[varset]]
jpeg(filename = file.path(tmpdir,"Figs/varset",paste0(varset,"_fut.jpg")),
width=8*sclr,height=7*sclr,units="in",res=250)
print(plot_varset[[varset]])
dev.off()
}
# indices used in the dat files
scenyr <- expand.grid(year=unique(hind$year),
scen=unique(fut$scen),
GCM=unique(fut$GCM))%>%filter(!is.na(scen),is.na(GCM))
lla <- fut%>%mutate(
season_lab = sapply(strsplit(var,"_"),"[",1) )%>%
select(season_lab,basin,year,var,val_use,val_use_scaled,
mnDate, GCM_scen,GCM,type,scen)%>%ungroup()
llb <- hind%>%rowwise%>%mutate(
mnDate = as.Date(paste0(year,"-02-23")),
season_lab = sapply(strsplit(var,"_"),"[",1) ,
GCM_scen = "A: Hindcast")%>%
mutate(GCM_scen =factor("A: Hindcast",levels = GCM_scen_lvls))%>%
full_join(scenyr)%>%
select(season_lab,basin,year,var,val_use,val_use_scaled
,mnDate, GCM_scen,GCM,type,scen)%>%ungroup()
ll_use <- rbind(lla,llb)%>%filter(!is.na(basin))%>%
mutate(GCM_scen = factor(GCM_scen,levels = GCM_scen_lvls),
scen = factor(scen,levels = scen_lvls))%>%ungroup()
aa <- sapply(strsplit(unique(ll_use$var)[grep("Fall",unique(ll_use$var))],"_"),"[",2:3)
tmpV <- data.frame(apply(aa,1,paste0))%>%mutate(var = paste0(X1,"_",X2))
varset_list <- tmpV$var; rm(tmpV)
plot_varset_scaled<-list()
for(varset in varset_list){
cat("plotting(",varset,")\n")
plot_varset_scaled[[varset]] <-
plotTS(ll_use%>%filter(!is.na(scen),var%in%varlist[grep(varset,varlist)]),
plotvalIN = "val_use_scaled")+
labs(title="CEATTLE Scaled Indices, delta corrected to the operational hindcast")+
geom_line(data = ll_use%>%
filter(GCM_scen=="A: Hindcast",var%in%varlist[grep(varset,varlist)]) ,
aes(x=mnDate,y=val_use_scaled,color= GCM_scen, linetype = basin),
fill=NA,inherit.aes = FALSE,
show.legend = TRUE) +
scale_color_manual(values=colIT,name="Scenario")+
scale_fill_manual(values=colIT,name="Scenario")+
facet_grid(season_lab ~ scen,scales="free_y")+
labs(subtitle = varset)+
ylab(varset)
plot_varset_scaled[[varset]]
jpeg(filename = file.path(tmpdir,"Figs/varset",paste0(varset,"_fut_scaled.jpg")),
width=8*sclr,height=7*sclr,units="in",res=250)
print(plot_varset_scaled[[varset]])
dev.off()
}
plot_varset_scaledv2<-list()
for(varset in varset_list){
cat("plotting(",varset,")\n")
plot_varset_scaledv2[[varset]] <-
plotTS(ll_use%>%filter(!is.na(scen),var%in%varlist[grep(varset,varlist)]),
plotvalIN = "val_use_scaled")+
labs(title="CEATTLE Scaled Indices, delta corrected to the operational hindcast")+
geom_line(data = ll_use%>%
filter(GCM_scen=="A: Hindcast",var%in%varlist[grep(varset,varlist)]) ,
aes(x=mnDate,y=val_use_scaled,color= GCM_scen, linetype = basin),
fill=NA,inherit.aes = FALSE,
show.legend = TRUE) +
scale_color_manual(values=colIT,name="Scenario")+
scale_fill_manual(values=colIT,name="Scenario")+
facet_grid(scen~season_lab,scales="free_y")+
labs(subtitle = varset)+
ylab(varset)
plot_varset_scaledv2[[varset]]
jpeg(filename = file.path(tmpdir,"Figs/varset",paste0(varset,"_fut_scaledv2.jpg")),
width=8*sclr,height=7*sclr,units="in",res=250)
print(plot_varset_scaledv2[[varset]])
dev.off()
}
plot_varset_scaledv3<-list()
for(varset in varset_list){
cat("plotting(",varset,")\n")
plot_varset_scaledv3[[varset]] <-
plotTS(ll_use%>%filter(!is.na(scen),var%in%varlist[grep(varset,varlist)]),
plotvalIN = "val_use_scaled")+
labs(title="CEATTLE Scaled Indices, delta corrected to the operational hindcast")+
geom_line(data = ll_use%>%
filter(GCM_scen=="A: Hindcast",var%in%varlist[grep(varset,varlist)]) ,
aes(x=mnDate,y=val_use_scaled,color= GCM_scen, linetype = basin),
fill=NA,inherit.aes = FALSE,
show.legend = TRUE) +
scale_color_manual(values=colIT)+
scale_fill_manual(values=colIT)+
facet_grid(season_lab~GCM,scales="free_y")+
labs(subtitle = varset)+
ylab(varset)
plot_varset_scaledv3[[varset]]
jpeg(filename = file.path(tmpdir,"Figs/varset",paste0(varset,"_fut_scaledv3.jpg")),
width=8*sclr,height=7*sclr,units="in",res=250)
print(plot_varset_scaledv3[[varset]])
dev.off()
}
# return to runfolder
setwd(tmpdir)
```
Rohan, S.K., Barnett L.A.K., and Charriere, N. 2022. Evaluating approaches to estimating mean temperatures and cold pool area from AFSC bottom trawl surveys of the eastern Bering Sea. U.S. Dep. Commer., NOAA Tech. Mem. NMFS-AFSC-456, 42 p. https://doi.org/10.25923/1wwh-q418
```{r setup, eval=FALSE, include = T}
#' HarvestMode == 3 get X% target of B0 HCR = 1.7atf first (to get B0 for pcod pollock), such that no B B35%
#' HarvestMode == 11 use set F
#' HarvestMode == 3 , HCR = 1.8 <- set B0 for B40 proxy
#' recMode : recruitment mode
#' 0 = project under mean rec (no RS)
#' 1 = mean RS function (mean RS no covariates, ricker; rs_data4CEATTLE_0_0_0)
#' 2 = RS function plus SST (rs_data4CEATTLE_SST
#' 3 = RS function based on top AIC selected environm. parms for each spp (rs_data4CEATTLE_TOP)
#' 4 = RS function based on model with top R2 value (rs_data4CEATTLE_TopR2)
#' 5 = RS function based on Recfile_name (above)
#' 6 = RS function plus bottom temp
#' 7 = RS function plus Cold Pool
#' 8 = RS function plus full model plus EAT (tot)
#'
# !! BEFORE RUNNING !!:
# Update docs/Assessment_setup.R
# 1) copy replace assmnt_2023 with the new file name
# 2) copy replace asmnt2023_ with the new control name
# Run this in a terminal (better than Rconsole on R studio)
# But if using R studio Copy paste into console don't use "run lines" in Rstudio
# R
# rm(list=ls());setwd("/Volumes/LaCie/GitHub_cloud/CEATTLE_projects/2023_Multispp_assessment")
# switches
thisYr <- as.numeric(format(Sys.time(), "%Y"))
today <- format(Sys.time(), "%b %d, %Y")
source("docs/Assessment_setup.R")
# -------------------------
# copy from 03_AK_climate_energetics on the PC to the data folder here
# -------------------------
#' diet_p4CEATTLE.Rdata
#' mnBy_Yr_JuvAdult.Rdata
#' mnBy_YrBin.Rdata
fllist <- c("diet_p4CEATTLE.Rdata","mnBy_Yr_JuvAdult.Rdata","mnBy_YrBin.Rdata" )
fl0 <- "/Users/KKH/Documents/GitHub_mac/AFSC_computer_github/03_AK_climate_engergtics/Data/out/biom_weighted/ebs/ED/DIG_lt_50/"
file.copy(file.path(fl0,"mnBy_Yr_JuvAdult.Rdata"),to = ("data/in/dietdata"), recursive = T, overwrite = T)
file.copy(file.path(fl0,"mnBy_YrBin.Rdata"),to = ("data/in/dietdata"), recursive = T, overwrite = T)
fl1 <- "/Users/KKH/Documents/GitHub_mac/AFSC_computer_github/03_AK_climate_engergtics/Figs/2024"
file.copy(file.path(fl1,"diet_p4CEATTLE.Rdata"),to = ("data/in/dietdata"), recursive = T, overwrite = T)
file.copy(file.path(fl1,"CEATTLE"),to = ("data/in/dietdata"), recursive = T, overwrite = T)
# source("update_dat_input_files.R")
# compile the model if needed:
if(compileTPL){
tryCatch(
expr = {
compiled <- "FALSE"
if(file.exists( file.path(run_fl,"model/tpl",modelIN) ) )
file.rename(form= file.path(run_fl,"model/tpl",modelIN),
to = file.path(run_fl,"model/tpl",
paste0(modelIN,"_",format(Sys.time(), "%Y%m%d_%H%M%S"))))
system(paste0("cd ",
file.path(run_fl,"model/tpl"),
"; admb ",modelIN,".tpl"))
if(file.exists( file.path(run_fl,"model/tpl",modelIN) ) )
compiled <- "TRUE"
},
error= function(e){
stop(paste0("Problem with model:", modelIN,"; error returned: ",e))
compiled <- "FALSE"
},
warning= function(e){
message(paste0("Compiling returned the following warnings:", e))
},
finally = {
#archive prev_version:
if( compiled){
if(file.exists(file.path(run_fl,"model",modelIN)))
file.rename(file.path(run_fl,"model",modelIN),
file.path(run_fl,"model",paste0(modelIN,"_",format(Sys.time(), "%Y%M%d%H%M%S"))))
file.copy(file.path(run_fl,"model/tpl",modelIN),
file.path(run_fl,"model",modelIN),overwrite=T)
message("-- Model compiled and copied to run_fl: ", run_fl,"\n")
}else{
message("-- Model failed to compile\n")
}
})
}
debugIT <- FALSE
setwd(tmpdir)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Step 1. fit the model
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
source(file.path("R/get_historicalFit.R"))
load(file.path(fl_0,"results/CEATTLE_results.Rdata")); ceattle_0<-tmp
load(file.path(fl_2,"results/CEATTLE_results.Rdata")); ceattle_2<-tmp
nyrs <- ceattle_0$nyrs[1,1]
source(file.path("R/get_prey_consumed_CEATTLE.R"))
# results avail :
#source("R/sub_fun/run_fut.R")
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# #' Step 2. project with F = 0 to get B0 under climate naive (persistence) (meanRicker)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# #' HarvestMode == 3 get X% target of B0 HCR = 1.7
# #' atf first (to get B0 for pcod pollock), such that no B B35%
source(file.path("R/get_ClimateNaiveBtarget.R"))
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#' Step 3 and finally get ABC using FABC+slopingHCR (h =3)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#' HarvestMode == 3 , HCR = 1.8 <- set B0 for B40 proxy
source(file.path("R/get_ClimateInformed_ABC.R"))
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Step 4 and finally get ABC set F (h = 11)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Project under constant climate and mean Ricker RS to get B0 for both modes
#' HarvestMode == 11 use set F to get ABC
source(file.path("R/get_ClimateInformed_ABC_part2.R"))
# q("no")
```
***
***
## >>Everything below this line is defunct for now<<
***
***
<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<!-- ## Defunct Step 6: Calculate F40 for different recruitment models -->
## Step 4: Calculate F40 for different recruitment models
There are two steps needed here to calculate a F40 from the B0 universal in Step 2 (i.e., B0 based on constant climate, rather than refit for each climate scenario).
1. update the B0_set values in .ctl (B) files using targetB0 values from Step 2 (note that these don't match the dynamic B0)
2. set CR to 1.8 in each .ctl file as well and run to find F40 based on cont (by holding ATF at historical F)
```{bash, eval=FALSE}
# R ~mean R/S using set B0 from above
./CEATTLE_run_fut.sh 0 -r 1 -h 3 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_0B -plot
./CEATTLE_run_fut.sh 2 -r 1 -h 3 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_2B -plot
# R ~R/S f(SST)
./CEATTLE_run_fut.sh 0 -r 2 -h 3 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_0B -plot
./CEATTLE_run_fut.sh 2 -r 2 -h 3 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_2B -plot
# R ~R/S f(specified covars)
./CEATTLE_run_fut.sh 0 -r 5 -h 3 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_0B -plot
./CEATTLE_run_fut.sh 2 -r 5 -h 3 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_2B -plot
# R ~R/S f( top 2)
./CEATTLE_run_fut.sh 0 -r 4 -h 3 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_0B -plot
./CEATTLE_run_fut.sh 2 -r 4 -h 3 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_2B -plot
# R ~R/S f( top aic)
./CEATTLE_run_fut.sh 0 -r 3 -h 3 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_0B -plot
./CEATTLE_run_fut.sh 2 -r 3 -h 3 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_2B -plot
## Step 2: FOR LATER Project under each future scenario to get target F35 under
# R ~mean R/S
# ./CEATTLE_run_fut.sh 0 -r 1 -h 3 -f assmnt_2020 -ctl aclim
# ./CEATTLE_run_fut.sh 2 -r 1 -h 3 -f assmnt_2020 -ctl aclim
# # R ~R/S f(SST)
# ./CEATTLE_run_fut.sh 0 -r 2 -h 3 -f assmnt_2020 -ctl aclim
# ./CEATTLE_run_fut.sh 2 -r 2 -h 3 -f assmnt_2020 -ctl aclim
# # R ~R/S f(specified covars)
# ./CEATTLE_run_fut.sh 0 -r 5 -h 3 -f assmnt_2020 -ctl aclim
# ./CEATTLE_run_fut.sh 2 -r 5 -h 3 -f assmnt_2020 -ctl aclim
```
## Step 4: Create target F40 dat files
```{bash, eval=FALSE}
# now create a data file for each sub scenario
R
rm(list=ls())
hcrset<-1.8
DIR_main<-path.expand("~/GitHub_new/CEATTLE")
ctl_main<-file.path(DIR_main,"src/Control_files")
source(file.path(DIR_main,"src/ceattle-master/Scripts/R_code/ASSESSMENT_RUN_FUN.R"))
main<-file.path(DIR_main,"runs")
setwd(main)
fn_0<-path.expand(file.path(DIR_main,"/src/Data/dat_input_files/set_FabcFofl_0.dat"))
fn_2<-path.expand(file.path(DIR_main,"src/Data/dat_input_files/set_FabcFofl_2.dat"))
filenm<-"assmnt_2020"
modelnm<-"assmnt_2020"
ctl_0<-"asmnt2020_0A.ctl"
ctl_2<-"asmnt2020_2A.ctl"
fl_0<-file.path(main,paste0(filenm,"_0"))
fl_2<-file.path(main,paste0(filenm,"_2"))
f40fn<-file.path(DIR_main,paste0("src/Data/",datapath,"/setF40_datfiles"))
datapath<-"dat_input_files/01_assesment_2019"
source(file.path(DIR_main,"src/ceattle-master/Scripts/R_code/ASSESSMENT_RUN_FUN.R"))
# get model names from the control file:
#______________________________________________
ctlfl<-dir(fl_2)[grep(".ctl",dir(fl_2))[1]]
tt<-scan(file=file.path(fl_2,ctlfl),what=character(),sep="\n")
futfile<-tt[grep("futfile_name",tt)+1]
tt<-scan(file.path(DIR_main,"src/Data",futfile),what=character(),sep="\n")
nscen<-as.numeric(tt[grep("num_runs",tt)[1]+1])
st<-grep("ncov_fut",tt)+3;ed<-st+nscen-1
mods<-tt[st:ed]
for(i in 1:nscen){ mods[i]<-strsplit(mods,split=" ")[[i]][3] }
nspp<-3
setflilenm<-"assmnt_2020_setB0"
nyrs_fut<-getF40(hcr=hcrset,flname=setflilenm)$nyrs_fut
# get F40 for all the models from step 3
#______________________________________________
F40_1_3<-F40fun(flname=setflilenm,m=0,r =1, h=3)
F40_2_3<-F40fun(m=0,r =2, h=3,flname=setflilenm)
# F40_0_3_3<-F40fun(m=0,r =3, h=3)
F40_4_3<-F40fun(m=0,r =4, h=3,flname=setflilenm)
F40_5_3<-F40fun(m=0,r =5, h=3,flname=setflilenm)
sptxt<-c("pollock","cod","arrowtooth")
dev.new(height=6,width=4)
# get comparitive F40 rates for each scenario x model
#______________________________________________
F40_smry<-compareF()
quartz.save(file=file.path(fl_2,"projections/Fcompare.jpg"),type="jpg")
save.image(file=file.path(fl_2,"projections/F40_info.Rdata"))
save.image(file=file.path(fl_0,"projections/F40_info.Rdata"))
# function to make Fabc dat file
# write F40 data files for projectin under 11 - 13 harvest modes
#______________________________________________
make_FabcDat(m=0,F40_In=F40_1_3,fn=file.path(f40fn,"F40In_0_1_9.dat"))
make_FabcDat(m=0,F40_In=F40_2_3,fn=file.path(f40fn,"F40In_0_2_9.dat"))
make_FabcDat(m=0,F40_In=F40_4_3,fn=file.path(f40fn,"F40In_0_4_9.dat"))
make_FabcDat(m=0,F40_In=F40_5_3,fn=file.path(f40fn,"F40In_0_5_9.dat"))
make_FabcDat(m=2,F40_In=F40_1_3,fn=file.path(f40fn,"F40In_2_1_9.dat"))
make_FabcDat(m=2,F40_In=F40_2_3,fn=file.path(f40fn,"F40In_2_2_9.dat"))
make_FabcDat(m=2,F40_In=F40_4_3,fn=file.path(f40fn,"F40In_2_4_9.dat"))
make_FabcDat(m=2,F40_In=F40_5_3,fn=file.path(f40fn,"F40In_2_5_9.dat"))
# get ABC for reporting
#______________________________________________
ABC<-matrix(-999,nspp,2)
ABC[1,]<-c((getsub(tt=F40_1_3[[2]][[1]],sp=1)$Catch_total_biom[1]),
(getsub(tt=F40_1_3[[2]][[2]],sp=1)$Catch_total_biom[1]))
ABC[2,]<-c((getsub(tt=F40_1_3[[2]][[1]],sp=2)$Catch_total_biom[1]),
(getsub(tt=F40_1_3[[2]][[2]],sp=2)$Catch_total_biom[1]))
ABC[3,]<-c((getsub(tt=F40_1_3[[2]][[1]],sp=3)$Catch_total_biom[1]),
(getsub(tt=F40_1_3[[2]][[2]],sp=3)$Catch_total_biom[1]))
ABC2<-matrix(-999,nspp,2)
ABC2[1,]<-c((getsub(tt=F40_5_3[[2]][[1]],sp=1,scn=2)$Catch_total_biom[1]),
(getsub(tt=F40_5_3[[2]][[2]],sp=1,scn=2)$Catch_total_biom[1]))
ABC2[2,]<-c((getsub(tt=F40_5_3[[2]][[1]],sp=2,scn=2)$Catch_total_biom[1]),
(getsub(tt=F40_5_3[[2]][[2]],sp=2,scn=2)$Catch_total_biom[1]))
ABC2[3,]<-c((getsub(tt=F40_5_3[[2]][[1]],sp=3,scn=2)$Catch_total_biom[1]),
(getsub(tt=F40_5_3[[2]][[2]],sp=3,scn=2)$Catch_total_biom[1]))
ABC3<-matrix(-999,nspp,2)
ABC3[1,]<-c((getsub(tt=F40_5_3[[2]][[1]],sp=1,scn=3)$Catch_total_biom[1]),
(getsub(tt=F40_5_3[[2]][[2]],sp=1,scn=3)$Catch_total_biom[1]))
ABC3[2,]<-c((getsub(tt=F40_5_3[[2]][[1]],sp=2,scn=3)$Catch_total_biom[1]),
(getsub(tt=F40_5_3[[2]][[2]],sp=2,scn=3)$Catch_total_biom[1]))
ABC3[3,]<-c((getsub(tt=F40_5_3[[2]][[1]],sp=3,scn=3)$Catch_total_biom[1]),
(getsub(tt=F40_5_3[[2]][[2]],sp=3,scn=3)$Catch_total_biom[1]))
save(ABC,file=file.path(fl_2,"projections/ABC1.Rdata"))
save(ABC2,file=file.path(fl_2,"projections/ABC2.Rdata"))
save(ABC3,file=file.path(fl_2,"projections/ABC3.Rdata"))
# Now calculate FmaxABC
#______________________________________________
# first get B40:
load(file.path(fl_0,"B0_list.Rdata"))
BatF40<-list()
r<-1
h<-3
hcrr<-1.8
m<-0
BatF40[["B0_0"]]<-getB0(mn=main,flname=setflilenm, rec =r, hvst=h, mode=0,hcr=hcrr)
BatF40[["B0_2"]]<-getB0(mn=main,flname=setflilenm, rec =r, hvst=h, mode=2,hcr=hcrr)
BatF40[["B0_0"]]$Fabc<-tier3(
Fin=BatF40[["B0_0"]]$F40_pls2,
Bratio= BatF40[["B0_0"]]$SSB_pls2/B0_list[["B0_0"]]$targetSSB0)
BatF40[["B0_2"]]$Fabc<-tier3(
Fin=BatF40[["B0_2"]]$F40_pls2,
Bratio= BatF40[["B0_2"]]$SSB_pls2/B0_list[["B0_2"]]$targetSSB0)
# for ATF cbeta = 0 not .2
cc<-which(BatF40[["B0_0"]]$sp==3)
BatF40[["B0_0"]][cc,]$Fabc<-tier3(cbeta=0,
Fin=BatF40[["B0_0"]][cc,]$F40_pls2,
Bratio= BatF40[["B0_0"]][cc,]$SSB_pls2/B0_list[["B0_0"]][cc,]$targetSSB0)
cc<-which(BatF40[["B0_2"]]$sp==3)
BatF40[["B0_2"]][cc,]$Fabc<-tier3(
Fin=BatF40[["B0_2"]][cc,]$F40_pls2,
Bratio= BatF40[["B0_2"]][cc,]$SSB_pls2/B0_list[["B0_2"]][cc,]$targetSSB0)
save(BatF40,file=file.path(fl_0,"BatF40.Rdata"))
tt0<-BatF40[["B0_0"]]
tmp0<-tt0[tt0$Scen==1,]$targetSSB0
replace_ctl(
flin=file.path(ctl_main,"asmnt2020_0B.ctl"),
flout=file.path(ctl_main,"asmnt2020_0B.ctl"),
nm="B0_set",rplac=tmp0)
tt2<-BatF40[["B0_2"]]
tmp2<-tt2[tt2$Scen==1,]$targetSSB0
replace_ctl(
flin=file.path(ctl_main,"asmnt2020_2B.ctl"),
flout=file.path(ctl_main,"asmnt2020_2B.ctl"),
nm="B0_set",rplac=tmp2)
####
q("no")
```
#Step 5: Solve to get FABC
New approach: take and back calculate to get F rate? Or better, use F40 rate from above and multiply it by TIER 3 to get Fmax ABC.
```{bash, eval=FALSE}
# Now run the Assessment model with FmaxABC to get maxABC in y+1 and y+2
# R ~mean R/S using set B0 from above
./CEATTLE_run_fut.sh 0 -r 1 -h 14 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_0B -plot
./CEATTLE_run_fut.sh 2 -r 1 -h 14 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_2B -plot
# R ~R/S f(SST)
./CEATTLE_run_fut.sh 0 -r 2 -h 14 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_0B -plot
./CEATTLE_run_fut.sh 2 -r 2 -h 14 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_2B -plot
# R ~R/S f(specified covars)
./CEATTLE_run_fut.sh 0 -r 5 -h 14 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_0B -plot
./CEATTLE_run_fut.sh 2 -r 5 -h 14 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_2B -plot
# R ~R/S f( top 2)
./CEATTLE_run_fut.sh 0 -r 4 -h 14 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_0B -plot
./CEATTLE_run_fut.sh 2 -r 4 -h 14 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_2B -plot
# R ~R/S f( top aic)
./CEATTLE_run_fut.sh 0 -r 3 -h 14 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_0B -plot
./CEATTLE_run_fut.sh 2 -r 3 -h 14 -f assmnt_2020_setB0 -m assmnt_2020 -ctl asmnt2020_2B -plot
```
# Step 6 now read in results and save them for the report:
TBA
########################################################################
BELOW HERE IS DEFUNCT CODE
########################################################################
# now create a data file for each sub scenario
R
setwd("~/GitHub_new/CEATTLE/runs/assmnt_2020_2")
load("projections/maxABC1.Rdata")
#update "/Users/kholsman/GitHub_new/CEATTLE/src/ceattle-master/main/catch_out.dat" with the target ABC from above
catchh<-maxABC[,1]
fn2<-("../../src/ceattle-master/main/catch_out.dat")
cat(round(catchh),file=fn2,append=FALSE,sep=" ")
fn<-("../../src/Data/dat_input_files/01_assesment_2017/set_catch.dat")
cat(c(1,1,1),file=fn,append=FALSE,sep=" ");cat("",file=fn,append=TRUE,sep="\n")
cat(round(catchh),file=fn,append=TRUE,sep=" ");cat("",file=fn,append=TRUE,sep="\n")
cat(12345,file=fn,append=TRUE,sep=" ")
system("cd ~/GitHub_new/CEATTLE/src/ceattle-master; ./CEATTLE_run_fut.sh 0 -r 1 -h 13 -f assmnt_2020 -m assmnt_2020 -ctl asmnt2020_0B -plot")
system("cd ~/GitHub_new/CEATTLE/src/ceattle-master; ./CEATTLE_run_fut.sh 0 -r 1 -h 11 -f assmnt_2020 -m assmnt_2020 -ctl asmnt2020_0B -plot")
catchh<-maxABC[,2]
fn<-("../../src/ceattle-master/main/catch_out.dat")
cat(round(catchh),file=fn,append=FALSE,sep=" ")
fn<-("../../src/Data/dat_input_files/01_assesment_2017/set_catch.dat")
cat(c(1,1,1),file=fn,append=FALSE,sep=" ");cat("",file=fn,append=TRUE,sep="\n")
cat(round(catchh),file=fn,append=TRUE,sep=" ");cat("",file=fn,append=TRUE,sep="\n")
cat(12345,file=fn,append=TRUE,sep=" ")
system("cd ~/GitHub_new/CEATTLE/src/ceattle-master; ./CEATTLE_run_fut.sh 2 -r 1 -h 13 -f assmnt_2020 -m assmnt_2020 -ctl asmnt2020_2B -plot")
system("cd ~/GitHub_new/CEATTLE/src/ceattle-master; ./CEATTLE_run_fut.sh 2 -r 1 -h 11 -f assmnt_2020 -m assmnt_2020 -ctl asmnt2020_2B -plot")
#--------------------------------------------------------
## Same thing but with climate variability effects:
#--------------------------------------------------------
load("projections/maxABC2.Rdata")
#update "/Users/kholsman/GitHub_new/CEATTLE/src/ceattle-master/main/catch_out.dat" with the target ABC from above
catchh<-maxABC[,1]
fn2<-("../../src/ceattle-master/main/catch_out.dat")
cat(round(catchh),file=fn2,append=FALSE,sep=" ")
fn<-("../../src/Data/dat_input_files/01_assesment_2017/set_catch.dat")
cat(c(1,1,1),file=fn,append=FALSE,sep=" ");cat("",file=fn,append=TRUE,sep="\n")
cat(round(catchh),file=fn,append=TRUE,sep=" ");cat("",file=fn,append=TRUE,sep="\n")
cat(12345,file=fn,append=TRUE,sep=" ")
system("cd ~/GitHub_new/CEATTLE/src/ceattle-master; ./CEATTLE_run_fut.sh 0 -r 5 -h 13 -f assmnt_2020_2 -m assmnt_2020 -ctl asmnt2020_0B -plot")
system("cd ~/GitHub_new/CEATTLE/src/ceattle-master; ./CEATTLE_run_fut.sh 0 -r 5 -h 11 -f assmnt_2020_2 -m assmnt_2020 -ctl asmnt2020_0B -plot")
catchh<-maxABC[,2]
fn<-("../../src/ceattle-master/main/catch_out.dat")
cat(round(catchh),file=fn,append=FALSE,sep=" ")
fn<-("../../src/Data/dat_input_files/01_assesment_2017/set_catch.dat")
cat(c(1,1,1),file=fn,append=FALSE,sep=" ");cat("",file=fn,append=TRUE,sep="\n")
cat(round(catchh),file=fn,append=TRUE,sep=" ");cat("",file=fn,append=TRUE,sep="\n")
cat(12345,file=fn,append=TRUE,sep=" ")
system("cd ~/GitHub_new/CEATTLE/src/ceattle-master; ./CEATTLE_run_fut.sh 2 -r 5 -h 13 -f assmnt_2020_2 -m assmnt_2020 -ctl asmnt2020_2B -plot")
system("cd ~/GitHub_new/CEATTLE/src/ceattle-master; ./CEATTLE_run_fut.sh 2 -r 5 -h 11 -f assmnt_2020_2 -m assmnt_2020 -ctl asmnt2020_2B -plot")
#--------------------------------------------------------
## Same thing but with climate change effects:
#--------------------------------------------------------
load("projections/maxABC3.Rdata")
#update "/Users/kholsman/GitHub_new/CEATTLE/src/ceattle-master/main/catch_out.dat" with the target ABC from above
catchh<-maxABC[,1]
fn2<-("../../src/ceattle-master/main/catch_out.dat")
cat(round(catchh),file=fn2,append=FALSE,sep=" ")
fn<-("../../src/Data/dat_input_files/01_assesment_2017/set_catch.dat")
cat(c(1,1,1),file=fn,append=FALSE,sep=" ");cat("",file=fn,append=TRUE,sep="\n")
cat(round(catchh),file=fn,append=TRUE,sep=" ");cat("",file=fn,append=TRUE,sep="\n")
cat(12345,file=fn,append=TRUE,sep=" ")
system("cd ~/GitHub_new/CEATTLE/src/ceattle-master; ./CEATTLE_run_fut.sh 0 -r 5 -h 13 -f assmnt_2020_3 -m assmnt_2020 -ctl asmnt2020_0B -plot")
system("cd ~/GitHub_new/CEATTLE/src/ceattle-master; ./CEATTLE_run_fut.sh 0 -r 5 -h 11 -f assmnt_2020_3 -m assmnt_2020 -ctl asmnt2020_0B -plot")
catchh<-maxABC[,2]
fn<-("../../src/ceattle-master/main/catch_out.dat")
cat(round(catchh),file=fn,append=FALSE,sep=" ")
fn<-("../../src/Data/dat_input_files/01_assesment_2017/set_catch.dat")
cat(c(1,1,1),file=fn,append=FALSE,sep=" ");cat("",file=fn,append=TRUE,sep="\n")
cat(round(catchh),file=fn,append=TRUE,sep=" ");cat("",file=fn,append=TRUE,sep="\n")
cat(12345,file=fn,append=TRUE,sep=" ")
system("cd ~/GitHub_new/CEATTLE/src/ceattle-master; ./CEATTLE_run_fut.sh 2 -r 5 -h 13 -f assmnt_2020_3 -m assmnt_2020 -ctl asmnt2020_2B -plot")
system("cd ~/GitHub_new/CEATTLE/src/ceattle-master; ./CEATTLE_run_fut.sh 2 -r 5 -h 11 -f assmnt_2020_3 -m assmnt_2020 -ctl asmnt2020_2B -plot")
q("no")
#Step 5: Run Amanda's function.Now change the F40 data file in the asmnt2020_2B.ctl and aclim_0B.ctl files to include the F40 in datafiles, first for mean rec (r=1), and then for climate(r=5).
# first with mean RS
#"dat_input_files/01_assesment_2017/setF40_datfiles/F40In_0_1_9"
#"dat_input_files/01_assesment_2017/setF40_datfiles/F40In_0_1_9"
cd ~/GitHub_new/CEATTLE/src/ceattle-master
./CEATTLE_run_fut.sh 0 -r 1 -h 12 -f assmnt_2020 -m assmnt_2020 -ctl asmnt2020_0B -plot
./CEATTLE_run_fut.sh 2 -r 1 -h 12 -f assmnt_2020 -m assmnt_2020 -ctl asmnt2020_0B -plot
./CEATTLE_run_fut.sh 0 -r 5 -h 12 -f assmnt_2020 -m assmnt_2020 -ctl asmnt2020_0B_5 -plot
./CEATTLE_run_fut.sh 0 -r 4 -h 12 -f assmnt_2020 -m assmnt_2020 -ctl asmnt2020_0B_4 -plot
./CEATTLE_run_fut.sh 0 -r 2 -h 12 -f assmnt_2020 -m assmnt_2020 -ctl asmnt2020_0B_2 -plot
./CEATTLE_run_fut.sh 2 -r 5 -h 12 -f assmnt_2020 -m assmnt_2020 -ctl aclim_2B_5 -plot
./CEATTLE_run_fut.sh 2 -r 4 -h 12 -f assmnt_2020 -m assmnt_2020 -ctl aclim_2B_4 -plot
./CEATTLE_run_fut.sh 2 -r 2 -h 12 -f assmnt_2020 -m assmnt_2020 -ctl asmnt2020_2B -plot
***
***
###################
DEFUNCT
## OLDStep 3: Get universal SSB0 values
```{bash, eval=FALSE}
# now create a data file for each sub scenario
R
DIR_main<-"~/GitHub_new/CEATTLE"
main<-file.path(DIR_main,"runs")
filenm<-"assmnt_2020"
modelnm<-"assmnt_2020"
fl_0<-file.path(main,paste0(filenm,"_0"))
fl_2<-file.path(main,paste0(filenm,"_2"))
ctlfl<-dir(fl_2)[grep(".ctl",dir(fl_2))[1]]
tt<-scan(file=file.path(fl_2,ctlfl),what=character(),sep="\n")
futfile<-tt[grep("futfile_name",tt)+1]
tt<-scan(file.path(DIR_main,"src/Data",futfile),what=character(),sep="\n")
nscen<-as.numeric(tt[grep("num_runs",tt)[1]+1])
st<-grep("ncov_fut",tt)+3;ed<-st+nscen-1
mods<-tt[st:ed]
for(i in 1:nscen){ mods[i]<-strsplit(mods,split=" ")[[i]][3] }
nspp<-3
setwd("~/GitHub_new/CEATTLE/runs")
fn_0<-"~/GitHub_new/CEATTLE/src/Data/dat_input_files/set_FabcFofl_0.dat"
fn_2<-"~/GitHub_new/CEATTLE/src/Data/dat_input_files/set_FabcFofl_2.dat"
B0_list<-list()
r<-1
h<-3
hcrr<-1.7
m<-0
B0_list[["B0_0"]]<-getB0(mn=main,flname=filenm, rec =r, hvst=h, mode=0,hcr=hcrr)
B0_list[["B0_2"]]<-getB0(mn=main,flname=filenm, rec =r, hvst=h, mode=2,hcr=hcrr)
tt<-B0_list[["B0_0"]];tt[tt$Scen==1,]$targetSSB0 # copy these values to asmnt2020_0B.ctl
tt<-B0_list[["B0_2"]];tt[tt$Scen==1,]$targetSSB0 # copy these values to asmnt2020_2B.ctl
B0_list[["setB0vals"]]<-data.frame(
ssm=B0_list[["B0_0"]][B0_list[["B0_0"]]$Scen==1,]$targetSSB0,
msm=B0_list[["B0_2"]][B0_list[["B0_2"]]$Scen==1,]$targetSSB0)
save(B0_list,file=file.path(paste0(modelnm,"_0"),"B0_list.Rdata"))
q("no")
```