knitr::opts_chunk$set(results = FALSE)
This example code demonstrates how to extract the purse-seine catch and length composition data for the stock assessment of yellowfin tuna in the eastern Pacific Ocean. Data are extracted for yellowfin between 1975 and 1999 based on the R package BSE (version r packageVersion("BSE")
). The package can be installed using devtools::install_github('HaikunXu/BSE',ref='main')
. Fishery definition for this data extraction is based on the benchmark assessment conducted in 2020.
# devtools::install_github('HaikunXu/BSE',ref='main') library(BSE) # Load the base files (please ask Haikun to get those data) 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") # the directory where output will be saved save_dir <- "D:/OneDrive - IATTC/IATTC/2022/BSE stuff from Cleridy/YFT/" yr.start <- 1975 yr.end <- 1999 Species <- "YFT" grow.increments <- grow.increments.betyftskj # the growth increment matrix
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 the strata definition for OBJ to make sure that it is correct
check.strat.flg.f(cae$latc5,cae$lonc5,cae.stratflg)
Loop through every year between yr.start
and yr.end
to get catch and composition data for YFT in the OBJ fishery
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") catch.estimates <- get.catch.estimates.7599.f(cae,cae.stratflg,corrected.unlds,lfgrpd,lfmm,year,2,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 OBJ 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)
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 the strata definition for NOA make sure that it is correct
check.strat.flg.f(cae$latc5,cae$lonc5,cae.stratflg)
Loop through every year between yr.start
and yr.end
to get catch and composition data for YFT in the NOA fishery
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") catch.estimates <- get.catch.estimates.7599.f(cae,cae.stratflg,corrected.unlds,lfgrpd,lfmm,year,2,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 NOA 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","A5")) YFT.NOA.Comp.19751999<-compile.sizecomps.output.7599.f(yr.start,yr.end,PS=PS,Species=Species)
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 the strata definition for DEL to make sure that it is correct
check.strat.flg.f(cae$latc5,cae$lonc5,cae.stratflg)
Loop through every year between yr.start
and yr.end
to get catch and composition data for YFT in the DEL fishery
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") catch.estimates <- get.catch.estimates.7599.f(cae,cae.stratflg,corrected.unlds,lfgrpd,lfmm,year,2,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 DEL 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")) YFT.DEL.Comp.19751999<-compile.sizecomps.output.7599.f(yr.start,yr.end,PS=PS,Species=Species)
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.