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')
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.
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 ")
GF module:
Pull all merged trips from CAMS_OBS_CATCH
.
Filter to only Groundfish trips (Use GF
column)
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
discaRd
discaRd
with discard rates rolled up for all Sectors# Assumed Stratification variables stratvars = c('SPECIES_STOCK' ,'CAMS_GEAR_GROUP' ,'MESHGROUP' ,'SECTOR_TYPE')
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
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.
The two passes are joined in a hierarchical manner. Rates and DISCARD_SOURCE
(in parentheses) are assigned for each trip according to:
(EM) EM estimates from EM trips where EM was reviewed.
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.
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)
same as above
same as above
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
Run first pass of discaRd
for full startififcation
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')
# Third PAss Stratification variables stratvars = c('SPECIES_STOCK' ,'CAMS_GEAR_GROUP')
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)
Rates and DISCARD_SOURCE
(in parentheses) are assigned for each trip according to:
(O) Observed values used from observed rate trips; discard rate is NOT USED.
CV calculations are available for (I), (T), (GM) and (G).
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 ")
Non GF module:
pull all merged trips from CAMS_OBS_CATCH
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
)
discaRd
# Assumed Stratification variables stratvars = c('SPECIES_STOCK' , 'CAMS_GEAR_GROUP' ,'MESHGROUP')
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'.
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.
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.
Rates and DISCARD_SOURCE
(in parentheses) are assigned for each trip according to:
(O) Observed values used from observed rate trips; discard rate is NOT USED.
CV calculations are available for (I), (T), (GM) and (G).
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)
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.