Skip to content

Commit

Permalink
fixing function to get_amak_dat
Browse files Browse the repository at this point in the history
  • Loading branch information
jimianelli committed Feb 15, 2024
1 parent d1605f9 commit 254c5b9
Showing 1 changed file with 32 additions and 47 deletions.
79 changes: 32 additions & 47 deletions content/AFSC-BSAI_AtkaMackerel.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,10 @@ FIMS_commit <- substr(packageDescription("FIMS")$GithubSHA1, 1, 7)

## Simplifications to the original assessment

The model presented in this case study was changed substantially from the operational version and should not be considered reflective of the pollock stock. This is intended as a demonstration and nothing more.
The model presented in this case study was changed substantially from the operational version and should not be considered reflective of the BSAI Atka mackerel stock.

To get the opertional model to more closely match FIMS I:
* Removed bias correction in log-normal index likelihoods
* Simplified catchability of survey 3 to be constant in time (removed random walk)
* Updated maturity to be parametric rather than empirical
* Used constant weight at age for all sources: spawning, fishery, surveys, and biomass calculations. The same matrix was used throughout.
* Changee timing to be Jan 1 for spawning and all surveys
* Removed prior on catchability for survey 2
* Removed time-varying fisheries selectivity (constant double logistic)
* Took off normalization of selectivity
* Removed age accumulation for fishery age compositions

* stumbled lots

