Skip to content

Commit

Permalink
Merge pull request #100 from NOAA-EDAB/dev_branch
Browse files Browse the repository at this point in the history
pkgdown fix for ROracle
  • Loading branch information
andybeet authored Apr 15, 2024
2 parents 13d4fa1 + 89123c3 commit 10210a9
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 105 deletions.
84 changes: 61 additions & 23 deletions .github/workflows/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,86 @@ on:

jobs:
pkgdown:
runs-on: macOS-latest
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: '4.3.1'

- uses: r-lib/actions/setup-pandoc@v2
- name: install Oracle instant client
run: |
sudo apt update
sudo apt-get install -y alien libaio1 libaio-dev
wget https://download.oracle.com/otn_software/linux/instantclient/2112000/oracle-instantclient-basic-21.12.0.0.0-1.el8.x86_64.rpm
wget https://download.oracle.com/otn_software/linux/instantclient/2112000/oracle-instantclient-devel-21.12.0.0.0-1.el8.x86_64.rpm
wget https://download.oracle.com/otn_software/linux/instantclient/2112000/oracle-instantclient-odbc-21.12.0.0.0-1.el8.x86_64.rpm
wget https://download.oracle.com/otn_software/linux/instantclient/2112000/oracle-instantclient-sqlplus-21.12.0.0.0-1.el8.x86_64.rpm
sudo alien -i oracle-instantclient-basic-21.12.0.0.0-1.el8.x86_64.rpm
sudo alien -i oracle-instantclient-devel-21.12.0.0.0-1.el8.x86_64.rpm
sudo alien -i oracle-instantclient-odbc-21.12.0.0.0-1.el8.x86_64.rpm
sudo alien -i oracle-instantclient-sqlplus-21.12.0.0.0-1.el8.x86_64.rpm
echo "export ORACLE_HOME=/usr/lib/oracle/21/client64" | sudo tee -a /etc/profile.d/oracle.sh
echo "export TNS_ADMIN=/usr/lib/oracle/21/client64/lib/network/admin" | sudo tee -a /etc/profile.d/oracle.sh
echo "export LD_LIBRARY_PATH=/usr/lib/oracle/21/client64/lib:${LD_LIBRARY_PATH}" | sudo tee -a /etc/profile.d/oracle.sh
echo "export OCI_LIB=/usr/lib/oracle/21/client64/lib" | sudo tee -a /etc/profile.d/oracle.sh
echo "export OCI_INC=/usr/include/oracle/21/client64}" | sudo tee -a /etc/profile.d/oracle.sh
echo "export PHP_DTRACE=yes" | sudo tee -a /etc/profile.d/oracle.sh
echo "export EXTENSION_DIR=/usr/lib64/php/modules" | sudo tee -a /etc/profile.d/oracle.sh
echo "export PATH=\$ORACLE_HOME/bin:\$PATH" | sudo tee -a /etc/profile.d/oracle.sh sudo chmod +x /etc/profile.d/oracle.sh
source /etc/profile.d/oracle.sh
shell: bash

- name: Install system dependencies
run: |
sudo apt-get install libudunits2-dev libharfbuzz-dev libfribidi-dev libcurl4-openssl-dev libgdal-dev
# sudo apt-get install libgdal-dev libcurl4-gnutls-dev libgit2-dev
shell: bash

- name: Query dependencies
- name: Install R packages
run: |
install.packages('remotes')
install.packages("remotes")
install.packages("DBI")
install.packages("ROracle", type = "source", configure.args = "--with-oci-lib=/usr/lib/oracle/21/client64/lib --with-oci-inc=/usr/include/oracle/21/client64")
saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
shell: Rscript {0}

- name: Cache R packages
uses: actions/cache@v2
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-


- name: Install binary dependencies
if: runner.os != 'Linux'
- name: Install package dependencies
#if: runner.os |= 'Linux'
run: |
remotes::install_deps(dependencies = TRUE, type="binary")
remotes::install_deps(dependencies = TRUE)
shell: Rscript {0}

