This vignette is designed to illustrate running alternative scenarios of standard CAMS discard functions. Here, Support tables are function variables. This allows them to be modified and run for diagnostic testing. You can output a summary of discard information by strata, including number of trips used, variance, CV, discard amount, and KALL. Youcan also output a table, by subtrip, with all information. This table can be summarized afterward as well. If testing several scenarios, it is recommended to only output the summary rather than the full subtrip table as each output is 1-2GB. The original function pushed .fst files directly to the Wind server at GARFO. This version does not do that and only produces local results.

knitr::opts_chunk$set(echo = T, warning = FALSE, 
                                            message = FALSE, cache = FALSE,
                                            progress = TRUE, verbose = FALSE, comment = F
                                            , error = FALSE, dev = 'png', dpi = 200)

options(knitr.kable.NA = '')
options(dplyr.summarise.inform = FALSE)

Get connected.

library(discaRd)

keyring::keyring_unlock(keyring = 'apsd_ma', password = readLines('~/pw.txt'))
con = apsdFuns::roracle_login(key_name = 'apsd_ma', key_service = 'cams_garfo')

Example 1

# look at CAMS_DISCARD_ALL_YEARS

disc = tbl(con, sql("
  select a.* , b.accessarea, b.tripcategory, b.camsid||'_'||b.subtrip as cams_subtrip
  from cams_discard_all_years a
  left join (select * from cams_subtrip) b  on (a.camsid = b.camsid and a.subtrip = b.subtrip)
   where a.FY = 2019 
  and a.itis_tsn = '172873'
")
)

# look by elements used 
#### N-OBS is incorrect by 1; the count is including NA... 

  disc %>% 
  filter(
    GF == 0 &
      SPECIES_STOCK == 'GBGOM' &
      CAMS_GEAR_GROUP == '050' &
      MESH_CAT == 'LM' &
      TRIPCATEGORY == 'all' & 
      ACCESSAREA == 'all'
  ) %>%
  collect() %>% 
  dplyr::summarise(N_UNOBSERVED = max(N_UNOBSERVED, na.rm = T)
                   , N_OBSERVED = max(N_OBSERVED, na.rm = T)
                   , N_total = n_distinct((CAMS_SUBTRIP)) ,
                   n_actual = n_distinct(na.omit(LINK1)),
                   nrow = nrow(.))


# grab obs trips 
#### will not have a STRATA_USED_DESC (NA)

disc %>%
  filter(
    GF == 0 &
      SPECIES_STOCK == 'GBGOM' &
      CAMS_GEAR_GROUP == '050' &
      MESH_CAT == 'LM' &
      TRIPCATEGORY == 'all' & 
      ACCESSAREA == 'all' &
    !is.na(LINK1)
  ) %>% 
  collect() %>% 
  dplyr::summarize(N_subtrips_obs = n_distinct((CAMS_SUBTRIP)) ,
                   n_link1 = n_distinct(na.omit(LINK1)),
                   nrow = nrow(.))

# look according to strata used
#### since sleecting by STRATA_UED_dESC, LINK1 will not be visible (n = 0)

disc %>% 
  filter(GF == 0 & STRATA_USED_DESC == 'GBGOM;050;LM;all;all') %>%
  collect() %>% 
  group_by(DISCARD_SOURCE, STRATA_USED_DESC) %>%
   dplyr::summarise(N_UNOBSERVED = max(N_UNOBSERVED, na.rm = T)
                   , N_OBSERVED = max(N_OBSERVED, na.rm = T)
                   , N_subtrips = n_distinct((CAMS_SUBTRIP)) ,
                   n_link1 = n_distinct(na.omit(LINK1)),
                   nrow = nrow(.))

example 2 (Dan Caless A rates)

ex2 = tbl(con, sql("select *
from cams_garfo.cams_obs_catch
where year in(2019, 2020)
and NEGEAR = '010'
and GF = 1
and itis_tsn = 171341"
))

arates = tbl(con, sql("select FY
  , itis_tsn
  , strata_used_desc
  , discard_source
  , count(distinct camsid)
  , cams_discard_rate
  , n_observed
  , n_unobserved
  from cams_garfo.cams_discard_all_years
  where FY IN (2019, 2020)
  and itis_tsn = '171341' 
  and cams_discard > 0
  and strata_used_desc = 'GOM;010;NA;SECTOR'
  group by FY, itis_tsn, strata_used_desc, discard_source, cams_discard_rate, n_observed
  , n_unobserved
  order by discard_source desc"
  )
)


arates2 = tbl(con, sql("select a.FY
  , a.itis_tsn
  , a.strata_used_desc
  , a.discard_source
  , a.mesh_cat
  , a.GF
  , a.cams_gear_group
  , a.species_stock
  , count(distinct a.camsid)
  , a.cams_discard_rate
  , b.accessarea
  , b.tripcategory
  , b.sectid
  , a.link1
  , b.camsid||'_'||b.subtrip as cams_subtrip
  from cams_discard_all_years a

  left join (select * from cams_subtrip) b  on (a.camsid = b.camsid and a.subtrip = b.subtrip)

  where a.FY IN (2019, 2020)
  and a.itis_tsn = '171341'
  and a.cams_discard > 0
  --and a.strata_used_desc = 'GOM;010;NA;SECTOR'
  group by a.FY
  , a.itis_tsn
  , a.strata_used_desc
  , a.discard_source
  , a.cams_discard_rate
  , b.accessarea
  , b.tripcategory
  , b.sectid
  , a.GF
    , a.mesh_cat
  , a.cams_gear_group
  , a.species_stock
  , a.link1
  , b.camsid||'_'||b.subtrip 
  order by discard_source desc"
  )
)

arates2 %>% 
  filter(
    # GF == 0 &
      # SPECIES_STOCK == 'GOM' &
      CAMS_GEAR_GROUP == '010' &
      # is.na(MESH_CAT)  &
      # !is.na(SECTID) &
     !is.na(LINK1)
     )%>% 
  collect()


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