Skip to contents

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.

Functions

A list of all functions in the packages can be viewed by:

ls("package:nwfscSurvey")

Examples

NWFSC WCGBT Survey

Pull data

Pull both the catch and biological data:

catch = PullCatch.fn(Name = "Pacific ocean perch", 
                     SurveyName = "NWFSC.Combo")

bio   = PullBio.fn(Name = "Pacific ocean perch", 
                   SurveyName = "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(
  dir = getwd(), 
  catch = catch)

plot_bio_patterns(
  dir = getwd(), 
  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 = Biomass.fn(dir = getwd(), 
                     dat = catch,  
                     strat.df = strata)

Biomass.fn() 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 “forSS” folder. The function returns a list with the second element containing the design-based estimates by year:

Year Season Fleet Value seLogB
2003 1 EnterFleet 21055083 0.357
2015 1 EnterFleet 9766200 0.563

Plot the coastwide design-based index of abundance:

PlotBio.fn(
  dir = getwd(), 
  dat = biomass)

Plot the coastwide design-based index of abundance for each strata:

PlotBioStrata.fn(
  dir = getwd(), 
  dat = biomass)

If dir does not equal NULL, then a “plot” folder will be created in the directory location and a png of the plot will be saved.

Length composition data

GetN() calculates the input sample size based on Stewart & Hamel (2014) which determined that the input sample size was related to the species group (flatfish, shelf rockfish, slope rockfish, thornyhead, others, or all groups) and number of tows. The function writes a csv file with the “forSS” folder containing the number of tows and observed fish by year.

n <- GetN(dir = getwd(), 
         dat = bio, 
         type = "length", 
         species = "shelfrock")

SurveyLFs.fn() calculates and formats the length-composition data for Stock Synthesis:

len_bins <- seq(10, 60, 2)

Length_Freq <- SurveyLFs.fn(dir = getwd(), 
                        datL =  bio, 
                        datTows = catch,
                        strat.df = strata,
                        lgthBins = len_bins)

The above call will calculate the length frequencies for use in Stock Synthesis and write the files inside the “forSS” folder. The example call does not assign unsexed fish to the sexed length comps but will produce csv files for both the sexed and unsexed fish. If you would like to assign the unsexed fish to a sex based on the sex ratio the user will need to specificy the sex ratio value (sexRatioUnsexed) to use for fish under a specified size (maxSizeUnsexed) where unsexed fish greater than the specified size will be assign based on the sex ratio from other observations.

There are many inputs to SurveyLFs.fn(), please look over the function inputs to explore additional ways to process the data.

To plot the length frequency data:

PlotFreqData.fn(dir = getwd(), 
                dat = Length_Freq)

A new function to visualize length frequency data is also availble:

plot_comps(data = Length_Freq)

If dir does not equal NULL, then a “plot” folder will be created in the directory location and a png of the plot will be saved.

Marginal age composition data

Calculate the marginal age sample size:

n <- getN(dir = getwd(), 
         dat = bio,
         type = "age", 
         species = "shelfrock")

SurveyAFs.fn() calculates and formats the age-composition data for Stock Synthesis:

age_bins <- 1:50

Ages <- SurveyAFs.fn(dir = getwd(), 
                     datA = bio,
                     datTows = catch, 
                     strat.df = strata,
                     ageBins = age_bins,
                     nSamps = n)

The above call will calculate the marginal age-composition data for the age data read in using readInExcelAgeComps.fn() and writes the files inside the “forSS” folder.

To plot the age frequency data:

PlotFreqData.fn(
  dir = getwd(), 
  dat = Ages)

plot_comps(
  data = Ages)

If dir is not NULL, then a “plot” folder will be created in the directory location and a png of the plot will be saved.

Conditional-age-at-length data

To calculate conditional-age-at-length data formatted for Stock Synthesis:

caal <- SurveyAgeAtLen.fn(dir = getwd(), 
                          datAL = bio, 
                          datTows = catch,
                          strat.df = strata,
                          lgthBins = len.bins, 
                          ageBins = age.bins)

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().