nwfscSurvey
Chantel Wetzel
2024-11-07
nwfscSurvey.Rmd
Introduction
The nwfscSurvey package was written by scientists at the Northwest Fisheries Science Center (NWFSC) to explore and process survey composition data for use in groundfish stockassessments. The package can be used for the NWFSC West Coast Groundfish Bottom Trawl (WCGBT) survey, the NWFSC slope survey, the Alaska Fisheries Science Center (AFSC) slope survey, and the AFSC Triennial survey. The package includes functions that query the NWFSC data warehouse, visualize, and process the data for use in groundfish assessments.
Use
nwfscSurvey can be used to:
Pull survey catch, haul, and biological data from the NWFSC data warehouse.
Calculate the design based indices based upon pre-specified stratification.
Create length- and age-composition data expanded by the design-based indices formated for use in Stock Synthesis.
Create unexpanded conditional age-at-length composition data for use in Stock Synthesis.
Create plots to visualize the data: design-based index plots, bubble plots of length and age data, observeed sex ratio, and distributions across depth and latitude.
Examples
NWFSC WCGBT Survey
Pull data
Pull both the catch and biological data:
catch = pull_catch(
common_name = "Pacific ocean perch",
survey = "NWFSC.Combo")
bio = pull_bio(
common_name = "Pacific ocean perch",
survey = "NWFSC.Combo")
Initial data visualization
There are a range of functions to create visualizations of the data by examining catch rates by latitude or depth, lengths or ages by latitude and depth, presence/absence in tows, and observed sex ratios.
plot_cpue(
catch = catch)
plot_bio_patterns(
bio = bio,
col_name = "Length_cm")
wh_plot_proportion(
data_catch = catch,
data_bio = bio
)
Index of abundance
Define the stratification by depth and latitude that will be used to calculate a design-based index of abundance:
strata = CreateStrataDF.fn(
names = c("shallow_s", "mid_s", "deep_s", "shallow_n", "mid_n", "deep_n"),
depths.shallow = c( 55, 200, 300, 55, 200, 300),
depths.deep = c(200, 300, 400, 200, 300, 400),
lats.south = c( 32, 32, 32, 42, 42, 42),
lats.north = c( 42, 42, 42, 49, 49, 49))
Calculate the design based index of abundance:
biomass = get_design_based(
data = catch,
strata = strata)
get_design_based()
returns a list with the second
element containing the design based index of abundance. The design based
index is calculated based on the defined stratas. The function writes a
csv file inside the dir input location to a “forSS3” folder. The
function returns a list with the second element containing the design
based estimates by year:
#> Warning in rbind(c(2003, 38888.94, 0.379, 18519.72, 81661.56), c("...", :
#> number of columns of result is not a multiple of vector length (arg 2)
year | est | se_log | lwr | upr |
---|---|---|---|---|
2003 | 38888.94 | 0.379 | 18519.72 | 81661.56 |
… | … | |||
2015 | 22317.6 | 0.135 | 17135.936 | 29066.13 |
Plot the coastwide design based index of abundance with uncertainty intervals:
plot_index(
data = biomass,
plot = 1)
Plot the design based index of abundance for each strata without uncertainty intervals:
plot_index(
data = biomass,
plot = 2)
Length composition data
get_expanded_comps()
calculates and formats the
length-composition data for Stock Synthesis:
length_comps <- get_expanded_comps(
bio_data = bio,
catch_data = catch,
comp_bins = seq(10, 40, 2),
strata = strata,
comp_column_name = "length_cm",
output = "full_expansion_ss3_format",
two_sex_comps = TRUE,
input_n_method = "stewart_hamel")
The above call will calculate the length frequencies for use in Stock Synthesis and write the files inside the “forSS3” folder. The example call will produce csv files for both the sexed and unsexed fish. This function returns a list of sexed and unsexed length composition data formatted for Stock Synthesis. In the above example the input sample size is calculated based on the Stewart and Hamel approach (e.g., unique samples calculated as a function of species type and tows).
To plot the length frequency data:
plot_comps(
data = length_comps)
If the dir
function input is specified, then a “plot”
folder will be created in the directory location and a png of the plot
will be saved.
There is also a function to create raw or unexpanded composition data that works for either length or age data.
raw_length_comps <- get_raw_comps(
data = bio,
comp_bins = seq(10, 40, 2),
comp_column_name = "length_cm",
two_sex_comps = TRUE)
This function returns a list of sexed and unsexed length composition data formatted for Stock Synthesis. The input sample size is set equal to the number of samples in the data frame.
Marginal age composition data
age_comps <- get_expanded_comps(
bio_data = bio,
catch_data = catch,
comp_bins = 1:40,
strata = strata,
comp_column_name = "length_cm",
output = "full_expansion_ss3_format",
two_sex_comps = TRUE,
input_n_method = "stewart_hamel")
The above call will calculate the marginal age-composition data for the age data in a format for Stock Synthesis. This function returns a list of sexed and unsexed marginal age composition data formatted for Stock Synthesis. The example call will produce csv files for both the sexed and unsexed fish. This function returns a list of sexed and unsexed length composition data formatted for Stock Synthesis. In the above example the input sample size is calculated based on the Stewart and Hamel approach (e.g., unique samples calculated as a function of species type and tows).
To plot the age frequency data:
plot_comps(
data = age_comps)
If the dir
function input is specified, then a “plot”
folder will be created in the directory location and a png of the plot
will be saved.
There is also a function to create raw or unexpanded composition data that works for either length or age data.
raw_age_comps <- get_raw_comps(
data = bio,
comp_bins = 1:40,
comp_column_name = "age",
two_sex_comps = TRUE)
This function returns a list of sexed and unsexed marginal age composition data formatted for Stock Synthesis. The input sample size is set equal to the number of samples in the data frame.
Conditional-age-at-length data
To calculate conditional-age-at-length data formatted for Stock Synthesis:
caal <- SurveyAgeAtLen.fn(
datAL = bio,
datTows = catch,
strat.df = strata,
lgthBins = seq(10, 40, 2),
ageBins = 1:40)
Creates unexpanded conditional-age-at-length data for both sexes with input sample sizes based on the observed number of fish in each length bin by year.
Maps
To make a map showing the distribution of density in aggregate and by year:
PlotMap.fn(
dat = catch)
Additional data visualization
There are a couple of additional plotting functions that are included
in the package:PlotVarLengthAtAge.fn()
and
PlotSexRatio.fn()
.