Skip to content

Commit

Permalink
Backup
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-rohan-NOAA committed Jan 8, 2024
1 parent 6c05232 commit 3e64274
Show file tree
Hide file tree
Showing 54 changed files with 902 additions and 165 deletions.
173 changes: 40 additions & 133 deletions 02_make_plots.R
Original file line number Diff line number Diff line change
@@ -1,142 +1,49 @@
library(ggplot2)
library(esrindex)

indicator_data = AI_INDICATOR
indicator_name = "misc_species"
bar_color = "#0085CA"
error_bars = TRUE


# AI
make_region_plot(indicator_data = AI_INDICATOR,
indicator_name = "misc_species",
bar_color = "#0085CA",
error_bars = TRUE)

make_region_plot(indicator_data = AI_INDICATOR,
indicator_name = "jellyfish",
bar_color = "#0085CA",
error_bars = TRUE)

make_region_plot(indicator_data = AI_INDICATOR,
indicator_name = "structural_epifauna",
bar_color = "#0085CA",
error_bars = TRUE)

make_subarea_plot(indicator_data = AI_INDICATOR,
indicator_name = "misc_species",
bar_color = "#0085CA",
error_bars = TRUE)

make_subarea_plot(indicator_data = AI_INDICATOR,
indicator_name = "jellyfish",
bar_color = "#0085CA",
error_bars = TRUE)

make_subarea_plot(indicator_data = AI_INDICATOR,
indicator_name = "structural_epifauna",
bar_color = "#0085CA",
error_bars = TRUE)
for(ii in 1:length(chapter_settings$AI)) {
make_region_plot(indicator_data = AI_INDICATOR,
indicator_name = names(chapter_settings$AI)[ii],
bar_color = "#0085CA",
error_bars = TRUE)
make_subarea_plot(indicator_data = AI_INDICATOR,
indicator_name = names(chapter_settings$AI)[ii],
bar_color = "#0085CA",
error_bars = TRUE)
}

# GOA
make_region_plot(indicator_data = GOA_INDICATOR,
indicator_name = "misc_species",
bar_color = "#0085CA",
error_bars = TRUE)

make_region_plot(indicator_data = GOA_INDICATOR,
indicator_name = "jellyfish",
bar_color = "#0085CA",
error_bars = TRUE)

make_region_plot(indicator_data = GOA_INDICATOR,
indicator_name = "structural_epifauna",
bar_color = "#0085CA",
error_bars = TRUE)

make_region_plot(indicator_data = GOA_INDICATOR,
indicator_name = "forage_fish",
bar_color = "#0085CA",
error_bars = TRUE)

make_subarea_plot(indicator_data = GOA_INDICATOR,
indicator_name = "misc_species",
bar_color = "#0085CA",
error_bars = TRUE)

make_subarea_plot(indicator_data = GOA_INDICATOR,
indicator_name = "jellyfish",
bar_color = "#0085CA",
error_bars = TRUE)

make_subarea_plot(indicator_data = GOA_INDICATOR,
indicator_name = "structural_epifauna",
bar_color = "#0085CA",
error_bars = TRUE)

make_subarea_plot(indicator_data = GOA_INDICATOR,
indicator_name = "forage_fish",
bar_color = "#0085CA",
error_bars = TRUE)
for(ii in 1:length(chapter_settings$GOA)) {
make_region_plot(indicator_data = GOA_INDICATOR,
indicator_name = names(chapter_settings$GOA)[ii],
bar_color = "#0085CA",
error_bars = TRUE)
make_subarea_plot(indicator_data = GOA_INDICATOR,
indicator_name = names(chapter_settings$GOA)[ii],
bar_color = "#0085CA",
error_bars = TRUE)
}

# EBS
make_region_plot(indicator_data = EBS_INDICATOR,
indicator_name = "misc_species",
bar_color = "#0085CA",
error_bars = TRUE)

