Skip to content

Commit

Permalink
add WCGBTS length comps (ages and triennials still to come)
Browse files Browse the repository at this point in the history
  • Loading branch information
iantaylor-NOAA committed Jan 16, 2025
1 parent 953f9d7 commit 29a025a
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 4 deletions.
Binary file added Data/Processed/ss3_wcgbts_length_comps.rds
Binary file not shown.
4 changes: 4 additions & 0 deletions Rscripts/bins.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# variable names copied from lingcod
# note that the variables in the lists created by r4ss::SS_read() are $lbin_vector and $agebin_vector
len_bin <- seq(20, 56, 2)
age_bin <- 1:25
6 changes: 2 additions & 4 deletions Rscripts/process_rec_comps.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,8 @@ rec_ages_smry_table |>
# | 2023| 1247| 1251| 0|
# | 2024| 613| 0| 0|

# note variables in list created by r4ss::SS_read() are $lbin_vector and $agebin_vector
len_bin <- seq(20, 56, 2)
age_bin <- 1:25

# get age and length bins
source("Rdata/bins.R")
# clean length comps
# exclude
# 1. missing lengths (1 out of 59808)
Expand Down
96 changes: 96 additions & 0 deletions Rscripts/process_survey_comps.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# process survey comps
# see also explorations of changes in growth over space and time in the
# "Survey data" section of /docs/data_summary_doc.qmd

require(dplyr)
require(ggplot2)

dir_wcgbts <- here::here("Data/Raw_not_confidential/wcgbts")
dir_tri <- here::here("Data/Raw_not_confidential/triennial")

# pull survey data from data warehouse (skip unless it's been updated)
new_pull <- FALSE
if (new_pull) {
yt_survey_bio <- nwfscSurvey::pull_bio(
common_name = "yellowtail rockfish",
survey = "NWFSC.Combo",
dir = dir_wcgbts
)
yt_tri_bio <- nwfscSurvey::pull_bio(
common_name = "yellowtail rockfish",
survey = "Triennial",
dir = dir_tri
)
yt_survey_catch <- nwfscSurvey::pull_catch(
common_name = "yellowtail rockfish",
survey = "NWFSC.Combo",
dir = dir_wcgbts
)
yt_tri_catch <- nwfscSurvey::pull_catch(
common_name = "yellowtail rockfish",
survey = "Triennial",
dir = dir_tri
)
} else {
# read saved data files TODO: update after 2024 survey data is available
load(file.path(dir_wcgbts, "bio_yellowtail rockfish_NWFSC.Combo_2025-01-14.rdata"))
yt_survey_bio <- x
load(file.path(dir_tri, "bio_yellowtail rockfish_Triennial_2025-01-14.rdata"))
yt_tri_bio <- x
load(file.path(dir_wcgbts, "catch_yellowtail rockfish_NWFSC.Combo_2025-01-15.rdata"))
yt_survey_catch <- x
load(file.path(dir_tri, "catch_yellowtail rockfish_Triennial_2025-01-15.rdata"))
yt_tri_catch <- x
}

# filter by latitude
yt_n_survey_bio <- filter(yt_survey_bio, Latitude_dd > 40 + 1 / 6)
yt_n_tri_bio <- purrr::map(yt_tri_bio, \(dat) filter(dat, Latitude_dd > 40 + 1 / 6))
yt_n_survey_catch <- filter(yt_survey_catch, Latitude_dd > 40 + 1 / 6)
yt_n_tri_catch <- filter(yt_tri_catch, Latitude_dd > 40 + 1 / 6)

strata <- nwfscSurvey::CreateStrataDF.fn(
names = c("shallow", "deep"),
depths.shallow = c(55, 183),
depths.deep = c(183, 400), # note 99.9% of fish are less than 253m
lats.south = c(40.166667, 40.166667),
lats.north = c(49, 49)
)

# get age and length bins
source(here::here("Rscripts/bins.R"))

wcgbts_length_comps <- nwfscSurvey::get_expanded_comps(
bio_data = yt_n_survey_bio,
catch_data = yt_n_survey_catch,
comp_bins = len_bin,
strata = strata,
comp_column_name = "length_cm",
output = "full_expansion_ss3_format",
two_sex_comps = TRUE,
input_n_method = "stewart_hamel",
month = 7,
fleet = 999,
dir = dir_wcgbts
)

wcgbts_raw_length_comps <- nwfscSurvey::get_raw_comps(
data = yt_n_survey_bio,
comp_bins = len_bin,
comp_column_name = "length_cm",
two_sex_comps = TRUE,
dir = dir_wcgbts)

nwfscSurvey::plot_comps(
data = wcgbts_raw_length_comps,
dir = dir_wcgbts)
file.copy(file.path(dir_wcgbts, "plots/length_frequency_sex_3.png"),
file.path(dir_wcgbts, "plots/length_frequency_raw_sex_3.png"))
file.copy(file.path(dir_wcgbts, "plots/length_r4ss_frequency_sex_3.png"),
file.path(dir_wcgbts, "plots/length_r4ss_frequency_raw_sex_3.png"))
nwfscSurvey::plot_comps(
data = wcgbts_length_comps,
dir = dir_wcgbts)

# save processed data as RDS file
saveRDS(wcgbts_length_comps$sexed, file = here::here("Data/Processed/ss3_wcgbts_length_comps.rds"))

0 comments on commit 29a025a

Please sign in to comment.