library(BSE)
# global setup
raw_data_dir <- "D:/OneDrive - IATTC/IATTC/2022/BSE stuff from Cleridy/single spp programs_PS_1975-1999/Raw data extractions/"
save_dir <- "D:/OneDrive - IATTC/IATTC/2022/BSE stuff from Cleridy/YFT/"
yr.start <- 1975
yr.end <- 1999
Species <- "YFT"
# grow.increments <- grow.increments.yftyftskj # the growth increment matrix
# Load the base files generated by Cleridy
load("D:/OneDrive - IATTC/IATTC/2022/BSE stuff from Cleridy/single spp programs_PS_1975-1999/Raw data extractions/base files_1975-1999_for SAC 2020.RData")
# Running yft OBJ
PS <- "OBJ"
cae.stratflg <- create.strat.flg.f(cae$latc5,cae$lonc5,is.lwrght=F,cae$month,cae$setype,cae$class,PS=PS,Species=Species)
check.strat.flg.f(cae$latc5,cae$lonc5,cae.stratflg)
# Loop to get all years' fishery estimates
for(year in yr.start:yr.end) {
print(paste0("Year: ",year))
print("Step 1: get well estimates")
well.estimates <- well.estimates.7599.f(year)
print("Step 2: get catch estimates")
if(year!=1988) catch.estimates <- get.catch.estimates.7599.f(cae,cae.stratflg,corrected.unlds,lfgrpd,lfmm,year,2,well.estimates,PS,Species)
else catch.estimates <- get.catch.estimates.7599.f(cae,cae.stratflg,corrected.unlds,lfgrpd,lfmm,year,1,well.estimates,PS,Species)
print("Step 3: get fishery estimates")
# str(catch.estimates$stratum.estimates.withsamps)
fishery.estimates <- call.fishery.estimates.f(catch.estimates$stratum.estimates.withsamps,catch.estimates$totunlds.bystrat,year,PS,Species)
fishery.estimates.yft <- fishery.estimates$yft
assign(paste0("fishery.estimates.yft.", year), fishery.estimates.yft, pos=1)
}
save(list=objects(pat="fishery.estimates.yft."),file=paste0(save_dir,"YFT_",PS,"_1975-1999.RData"))
# get final catch and comp output for the stock assessment
YFT.OBJ.Catch.19751999<-compile.catch.output.7599.f(yr.start,yr.end,PS=PS,Species=Species,c("A1","A2","A3","A4","A5"))
YFT.OBJ.Comp.19751999<-compile.sizecomps.output.7599.f(yr.start,yr.end,PS=PS,Species=Species)
# Running yft NOA
PS <- "NOA"
cae.stratflg <- create.strat.flg.f(cae$latc5,cae$lonc5,is.lwrght=F,cae$month,cae$setype,cae$class,PS=PS,Species=Species)
check.strat.flg.f(cae$latc5,cae$lonc5,cae.stratflg)
# Loop to get all years' fishery estimates
for(year in yr.start:yr.end) {
print(paste0("Year: ",year))
print("Step 1: get well estimates")
well.estimates <- well.estimates.7599.f(year)
print("Step 2: get catch estimates")
if(year!=1988) catch.estimates <- get.catch.estimates.7599.f(cae,cae.stratflg,corrected.unlds,lfgrpd,lfmm,year,2,well.estimates,PS,Species)
else catch.estimates <- get.catch.estimates.7599.f(cae,cae.stratflg,corrected.unlds,lfgrpd,lfmm,year,1,well.estimates,PS,Species)
print("Step 3: get fishery estimates")
# str(catch.estimates$stratum.estimates.withsamps)
fishery.estimates <- call.fishery.estimates.f(catch.estimates$stratum.estimates.withsamps,catch.estimates$totunlds.bystrat,year,PS,Species)
fishery.estimates.yft <- fishery.estimates$yft
assign(paste0("fishery.estimates.yft.", year), fishery.estimates.yft, pos=1)
}
save(list=objects(pat="fishery.estimates.yft."),file=paste0(save_dir,"YFT_",PS,"_1975-1999.RData"))
# get final catch and comp output for the stock assessment
YFT.NOA.Catch.19751999<-compile.catch.output.7599.f(yr.start,yr.end,PS=PS,Species=Species,c("A1","A2","A3","A4"))
YFT.NOA.Comp.19751999<-compile.sizecomps.output.7599.f(yr.start,yr.end,PS=PS,Species=Species)
# Running yft DEL
PS <- "DEL"
cae.stratflg <- create.strat.flg.f(cae$latc5,cae$lonc5,is.lwrght=F,cae$month,cae$setype,cae$class,PS=PS,Species=Species)
check.strat.flg.f(cae$latc5,cae$lonc5,cae.stratflg)
# Loop to get all years' fishery estimates
for(year in yr.start:yr.end) {
print(paste0("Year: ",year))
print("Step 1: get well estimates")
well.estimates <- well.estimates.7599.f(year)
print("Step 2: get catch estimates")
if(year!=1988) catch.estimates <- get.catch.estimates.7599.f(cae,cae.stratflg,corrected.unlds,lfgrpd,lfmm,year,2,well.estimates,PS,Species)
else catch.estimates <- get.catch.estimates.7599.f(cae,cae.stratflg,corrected.unlds,lfgrpd,lfmm,year,1,well.estimates,PS,Species)
print("Step 3: get fishery estimates")
# str(catch.estimates$stratum.estimates.withsamps)
fishery.estimates <- call.fishery.estimates.f(catch.estimates$stratum.estimates.withsamps,catch.estimates$totunlds.bystrat,year,PS,Species)
fishery.estimates.yft <- fishery.estimates$yft
assign(paste0("fishery.estimates.yft.", year), fishery.estimates.yft, pos=1)
}
save(list=objects(pat="fishery.estimates.yft."),file=paste0(save_dir,"YFT_",PS,"_1975-1999.RData"))
# get final catch and comp output for the stock assessment
YFT.DEL.Catch.19751999<-compile.catch.output.7599.f(yr.start,yr.end,PS=PS,Species=Species,c("A1","A2","A3","A4","A5","A6","A7"))
YFT.DEL.Comp.19751999<-compile.sizecomps.output.7599.f(yr.start,yr.end,PS=PS,Species=Species)
# save results
write.csv(YFT.OBJ.Catch.19751999,file=paste0(save_dir,"YFT.OBJ.Catch.19751999.csv"),row.names = FALSE)
write.csv(YFT.OBJ.Comp.19751999,file=paste0(save_dir,"YFT.OBJ.Comp.19751999.csv"),row.names = FALSE)
write.csv(YFT.NOA.Catch.19751999,file=paste0(save_dir,"YFT.NOA.Catch.19751999.csv"),row.names = FALSE)
write.csv(YFT.NOA.Comp.19751999,file=paste0(save_dir,"YFT.NOA.Comp.19751999.csv"),row.names = FALSE)
write.csv(YFT.DEL.Catch.19751999,file=paste0(save_dir,"YFT.DEL.Catch.19751999.csv"),row.names = FALSE)
write.csv(YFT.DEL.Comp.19751999,file=paste0(save_dir,"YFT.DEL.Comp.19751999.csv"),row.names = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.