-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
251 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
#' Find all groundfish species length data caught by groundfish fleets. | ||
#' | ||
#' Pick trips identified as groundfish to find species lengths. | ||
#' Use to estimate selectivity | ||
|
||
|
||
# pull groundfish data | ||
lbstotons <- 2204.62 | ||
boundaryBoxes <- c(0,23:29) | ||
gfData <- readRDS(here::here("data/NEGroundfishDataCAMS.rds")) | ||
gf <- gfData$neus |> | ||
dplyr::mutate(Year = as.integer(Year)) |> | ||
dplyr::mutate(InsideLANDED = InsideLANDED/lbstotons) | ||
|
||
if(0) { | ||
# attempts to join tables with GARFO | ||
channel <- dbutils::connect_to_database("NEFSC_USERS","abeet") | ||
|
||
sql1 <- "select distinct CAMSID, VTR_IMGID | ||
from CAMS_GARFO.CAMS_SUBTRIP | ||
where YEAR >= 1996 | ||
and VTR_IMGID IS NOT NULL" | ||
subtrip <- DBI::dbGetQuery(channel,sql1) | ||
|
||
# this table is a list of camsid and original vtr ids | ||
saveRDS(subtrip,here::here("data-raw/subtrip.rds")) | ||
} | ||
|
||
subtrip <- readRDS(here::here("data-raw/subtrip.rds")) |> | ||
dplyr::as_tibble() | ||
|
||
#select trips | ||
trips <- gf |> | ||
dplyr::distinct(TRIPID) |> | ||
dplyr::pull() | ||
|
||
camstrips <- subtrip |> | ||
dplyr::filter(VTR_IMGID %in% trips) |> | ||
dplyr::pull(CAMSID) | ||
|
||
# now pull lengths | ||
if(0) { | ||
sqlLengths <- "select CAMSID, NESPP3, LENGTH, NUMLEN | ||
from CAMS_GARFO.cams_cflen_aa | ||
where YEAR >= 1996" | ||
|
||
lengths <- DBI::dbGetQuery(channel,sqlLengths) |> | ||
dplyr::as_tibble() | ||
} | ||
|
||
lengths <- readRDS(here::here("data-raw/gflengths.rds")) | ||
|
||
# filter trips based on GF trips | ||
gflengths <- lengths |> | ||
dplyr::filter(CAMSID %in% camstrips) |> | ||
dplyr::mutate(NESPP3 = as.double(NESPP3)) | ||
|
||
gfcodes <- c("RED", "WHK", "COD" ,"HAD" ,"POL", "WTF", "WIF", "HAL", "PLA", "YTF" ,"WPF" ,"WOL", "OPT") | ||
|
||
atlantisGroups <- readr::read_csv("https://raw.githubusercontent.com/NEFSC/READ-EDAB-neusAtlantis/dev_branch/data-raw/data/Atlantis_2_0_groups_svspp_nespp3.csv") | ||
gfgroups <- atlantisGroups |> | ||
dplyr::filter(Code %in% gfcodes) | ||
|
||
|
||
allgflengths <- gflengths |> | ||
dplyr::left_join(gfgroups,by = "NESPP3") |> | ||
dplyr::filter(Code %in% gfcodes) | ||
|
||
replicatelengths <- allgflengths |> | ||
tidyr::uncount(NUMLEN) | ||
|
||
# over all fleets. | ||
# to do this by fleet we 'd need to filter out tripid's | ||
# plot histogram of lengths | ||
replicatelengths |> | ||
ggplot2::ggplot() + | ||
ggplot2::geom_histogram(ggplot2::aes(x=LENGTH)) + | ||
ggplot2::facet_wrap(~Code,scale = "free_x") + | ||
ggplot2::ylab("Number of fish") + | ||
ggplot2::xlab("length (cm)") | ||
|
||
# plot prob curve by species | ||
replicatelengths |> | ||
dplyr::select(Code,LENGTH) |> | ||
dplyr::arrange(Code,LENGTH) |> | ||
dplyr::group_by(Code) |> | ||
dplyr::mutate(prob = (1:dplyr::n())/dplyr::n()) |> | ||
ggplot2::ggplot(ggplot2::aes(x=LENGTH,y=prob)) + | ||
ggplot2::geom_line() + | ||
ggplot2::geom_point(size = 0.5) + | ||
ggplot2::facet_wrap(~Code,scale = "free_x") + | ||
ggplot2::ylab("Probability") + | ||
ggplot2::xlab("length (cm)") | ||
|
||
# plot all on same figure | ||
p <- replicatelengths |> | ||
dplyr::select(Code,LENGTH) |> | ||
dplyr::arrange(Code,LENGTH) |> | ||
dplyr::group_by(Code) |> | ||
dplyr::mutate(prob = (1:dplyr::n())/dplyr::n()) |> | ||
ggplot2::ggplot(ggplot2::aes(x=LENGTH,y=prob, col=Code)) + | ||
ggplot2::geom_line() + | ||
ggplot2::geom_point(size = 0.5) + | ||
ggplot2::ylab("Probability") + | ||
ggplot2::xlab("length (cm)") | ||
|
||
plotly::ggplotly(p) | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters