knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

source("../data-raw/R/create_species_rules_table.r")

When working with mscatch, depending on what you want to do, you will need to:

Assuming you have assembled the data (for a sample data set see, get_sample_data), the next step is to determine how the data should be aggregate and how to deal with missing length samples in YEARs/QTRs where there are catch.

There are two approaches a user can take:

Define a species object

A species object can be defined and passed as an argument to the aggregate_landings function. This object specifies decision rules to be used in the aggregation step that answer the following questions:

General rules

This option is for exploring the data and assessing the impacts related to aggregation decisions to help inform building a species object. For example:

Examples

Using the exploratory approach

 aggregatedData <- mscatch::aggregate_landings(channel,
                                               landingsData,
                                               lengthData,
                                               outputDir=here::here("output/Haddok"),
                                               speciesName = "Haddock"
                                               landingThresholdGear = 0.9,
                                               nLengthSamples = 1,
                                               aggregate_to = "YEAR",
                                               borrowLengths = T,
                                               otherGear = "998",
                                               logfile = "logfile.txt"
                                               outputPlots = T,
                                               speciesRules = NULL)

At this point, aggregateData contains length samples for every combination of YEAR, NEGEAR, MARKET_CODE. All decisions made regarding gear type selection, market code selection, and which YEAR length samples were borrowed from are recorded in the logfile. If outputPlots=T a suite of plots are also output in the outputDir.

Using a species object

A template for the species object is bundled with mscatch which can then be adapted

# Haddock species itis code = 164744
species_itis <- 164744
speciesRules <- mscatch::get_species_object(species_itis)
speciesRules$marketCodes  |>  
  flextable::flextable()

This specifies the market code aggregation; LG and XG codes are combind and relabeled as LG, SR and SK remain as they are. All other market codes are treated as unclassifieds, UN.

speciesRules$gearCodes |> 
  flextable::flextable()

All gear codes are aggregated and labelled as gear code "050"

Other related rules:

create_species_rules_table(spitis = species_itis)

This speciesRules object is then passed as an argument to aggregate_landings

Expand the catch (Length & Numbers)

To expand the catch to weight-by-length a length-weight key is required. This is achieved by obtaining parameter values that satisfy the length-weight relationship. This can be obtained in one of two ways:

or

The data is pulled using the function get_length_weight_data from the survdat package and fit using fit_length_weight()

# Permissions and credentials are required to conect to the database
channel <- dbutils::connect_to_database("server","user")
# Haddock data are pulled (SVSPP = 74)
lengthWeightData <- survdat::get_length_weight_data(channel,year="all", species=74)
# Length-Weight models are thenn fit
fits <- mscatch::fit_length_weight(lengthWeightData$data,speciesName,speciesRules,outputDir,logfile="logfile.txt")
  expandedLandings <- mscatch::expand_landings_to_lengths(aggregatedData$landings,aggregatedData$lengthData,fits$paramsH0) |> 
    dplyr::mutate(speciesName = speciesName)


NOAA-EDAB/neusCatch documentation built on Jan. 23, 2025, 3:29 a.m.