knitr::opts_chunk$set(echo = TRUE)

library(tidyverse)
library(odbc)
library(ROracle)
library(dplyr, warn.conflicts = FALSE)

# # unlock keyring
# keyring::keyring_unlock("apsd_ma")
# 
# # local run
# # dw_apsd <- config::get(value = "apsd", file = "K:/R_DEV/config.yml")
# 
# # if on server..
# # dw_apsd <- config::get(value = "maps", file = "~/config.yml")
# 
# 
# # connect to MAPS
# 
# con_maps = apsdFuns::roracle_login(key_name = 'apsd_ma', key_service = 'maps')
Sys.setenv(TZ = "America/New_York")
Sys.setenv(ORA_SDTZ = "America/New_York")

if(file.exists(here::here("vignettes/articles", "pw.csv"))) {
  pw_df <- readr::read_csv(here::here("vignettes/articles", "pw.csv"), col_types = "c")
  pw <- pw_df$pw
} else {
  pw <- rstudioapi::askForPassword("Enter keyring password")
}

keyring::keyring_unlock("apsd_ma", password = pw) # will prompt for password
con_maps <- apsdFuns::roracle_login(key_name = 'apsd_ma', key_service = 'maps')

Summary

This table provides discard estimates by subtrip for both GF and non GF species. Table output is from the GF and Non GF discard modules available in the R package discaRd.

Description

Data Sources

CAMS_OBS_CATCH GF_EM_DISCARDS_ARCH GF_EM_DELTA_VTR_DISCARDS CAMS_DISCARD_MORTALITY_STOCK CAMS_OBS_CATCH CAMS_GEARCODE_STRATA CAMS_STATAREA_STOCK