make_region_plot(indicator_data = EBS_INDICATOR,
indicator_name = "jellyfish",
bar_color = "#0085CA",
error_bars = TRUE)

make_region_plot(indicator_data = EBS_INDICATOR,
indicator_name = "structural_epifauna",
bar_color = "#0085CA",
error_bars = TRUE)

make_subarea_plot(indicator_data = EBS_INDICATOR,
indicator_name = "misc_species",
bar_color = "#0085CA",
error_bars = TRUE)

make_subarea_plot(indicator_data = EBS_INDICATOR,
indicator_name = "jellyfish",
bar_color = "#0085CA",
error_bars = TRUE)

make_subarea_plot(indicator_data = EBS_INDICATOR,
indicator_name = "structural_epifauna",
bar_color = "#0085CA",
error_bars = TRUE)
for(ii in 1:length(chapter_settings$EBS)) {
make_region_plot(indicator_data = EBS_INDICATOR,
indicator_name = names(chapter_settings$EBS)[ii],
bar_color = "#0085CA",
error_bars = TRUE)
make_subarea_plot(indicator_data = EBS_INDICATOR,
indicator_name = names(chapter_settings$EBS)[ii],
bar_color = "#0085CA",
error_bars = TRUE)
}

# NBS
make_region_plot(indicator_data = NBS_INDICATOR,
indicator_name = "misc_species",
bar_color = "#0085CA",
error_bars = TRUE)

make_region_plot(indicator_data = NBS_INDICATOR,
indicator_name = "jellyfish",
bar_color = "#0085CA",
error_bars = TRUE)

make_region_plot(indicator_data = NBS_INDICATOR,
indicator_name = "structural_epifauna",
bar_color = "#0085CA",
error_bars = TRUE)

make_subarea_plot(indicator_data = NBS_INDICATOR,
indicator_name = "misc_species",
bar_color = "#0085CA",
error_bars = TRUE)

make_subarea_plot(indicator_data = NBS_INDICATOR,
indicator_name = "jellyfish",
bar_color = "#0085CA",
error_bars = TRUE)

make_subarea_plot(indicator_data = NBS_INDICATOR,
indicator_name = "structural_epifauna",
bar_color = "#0085CA",
error_bars = TRUE)
for(ii in 1:length(chapter_settings$NBS)) {
make_region_plot(indicator_data = NBS_INDICATOR,
indicator_name = names(chapter_settings$NBS)[ii],
bar_color = "#0085CA",
error_bars = TRUE)
# make_subarea_plot(indicator_data = NBS_INDICATOR,
# indicator_name = names(chapter_settings$NBS)[ii],
# bar_color = "#0085CA",
# error_bars = TRUE)
}
15 changes: 15 additions & 0 deletions 03_render_chapters.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Knit chapters
library(esrindex)

make_esr_chapter(xml_path = "./chapters/AI_jellyfish.xml")
make_esr_chapter(xml_path = "./chapters/AI_misc_species.xml")
make_esr_chapter(xml_path = "./chapters/AI_structural_epifauna.xml")

make_esr_chapter(xml_path = "./chapters/GOA_jellyfish.xml")
make_esr_chapter(xml_path = "./chapters/GOA_misc_species.xml")
make_esr_chapter(xml_path = "./chapters/GOA_structural_epifauna.xml")
make_esr_chapter(xml_path = "./chapters/GOA_forage_fish.xml")