- name: Install pkgdown
run: |
install.packages("pkgdown", type = "binary")
install.packages("pkgdown")
shell: Rscript {0}

- name: Install package
run: R CMD INSTALL .

- name: Deploy package
run: |
git config --local user.email "actions@github.com"
git config --local user.name "GitHub Actions"
Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)'

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.4.1
with:
clean: false
branch: gh-pages
folder: docs
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Remotes:
NOAA-EDAB/survdat,
NOAA-EDAB/ecodata,
r4atlantis/atlantisom,
NEFSC/NEFSC-spatial
NEFSC/NEFSC-Spatial
VignetteBuilder: knitr
Suggests:
NEFSCspatial,
Expand Down Expand Up @@ -55,7 +55,6 @@ Suggests:
dplyr,
here,
data.table,
rgdal,
ggthemes,
FSA,
ecodata,
Expand Down
128 changes: 50 additions & 78 deletions vignettes/GBSurveySet.Rmd
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
---
title: "MS Keyrun - GB survey footprint"
author: "Sean Lucey"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
html_document:
code_fold: hide
bookdown::html_document2:
number_sections: false
link-citations: yes
pkgdown:
as_is: true
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
message = FALSE,
warning = FALSE)
library(data.table); library(here); library(rgdal); library(survdat); library(sf)
library(data.table); library(here); library(survdat); library(sf)
```

Expand All @@ -27,113 +28,84 @@ While work is ongoing towards segregating the fisheries dependent data, there is
### Option 1 - use survey design {#opt1}
The NEFSC bottom trawl survey uses a stratified random design. The rationale behind a stratified random design is to minimize variance. The figure below shows the full range of strata with the Georges Bank EPU overlaid in red. As you will notice, some of the survey strata extend beyond the EPU boundary. There are several ways that this can be accounted for. The simplest option is to include all strata that are partially within the EPU boundary.

```{r shapefile load}
coast <- readOGR(dsn=here::here("data-raw/gis"), layer='NES_LME_coast', verbose = F)
coast <- spTransform(coast, CRS('+init=epsg:4326'))

strata <- readOGR(dsn=here::here("data-raw/gis"), layer='strata', verbose = F)
strata <- spTransform(strata, CRS('+init=epsg:4326'))
```{r Survey_map, fig.cap="Survey strata overlaid with Georges Bank EPU", fig.align='center'}
# load in shape files and plot
coast <- sf::st_read(dsn=here::here("data-raw/gis"), layer='NES_LME_coast', quiet=T) |>
sf::st_transform(.,crs=4326)
epu <- readOGR(here::here("data-raw/gis"), 'EPU_extended', verbose = F)
epu <- spTransform(epu, CRS('+init=epsg:4326'))
strata <- sf::st_read(dsn=here::here("data-raw/gis"), layer='strata', quiet=T) |>
sf::st_transform(.,crs=4326)
epu <- sf::st_read(here::here("data-raw/gis"), 'EPU_extended', quiet=T) |>
sf::st_transform(.,crs=4326)
GB.strata <- sf::st_read(here::here("data-raw/gis"), 'EPU_strata', quiet=T) |>
sf::st_transform(.,crs=4326) |>
dplyr::mutate(Strata=as.factor(Strata))
GB.strata <- readOGR(here::here("data-raw/gis"), 'EPU_strata', verbose = F)
GB.strata <- spTransform(GB.strata, CRS('+init=epsg:4326'))
MAB <- c(1010:1080, 1100:1120, 1600:1750, 3010:3450, 3470, 3500, 3510)
GB <- c(1090, 1130:1210, 1230, 1250, 3460, 3480, 3490, 3520:3550)
GOM <- c(1220, 1240, 1260:1290, 1360:1400, 3560:3830)
SS <- c(1300:1352, 3840:3990)
```

```{r Survey_map}
opar <- par(mar = c(3, 3.5, 2, 2))
plot(0, 0, xlim = c(-77, -65), ylim = c(35, 45), xlab = '', ylab = '', axes = F,
typ = 'n')
box()
axis(1, at = c(-75, -70, -65), labels = c(expression('75'* degree * ' W'),
expression('70'* degree * ' W'),
expression('65'* degree * ' W')))
axis(2, at = c(35, 40, 45), labels = c(expression(35 * degree * ' N'),
expression(40 * degree * ' N'),
expression(45 * degree * ' N')), las = T)
plot(strata, add = T)
plot(epu[which(epu@data$EPU == 'GB'), ], add = T, border = 'red', lwd = 2)
epus <- data.frame(EPU = as.factor(c(rep("MAB",length(MAB)), rep("GB",length(GB)), rep("GOM",length(GOM)), rep("SS",length(SS)))),STRATA = c(MAB,GB,GOM,SS))
plot(coast, col = 'grey', add = T)
strata <- strata |>
dplyr::left_join(epus,by="STRATA") |>
dplyr::filter(!is.na(EPU))
legend('bottomright', legend = c('Survey Strata', 'Georges Bank EPU'),
col = c('black', 'red'), lty = 1, lwd = 3)
ggplot2::ggplot() +
ggplot2::geom_sf(data = coast,color = "Grey") +
ggplot2::geom_sf(data = strata, fill = "white")+
ggplot2::geom_sf(data = epu |> dplyr::filter(EPU == "GB"), color = "red", fill = "white", alpha = 0) +
ggplot2::coord_sf(xlim = c(-77,-65), ylim = c(35,45)) +
ggplot2::theme_classic()
```

Another option is to include only those strata that are at least 50% within the EPU boundary by area. This was the preferred method of the Northeast IEA program for their State of the Ecosystem report. The map below shows the strata that were included. The medium blue color represents Georges Bank.

```{r SOE}
opar <- par(mar = c(3, 3.5, 2, 2))
plot(0, 0, xlim = c(-77, -65), ylim = c(35, 45), xlab = '', ylab = '', axes = F,
typ = 'n')
box()
axis(1, at = c(-75, -70, -65), labels = c(expression('75'* degree * ' W'),
expression('70'* degree * ' W'),
expression('65'* degree * ' W')))

axis(2, at = c(35, 40, 45), labels = c(expression(35 * degree * ' N'),
expression(40 * degree * ' N'),
expression(45 * degree * ' N')), las = T)
```{r SOE, fig.cap="Survey strata by EPU",fig.align='center'}
plot(strata[which(strata@data$STRATA %in% MAB), ], add = T, col = '#0093D0')
plot(strata[which(strata@data$STRATA %in% GB), ], add = T, col = '#0055A4')
plot(strata[which(strata@data$STRATA %in% GOM), ], add = T, col = '#00467F')
plot(strata[which(strata@data$STRATA %in% SS), ], add = T, col = '#007078')
plot(epu[which(epu@data$EPU == 'GB'), ], add = T, border = '#D65f00', lwd = 2)
ggplot2::ggplot() +
ggplot2::geom_sf(data = coast,color = "Grey") +
ggplot2::geom_sf(data = strata, ggplot2::aes(fill = EPU),color = "Black")+
ggplot2::geom_sf(data = epu |> dplyr::filter(EPU == "GB"), color = "red", fill = "white", alpha = 0) +
ggplot2::coord_sf(xlim = c(-77,-65), ylim = c(35,45)) +
ggplot2::theme_classic() +
ggplot2::scale_fill_manual(values=c('#0093D0', '#0055A4','#00467F','#007078'))
plot(coast, col = 'grey', add = T)
```

legend('bottomright', legend = c('Scotian Shelf', 'Gulf of Maine', 'Georges Bank',
'Mid-Atlantic', 'EPU'),
fill = c('#007078', '#00467F', '#0055A4', '#0093D0', NA),
border = c(rep('black', 4), NA),
col = c(rep(0, 4), '#D65f00'), lty = c(rep(NA, 4), 1), lwd = 3,
x.intersp = c(rep(-0.5, 4), 1))


```

