View source: R/discard_generic_diagnostic.R
discard_generic_diagnostic | R Documentation |
The original function pushed .fst files directly to the Wind server at GARFO. This version does not do that and only produces local results.
discard_generic_diagnostic(
con = con_maps,
species = species,
FY = fy,
all_dat = all_dat,
return_table = T,
return_summary = F,
CAMS_GEAR_STRATA = CAMS_GEAR_STRATA,
STOCK_AREAS = STOCK_AREAS,
CAMS_DISCARD_MORTALITY_STOCK = CAMS_DISCARD_MORTALITY_STOCK
)
con |
Oracle connection |
species |
data frame of species for evaluation. Can be a dataframe of multiple species or single row (preferred for testing) |
FY |
fishing year for evaluation |
all_dat |
input data sourced from CAMS_OBS_CATCH |
return_table |
logical, should a table (very large!) of trip level info be returned? |
return_summary |
logical, should a summary (very not large) be returned? |
CAMS_GEAR_STRATA |
support table sourced from Oracle |
STOCK_AREAS |
support table sourced from Oracle |
CAMS_DISCARD_MORTALITY_STOCK |
support table sourced from Oracle |
Benjamin Galuardi
#--------------------------------------------------------------------------#
# you can also use odbc, or connect via server using keyring or other method
library(discaRd)
con <- ROracle::dbConnect(
drv = ROracle::Oracle(),
username = uid,
password = pwd,
dbname = "NERO.world"
)
# define species of interest
## ----get obs and catch data from oracle ----
# you need to get enough years to cover the current (focal) and previous fishing year. This is for transitions rate determination
start_year = 2017
end_year = year(today())
dat = get_catch_obs(con, start_year, end_year)
gf_dat = dat$gf_dat
non_gf_dat = dat$non_gf_dat
all_dat = dat$all_dat
rm(dat)
gc()
# get calendar year species list ----
species <- tbl(con, sql("
select *
from CFG_DISCARD_RUNID
")) %>%
filter(RUN_ID == 'CALENDAR') %>%
collect() %>%
group_by(ITIS_TSN) %>%
slice(1) %>%
ungroup()
# get one species for testing (black sea bass)
species = species %>%
filter(NESPP3 == 335)
# GEAR TABLE
CAMS_GEAR_STRATA = tbl(con, sql(' select * from CFG_GEARCODE_STRATA')) %>%
collect() %>%
dplyr::rename(GEARCODE = SECGEAR_MAPPED) %>%
filter(ITIS_TSN == species$ITIS_TSN) %>%
dplyr::select(-NESPP3, -ITIS_TSN)
# Stock (Estimation) areas table ----
STOCK_AREAS = tbl(con, sql('select * from CFG_STATAREA_STOCK')) %>%
collect() %>%
filter(ITIS_TSN == species$ITIS_TSN) %>%
group_by(AREA_NAME, ITIS_TSN) %>%
distinct(AREA) %>%
mutate(AREA = as.character(AREA)
, SPECIES_STOCK = AREA_NAME) %>%
ungroup()
# Discard Mortality table ----
CAMS_DISCARD_MORTALITY_STOCK = tbl(con, sql("select * from CFG_DISCARD_MORTALITY_STOCK")) %>%
collect() %>%
mutate(SPECIES_STOCK = AREA_NAME
, GEARCODE = CAMS_GEAR_GROUP
, CAMS_GEAR_GROUP = as.character(CAMS_GEAR_GROUP)) %>%
select(-AREA_NAME) %>%
filter(ITIS_TSN == species$ITIS_TSN) %>%
dplyr::select(-ITIS_TSN)
# Now, modify anything you wish to test in the support tables! For example, here is an example for scallop estiamtion areas. CAMS do not match the previous assessment and were worth investigating. CAMS ended up doing a good job in this case, regardless of the area splits.
if(species$ITIS_TSN == '079718'){
STOCK_AREAS = tbl(con, sql("
select ITIS_TSN
, AREA
, case when area > 599 then 'MA'
when area like '53%' then 'SNE'
when area >= 520 and area <599 and area not like '53%' then 'GB'
when area < 520 then 'GOM'
end as AREA_NAME
, case when area > 599 then 'MA'
when area like '53%' then 'SNE'
when area >= 520 and area <599 and area not like '53%' then 'GB'
when area < 520 then 'GOM'
end as SPECIES_STOCK
from CFG_STATAREA_STOCK
where ITIS_TSN = '079718'")) %>%
collect() %>%
group_by(AREA_NAME, ITIS_TSN) %>%
distinct(AREA) %>%
mutate(AREA = as.character(AREA)
, SPECIES_STOCK = AREA_NAME) %>%
ungroup()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.