make_esr_chapter(xml_path = "./chapters/EBS_jellyfish.xml")
make_esr_chapter(xml_path = "./chapters/EBS_misc_species.xml")
make_esr_chapter(xml_path = "./chapters/EBS_structural_epifauna.xml")
4 changes: 2 additions & 2 deletions R/extract_figures.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ extract_figures <- function(x) {
for(ii in 1:n_figs) {

num_range <- grep(x = x, pattern = "<figureNumber>")[ii]:grep(x = x, pattern = "</figureNumber>")[ii]
path_range <- grep(x = x, pattern = "<figureBasename>")[ii]:grep(x = x, pattern = "</figureBasename>")[ii]
path_range <- grep(x = x, pattern = "<figurePath>")[ii]:grep(x = x, pattern = "</figurePath>")[ii]
caption_range <- grep(x = x, pattern = "<figureCaption>")[ii]:grep(x = x, pattern = "</figureCaption>")[ii]

fig_list[[ii]] <- list(fig_number = extract_tag(x = x[num_range],
tag = "figureNumber"),
fig_path = extract_tag(x = x[path_range],
tag = "figureBasename"),
tag = "figurePath"),
caption = extract_tag(x = x[caption_range],
tag = "figureCaption"))
}
Expand Down
1 change: 1 addition & 0 deletions R/extract_tag.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extract_tag <- function(x, tag, remove_tabs = TRUE) {
x_sub <- x[min(tag_range):max(tag_range)]

x_sub <- gsub(x = x_sub, pattern = paste0("<", tag, ">"), replacement = "")

x_sub <- gsub(x = x_sub, pattern = paste0("</", tag, ">"), replacement = "")

x_sub <- x_sub[nchar(x_sub) > 0]
Expand Down
19 changes: 16 additions & 3 deletions R/make_esr_chapter.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#' Create ESR Chapter Document
#'
#' This function generates an R Markdown document for an ESR chapter using an ESR XML template file then renders as a docx.
#' This function generates an R Markdown document for an ESR chapter using an ESR XML template file then renders as a .docx.
#'
#' @param xml_path Path to the XML file containing ESR chapter information.
#' @param xml_path Path to the ESR template file containing ESR chapter information.
#' @param output_path Path to save the generated R Markdown document. If not specified, a default path will be used.
#' @return None
#' @examples
#' \dontrun{
#' make_esr_chapter(xml_path = "esr_template.xml")
#' make_esr_chapter(xml_path = "./chapters/AI_misc_species.xml")
#' }
#'
#' @import rmarkdown
Expand All @@ -28,6 +28,19 @@ make_esr_chapter <- function(xml_path, output_path = NULL) {

lines <- readLines(system.file("extdata/esr_index_template.Rmd", package = "esrindex"))

replace_lines <- function(x, pattern, replacement) {

ind <- grep(x = x, pattern = "\\[AUTHOR\\]")

leading <- x[1:(ind-1)]
trailing <- x[(ind+1):length(ind)]

output <- c(leading, replacement, trailing)

return(output)

}

lines <- gsub(pattern = "\\[AUTHOR\\]",
replacement = chapter_data$text_data$authors,
x = lines)
Expand Down
6 changes: 2 additions & 4 deletions R/read_esr_xml.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
#'
#' @param xml_path The path to the ESR XML template file.
#'
#' @return A list containing information extracted from various XML tags.
#' @return A list containing information extracted from XML tags.
#' @export

read_esr_xml <- function(xml_path) {

xml_path <- "AI_misc_species.xml"

stopifnot("read_esr_xml: File path (xml_path) not found." = file.exists(xml_path))
stopifnot("read_esr: File path (xml_path) not found." = file.exists(xml_path))

lines <- readLines(con = xml_path)

Expand Down
2 changes: 1 addition & 1 deletion R/themes.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Blue Strip Theme
#' Blue strip theme
#'
#' Custom theme for ggplot2 with a blue strip at the top and specific styling for axes, legend, and strip text.
#'
Expand Down
31 changes: 31 additions & 0 deletions chapters/AI_jellyfish.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: 'Jellyfish in the Aleutian Islands'
output: word_document
---

```{r setup, include=FALSE}
library(esrindex)
library(knitr)
```

Contributed by Ned Laman
Resource Assessment and Conservation Engineering Division, Alaska Fisheries Science Center, NOAA Fisheries

**Contact**: [email protected]

**Last updated**: October 2022

**Description of Indicator**: The RACE Groundfish Assessment Program (GAP) bottom trawl surveys in the Aleutian Islands (AI) are designed primarily to assess populations of commercially important fish and invertebrates. However, many other species are identified, weighed, and counted during the course of these surveys and these data may provide a measure of relative abundance for some of these species. Jellyfish are likely not sampled thoroughly and in a representative manner by our trawl gear due to their fragility and potential for catch in the mid-water during net deployment or retrieval. Therefore, jellyfish encountered in our trawl catches may or may not reflect their true abundance in the AI. The fishing gear used aboard the Japanese vessels that participated in all AI surveys prior to 1990 was very different from the gear used by all vessels since and likely influenced jellyfish catch rates on those surveys. Jellyfish catches in each year were scaled to the largest catch over the time series (which was arbitrarily scaled to a value of 100). The standard error (±1 SE) was weighted proportionally to the catch per unit effort (CPUE) to produce a relative SE. The percentage of catches with jellyfish present in the survey bottom trawl hauls was also calculated.

**Status and Trends**: Jellyfish mean CPUE is typically higher in the western and eastern AI than in other areas (Figure 27). The frequency of jellyfish occurrence in trawl catches is generally from 20–60% across all areas, but has been variable. The 2006 AI survey experienced peak biomasses in all survey areas, whereas the 1992 survey had high abundance in the western AI only. Jellyfish CPUE and frequency of occurrence increased in 2022 relative to 2018. Frequency of jellyfish occurrence in trawl catches in 2022 exceeds that of the next highest previous survey (2016), but mean CPUE in 2022 remains below the 2016 CPUE levels.

**Factors influencing observed trends**: Unknown

**Implications**: The 2022 increase in CPUE and frequency of occurrence of jellyfish is in contrast to the decline in occurrence and abundance between 2016 and 2018. Some of the warmest mean temperatures recorded on our AI surveys occurred in 2016 and 2018. While water temperatures were relatively cooler in 2022, the mean surface and bottom temperatures measured at the trawl net remained above the long term 20-year average. Temperatures are also indicative of water flow in the AI, where water movement is directly influenced by the Aleutian Passes so that it is difficult to attribute any one environmental factor to the patterns observed in jellyfish CPUE and occurrence.


```{r fig1, include = TRUE, echo = FALSE, fig.cap='\\label{fig:figs}Figure 1. Relative mean CPUE of jellyfish species by INPFC area from RACE Groundfish Assessment Program bottom trawl surveys in the Aleutian Islands from 1980 through 2022. Error bars represent relative standard errors. The gray lines represent the percentage of non-zero catches.'}
knitr::include_graphics('../plots/AI/AI_jellyfish_full_region.png')
```

## References
Binary file added chapters/AI_jellyfish.docx
Binary file not shown.
55 changes: 55 additions & 0 deletions chapters/AI_jellyfish.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<indicatorShortName>
jellyfish
</indicatorShortName>

<indicatorTitle>
Jellyfish in the Aleutian Islands
</indicatorTitle>

<indicatorRegion>
AI
</indicatorRegion>

<authors>
Ned Laman
</authors>

<contactEmail>
[email protected]
</contactEmail>

<authorAffiliations>
Resource Assessment and Conservation Engineering Division, Alaska Fisheries Science Center, NOAA Fisheries
</authorAffiliations>

<lastUpdate>
October 2022
</lastUpdate>

<indicatorDescription>
The RACE Groundfish Assessment Program (GAP) bottom trawl surveys in the Aleutian Islands (AI) are designed primarily to assess populations of commercially important fish and invertebrates. However, many other species are identified, weighed, and counted during the course of these surveys and these data may provide a measure of relative abundance for some of these species. Jellyfish are likely not sampled thoroughly and in a representative manner by our trawl gear due to their fragility and potential for catch in the mid-water during net deployment or retrieval. Therefore, jellyfish encountered in our trawl catches may or may not reflect their true abundance in the AI. The fishing gear used aboard the Japanese vessels that participated in all AI surveys prior to 1990 was very different from the gear used by all vessels since and likely influenced jellyfish catch rates on those surveys. Jellyfish catches in each year were scaled to the largest catch over the time series (which was arbitrarily scaled to a value of 100). The standard error (±1 SE) was weighted proportionally to the catch per unit effort (CPUE) to produce a relative SE. The percentage of catches with jellyfish present in the survey bottom trawl hauls was also calculated.
</indicatorDescription>

<methodologicalChanges>NA</methodologicalChanges>

<statusAndTrends>
Jellyfish mean CPUE is typically higher in the western and eastern AI than in other areas (Figure 27). The frequency of jellyfish occurrence in trawl catches is generally from 20–60% across all areas, but has been variable. The 2006 AI survey experienced peak biomasses in all survey areas, whereas the 1992 survey had high abundance in the western AI only. Jellyfish CPUE and frequency of occurrence increased in 2022 relative to 2018. Frequency of jellyfish occurrence in trawl catches in 2022 exceeds that of the next highest previous survey (2016), but mean CPUE in 2022 remains below the 2016 CPUE levels.
</statusAndTrends>

<factorsInfluencingTrends>
Unknown
</factorsInfluencingTrends>

<implications>
The 2022 increase in CPUE and frequency of occurrence of jellyfish is in contrast to the decline in occurrence and abundance between 2016 and 2018. Some of the warmest mean temperatures recorded on our AI surveys occurred in 2016 and 2018. While water temperatures were relatively cooler in 2022, the mean surface and bottom temperatures measured at the trawl net remained above the long term 20-year average. Temperatures are also indicative of water flow in the AI, where water movement is directly influenced by the Aleutian Passes so that it is difficult to attribute any one environmental factor to the patterns observed in jellyfish CPUE and occurrence.
</implications>

<researchPriorities>NA</researchPriorities>

<figures>
<fig>
<figureNumber>1</figureNumber>
<figurePath>AI_jellyfish_full_region.png</figurePath>
<figureCaption>Relative mean CPUE of jellyfish species by INPFC area from RACE Groundfish Assessment Program bottom trawl surveys in the Aleutian Islands from 1980 through 2022. Error bars represent relative standard errors. The gray lines represent the percentage of non-zero catches.</figureCaption>
</fig>
</figures>
6 changes: 1 addition & 5 deletions chapters/AI_misc_species.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ Resource Assessment and Conservation Engineering Division, Alaska Fisheries Scie
**Implications**: AI survey results provide limited information about abundance or abundance trends for these species due to problems in catchability. Therefore, the indices presented are likely of limited value to fisheries management. These species are not typically commercially important, but the trends in shrimp especially should be monitored as these are an important prey base for benthic commercial species.


```{r fig1, include = TRUE, echo = FALSE, fig.cap='\\label{fig:figs}Figure 1. AI miscellaneous species'}
```{r fig1, include = TRUE, echo = FALSE, fig.cap='\\label{fig:figs}Figure 1. Relative mean CPUE of miscellaneous species by area from RACE bottom trawl surveys in the Aleutian Islands from 1980 through 2016. Error bars represent standard errors. The gray lines represent the percentage of non-zero catches. The Western, Central, and Eastern Aleutians correspond to management areas 543, 542, and 541, respectively. The Southern Bering Sea corresponds to management areas 519 and 518.'}
knitr::include_graphics('../plots/AI/AI_misc_species_full_region.png')
```

```{r fig2, include = TRUE, echo = FALSE, fig.cap='\\label{fig:figs}Figure 2. AI Echinoderms'}
knitr::include_graphics('../plots/AI/AI_misc_species_Echinoderms_stratum.png')
```

## References
Binary file modified chapters/AI_misc_species.docx
Binary file not shown.
Loading

0 comments on commit 3e64274

Please sign in to comment.