Skip to content

Commit

Permalink
added NE groundfish rmd
Browse files Browse the repository at this point in the history
  • Loading branch information
andybeet committed Jun 25, 2024
1 parent d707923 commit 27386b9
Showing 1 changed file with 373 additions and 0 deletions.
373 changes: 373 additions & 0 deletions vignettes/groundfishNEFleet.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,373 @@
---
title: "NE Groundfish fleet"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{NE Groundfish fleet}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---



```{r setup, warning=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
library(atlantiscas)
library(ncdf4)
library(sf)
```


## Species

The [NE multispecies (Groundfish) FMP](https://www.nefmc.org/management-plans/northeast-multispecies) comprises the following species:

* Atlantic Cod (COD)
* Haddock (HAD)
* Yellowtail Flounder (YTF)
* Pollock (POL)
* American Plaice (PLA)
* Witch Flounder (WTF)
* White Hake (WHK)
* Winter Flounder (WIF)
* Redfish (RED)
* Atlantic Halibut (HAL)

Non target species

* Windowpane flounder (WPF)
* Ocean Pout (OPT)
* Atlantic Wolffish (WOL)

These GEARCAT(s) associated with groundfish species are:

* Bottom Trawl
* Sink Gillnet

** Still need to separate some species (skates, sharks) **


```{r groundfishdata, echo = F}
gf <- readRDS(here::here("data/NEGroundfishDataCAMS.rds")) |>
dplyr::mutate(Year = as.integer(Year))
gfCodes <- c("COD","HAD","YTF","POL","PLA","WTF","WHK","WIF","RED","HAL","WPF","OPT","WOL")
gf |> dplyr::distinct(GEARCAT,GEARCODE) |>
dplyr::arrange(GEARCAT) |>
DT::datatable()
```

## Landings

The landings of trips with associated bycatch

```{r plotland1, echo = F}
landings <- gf |>
dplyr::group_by(Year,Functional_Group) |>
dplyr::summarise(lbs = sum(InsideLANDED),
.groups = "drop")
speciesLanded <- landings |>
dplyr::group_by(Functional_Group) |>
dplyr::summarise(nyrs = dplyr::n(),
.groups = "drop") |>
dplyr::filter(nyrs > 1) |>
dplyr::pull(Functional_Group)
landings |>
dplyr::filter(Functional_Group %in% speciesLanded) |>
ggplot2::ggplot() +
ggplot2::geom_line(ggplot2::aes(x=Year,y=lbs)) +
ggplot2::facet_wrap(~Functional_Group)
```

## Total groundfish landings for species in FMP

```{r plotcompare, echo = F}
landings <- gf |>
dplyr::filter(Code %in% gfCodes) |>
dplyr::group_by(Year,Code) |>
dplyr::summarise(lbs = sum(InsideLANDED),
.groups = "drop")
landings |>
ggplot2::ggplot() +
ggplot2::geom_line(ggplot2::aes(x=Year,y=lbs)) +
ggplot2::facet_wrap(~Code)
```

## Total groundfish landings for bycatch species

```{r plotcompare2, echo = F}
landings <- gf |>
dplyr::filter(!(Code %in% gfCodes)) |>
dplyr::group_by(Year,Code) |>
dplyr::summarise(lbs = sum(InsideLANDED),
.groups = "drop")
landings |>
ggplot2::ggplot() +
ggplot2::geom_line(ggplot2::aes(x=Year,y=lbs)) +
ggplot2::facet_wrap(~Code)
```

## Landings of groundfish by species

```{r plotland2, echo =F}
gf |>
dplyr::group_by(Functional_Group,Code) |>
dplyr::summarise(millionlbs = sum(InsideLANDED)/1000000,
.groups = "drop") |>
dplyr::arrange(desc(millionlbs)) |>
DT::datatable(options = list(pageLength = 10,
order = list(list(0, 'asc'))
))
```


## Landings of Groundfish by state

```{r plotland3, echo = F}
landings <- gf |>
dplyr::filter(Code %in% gfCodes) |>
dplyr::group_by(Year,STATEABB) |>
dplyr::summarise(lbs = sum(InsideLANDED),
.groups = "drop")
landings |>
ggplot2::ggplot() +
ggplot2::geom_line(ggplot2::aes(x=Year,y=lbs)) +
ggplot2::facet_wrap(~STATEABB)
```

## Landings of groundfish by port (species in FMP)

```{r plotland4, echo=F}
landings <- gf |>
dplyr::filter(Code %in% gfCodes) |>
dplyr::group_by(Year,STATEABB,newport) |>
dplyr::summarise(lbs = sum(InsideLANDED),
.groups = "drop")
ports10 <- landings |>
dplyr::group_by(newport,STATEABB) |>
dplyr::summarise(lbs = sum(lbs),
.groups = "drop") |>
dplyr::arrange(desc(lbs)) |>
dplyr::slice(1:10) |>
dplyr::pull(newport)
landings |>
dplyr::filter(newport %in% ports10) |>
dplyr::group_by(Year,newport) |>
dplyr::summarise(lbs = sum(lbs),
.groups="drop") |>
ggplot2::ggplot() +
ggplot2::geom_line(ggplot2::aes(x=Year,y=lbs)) +
ggplot2::facet_wrap(~newport)
```


## Landings by Atlantis Box
compared to model output from v2.2.0

```{r plotland5, echo=F}
landings <- gf |>
dplyr::filter(Code %in% gfCodes) |>
dplyr::group_by(Year,Area) |>
dplyr::summarise(lbs = sum(InsideLANDED),
.groups = "drop") |>
tidyr::separate(col=Area,into = c("text","Box"),sep = "ID_") |>
dplyr::mutate(Box = as.numeric(Box)) |>
dplyr::mutate(mt = lbs*0.000453592) |>
dplyr::select(-text,-lbs) |>
dplyr::mutate(source = "CAMS")
# Compare to atlantis
#
# x.nc = nc_open(here::here("data-raw/atlantis",'neus_outputCATCH.nc'))
# varname = names(x.nc$var)
# vn <- grep('SCA_Catch_FC1',varname,value = T)
#
# dd <- ncvar_get(x.nc,"SCA_Catch_FC1",collapse_degen = F)
# nc_close(x.nc)
#
# rownames(dd) <- 1:nrow(dd)
# colnames(dd) <- 1:ncol(dd)
#
# d2 <- as.data.frame(dd) |>
# tibble::rownames_to_column(var="Box") |>
# dplyr::mutate(Box = as.integer(Box) -1) |>
# tidyr::pivot_longer(cols=-Box,names_to = "t",values_to = "value") |>
# dplyr::mutate(t = as.integer(t),
# Year = 1963+ceiling(t/5)) |>
# dplyr::group_by(Box,Year) |>
# dplyr::summarise(mt = mean(value),
# .groups="drop") |>
# dplyr::relocate(Year,Box,mt) |>
# dplyr::mutate(source = "atlantis")
#
# dataF <- rbind(d2,landings) |>
# dplyr::filter(Year > 1995)
#
dataF <- landings
dataF |>
ggplot2::ggplot() +
ggplot2::geom_line(ggplot2::aes(x=Year,y=mt,color=source)) +
ggplot2::facet_wrap(~Box) +
ggplot2::theme(axis.text.x = ggplot2::element_text(angle = 90))
```

## Landings (data) by box spatially

```{r plotland6, echo =F}
dataBox <- dataF |>
dplyr::filter(source == "CAMS") |>
dplyr::group_by(Box) |>
dplyr::summarise(mt = sum(mt))
# select boxes which account fo 95% of landings
landings <- dataBox |>
dplyr::arrange(desc(mt)) |>
dplyr::mutate(cumsum = cumsum(mt), prop = cumsum/sum(mt)) |>
dplyr::filter(prop <= 0.95)
NEFSCspatial::Neus_atlantis |>
dplyr::left_join(landings,by = c("BOX_ID"="Box")) |>
ggplot2::ggplot() +
ggplot2::geom_sf(ggplot2::aes(fill = mt)) +
ggplot2::geom_sf_text(ggplot2::aes(label = BOX_ID),
position = ggplot2::position_dodge(width=0.9), size=3)
```

Boxes that contribute 95% of landings `r landings |> dplyr::pull(Box) |> sort()`


## Landings (data) by box spatially for main ports

```{r plotland7, echo =F}
# pick out 3 busiest ports based on landings
ports <- gf |>
dplyr::filter(Code %in% gfCodes) |>
dplyr::group_by(newport,PORTID,lat,lon) |>
dplyr::summarise(lb = sum(InsideLANDED),
.groups = "drop") |>
dplyr::arrange(desc(lb)) |>
dplyr::slice(1:3)
portids <- ports |> dplyr::pull(PORTID)
landings <- gf |>
dplyr::filter(Code %in% gfCodes,PORTID %in% portids) |>
dplyr::group_by(Year,Area,PORTID) |>
dplyr::summarise(lbs = sum(InsideLANDED),
.groups = "drop") |>
tidyr::separate(col=Area,into = c("text","Box"),sep = "ID_") |>
dplyr::mutate(Box = as.numeric(Box)) |>
dplyr::mutate(mt = lbs*0.000453592) |>
dplyr::select(-text,-lbs)
# create map for each
for (iport in portids) {
portName <- ports |>
dplyr::filter(PORTID == iport) |>
dplyr::pull(newport)
# portlatlon <- ports |>
# dplyr::filter(PORTID == iport)
dataBox <- landings |>
dplyr::filter(PORTID == iport) |>
dplyr::group_by(Box) |>
dplyr::summarise(mt = sum(mt),
.groups="drop")
# create landings by box (summed over time)
boxLandings <- dataBox |>
dplyr::arrange(desc(mt)) |>
dplyr::mutate(cumsum = cumsum(mt), prop = cumsum/sum(mt)) |>
dplyr::filter(prop <= 0.95)
# select boxes which account fo 95% of landings
p <- NEFSCspatial::Neus_atlantis |>
dplyr::left_join(boxLandings,by = c("BOX_ID"="Box")) |>
ggplot2::ggplot() +
ggplot2::geom_sf(ggplot2::aes(fill = mt)) +
ggplot2::geom_sf_text(ggplot2::aes(label = BOX_ID),
size=3) +
ggplot2::geom_point(data = ports,
mapping=ggplot2::aes(x=lon,y=lat),
color="red") +
ggplot2::geom_text(data = ports,
ggplot2::aes(x=lon,y=lat,label = newport),
size = 2.5,
hjust=1, vjust=0) +
ggplot2::ggtitle(portName) +
ggplot2::coord_sf(xlim = c(-80,-62))
suppressWarnings(print(p))
}
```

## Location of ports

Location of ports that land gf

```{r ports1, echo =F}
ports <- gf |>
dplyr::filter(Code %in% gfCodes) |>
dplyr::group_by(newport,PORTID,lat,lon) |>
dplyr::summarise(lb = sum(InsideLANDED),
.groups = "drop") |>
dplyr::arrange(desc(lb)) |>
DT::datatable()
ports
```



## Effort

```{r effort1, echo =F}
effort <- gf |>
dplyr::filter(Code %in% gfCodes) |>
dplyr::group_by(Year,newport) |>
dplyr::summarise(effort = sum(InsideDAS),
lbs = sum(InsideLANDED),
.groups = "drop") |>
dplyr::filter(newport %in% ports10)
# |>
# tidyr::pivot_longer(-c(Year,PORTLANDED),names_to = "type",values_to = "value")
ggplot2::ggplot(effort) +
ggplot2::geom_line(ggplot2::aes(x=Year,y=effort)) +
ggplot2::facet_wrap(~as.factor(newport)) +
ggplot2::ylab("Effort (Days)") +
ggplot2::ggtitle("Effort by port for top 10 productive ports")
```





0 comments on commit 27386b9

Please sign in to comment.