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 bigeye tuna in the eastern Pacific Ocean. Data are extracted for bigeye 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/2024/SAC15/PS Database/BSE/"
yr.start <- 1975
yr.end <- 1999
Species <- "BET"
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 BET 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")
  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")
  fishery.estimates <- call.fishery.estimates.f(catch.estimates$stratum.estimates.withsamps,catch.estimates$totunlds.bystrat,year,PS,Species)

  fishery.estimates.bet <- fishery.estimates$bet

  assign(paste0("fishery.estimates.bet.", year), fishery.estimates.bet, pos=1)
}
save(list=objects(pat="fishery.estimates.bet."),file=paste0(save_dir,"BET_",PS,"_1975-1999.RData"))

Get final OBJ catch and comp output for the stock assessment

BET.OBJ.Catch.19751999<-compile.catch.output.7599.f(yr.start,yr.end,PS=PS,Species=Species,c("A1","A2","A3","A4","A5"))
BET.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 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 BET 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")
  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")
  fishery.estimates <- call.fishery.estimates.f(catch.estimates$stratum.estimates.withsamps,catch.estimates$totunlds.bystrat,year,PS,Species)

  fishery.estimates.bet <- fishery.estimates$bet

  assign(paste0("fishery.estimates.bet.", year), fishery.estimates.bet, pos=1)
}
save(list=objects(pat="fishery.estimates.bet."),file=paste0(save_dir,"BET_",PS,"_1975-1999.RData"))

Get final NOA catch and comp output for the stock assessment

BET.NOA.Catch.19751999<-compile.catch.output.7599.f(yr.start,yr.end,PS=PS,Species=Species,c("A1","A2"))
BET.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 BET 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")
  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")
  fishery.estimates <- call.fishery.estimates.f(catch.estimates$stratum.estimates.withsamps,catch.estimates$totunlds.bystrat,year,PS,Species)

  fishery.estimates.bet <- fishery.estimates$bet

  assign(paste0("fishery.estimates.bet.", year), fishery.estimates.bet, pos=1)
}
save(list=objects(pat="fishery.estimates.bet."),file=paste0(save_dir,"BET_",PS,"_1975-1999.RData"))

Get final DEL catch and comp output for the stock assessment

BET.DEL.Catch.19751999<-compile.catch.output.7599.f(yr.start,yr.end,PS=PS,Species=Species,c("A1","A2"))
BET.DEL.Comp.19751999<-compile.sizecomps.output.7599.f(yr.start,yr.end,PS=PS,Species=Species)
write.csv(BET.OBJ.Catch.19751999,file=paste0(save_dir,"BET.OBJ.Catch.19751999.csv"),row.names = FALSE)
write.csv(BET.OBJ.Comp.19751999,file=paste0(save_dir,"BET.OBJ.Comp.19751999.csv"),row.names = FALSE)
write.csv(BET.NOA.Catch.19751999,file=paste0(save_dir,"BET.NOA.Catch.19751999.csv"),row.names = FALSE)
write.csv(BET.NOA.Comp.19751999,file=paste0(save_dir,"BET.NOA.Comp.19751999.csv"),row.names = FALSE)
write.csv(BET.DEL.Catch.19751999,file=paste0(save_dir,"BET.DEL.Catch.19751999.csv"),row.names = FALSE)
write.csv(BET.DEL.Comp.19751999,file=paste0(save_dir,"BET.DEL.Comp.19751999.csv"),row.names = FALSE)


HaikunXu/BSE documentation built on Nov. 22, 2024, 8:22 a.m.