## Script to prepare data for building FIMS object
```{r}
Expand All @@ -68,8 +59,8 @@ To get the opertional model to more closely match FIMS I:
## define the dimensions and global variables
# Opent the original AMAK file
atka_dat <- readRDS("data_files/atka_dat.RDS")
atka_rep <- readRDS("data_files/atka_rep.RDS")
atka_dat <- readRDS(here::here("content","data_files","atka_dat.RDS"))
atka_rep <- readRDS(here::here("content","data_files","atka_rep.RDS"))
## define the dimensions and global variables
years <- atka_dat$styr:atka_dat$endyr
nyears <- length(years)
Expand All @@ -92,6 +83,7 @@ ages <- 1:nages


How I simplified my assessment:
* Haven't got there yet...


## Script that sets up and runs the model
Expand Down Expand Up @@ -125,83 +117,76 @@ estimate_recdevs <- TRUE
# q: What is the definition of the standard deviation of the index data?
# a: The standard deviation of the index data is the standard deviation of the log-transformed index data. This is the standard deviation of the log-transformed index data, not the standard deviation of the index data itself. The standard deviation of the index data is the standard deviation of the index data itself.
fimsdat<-atka_dat
get_amak_data <- function(rdat){
get_amak_data <- function(rdat,rrep){
## put into fims friendly form
res <- data.frame(type = character(),
res <- data.frame(type = character(),
name = character(),
age = integer(),
datestart = character(),
dateend = character(),
value = double(),
unit = character(),
uncertainty = double())
landings <- data.frame(type = "landings",
landings <- data.frame(type = "landings",
name = "fleet1",
age = NA,
datestart = paste0(seq(fimsdat$styr, fimsdat$endyr), "-01-01"),
dateend = paste0(seq(fimsdat$styr, fimsdat$endyr), "-12-31"),
value = as.numeric(fimsdat$catch),
datestart = paste0(seq(rdat$styr, rdat$endyr), "-01-01"),
dateend = paste0(seq(rdat$styr, rdat$endyr), "-12-31"),
value = as.numeric(rdat$catch),
unit = "t",
uncertainty = fimsdat$catch_cv)
# Now do same loop but fill in where data exists
# [1] "styr" "endyr" "rec_age" "n_ages" "number_length_inter"
#[6] "Length_bins" "nfsh" "catch" "catch_cv" "n_ages_fsh"
#[11] "n_lengths_fsh" "yrs_ages_fsh" "sample_ages_fsh" "page_fsh" "wt_age_fsh"
#[16] "nind" "nobs_ind" "yrs_ind" "month_ind" "biom_ind"
#[21] "biom_std" "n_ages_ind" "n_lengths_ind" "yrs_ages_ind" "sample_ages_ind"
#[26] "page_ind" "wt_age_ind" "wt_age_pop" "maturity" "spmonth"
#[31] "age_err"
uncertainty = rdat$catch_cv)
## need to fill missing years with -999 so it's ignored in FIMS
indtmp <- 0*fimsdat$catch-999
indtmp[which(years %in% fimsdat$yrs_ind )] <- fimsdat$biom_ind
indtmp <- 0*rdat$catch-999
indtmp[which(years %in% rdat$yrs_ind )] <- rdat$biom_ind
#indtmp
CVtmp <- rep(1, length=nyears) # actually SE in log space
CVtmp[which(years %in% fimsdat$yrs_ind)] <- fimsdat$biom_std/fimsdat$biom_ind
CVtmp <- rep(1, length=nyears) # actually SE in log space
CVtmp[which(years %in% rdat$yrs_ind)] <- rdat$biom_std/rdat$biom_ind
## repeat with fish catch at age, using expected in missing years
#names(atka_rep)
caa <- 0*atka_rep$N[,-1]-999
caa[which(years %in% fimsdat$yrs_ages_fsh), ] <- fimsdat$page_fsh
caa <- 0*rrep$N[,-1]-999
caa[which(years %in% rdat$yrs_ages_fsh), ] <- rdat$page_fsh
Ncaa <- rep(1, nyears)
Ncaa[which(years %in% fimsdat$yrs_ages_fsh)] <- fimsdat$sample_ages_fsh
paa2 <- 0*atka_rep$N[,-1]-999
paa2[which(years %in% fimsdat$yrs_ages_ind), ] <- fimsdat$page_ind
Ncaa[which(years %in% rdat$yrs_ages_fsh)] <- rdat$sample_ages_fsh
paa2 <- 0*rrep$N[,-1]-999
paa2[which(years %in% rdat$yrs_ages_ind), ] <- rdat$page_ind
Npaa2 <- rep(1, nyears)
Npaa2[which(years %in% fimsdat$yrs_ages_ind)] <- fimsdat$sample_ages_ind
Npaa2[which(years %in% rdat$yrs_ages_ind)] <- rdat$sample_ages_ind
index <- data.frame(type = "index",
name = "survey",
age = NA,
datestart = paste0(seq(fimsdat$styr, fimsdat$endyr), "-01-01"),
dateend = paste0(seq(fimsdat$styr, fimsdat$endyr), "-12-31"),
datestart = paste0(seq(rdat$styr, rdat$endyr), "-01-01"),
dateend = paste0(seq(rdat$styr, rdat$endyr), "-12-31"),
value = ifelse(indtmp>0, indtmp, indtmp),
unit = "",
uncertainty = CVtmp)
## these have -999 for missing data years
catchage <- data.frame(type = "age",
name = "fleet1",
age = rep(seq(1,nages), nyears),
datestart = rep(paste0(seq(fimsdat$styr, fimsdat$endyr), "-01-01"), each=nages),
dateend = rep(paste0(seq(fimsdat$styr, fimsdat$endyr), "-12-31"), each=nages),
datestart = rep(paste0(seq(rdat$styr, rdat$endyr), "-01-01"), each=nages),
dateend = rep(paste0(seq(rdat$styr, rdat$endyr), "-12-31"), each=nages),
value = as.numeric(t(caa)),
unit = "",
uncertainty = rep(Ncaa, each=nages))
indexage <- data.frame(
type = "age",
name = "survey",
age = rep(seq(1, nages), nyears),
datestart = rep(paste0( seq(fimsdat$styr, fimsdat$endyr), "-01-01" ), each = nages),
dateend = rep(paste0( seq(fimsdat$styr, fimsdat$endyr), "-12-31" ), each = nages),
datestart = rep(paste0( seq(rdat$styr, rdat$endyr), "-01-01" ), each = nages),
dateend = rep(paste0( seq(rdat$styr, rdat$endyr), "-12-31" ), each = nages),
value = as.numeric(t(paa2)),
unit = "",
uncertainty = rep(Npaa2, each = nages)
)
## indexage=indexage2
## index=index2
res <- rbind(res, landings, index, catchage, indexage)
## rm(landings, index, catchage, indexage)
return(res)
}
fimsdat<-get_amak_data(atka_dat,atka_rep)
age_frame <- FIMS::FIMSFrameAge(res)
age_frame <- FIMS::FIMSFrameAge(fimsdat)
fishery_catch <- FIMS::m_landings(age_frame)
fishery_agecomp <- FIMS::m_agecomp(age_frame, "fleet1")
survey_index <- FIMS::m_index(age_frame, "survey")
Expand Down

0 comments on commit 254c5b9

Please sign in to comment.