The difference between these two options would be the inclusion of strata 01100, 01110, and 01120 in the southwest corner of the EPU.

### Option 2 - ignore survey design
Ignoring the survey design leaves us with two options: a straight mean of the EPU or a post-stratified design. The first option creates large variances which make it difficult to conduct any kind of statistical testing. Other previous work by EDAB stratified Georges Bank into large strata based on whether the area was considered open access or withing a closed area, inside or outside of US waters, and the shelf break.

```{r GB}
opar <- par(mar = c(3, 3.5, 2, 2))
plot(0, 0, xlim = c(-72, -65), ylim = c(38, 43), xlab = '', ylab = '', axes = F,
typ = 'n')
box()
axis(1, at = c(-75, -70, -65), labels = c(expression('75'* degree * ' W'),
expression('70'* degree * ' W'),
expression('65'* degree * ' W')))
axis(2, at = c(35, 40, 45), labels = c(expression(35 * degree * ' N'),
expression(40 * degree * ' N'),
expression(45 * degree * ' N')), las = T)


plot(GB.strata, add = T, border = '#D65f00', lwd = 2)
```{r GB,fig.cap="Gearoges Bank EPU defined by survey strata",fig.align='center'}
plot(coast, col = 'grey', add = T)
ggplot2::ggplot() +
ggplot2::geom_sf(data = coast,color = "Grey") +
ggplot2::geom_sf(data = GB.strata, ggplot2::aes(fill = Strata),color = "Black") +
ggplot2::scale_fill_brewer(palette = "Blues") +
ggplot2::coord_sf(xlim = c(-72,-65), ylim = c(38,43)) +
ggplot2::theme_classic()
```


## Testing the options
To see if there was an noticeable difference between the three options outlined above (All - Any strata that is at least partially within the GB EPU boundary, SOE - strata set used by the State of the Ecosystem report, and EPU - post-stratified EPU) biomass indices were calculated for the top 11 species that will be included in the MS Keyrun project.

```{r test, results="hide"}
library(data.table); library(here); library(rgdal)#; library(Survdat);
library(ggplot2); library(survdat)

```{r test, results="hide"}
#source(here('Survdat.r'))
#load(here('data-raw/data/Survdat.RData'))
Expand Down Expand Up @@ -197,10 +169,10 @@ epu.mean[, subset := 'EPU']
#Combine data
combo.data <- rbindlist(list(all.mean, soe.mean, epu.mean))
survey.plot <- ggplot(combo.data,
aes(x = YEAR, y = strat.biomass)) +
geom_point(aes(color = subset)) +
facet_wrap(~SVSPP, ncol = 2, nrow = 6, scales = 'free_y')
survey.plot <- ggplot2::ggplot(combo.data,
ggplot2::aes(x = YEAR, y = strat.biomass)) +
ggplot2::geom_point(ggplot2::aes(color = subset)) +
ggplot2::facet_wrap(~SVSPP, ncol = 2, nrow = 6, scales = 'free_y')
plot(survey.plot)
Expand Down
4 changes: 2 additions & 2 deletions vignettes/allocateLandingsEPU.Rmd
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
title: "Allocate landings to Georges Bank EPU"
author: Andy Beet
date: "`r format(Sys.time(), '%d %B, %Y')`"
output:
bookdown::html_document2:
number_sections: false
csl: apa-annotated-bibliography.csl
bibliography: references.bib
link-citations: yes
pkgdown:
as_is: true
---

```{r setup, include=FALSE}
Expand Down

0 comments on commit 10210a9

Please sign in to comment.