DiagrammeR::mermaid("
  graph LR
  CAMS_OBS_CATCH --> GF_Discard_Module
  CAMS_DISCARD_MORTALITY_STOCK --> GF_Discard_Module
  CAMS_GEARCODE_STRATA --> GF_Discard_Module
  CAMS_STATAREA_STOCK --> GF_Discard_Module
  CAMS_GF_EM_DISCARDS_ARCH --> GF_Discard_Module
  CAMS_GF_EM_DELTA_VTR_DISCARDS --> GF_Discard_Module
  GF_Discard_Module --> CAMS_DISCARDS_ALL_YEARS
        ")

Approach

GF module:

  1. Pull all merged trips from CAMS_OBS_CATCH.

  2. Filter to only Groundfish trips (Use GF column)

  3. Set stratification variables for groundfish trips

# FULL Stratification variables

stratvars = c( 'SPECIES_STOCK'
              , 'CAMS_GEAR_GROUP'
              , 'MESHGROUP'
              , 'SECTID'
              , 'EM'
              , "REDFISH_EXEMPTION"
              , "SNE_SMALLMESH_EXEMPTION"
              , "XLRG_GILLNET_EXEMPTION")

By Species: - SPECIES_STOCK is taken from CAMS support table CAMS_STATAREA_STOCK - CAMS_GEAR_GROUP is derived from a support table (CAMS_GEARCODE_STRATA) - MESHGROUP is hardcoded for all trips according to decisions made by the mesh subgroup (see summary when available) - SECTID comes from a CAMS matching table (MATCH_MULT_SECTID) - EFP and Exemptions are built in to CAMS_LANDINGS, the precursor for CAMS_OBS_CATCH

  1. Perform first pass of discaRd
    • there are two sub-passes for year t and year t-1
  2. Perform second pass of discaRd with discard rates rolled up for all Sectors
    • Common Pool is distinguished from the rest of Sectors
    • Simplified stratification is used:
# Assumed Stratification variables

stratvars = c('SPECIES_STOCK'
              ,'CAMS_GEAR_GROUP'
              ,'MESHGROUP'
                            ,'SECTOR_TYPE') 
  1. The discaRd functions allow for an assumed rate to be calculated. This assumed rate is relative to the stratification used in the functions. Here, we utilize this feature to generate a broad stock rate. the stratification here is simply SPECIES_STOCK

  2. For each pass, a transition rate is calculated between year t and year t-1. This rate determines how much, if any, information is used from previous years.

  3. The two passes are joined in a hierarchical manner. Rates and DISCARD_SOURCE (in parentheses) are assigned for each trip according to:

  4. (I) in season rate; >= 5 trips in Full Stratification
  5. (T) Transition in season rate; < 5 trips in Full Stratification, year t, AND >= 5 trips in year t-1
  6. (A) Assumed rate. This is the second pass rate when there were >=5 trips in season
  7. (B) Broad stock rate is used when other criteria are not met.
  8. (O) Observed values used from observed trips; discard rate is NOT USED.
  9. (VTR) VTR estimates from EM trips prior to implementation of the audit model during GF FY21.
  10. (Delta) Delta estimates from EM trips after implementation of the audit model.
  11. (EM) EM estimates from EM trips where EM was reviewed.

  12. CV calculations are available for (I), (T), and (A). Obtaining a CV estimate for (B) would require a third pass of discaRd functions. (O) rates are not used and final discard values are not estimated.

  13. Discard pounds per trip are calculated according to

    mutate(coalesce(DISC_MORT_RATIO, 1)) %>%
    mutate(DISCARD = case_when(!is.na(LINK1) ~ DISC_MORT_RATIO*OBS_DISCARD
                                                         , is.na(LINK1) ~ DISC_MORT_RATIO*COAL_RATE*LIVE_POUNDS)

Steps for estimation of groundfish discard on non-Groundfish Trips

  1. same as above

  2. same as above

  3. Set stratification variables

# Full (First Pass) Stratification variables

stratvars = c('SPECIES_STOCK'
              ,'CAMS_GEAR_GROUP'
                            , 'MESHGROUP'
                          , 'TRIPCATEGORY'
                          , 'ACCESSAREA')
- SPECIES_STOCK is taken from CAMS support table `CAMS_STATAREA_STOCK`
- CAMS_GEAR_GROUP is derived from a support table (`CAMS_GEARCODE_STRATA`)
- MESHGROUP is hardcoded for all trips according to decisions made by the mesh subgroup (see summary when available)
- TRIPCATEGORY is specific to scallop trips and indicates Limited Access or General Category Fleets
- ACCESS AREA is specific to scallop trips and indicates Scallop Access Area
  1. Run first pass of discaRd for full startififcation

    • there are sub-passes for year t and year t-1
  2. Run a second pass using a coarsened stratification : 'SPECIES_STOCK', 'CAMS_GEAR_GROUP' and 'MESHGROUP'.

# Second Pass Stratification variables

stratvars = c('SPECIES_STOCK'
              ,'CAMS_GEAR_GROUP'
              ,'MESHGROUP')
  1. Run a third pass using Stock and Gear only *Note: This pass uses data from the focal and previous year.
# Third PAss Stratification variables

stratvars = c('SPECIES_STOCK'
              ,'CAMS_GEAR_GROUP')
  1. Trips/Gear strata that are unobserved after these steps are not assigned rates as no observer coverage exists for these gear types (e.g. Menhaden purse seine)

  2. Rates and DISCARD_SOURCE (in parentheses) are assigned for each trip according to:

  3. (I) in season rate; >= 5 trips in Full Stratification
  4. (T) Transition in season rate; < 5 trips in Full Stratification, year t, AND >= 5 trips in year t-1
  5. (GM) Broad stock/gear/mesh size rate. This is the rate when there were <5 trips in season and <5 in previous season.
  6. (G) Broad stock/gear rate. <5 trips in season and <5 trips in previous season
  7. (N) No coverage in focal season and previous season; discard rate is not possible to estimate.
  8. (O) Observed values used from observed rate trips; discard rate is NOT USED.

  9. CV calculations are available for (I), (T), (GM) and (G).

  10. Discard pounds per trip are calculated according to

    mutate(DISC_MORT_RATIO = coalesce(DISC_MORT_RATIO, 1)) %>%
    mutate(DISCARD = case_when(!is.na(LINK1) ~ DISC_MORT_RATIO*OBS_DISCARD
                                                         , is.na(LINK1) ~ DISC_MORT_RATIO*COAL_RATE*LIVE_POUNDS)
DiagrammeR::mermaid("
  graph LR
  CAMS_OBS_CATCH --> Non_GF_Discard_Module
  CAMS_DISCARD_MORTALITY_STOCK --> Non_GF_Discard_Module
  CAMS_GEARCODE_STRATA --> Non_GF_Discard_Module
  CAMS_STATAREA_STOCK --> Non_GF_Discard_Module
  Non_GF_Discard_Module --> CAMS_DISCARDS_ALL_YEARS
        ")

Approach

Non GF module:

  1. pull all merged trips from CAMS_OBS_CATCH

  2. Set stratification variables for all trips

# FULL Stratification variables

stratvars = c('SPECIES_STOCK'
              ,'CAMS_GEAR_GROUP'
                            , 'MESHGROUP'
                          , 'TRIPCATEGORY'
                          , 'ACCESSAREA')

By Species: - SPECIES_STOCK is taken from CAMS support table CAMS_STATAREA_STOCK - CAMS_GEAR_GROUP is derived from a support table (CAMS_GEARCODE_STRATA) - MESHGROUP is hardcoded for all trips according to decisions made by the mesh subgroup (see summary when available) - SECTID comes from a CAMS matching table (MATCH_MULT_SECTID)

  1. Run discaRd
    • there are sub-passes for year t and year t-1
# Assumed Stratification variables

stratvars = c('SPECIES_STOCK'
              , 'CAMS_GEAR_GROUP'
              ,'MESHGROUP')
  1. The discaRd functions allow for an assumed rate to be calculated. This assumed rate is relative to the stratification used in the functions. Here, the stratification is coarsened to 'SPECIES_STOCK', 'CAMS_GEAR_GROUP' and 'MESHGROUP'.

  2. A transition rate is calculated between year t and year t-1. This rate determines how much, if any, information is used from previous years.

  3. A broad stock/gear stratification is applied to subtrips that do not meet the requirements for the full or assumed stratification. This broad stock/gear stratification utilizes observed coverage from both the focal year and the previous year as it includes gear types with low observer coverage.

  4. Rates and DISCARD_SOURCE (in parentheses) are assigned for each trip according to:

  5. (I) in season rate; >= 5 trips in Full Stratification
  6. (T) Transition in season rate; < 5 trips in Full Stratification, year t, AND >= 5 trips in year t-1
  7. (GM) Broad stock/gear/mesh size rate. This is the rate when there were <5 trips in season and <5 in previous season.
  8. (G) Broad stock/gear rate. <5 trips in season and <5 trips in previous season
  9. (N) No coverage in focal season and previous season; discard rate is not possible to estimate.
  10. (O) Observed values used from observed rate trips; discard rate is NOT USED.

  11. CV calculations are available for (I), (T), (GM) and (G).

  12. Discard pounds per trip are calculated according to

    mutate(DISC_MORT_RATIO = coalesce(DISC_MORT_RATIO, 1)) %>%
    mutate(DISCARD = case_when(!is.na(LINK1) ~ DISC_MORT_RATIO*OBS_DISCARD
                                                         , is.na(LINK1) ~ DISC_MORT_RATIO*COAL_RATE*LIVE_POUNDS)

Data Dictionary

comments <- ROracle::dbGetQuery(con_maps, "SELECT * FROM all_col_comments WHERE owner = 'MAPS' AND table_name = 'CAMS_DISCARD_MONKFISH_19'")

comments %>%
dplyr::select(
COLUMN = COLUMN_NAME,
DESCRIPTION = COMMENTS) %>%
knitr::kable(booktabs = TRUE) %>%
kableExtra::kable_styling(bootstrap_options = c("striped", 
"hover", "condensed", "responsive"),full_width = FALSE,position = "left", fixed_thead = TRUE,
font_size = 10)


noaa-garfo/discaRd documentation built on April 17, 2025, 10:32 p.m.