Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.2.0 Age Structure and v6681 Code Update #244

Merged
merged 178 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
178 commits
Select commit Hold shift + click to select a range
f5448f2
rearranged at_harvest.prm for easier readability and calibration.
andybeet Sep 30, 2023
2a8af4f
reorg effort displacement params
andybeet Oct 2, 2023
9e7280a
Vertical, positional and habitat scalars of the fishing effort
andybeet Oct 2, 2023
22ec0b3
Fisheries gear selectivity, swept area and conflict
andybeet Oct 2, 2023
08327f3
Initial v6665 run
RGamble1 Oct 4, 2023
67c268f
Initial run
RGamble1 Oct 4, 2023
09054cd
add fishieries discarding params
andybeet Oct 4, 2023
54e6b4b
added temporal changes in harvest
andybeet Oct 4, 2023
b05d538
add management, TAC params
andybeet Oct 4, 2023
747ed33
sample setup file for cloud calibration workflow
jcaracappa1 Oct 5, 2023
17dee81
sample setup file for cloud calibration workflow
jcaracappa1 Oct 5, 2023
6959c84
Merge branch 'cloud_calibration' of https://github.com/NOAA-EDAB/neus…
jcaracappa1 Oct 5, 2023
076a4c2
Merge branch 'cloud_calibration' of https://github.com/NOAA-EDAB/neus…
jcaracappa1 Oct 5, 2023
e6d2f4f
Merge branch 'cloud_calibration' of https://github.com/NOAA-EDAB/neus…
jcaracappa1 Oct 5, 2023
77afbb3
Mortality cases complete
jcaracappa1 Oct 5, 2023
7fc4698
Add economics section
andybeet Oct 6, 2023
6d1877f
finished script & tested
jcaracappa1 Oct 6, 2023
cc85366
Merge branch 'cloud_calibration' of https://github.com/NOAA-EDAB/neus…
Oct 9, 2023
95091a9
Plotting Script and Calibration Script bug fixes
Oct 9, 2023
6aeaf4d
add contents to harvest.prm
andybeet Oct 10, 2023
35c195b
Fixed migratory groups
RGamble1 Oct 11, 2023
c3e9114
Change output flag and periodicity
RGamble1 Oct 16, 2023
20c0a96
Changed age-based parameters to reflect fishbase and NOAA data
jcaracappa1 Oct 16, 2023
df26885
add assimilation efficiency
jcaracappa1 Oct 18, 2023
7befdc7
biomass comparison plots for cloud calibration workflow
jcaracappa1 Oct 19, 2023
3fcb78f
temporarily removed new length-weight (will test separately)
jcaracappa1 Oct 19, 2023
69f833b
fix hanging tab
jcaracappa1 Oct 19, 2023
6403ecc
code to rescale mum/C for new age classes
jcaracappa1 Oct 19, 2023
3161010
tools for generating new age structure
jcaracappa1 Oct 24, 2023
ddd35a6
add stop condition for incompatible Type entry
jcaracappa1 Oct 24, 2023
3e64090
Merge branch 'cloud_calibration' of https://github.com/NOAA-EDAB/neus…
jcaracappa1 Oct 24, 2023
e91caf5
rescale init conditions to match v2.0.1
jcaracappa1 Oct 25, 2023
96ed4ab
scripts to create _nofill version of init.nc and tested post-processing
jcaracappa1 Oct 25, 2023
ffdc05a
revert run scalar
jcaracappa1 Nov 1, 2023
ea51fcb
compare and rescale initial conditions based on biomass/numbers
jcaracappa1 Nov 6, 2023
eb6b749
configure for 6536
jcaracappa1 Nov 6, 2023
ca1ece2
biology file with new age classes
jcaracappa1 Nov 6, 2023
001931e
fixed bug in edit_param_mortality_age.R more generalized case for man…
jcaracappa1 Nov 7, 2023
8b09d88
fix paths
jcaracappa1 Nov 14, 2023
6ac01bb
weight/length calibration tools
jcaracappa1 Nov 14, 2023
acd12a5
keep correct mum scaling
jcaracappa1 Nov 14, 2023
9400a62
Merge pull request #226 from NOAA-EDAB/cloud_calibration
jcaracappa1 Nov 14, 2023
5d69892
Rename rescaled age param files to base name
jcaracappa1 Nov 14, 2023
742c63c
remove rescale files
jcaracappa1 Nov 14, 2023
7b1cb5d
exception
jcaracappa1 Nov 14, 2023
5b77124
exception
jcaracappa1 Nov 14, 2023
05b5266
fix merge
jcaracappa1 Nov 14, 2023
f91b685
fixed neg SUF growth
jcaracappa1 Nov 15, 2023
8c28716
fixed bug in single-species option
jcaracappa1 Nov 15, 2023
42599a4
test
jcaracappa1 Nov 15, 2023
2776edd
fixed Run.Group to be more sensible
jcaracappa1 Nov 16, 2023
1c336a8
Merge branch '6536_age_process' of https://github.com/NOAA-EDAB/neus-…
jcaracappa1 Nov 16, 2023
ad24e5f
cloud_new_age_1: general calibration
jcaracappa1 Nov 17, 2023
2a03933
incorporate new_age_1 fixes
jcaracappa1 Nov 20, 2023
2e48d4f
cloud_new_age_mumC fix
jcaracappa1 Nov 20, 2023
333ef7e
mumC changes
jcaracappa1 Nov 21, 2023
3662e7e
Merge branch '6536_age_process' of https://github.com/NEFSC/READ-EDAB…
jcaracappa1 Nov 21, 2023
4734b01
fix trailing NAs
jcaracappa1 Nov 21, 2023
d82a392
new_age_SB_2
jcaracappa1 Nov 29, 2023
dd820d4
new_age_SB_2
jcaracappa1 Nov 29, 2023
6002e52
Merge branches '6536_age_process' and '6536_age_process' of https://g…
jcaracappa1 Nov 29, 2023
082d968
cloud_new_age_2 setup
jcaracappa1 Dec 5, 2023
21e665d
cloud_new_age_2b
jcaracappa1 Dec 5, 2023
4c7c572
cloud_new_age_2b
jcaracappa1 Dec 5, 2023
637e924
cloud_new_age_2b merge
jcaracappa1 Dec 6, 2023
55e6eb5
cloud_new_age_2b
jcaracappa1 Dec 7, 2023
52047ac
cloud_new_age_3 setup
jcaracappa1 Dec 7, 2023
27dd945
cloud_new_age_3 fixes
jcaracappa1 Dec 8, 2023
f329b5c
cloud_new_age_3 fixes
jcaracappa1 Dec 8, 2023
9e1afbf
Merge branch '6536_age_process' of https://github.com/NEFSC/READ-EDAB…
jcaracappa1 Dec 8, 2023
0b2c5bd
cloud_new_age_4
jcaracappa1 Dec 11, 2023
9394701
new_age_5 setup files
jcaracappa1 Dec 11, 2023
15a84a9
new_age_5 fixes
jcaracappa1 Dec 13, 2023
45a5ae6
WOL & FDF & new_age_6 setup
jcaracappa1 Dec 13, 2023
40a7fd2
new_age_6
jcaracappa1 Dec 14, 2023
7e08c51
cloud_new_age_7
jcaracappa1 Dec 19, 2023
394a40d
cloud_new_age_7
jcaracappa1 Dec 22, 2023
1716d41
new_age_8
jcaracappa1 Dec 22, 2023
bc5e4b7
fixed cloud calibration plotting
jcaracappa1 Dec 26, 2023
b63dc8a
cloud_new_age_8
jcaracappa1 Dec 26, 2023
22a859c
Merge branch '6536_age_process' of https://github.com/NEFSC/READ-EDAB…
jcaracappa1 Dec 27, 2023
439d644
Merge branch 'dev_branch' into 6536_age_process
jcaracappa1 Dec 27, 2023
55eeedc
Merge pull request #228 from NEFSC/6536_age_process
andybeet Jan 3, 2024
fb6e913
Update at_biology.prm - Include v6681 changes
RGamble1 Jan 30, 2024
cb226f4
Update at_harvest.prm
RGamble1 Jan 30, 2024
aebd9f8
Create neus_migrations.csv
RGamble1 Jan 30, 2024
c673a19
modified to include migrations file
RGamble1 Jan 30, 2024
e9d6dec
Update RunAtlantis.sh - added migrations.csv file
RGamble1 Jan 30, 2024
66eeca6
Update neus_groups.csv with new columns for v6665
RGamble1 Jan 30, 2024
9b1c354
Update neus_groups.csv - v6665 changes
RGamble1 Jan 30, 2024
ee18459
Update neus_groups.csv - included age class changes
RGamble1 Jan 30, 2024
d29a639
Update neus_groups.csv - Set SB to inactive
RGamble1 Jan 30, 2024
bf0eb8e
Update general_calibration.R - point to 6681.sif
RGamble1 Feb 5, 2024
dfbfd34
test commit
jcaracappa1 Feb 8, 2024
9d61727
Pushing some changes
RGamble1 Feb 8, 2024
fa21fe1
cloud files
jcaracappa1 Feb 12, 2024
4202ab5
Merge branch '6536_age_process' of https://github.com/NEFSC/READ-EDAB…
jcaracappa1 Feb 12, 2024
8470fb7
Commit changed biology.prm
RGamble1 Feb 12, 2024
fd92bde
Update RunAtlantis_cloud.sh
RGamble1 Feb 12, 2024
382d531
fixed bug with paired parameter changes (BHalpha and BHbeta)
jcaracappa1 Feb 12, 2024
bfcb7dd
missing value BHalpha_MAK
jcaracappa1 Feb 12, 2024
d589a74
Merge pull request #230 from NEFSC/general_calibration_fix
jcaracappa1 Feb 12, 2024
05011b0
v6681 params and cloud setup
jcaracappa1 Feb 12, 2024
f42d2e5
v6681 params and cloud setup
jcaracappa1 Feb 12, 2024
3deaacf
Merge branch 'jcc_6681_calibration' of https://github.com/NOAA-EDAB/n…
jcaracappa1 Feb 12, 2024
069d596
add
jcaracappa1 Feb 12, 2024
a181f7f
Merge branch 'jcc_6681_calibration' of https://github.com/NEFSC/READ-…
jcaracappa1 Feb 12, 2024
7ddfeeb
MAK_46 (With Mak's BHalpha corrected, the BHbeta reverted to Dev, and…
RGamble1 Feb 13, 2024
43066f0
Merge branch 'RJG_6681_Calibration_1_29_24' of https://github.com/NEF…
RGamble1 Feb 13, 2024
6fe7490
add migrations to gitignore
jcaracappa1 Feb 13, 2024
f790b8f
update to 6681
jcaracappa1 Feb 13, 2024
4dcf6e4
Merge branch 'jcc_6681_calibration' into RJG_6681_Calibration_1_29_24
jcaracappa1 Feb 13, 2024
8447156
Merge pull request #231 from NEFSC/RJG_6681_Calibration_1_29_24
jcaracappa1 Feb 13, 2024
9876c7b
Merge branch 'jcc_6681_calibration' of https://github.com/NOAA-EDAB/n…
jcaracappa1 Feb 13, 2024
9b34dc3
add suf
jcaracappa1 Feb 13, 2024
f768361
Merge branch 'jcc_6681_calibration' of https://github.com/NOAA-EDAB/n…
jcaracappa1 Feb 13, 2024
3bb2fad
Merge branch 'jcc_6681_calibration' of https://github.com/NOAA-EDAB/n…
jcaracappa1 Feb 13, 2024
abc69aa
Merge branch 'jcc_6681_calibration' of https://github.com/NOAA-EDAB/n…
jcaracappa1 Feb 13, 2024
2272ac3
Merge branch 'jcc_6681_calibration' of https://github.com/NOAA-EDAB/n…
jcaracappa1 Feb 13, 2024
abfaec0
Merge branch 'jcc_6681_calibration' of https://github.com/NOAA-EDAB/n…
jcaracappa1 Feb 13, 2024
21e82a6
v6681_1
jcaracappa1 Feb 15, 2024
aab0e3e
added FSP and FSPB to calibration routine
jcaracappa1 Feb 15, 2024
444930f
v6681_1 changes
jcaracappa1 Feb 15, 2024
5ce1689
Merge branch 'jcc_6681_calibration' of https://github.com/NEFSC/READ-…
jcaracappa1 Feb 15, 2024
4624b4a
setup file for v6681_calib_2
jcaracappa1 Feb 15, 2024
cc96bc3
Update at_biology.prm - WSK mQj modified
RGamble1 Feb 16, 2024
e683c80
Merge branch 'jcc_6681_calibration' of https://github.com/NEFSC/READ-…
jcaracappa1 Feb 16, 2024
bc8f35c
Merge pull request #233 from NEFSC/jcc_6681_calibration
RGamble1 Feb 16, 2024
4e1efa2
jcc_6681_calibration_2
jcaracappa1 Feb 20, 2024
926b231
Merge pull request #234 from NEFSC/jcc_6681_calibration
RGamble1 Feb 20, 2024
481a02e
setup cloud_v6681_calib_3
jcaracappa1 Feb 20, 2024
e7b05a5
Merge branch 'jcc_6681_calibration' of https://github.com/NOAA-EDAB/n…
jcaracappa1 Feb 20, 2024
6da1fcf
Merge branch 'jcc_6681_calibration' of https://github.com/NOAA-EDAB/n…
jcaracappa1 Feb 20, 2024
8c77cc2
Merge branch 'jcc_6681_calibration' of https://github.com/NOAA-EDAB/n…
jcaracappa1 Feb 20, 2024
aa8f38d
V6681_calib_3
jcaracappa1 Feb 22, 2024
c78437e
Merge branch 'jcc_6681_calibration' of https://github.com/NEFSC/READ-…
jcaracappa1 Feb 22, 2024
b688e16
Changes to WSK, RED, BWH and RWH
RGamble1 Feb 22, 2024
300d72b
Merge pull request #235 from NEFSC/RJG_6681_Calibration_1_29_24
jcaracappa1 Feb 22, 2024
2bb3729
Merge pull request #236 from NEFSC/jcc_6681_calibration
RGamble1 Feb 22, 2024
741d194
incorrect NESPP3 codes (326, 526)
andybeet Feb 22, 2024
ae772e1
Merge branch 'dev_branch' of https://github.com/NEFSC/READ-EDAB-neusA…
andybeet Feb 22, 2024
61a9865
Update at_biology.prm
RGamble1 Feb 26, 2024
28a4536
Revert "Merge pull request #235 from NEFSC/RJG_6681_Calibration_1_29_24"
jcaracappa1 Feb 26, 2024
9b15e4a
Revert to prior version before last merge
RGamble1 Feb 26, 2024
74eed4b
Merge pull request #237 from NEFSC/jcc_6681_calibration
RGamble1 Feb 26, 2024
d829836
Update at_biology.prm - Changes to RWH, BWH, WSK and RED
RGamble1 Feb 26, 2024
804263c
Merge pull request #238 from NEFSC/RJG_6681_Calibration_1_29_24
jcaracappa1 Feb 26, 2024
5d46b97
cloud calib 4 setup
jcaracappa1 Feb 28, 2024
2349929
cloud calib 3 setup
jcaracappa1 Feb 28, 2024
569bf8c
Merge branch 'jcc_6681_calibration' of https://github.com/NOAA-EDAB/n…
jcaracappa1 Feb 28, 2024
89f94db
ZL, HER, MEN, and WSK fixes (v6681_calib_4)
jcaracappa1 Mar 1, 2024
961d977
Changes to SCA and RED
RGamble1 Mar 1, 2024
c3d56a3
Update neus_migrations.csv - TUN, BFT and BIL
RGamble1 Mar 1, 2024
5c89be5
Merge pull request #239 from NEFSC/RJG_6681_Calibration_1_29_24
jcaracappa1 Mar 1, 2024
8ab1ab8
Merge pull request #240 from NEFSC/jcc_6681_calibration
RGamble1 Mar 1, 2024
15b163e
cloud calib 5 setup
jcaracappa1 Mar 4, 2024
354b69e
Merge branch 'jcc_6681_calibration' of https://github.com/NOAA-EDAB/n…
jcaracappa1 Mar 4, 2024
b505c44
cloud_calib_5
jcaracappa1 Mar 6, 2024
85b3b71
cloud_v6681_calib_6 setup
jcaracappa1 Mar 6, 2024
502312d
Merge branch 'jcc_6681_calibration' of https://github.com/NOAA-EDAB/n…
jcaracappa1 Mar 6, 2024
ce7a78a
cloud_v6681_calib_6 setup
jcaracappa1 Mar 6, 2024
4bb9abe
merge fix
jcaracappa1 Mar 6, 2024
6f72455
Merge branch 'jcc_6681_calibration' of https://github.com/NOAA-EDAB/n…
jcaracappa1 Mar 6, 2024
d0e4381
merge fix
jcaracappa1 Mar 6, 2024
c8d31c4
merge
jcaracappa1 Mar 6, 2024
457b273
Merge branch 'jcc_6681_calibration' of https://github.com/NOAA-EDAB/n…
jcaracappa1 Mar 6, 2024
4a58403
biomass-at-age plot for run scripts
jcaracappa1 Mar 7, 2024
0656e33
Merge pull request #241 from NEFSC/jcc_6681_calibration
RGamble1 Mar 7, 2024
99a0f99
cloud_calib_6b
jcaracappa1 Mar 8, 2024
e6e2b6f
cloud_calib_v6681_6b
jcaracappa1 Mar 11, 2024
0a09bce
Merge pull request #242 from NEFSC/jcc_6681_calibration
RGamble1 Mar 12, 2024
1ae7f6e
Update at_run.prm (Set scalar to 10x for cod's initial biomass)
RGamble1 Mar 13, 2024
0c57f11
Merge pull request #243 from NEFSC/RJG_6681_Calibration_1_29_24
andybeet Mar 13, 2024
00fbb75
Merge branch 'andy_communities' into dev_branch
andybeet Mar 15, 2024
3cd4615
fixed error in bhBeta_WHK
jcaracappa1 Mar 15, 2024
70b51f0
Merge branch 'dev_branch' of https://github.com/NOAA-EDAB/neus-atlant…
jcaracappa1 Mar 15, 2024
2950888
Revert "Merge branch 'andy_communities' into dev_branch"
andybeet Mar 15, 2024
e139728
undo strange error in Bhbeta_whk
jcaracappa1 Mar 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*.Rproj
/Atlantis_Runs/
/Run_Code/
/Setup_Files/
/Figures/
/currentVersion/archive/

Expand Down Expand Up @@ -39,6 +38,7 @@ outputFolder
# except csv
!/currentVersion/neus_fisheries.csv
!/currentVersion/neus_groups.csv
!/currentVersion/neus_migrations.csv
# except bgm
!/currentVersion/neus_tmerc_RM2.bgm
# except rmd
Expand Down Expand Up @@ -70,3 +70,8 @@ diagnostics/Obs_Hindcast_Group_Progress.xlsx
#data files
data/fishing_sensitivity_extended_constant_2/*


#Setup Files for Cloud
/Setup_Files/*
!/Setup_Files/cloud*

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#Script to scale Mum_C for age groups
library(dplyr)
source(here::here('R','edit_param_mum_age.R'))
source(here::here('R','edit_param_C_age.R'))
source(here::here('R','Calibration_Tools','edit_param_mum_age.R'))
source(here::here('R','Calibration_Tools','edit_param_C_age.R'))

group.names = 'RED'
group.names = 'HER'

mum.scale = 2
C.scale = 1.5
mum.scale = 1
C.scale = 0.8

bio.prm = here::here('currentVersion','at_biology.prm')

Expand All @@ -19,8 +19,10 @@ c.base.age = get_param_C_age(bio.prm)%>%

group.id = which(group.names == mum.base.age[,1])

new.mum = mum.base.age[group.id,2:11]*mum.scale
new.C = c.base.age[group.id,2:11]*C.scale
new.mum = as.numeric(mum.base.age[group.id,2:ncol(mum.base.age)])*mum.scale
new.mum = new.mum[!is.na(new.mum)]
new.C = as.numeric(c.base.age[group.id,2:ncol(mum.base.age)])*C.scale
new.C = new.C[!is.na(new.C)]

edit_param_mum_age(bio.prm ,
overwrite = T,
Expand Down
44 changes: 44 additions & 0 deletions R/Calibration_Tools/compare_init_numbers.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#Script to compare initial numbers weight between reference and run
library(ncdf4)
dev.init = nc_open('/net/work3/EDAB/atlantis/dev_branch/currentVersion/neus_init.nc')
master.init = nc_open('/net/work3/EDAB/atlantis/master_branch/currentVersion/neus_init.nc')
new.6536.init = nc_open(here::here('currentVersion','neus_init_rescale_age.nc'))
nre.6665.init = nc_open('/net/work3/EDAB/atlantis/Rob_proj/currentVersion/neus_init.nc')


fgs.dev = read.csv('/net/work3/EDAB/atlantis/dev_branch/currentVersion/neus_groups.csv',as.is = T)
fgs.master = read.csv('/net/work3/EDAB/atlantis/master_branch/currentVersion/neus_groups.csv',as.is = T)
fgs.6536 = read.csv(here::here('currentVersion','neus_groups.csv'),as.is = T)
fgs.6665 = read.csv('/net/work3/EDAB/atlantis/Rob_proj/currentVersion/neus_groups.csv',as.is = T)

vert.names = fgs.dev$Name[which(fgs.dev$NumCohorts >2)]

out.df = data.frame(Name = vert.names, dev = NA,master = NA, new.6536 = NA, new.6665 = NA)

i=1
for(i in 1:length(vert.names)){

ncohort.dev = fgs.dev$NumCohorts[which(fgs.dev$Name == vert.names[i])]
ncohort.master = fgs.master$NumCohorts[which(fgs.master$Name == vert.names[i])]
ncohort.6536 = fgs.6536$NumCohorts[which(fgs.6536$Name == vert.names[i])]
ncohort.6665 = fgs.6665$NumCohorts[which(fgs.6665$Name == vert.names[i])]

out.dev = lapply(1:ncohort.dev,function(x){
return(sum(ncvar_get(dev.init,paste0(vert.names[i],x,'_Nums')),na.rm=T))
})
out.master = lapply(1:ncohort.master,function(x){
return(sum(ncvar_get(master.init,paste0(vert.names[i],x,'_Nums')),na.rm=T))
})
out.6536 = lapply(1:ncohort.6536,function(x){
return(sum(ncvar_get(new.6536.init,paste0(vert.names[i],x,'_Nums')),na.rm=T))
})
out.6665 = lapply(1:ncohort.6665,function(x){
return(sum(ncvar_get(nre.6665.init,paste0(vert.names[i],x,'_Nums')),na.rm=T))
})

out.df$dev[i] = sum(unlist(out.dev))
out.df$master[i] = sum(unlist(out.master))
out.df$new.6536[i] = sum(unlist(out.6536))
out.df$new.6665[i] = sum(unlist(out.6665))

}
112 changes: 112 additions & 0 deletions R/Calibration_Tools/compare_weight_age.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#Script to compare weight at age for species between reference data and run
#Determine if mum needs to be rescaled
library(ggplot2)
library(dplyr)

#get run info
run.name = '6536_new_age_param_init_rescale_2'
run.dir = here::here('Atlantis_Runs',run.name,'')

fgs = read.csv(here::here('currentVersion','neus_groups.csv'),as.is = T)%>%
select(Code,LongName,NumCohorts,NumAgeClassSize)
fgs.old = read.csv(here::here('diagnostics','neus_groups_v2_0_1.csv'),as.is = T)%>%
select(Code,LongName,NumCohorts,NumAgeClassSize)
fgs$spp.change= fgs.old$NumCohorts != fgs$NumCohorts

#Read in reference survey length weigth age: indwt = kg, len = cm
ref.stats.survdat = readRDS(here::here('data','survey_lenagewgt.rds'))%>%
group_by(Code,AGE)%>%
summarise(LENGTH = mean(LENGTH,na.rm=T),
WEIGHT = mean(INDWT,na.rm=T))%>%
rename(ref.len = 'LENGTH',
ref.wgt = 'WEIGHT')

ref.stats.fishbase = read.csv(here::here('diagnostics','fishbase_len_wgt_ref.csv'),as.is = T)%>%
mutate(ref.wgt = Weight_g/1000)%>%
rename(ref.len = 'Length',
AGE = 'Age')%>%
select(Code,AGE,ref.len,ref.wgt)

ref.stats.all = ref.stats.survdat %>%
bind_rows(ref.stats.fishbase)

ref.spp = unique(ref.stats.all$Code)
i=1
ref.stats.spp.ls = list()
for(i in 1:length(ref.spp)){

fgs.match = which(fgs$Code == ref.spp[i])

spp.agecl = 1:fgs$NumCohorts[fgs.match]
spp.age = c(0,(1:fgs$NumCohorts[fgs.match])*fgs$NumAgeClassSize[fgs.match],Inf)

ref.stats.spp = ref.stats.all %>%
filter(Code == ref.spp[i] & !is.na(AGE))

spp.age.match = cut(ref.stats.spp$AGE+1,spp.age,labels = F,right =F)
spp.age.match[spp.age.match>fgs$NumCohorts[fgs.match]] = fgs$NumCohorts[fgs.match]

ref.stats.spp$agecl = spp.age.match
ref.stats.spp.ls[[i]] = ref.stats.spp
}
ref.stats.all2 = bind_rows(ref.stats.spp.ls)


#Get run length weight stats
run.wgt = readRDS(paste0(run.dir,'Post_Processed/Data/max_weight.rds'))%>%
group_by(species,agecl)%>%
summarise(maxMeanWeight = max(maxMeanWeight,na.rm=T)/1000)
run.len = readRDS(paste0(run.dir,'Post_Processed/Data/length_age.rds'))%>%
group_by(species,agecl)%>%
summarise(length = mean(atoutput,na.rm=T))

run.stats = run.wgt %>%
left_join(run.len)%>%
left_join(fgs,by = c(species = 'LongName'))%>%
# mutate(AGE = agecl * NumAgeClassSize)%>%
rename(run.wgt = 'maxMeanWeight',
run.len = 'length')

#Combine and create scalar based on length and weight
combined.stats = run.stats%>%
left_join(ref.stats.all2)%>%
select(Code,species,spp.change,agecl,AGE,run.len,ref.len,run.wgt,ref.wgt)%>%
mutate(len.scale = ref.len / run.len,
wgt.scale = ref.wgt / run.wgt)

mean.scale.wgt = combined.stats %>%
group_by(Code,spp.change,agecl)%>%
summarise(mum.scale = mean(wgt.scale,na.rm=T))%>%
# group_by(Code,spp.change)%>%
# summarise(mum.scale = mean(mum.scale,na.rm=T))%>%
filter(spp.change == T)
# filter(spp.change == T & is.na(mum.scale))

source(here::here('R','Calibration_Tools','edit_param_mum_age.R'))
mum.orig = get_param_mum_age(bio.prm = here::here('currentVersion','at_biology_rescale_mumC.prm'))
new.mum = mum.orig

spp.names = sort(unique(mean.scale.wgt$Code))

j = 1
for(j in 1:length(spp.names)){

which.mum = which(mum.orig$group == spp.names[j] )

mum.age.scale = filter(mean.scale.wgt,Code == spp.names[j]) %>% arrange(agecl)

mean.scale = mean(mum.age.scale$mum.scale,na.rm=T)

mum.scale.spp = mum.age.scale$mum.scale
mum.scale.spp[is.na(mum.scale.spp)] = mean.scale

mum.orig.spp = as.numeric(mum.orig[which.mum,2:ncol(mum.orig)])

new.mum[which.mum,2:ncol(new.mum)] = signif(mum.orig.spp * mum.scale.spp,2)

}

edit_param_mum_age(bio.prm = here::here('currentVersion','at_biology_rescale_mumC.prm'),
single.group = F,
new.mum = new.mum,
overwrite = T)
12 changes: 8 additions & 4 deletions R/Calibration_Tools/edit_param_BH.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ edit_param_BH = function(bio.prm,group.name,alpha,beta,overwrite = F, new.file.n
alpha.line = grep(paste0('BHalpha_',group.name[i]),bio.lines)
beta.line = grep(paste0('BHbeta_',group.name[i]),bio.lines)

new.alpha = paste0('BHalpha_',group.name[i],' ',alpha[i])
new.beta = paste0('BHbeta_',group.name[i],' ',beta[i])
if(!is.na(alpha)){
new.alpha = paste0('BHalpha_',group.name[i],' ',alpha[i])
bio.lines[alpha.line] = new.alpha
}

bio.lines[alpha.line] = new.alpha
bio.lines[beta.line] = new.beta
if(!is.na(beta)){
new.beta = paste0('BHbeta_',group.name[i],' ',beta[i])
bio.lines[beta.line] = new.beta
}
}

if(overwrite){
Expand Down
44 changes: 35 additions & 9 deletions R/Calibration_Tools/edit_param_C_age.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,29 @@
get_param_C_age = function(bio.prm, write.output = F, output.dir, out.name ){

bio.lines = readLines(bio.prm)
bio.lines.id = grep('^C_.*10',bio.lines)
bio.lines.id = grep('^C_.*',bio.lines)
bio.lines.vals1 = bio.lines[bio.lines.id]
which.invert = grepl('_T15',bio.lines.vals1)
bio.lines.vals1 = bio.lines.vals1[!which.invert]
bio.lines.id = bio.lines.id[!which.invert]

group.names =unname(sapply(bio.lines.vals1,function(x) strsplit(x,'C_|\t10.00|\t| ')[[1]][2]))
max.age = max(as.numeric(sapply(bio.lines.vals1,function(x) strsplit(x,'C_|\t| ')[[1]][3])))

C.mat = matrix(NA, nrow = length(group.names),ncol = max.age)
colnames(C.mat) = paste0('C',1:max.age)
out.df = data.frame(C.mat)
out.df = cbind(data.frame(group = group.names),out.df)

group.names =unname(sapply(bio.lines.vals1,function(x) strsplit(x,'C_|\t|10.00')[[1]][2]))
out.df = data.frame(group = group.names,
C1 = NA, C2 = NA, C3 = NA, C4 = NA, C5 = NA, C6 = NA, C7 = NA, C8 = NA, C9 = NA, C10 = NA)
for(i in 1:length(bio.lines.id)){
C.group = bio.lines[bio.lines.id[i] + 1 ]
out.df[i,2:11] = strsplit(C.group,split = "\t| ")[[1]]
C.split = strsplit(C.group,split = "\t| | ")[[1]]

if(length(C.split)>max.age){print(paste0(group.names[i],' has ',length(C.split)-10,' trailing tabs ',i))}

C.out = rep(NA,max.age)
C.out[1:length(C.split)] = C.split
out.df[i,2:ncol(out.df)] = C.out
}
if(write.output){
write.csv(out.df, file = paste0(output.dir,out.name,'.csv'),row.names = F)
Expand All @@ -32,21 +46,33 @@ edit_param_C_age = function(bio.prm, new.C, overwrite = F,new.file.name,single.g

#Get C_XXX bio.prm lines
bio.lines = readLines(bio.prm)
bio.lines.id = grep('^C.*10',bio.lines)
bio.lines.id = grep('^C_',bio.lines)
bio.lines.vals = bio.lines[bio.lines.id]
group.names =unname(sapply(bio.lines.vals,function(x) strsplit(x,'C_|\t10| 10.00')[[1]][2]))
which.invert = grepl('_T15',bio.lines.vals)
bio.lines.vals = bio.lines.vals[!which.invert]
bio.lines.id = bio.lines.id[!which.invert]

group.names =unname(sapply(bio.lines.vals,function(x) strsplit(x,'C_|\t10.00|\t| ')[[1]][2]))
max.age = max(as.numeric(sapply(bio.lines.vals,function(x) strsplit(x,'C_|\t| ')[[1]][3])))

if(single.group){

ind = which(group.name == group.names)
new.C = new.C[!is.na(new.C)]
C.string = paste(new.C,collapse = '\t')
bio.lines[bio.lines.id[ind]+1] = C.string
}else{
for(i in 1:nrow(new.C)){

ind = which(new.C$group[i] == group.names)
C.string = paste(new.C[i,2:11],collapse='\t')
ind = which(group.names == new.C$group[i])

C.string = new.C[i,2:ncol(new.C)]
which.na = which(is.na(C.string))
if(length(which.na > 0)){C.string = C.string[-which.na]}
C.string = paste(C.string,collapse='\t')

bio.lines[bio.lines.id[ind]+1] = C.string

}
}

Expand Down
47 changes: 47 additions & 0 deletions R/Calibration_Tools/edit_param_FSP.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#Changes FSP parameter in at_biology.prm


get_param_FSP = function(bio.prm, group.name = NA){

bio.lines = readLines(bio.prm)

FSP.line = grep(paste0('^FSP_'),bio.lines)

groups = sapply(bio.lines[FSP.line],function(x) return(strsplit(x,'\t| |_')[[1]][2]),USE.NAMES = F)

group.vals = sapply(bio.lines[FSP.line],function(x) strsplit(x,' |\t')[[1]][2], USE.NAMES = F)

if(is.na(group.name)){

return(data.frame(Code = groups, FSP = group.vals))

}else{

return(group.vals[which(groups == group.name)])
}

return(out.df)
}

edit_param_FSP = function(bio.prm,group.name,value,unit = 'value',overwrite = F, new.file.name){

bio.lines = readLines(bio.prm)

FSP.line = grep(paste0('FSP_',group.name),bio.lines)

if(unit == 'value'){
new.val = value
}else{
old.val = as.numeric(strsplit(bio.lines[FSP.line],' |\t')[[1]][2])
new.val = old.val * value
}

bio.lines[FSP.line] = paste0('FSP_',group.name,' ',new.val)

if(overwrite){
writeLines(bio.lines, con = bio.prm)
}else{
file.copy(bio.prm, new.file.name, overwrite = T)
writeLines(bio.lines, con = new.file.name )
}
}
4 changes: 2 additions & 2 deletions R/Calibration_Tools/edit_param_FSPB.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ get_param_FSPB = function(bio.prm){

groups = sapply(bio.lines[FSPB.line],function(x) return(strsplit(x,'\t| |_')[[1]][2]),USE.NAMES = F)

out.df = as.data.frame(matrix(NA,nrow = length(groups), ncol = 11))
colnames(out.df) = c('group',paste0('age.',1:10))
out.df = as.data.frame(matrix(NA,nrow = length(groups), ncol = 13))
colnames(out.df) = c('group',paste0('age.',1:12))
out.df$group = groups

for(i in 1:length(groups)){
Expand Down
Loading
Loading