diff --git a/..Rcheck/00check.log b/..Rcheck/00check.log new file mode 100644 index 00000000..aec3c1a5 --- /dev/null +++ b/..Rcheck/00check.log @@ -0,0 +1,13 @@ +* using log directory ‘/home/rklasky/R/packages/Rpath/..Rcheck’ +* using R version 4.3.1 (2023-06-16) +* using platform: x86_64-pc-linux-gnu (64-bit) +* R was compiled by + gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 + GNU Fortran (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 +* running under: Linux Mint 20 +* using session charset: UTF-8 +* checking for file ‘./DESCRIPTION’ ... ERROR +Required fields missing or empty: + ‘Author’ ‘Maintainer’ +* DONE +Status: 1 ERROR diff --git a/.Rbuildignore b/.Rbuildignore index d416705d..7e1d6e4c 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,8 +1,10 @@ - -^.*\.Rproj$ -^\.Rproj\.user$ -^\.github$ -^_pkgdown\.yml$ -^docs$ -^pkgdown$ -^data-raw$ + +^.*\.Rproj$ +^\.Rproj\.user$ +^\.github$ +^_pkgdown\.yml$ +^docs$ +^pkgdown$ +^data-raw$ +^doc$ +^Meta$ diff --git a/.Renviron b/.Renviron new file mode 100644 index 00000000..357e3a04 --- /dev/null +++ b/.Renviron @@ -0,0 +1 @@ +_R_CHECK_DONTTEST_EXAMPLES_=FALSE diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 05282628..12449b10 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,8 +1,8 @@ -# Workflow derived from https://github.com/r-lib/actions/tree/master/examples +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: [main, master] + branches: [main, master, UnitTests] pull_request: branches: [main, master] @@ -18,7 +18,7 @@ jobs: fail-fast: false matrix: config: - - {os: macOS-latest, r: 'release'} + - {os: macos-latest, r: 'release'} - {os: windows-latest, r: 'release'} - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} - {os: ubuntu-latest, r: 'release'} @@ -29,30 +29,21 @@ jobs: R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: r-lib/actions/setup-pandoc@v1 + - uses: r-lib/actions/setup-pandoc@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} http-user-agent: ${{ matrix.config.http-user-agent }} use-public-rspm: true - - uses: r-lib/actions/setup-r-dependencies@v1 + - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: rcmdcheck - - - uses: r-lib/actions/check-r-package@v1 - - - name: Show testthat output - if: always() - run: find check -name 'testthat.Rout*' -exec cat '{}' \; || true - shell: bash + extra-packages: any::rcmdcheck + needs: check - - name: Upload check results - if: failure() - uses: actions/upload-artifact@main + - uses: r-lib/actions/check-r-package@v2 with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check + upload-snapshots: true diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index 2623cee6..187ab501 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -12,7 +12,7 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-r@master diff --git a/.github/workflows/secretScan.yml b/.github/workflows/secretScan.yml index 51301a68..e55a4aba 100644 --- a/.github/workflows/secretScan.yml +++ b/.github/workflows/secretScan.yml @@ -8,6 +8,6 @@ jobs: steps: - uses: actions/checkout@v2 with: - fetch-depth: '0' + fetch-depth: '2' - name: gitleaks-action - uses: zricethezav/gitleaks-action@master + uses: gitleaks/gitleaks-action@v1.6.0 \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..b78d0619 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,94 @@ + +on: + push: + paths: + - '.github/workflows/tests.yml' + - 'R/*' + - 'tests/testthat/*' + - 'README.md' + - 'DESCRIPTION' + pull_request: + paths: + - '.github/workflows/tests.yml' + - 'R/*' + - 'tests/testthat/*' + +name: Unit-Tests + +jobs: + # build: + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v2 + # - uses: r-lib/actions/setup-r@v2 + # - uses: r-lib/actions/setup-pandoc@v2 + # - name: Install dependencies + # run: Rscript -e "install.packages(c('testthat', 'tidyverse', 'here'))" + # - name: Run tests + # run: Rscript -e "source('tests/testthat.R')" + + Unit-Tests: + runs-on: ${{matrix.config.os}} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + #os: [macos-latest, ubuntu-latest, windows-latest] + #os: [ubuntu-latest] + config: + - {os: macos-latest, r: 'release'} + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} +# R_REMOTES_NO_ERRORS_FROM_WARNINGS: false + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v4 +# with: +# fetch-depth: 0 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true +# r-version: '4.3.1' + + - uses: r-lib/actions/setup-r-dependencies@v2 + + - name: Install command line packages + if: runner.os == 'Linux' + run: | + sudo apt update + sudo apt-get install libcurl4-openssl-dev libgit2-dev + + - name: Install dependencies + #run: Rscript -e "install.packages(c('remotes','testthat', 'tidyverse', 'here'))" + run: | + install.packages(c('usethis','remotes','testthat','tidyverse','here','rmarkdown','qpdf','distillery','ggpubr','rlist')) + remotes::install_github("NOAA-EDAB/Rpath") + shell: Rscript {0} + + - name: Run tests + #run: Rscript -e "source('tests/testthat.R')" + run: | + source(here::here("data-raw/REcosystem.R")) + source(here::here("tests/testthat.R")) + shell: Rscript {0} + + # - name: commit data files + # run: | + # git config user.name github-actions + # git config user.email github-actions@github.com + # file.copy('here::here("tests/testthat/Rplots.pdf")",to=here::here("inst/extdata/Rplots.pdf")) + # git add inst/extdata/Rplots.pdf + # git commit -m "automated commit from testthat yml" + # git push diff --git a/.gitignore b/.gitignore index 3b6055a1..e1695a29 100644 --- a/.gitignore +++ b/.gitignore @@ -1,17 +1,28 @@ .Rproj.user .Rhistory .RData -*.png +.Renviron *.jpg *.tif +*.tar +*.so outputs code *.xlsx *.docx +*.pdf Ecopath_dev Rpath.Rcheck* src/*.o src/*.dll -NAMESPACE +tests/testthat/data/output/* +tests/testthat/data/bkup/* +tests/testthat/data/input/REcosystem_Current_*.dat +tests/testthat/data/input/REcosystem_Current_*.csv +tests/testthat/old/* +tests/testthat/bkup/* +tests/testthat/old dat files/* docs -Rpath.Rproj +doc +Meta +Rpath.Rproj \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 5f26165c..84d7820c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,34 +1,48 @@ -Package: Rpath -Type: Package -Title: R implementation of Ecopath with Ecosim -Version: 0.0.1.2 -Date: 2016-07-15 -Authors@R: c( - person("Kerim", "Aydin", email = "Kerim.Aydin@NOAA.gov", role = "aut"), - person("Sean", "Lucey", email = "Sean.Lucey@NOAA.gov", - role = c("aut", "cre")), - person("Sarah", "Gaichas", email = "Sarah.Gaichas@NOAA.gov", role = "aut")) -Description: This package implements the core mass balance equations made popular - by Ecopath with Ecosim. There are two parts to the package, the static snapshot - of energy flow through the system using rpath and dynamic simulations run using - the rsim family of functions. -License: file LICENSE -Encoding: UTF-8 -Imports: - data.table, - graphics, - grDevices, - MASS, - Rcpp (>= 0.11.3), - stats, - utils -LinkingTo: Rcpp -Suggests: - knitr, - rmarkdown -VignetteBuilder: knitr -RoxygenNote: 7.1.1 -URL: https://github.com/NOAA-EDAB/Rpath -BugReports: https://github.com/NOAA-EDAB/Rpath/issues -Depends: - R (>= 2.10) +Package: Rpath +Type: Package +Title: R implementation of Ecopath with Ecosim +Version: 0.0.1.2 +Date: 2016-07-15 +Authors@R: c( + person("Kerim", "Aydin", email = "Kerim.Aydin@NOAA.gov", role = "aut"), + person("Sean", "Lucey", email = "Sean.Lucey@NOAA.gov", + role = c("aut", "cre")), + person("Sarah", "Gaichas", email = "Sarah.Gaichas@NOAA.gov", role = "aut")) +Description: This package implements the core mass balance equations made popular + by Ecopath with Ecosim. There are two parts to the package, the static snapshot + of energy flow through the system using rpath and dynamic simulations run using + the rsim family of functions. +License: file LICENSE +Encoding: UTF-8 +Imports: + data.table, + methods, + graphics, + grDevices, + MASS, + Rcpp (>= 0.11.3), + stats, + utils +LinkingTo: Rcpp +Suggests: + here, + knitr, + rmarkdown, + distillery, + ggplot2, + ggpubr, + rlist, + stringr, + qpdf, + usethis, + dplyr, + generics, + testthat (>= 3.0.0) +VignetteBuilder: knitr +RoxygenNote: 7.2.3 +URL: https://github.com/NOAA-EDAB/Rpath +BugReports: https://github.com/NOAA-EDAB/Rpath/issues +Depends: + R (>= 2.10) +Config/testthat/edition: 3 +LazyData: true diff --git a/NAMESPACE b/NAMESPACE index 37e75875..74469e54 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -53,4 +53,5 @@ import(stats) import(utils) importFrom(Rcpp,sourceCpp) importFrom(grDevices,rainbow) +importFrom(methods,is) useDynLib(Rpath) diff --git a/R/RcppExports.R b/R/RcppExports.R index f738567e..77fa2f96 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -1,23 +1,23 @@ -# Generated by using Rcpp::compileAttributes() -> do not edit by hand -# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 - -rk4_run <- function(params, instate, forcing, fishing, stanzas, StartYear, EndYear) { - .Call('_Rpath_rk4_run', PACKAGE = 'Rpath', params, instate, forcing, fishing, stanzas, StartYear, EndYear) -} - -Adams_run <- function(params, instate, forcing, fishing, stanzas, StartYear, EndYear, InitDeriv) { - .Call('_Rpath_Adams_run', PACKAGE = 'Rpath', params, instate, forcing, fishing, stanzas, StartYear, EndYear, InitDeriv) -} - -deriv_vector <- function(params, state, forcing, fishing, stanzas, inyear, m, tt) { - .Call('_Rpath_deriv_vector', PACKAGE = 'Rpath', params, state, forcing, fishing, stanzas, inyear, m, tt) -} - -SplitSetPred <- function(stanzas, state) { - .Call('_Rpath_SplitSetPred', PACKAGE = 'Rpath', stanzas, state) -} - -SplitUpdate <- function(stanzas, state, forcing, deriv, yr, mon) { - .Call('_Rpath_SplitUpdate', PACKAGE = 'Rpath', stanzas, state, forcing, deriv, yr, mon) -} - +# Generated by using Rcpp::compileAttributes() -> do not edit by hand +# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 + +rk4_run <- function(params, instate, forcing, fishing, stanzas, StartYear, EndYear) { + .Call('_Rpath_rk4_run', PACKAGE = 'Rpath', params, instate, forcing, fishing, stanzas, StartYear, EndYear) +} + +Adams_run <- function(params, instate, forcing, fishing, stanzas, StartYear, EndYear, InitDeriv) { + .Call('_Rpath_Adams_run', PACKAGE = 'Rpath', params, instate, forcing, fishing, stanzas, StartYear, EndYear, InitDeriv) +} + +deriv_vector <- function(params, state, forcing, fishing, stanzas, inyear, m, tt) { + .Call('_Rpath_deriv_vector', PACKAGE = 'Rpath', params, state, forcing, fishing, stanzas, inyear, m, tt) +} + +SplitSetPred <- function(stanzas, state) { + .Call('_Rpath_SplitSetPred', PACKAGE = 'Rpath', stanzas, state) +} + +SplitUpdate <- function(stanzas, state, forcing, deriv, yr, mon) { + .Call('_Rpath_SplitUpdate', PACKAGE = 'Rpath', stanzas, state, forcing, deriv, yr, mon) +} + diff --git a/R/Rpath_support.R b/R/Rpath_support.R index f9664c38..db6faf06 100644 --- a/R/Rpath_support.R +++ b/R/Rpath_support.R @@ -1,12 +1,18 @@ +library(methods) + ######################################################################################## # Set of functions for returning functional group names (character vector) # using the type input column # # Internal supporting function for group names to check type -grouptype <- function(Rpath){ - if(class(Rpath)=="Rpath"){gt<-list(type=Rpath$type, grp=Rpath$Group)} - else{ - if(class(Rpath)=="Rpath.params"){ +#' +#' @importFrom methods is +#' +grouptype <- function(Rpath) { + if (is(Rpath,"Rpath")) { + gt<-list(type=Rpath$type, grp=Rpath$Group) + } else { + if (is(Rpath,"Rpath.params")) { gt<-list(type=Rpath$model$Type, grp=Rpath$model$Group)} else{ stop("Input must be an Rpath (balanced) or Rpath.params (unbalanced) object.") diff --git a/R/data.R b/R/data.R index 59ccb377..2ed34e3c 100644 --- a/R/data.R +++ b/R/data.R @@ -1,3 +1,33 @@ + + +#' AB.params +#' +#' A tutorial ecosystem for teaching Rpath +#' +#' @format An Rpath balanced model object that contains: +#' \describe{ +#' \item{model}{A data.table containing Ecopath unbalanced ecosystem parameters (base parameters and fisheries).} +#' \item{diet}{A data.table containing the Ecopath model's diet matrix.} +#' \item{stanzas}{Parameters for multistanza groups.} +#' \item{pedigree}{A data.table containing the data quality (pedigree) for the Ecopath model.} +#' ... +#' } +"AB.params" + +#' REco.params +#' +#' A sample ecosystem for Rpath - Anchovy Bay. +#' +#' @format An Rpath balanced model object that contains: +#' \describe{ +#' \item{model}{A data.table containing Ecopath unbalanced ecosystem parameters (base parameters and fisheries).} +#' \item{diet}{A data.table containing the Ecopath model's diet matrix.} +#' \item{stanzas}{Parameters for multistanza groups.} +#' \item{pedigree}{A data.table containing the data quality (pedigree) for the Ecopath model.} +#' ... +#' } +"REco.params" + #' Eastern Bering Sea 1990s Ecopath model (53 biological groups and 1 fleet). #' #' Rpath inputs (unbalanaced model). diff --git a/R/ecopath.R b/R/ecopath.R index d7165ef6..6bbe99e2 100644 --- a/R/ecopath.R +++ b/R/ecopath.R @@ -15,7 +15,7 @@ #'@return Returns an Rpath object that can be supplied to the rsim.scenario function. #'@import data.table #'@export -rpath <- function(Rpath.params, eco.name = NA, eco.area = 1){ +rpath <- function(Rpath.params, eco.name = NA, eco.area = 1) { #Need to define variables to eliminate check() note about no visible binding Type <- Group <- DetInput <- ProdCons <- PB <- QB <- noB <- noEE <- alive <- NULL BEE <- Biomass <- Q <- BioAcc <- BioQB <- diag.a <- EEa <- B <- M0 <- NULL @@ -340,11 +340,9 @@ rpath.stanzas <- function(Rpath.params){ lastmonth <- rep(NA,Nsplit) for(isp in 1:Nsplit){ #Put the stanzas in order for each split species - stnum <- order(stanzafile[StGroupNum == isp, First]) - + stnum <- order(stanzafile[StGroupNum == isp, First]) stanzafile[StGroupNum == isp, StanzaNum := stnum] - #Calculate the last month for the final ("leading") stanza #KYA Aug 2021: # Formerly used fraction of Winf, but that didn't work for species diff --git a/R/ecosim.R b/R/ecosim.R index d3d07611..f50b226c 100755 --- a/R/ecosim.R +++ b/R/ecosim.R @@ -57,6 +57,15 @@ rsim.scenario <- function(Rpath, Rpath.params, years = 1:100){ return(rsim) } +# +# Test function +# +rsim.check <- function(Rsim.scenario) { + scene <- copy(Rsim.scenario) + scene.years <- list(1900:2000) + return (scene.years) +} + #'Run Rsim #' #'Carries out the numerical integration of the Rsim alogrithms. @@ -73,35 +82,40 @@ rsim.scenario <- function(Rpath, Rpath.params, years = 1:100){ #' #'@export #' -rsim.run <- function(Rsim.scenario, method = 'RK4', years = 1:100){ +rsim.run <- function(Rsim.scenario, method = 'RK4', years = 1:100) { + scene <- copy(Rsim.scenario) - # Figure out starting and ending years for run - # KYA 4/23/18 single year (e.g. 1971:1971) reduces to a scalar so take out length trap - #if (length(years)<2){stop("Years should be a vector of year labels")} + # Perform argument checks: Check method name and figure out starting and ending years for run + if (method != 'RK4' && method != 'AB') { + stop("Invalid method name for solving nonlinear equations") + } + + # KYA 4/23/18 single year (e.g. 1971:1971) reduces to a scalar so take out length trap + #if (length(years) < 2) {stop("Years should be a vector of year labels")} scene.years <- row.names(Rsim.scenario$fishing$ForcedFRate) - syear <- which(as.character(head(years,1))==scene.years) - eyear <- which(as.character(tail(years,1))==scene.years) - if (eyear - Rpath ===== -![gitleaks](https://github.com/NOAA-EDAB/LeMANS/workflows/gitleaks/badge.svg) + +[![gitleaks](https://github.com/NOAA-EDAB/Rpath/actions/workflows/secretScan.yml/badge.svg)](https://github.com/NOAA-EDAB/Rpath/actions/workflows/secretScan.yml) +[![pkgdown](https://github.com/NOAA-EDAB/Rpath/actions/workflows/pkgdown.yaml/badge.svg)](https://github.com/NOAA-EDAB/Rpath/actions/workflows/pkgdown.yaml) +[![R-CMD-check](https://github.com/NOAA-EDAB/Rpath/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/NOAA-EDAB/Rpath/actions/workflows/R-CMD-check.yaml) +[![tests](https://github.com/NOAA-EDAB/Rpath/actions/workflows/tests.yml/badge.svg)](https://github.com/NOAA-EDAB/Rpath/actions/workflows/R-CMD-check.yaml) + + This is the repository for Rpath - the R implementation of the mass balance algorithms. diff --git a/Rpath.Rproj b/Rpath.Rproj index fec809a6..eaa6b818 100644 --- a/Rpath.Rproj +++ b/Rpath.Rproj @@ -1,18 +1,18 @@ -Version: 1.0 - -RestoreWorkspace: Default -SaveWorkspace: Default -AlwaysSaveHistory: Default - -EnableCodeIndexing: Yes -UseSpacesForTab: Yes -NumSpacesForTab: 2 -Encoding: UTF-8 - -RnwWeave: Sweave -LaTeX: pdfLaTeX - -BuildType: Package -PackageUseDevtools: Yes -PackageInstallArgs: --no-multiarch --with-keep.source -PackageRoxygenize: rd,collate,namespace +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 2 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX + +BuildType: Package +PackageUseDevtools: Yes +PackageInstallArgs: --no-multiarch --with-keep.source +PackageRoxygenize: rd,collate,namespace diff --git a/data-raw/REcosystem.R b/data-raw/REcosystem.R new file mode 100644 index 00000000..f1f011f0 --- /dev/null +++ b/data-raw/REcosystem.R @@ -0,0 +1,142 @@ +#R Ecosystem +#Tutorial ecosystem for teaching Rpath + +#' +#' Script that creates REco.params example model file +#' +#' @param REco.params Rpath parameters +#' + +library(Rpath); library(data.table); library(here); library(qpdf) + +#Groups and types for the R Ecosystem---- + +groups <- c('Seabirds', 'Whales', 'Seals', 'JuvRoundfish1', 'AduRoundfish1', + 'JuvRoundfish2', 'AduRoundfish2', 'JuvFlatfish1', 'AduFlatfish1', + 'JuvFlatfish2', 'AduFlatfish2', 'OtherGroundfish', 'Foragefish1', + 'Foragefish2', 'OtherForagefish', 'Megabenthos', 'Shellfish', + 'Macrobenthos', 'Zooplankton', 'Phytoplankton', 'Detritus', + 'Discards', 'Trawlers', 'Midwater', 'Dredgers') +stgroups <- c(rep(NA, 3), rep('Roundfish1', 2), rep('Roundfish2', 2), + rep('Flatfish1', 2), rep('Flatfish2', 2), rep(NA, 14)) + +types <- c(rep(0, 19), 1, rep(2, 2), rep(3, 3)) + +#Model---- +#Create Model File +REco.params <- create.rpath.params(group = groups, type = types, stgroup = stgroups) + +biomass <- c(0.0149, 0.454, NA, NA, 1.39, NA, 5.553, NA, 5.766, NA, + 0.739, 7.4, 5.1, 4.7, 5.1, NA, 7, 17.4, 23, 10, rep(NA, 5)) + +pb <- c(0.098, 0.031, 0.100, 2.026, 0.42, 2.1, 0.425, 1.5, 0.26, 1.1, 0.18, 0.6, + 0.61, 0.65, 1.5, 0.9, 1.3, 7, 39, 240, rep(NA, 5)) + +qb <- c(76.750, 6.976, 34.455, NA, 2.19, NA, 3.78, NA, 1.44, NA, 1.69, + 1.764, 3.52, 5.65, 3.6, 2.984, rep (NA, 9)) + +REco.params$model[, Biomass := biomass] +REco.params$model[, PB := pb] +REco.params$model[, QB := qb] + +#EE for groups w/o biomass +REco.params$model[Group %in% c('Seals', 'Megabenthos'), EE := 0.8] + +#Production to Consumption for those groups without a QB +REco.params$model[Group %in% c('Shellfish', 'Zooplankton'), ProdCons:= 0.25] +REco.params$model[Group == 'Macrobenthos', ProdCons := 0.35] + +#Biomass accumulation and unassimilated production +REco.params$model[, BioAcc := c(rep(0, 22), rep(NA, 3))] +REco.params$model[, Unassim := c(rep(0.2, 18), 0.4, rep(0, 3), rep(NA, 3))] + +#Detrital Fate +REco.params$model[, Detritus := c(rep(1, 20), rep(0, 5))] +REco.params$model[, Discards := c(rep(0, 22), rep(1, 3))] + +#Fisheries +#Landings +trawl <- c(rep(0, 4), 0.08, 0, 0.32, 0, 0.09, 0, 0.05, 0.2, rep(0, 10), rep(NA, 3)) +mid <- c(rep(0, 12), 0.3, 0.08, 0.02, rep(0, 7), rep(NA, 3)) +dredge <- c(rep(0, 15), 0.1, 0.5, rep(0, 5), rep(NA, 3)) +REco.params$model[, Trawlers := trawl] +REco.params$model[, Midwater := mid] +REco.params$model[, Dredgers := dredge] + +#Discards +trawl.d <- c(1e-5, 1e-7, 0.001, 0.001, 0.005, 0.001, 0.009, 0.001, 0.04, 0.001, + 0.01, 0.08, 0.001, 0.001, 0.001, rep(0, 7), rep(NA, 3)) +mid.d <- c(rep(0, 2), 0.001, 0.001, 0.01, 0.001, 0.01, rep(0, 4), 0.05, 0.05, + 0.01, 0.01, rep(0, 7), rep(NA, 3)) +dredge.d <- c(rep(0, 3), 0.001, 0.05, 0.001, 0.05, 0.001, 0.05, 0.001, 0.01, 0.05, + rep(0, 3), 0.09, 0.01, 1e-4, rep(0, 4), rep(NA, 3)) +REco.params$model[, Trawlers.disc := trawl.d] +REco.params$model[, Midwater.disc := mid.d] +REco.params$model[, Dredgers.disc := dredge.d] + +#Stanzas---- +#Calculate the multistanza biomass/consumption +#Group parameters +REco.params$stanzas$stgroups[, VBGF_Ksp := c(0.145, 0.295, 0.0761, 0.112)] +#REco.params$stanzas$stgroups[, Wmat := c(0.0769, 0.561, 0.117, 0.321)] +REco.params$stanzas$stgroups[, Wmat := c(0.0577, 0.421, 0.088, 0.241)] + + +#Individual stanza parameters +REco.params$stanzas$stindiv[, First := c(rep(c(0, 24), 3), 0, 48)] +REco.params$stanzas$stindiv[, Last := c(rep(c(23, 400), 3), 47, 400)] +REco.params$stanzas$stindiv[, Z := c(2.026, 0.42, 2.1, 0.425, 1.5, + 0.26, 1.1, 0.18)] +REco.params$stanzas$stindiv[, Leading := rep(c(F, T), 4)] + +REco.params <- rpath.stanzas(REco.params) + +#Diet File---- +REco.params$diet[, Seabirds := c(rep(NA, 11), 0.1, 0.25, 0.2, 0.15, + rep(NA, 6), 0.3, NA)] +REco.params$diet[, Whales := c(rep(NA, 3), 0.01, NA, 0.01, NA, 0.01, + NA, 0.01, rep(NA, 4), 0.1, rep(NA, 3), + 0.86, rep(NA, 4))] +REco.params$diet[, Seals := c(rep(NA, 3), 0.05, 0.1, 0.05, 0.2, 0.005, + 0.05, 0.005, 0.01, 0.24, rep(0.05, 4), + 0.09, rep(NA, 6))] +REco.params$diet[, JuvRoundfish1 := c(rep(NA, 3), rep(c(1e-4, NA), 4), 1e-3, + rep(NA, 2), 0.05, 1e-4, NA, .02, 0.7785, + 0.1, 0.05, NA, NA)] +REco.params$diet[, AduRoundfish1 := c(rep(NA, 5), 1e-3, 0.01, 1e-3, 0.05, 1e-3, + 0.01, 0.29, 0.1, 0.1, 0.347, 0.03, NA, + 0.05, 0.01, rep(NA, 4))] +REco.params$diet[, JuvRoundfish2 := c(rep(NA, 3), rep(c(1e-4, NA), 4), 1e-3, + rep(NA, 2), 0.05, 1e-4, NA, .02, 0.7785, + 0.1, .05, NA, NA)] +REco.params$diet[, AduRoundfish2 := c(rep(NA, 3), 1e-4, NA, 1e-4, NA, rep(1e-4, 4), + 0.1, rep(0.05, 3), 0.2684, 0.01, 0.37, 0.001, + NA, 0.1, NA, NA)] +REco.params$diet[, JuvFlatfish1 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 3), + rep(1e-4, 2), NA, 0.416, 0.4334, 0.1, 0.05, + NA, NA)] +REco.params$diet[, AduFlatfish1 := c(rep(NA, 7), rep(1e-4, 5), rep(NA, 2), 0.001, + 0.05, 0.001, 0.6, 0.2475, NA, 0.1, NA, NA)] +REco.params$diet[, JuvFlatfish2 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 3), + rep(1e-4, 2), NA, 0.416, 0.4334, 0.1, 0.05, + NA, NA)] +REco.params$diet[, AduFlatfish2 := c(rep(NA, 7), 1e-4, NA, 1e-4, rep(NA, 4), + rep(1e-4, 3), 0.44, 0.3895, NA, 0.17, + NA, NA)] +REco.params$diet[, OtherGroundfish := c(rep(NA, 3), rep(1e-4, 8), 0.05, 0.08, 0.0992, + 0.3, 0.15, 0.01, 0.3, 0.01, rep(NA, 4))] +REco.params$diet[, Foragefish1 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 7), + 0.8196, 0.06, 0.12, NA, NA)] +REco.params$diet[, Foragefish2 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 7), + 0.8196, 0.06, 0.12, NA, NA)] +REco.params$diet[, OtherForagefish := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 7), + 0.8196, 0.06, 0.12, NA, NA)] +REco.params$diet[, Megabenthos := c(rep(NA, 15), 0.1, 0.03, 0.55, rep(NA, 2), 0.32, + NA, NA)] +REco.params$diet[, Shellfish := c(rep(NA, 18), 0.3, 0.5, 0.2, NA, NA)] +REco.params$diet[, Macrobenthos := c(rep(NA, 16), 0.01, rep(0.2, 2), NA, 0.59, + NA, NA)] +REco.params$diet[, Zooplankton := c(rep(NA, 18), 0.2, 0.6, 0.2, NA, NA)] + +#usethis::use_data(REco.params, overwrite = T) + diff --git a/data/AB.params.rda b/data/AB.params.rda new file mode 100644 index 00000000..a7f85fa9 Binary files /dev/null and b/data/AB.params.rda differ diff --git a/data/REco.params.rda b/data/REco.params.rda new file mode 100644 index 00000000..074a4bef Binary files /dev/null and b/data/REco.params.rda differ diff --git a/man/AB.params.Rd b/man/AB.params.Rd new file mode 100644 index 00000000..6342ccbb --- /dev/null +++ b/man/AB.params.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{AB.params} +\alias{AB.params} +\title{AB.params} +\format{ +An Rpath balanced model object that contains: +\describe{ + \item{model}{A data.table containing Ecopath unbalanced ecosystem parameters (base parameters and fisheries).} + \item{diet}{A data.table containing the Ecopath model's diet matrix.} + \item{stanzas}{Parameters for multistanza groups.} + \item{pedigree}{A data.table containing the data quality (pedigree) for the Ecopath model.} + ... +} +} +\usage{ +AB.params +} +\description{ +A tutorial ecosystem for teaching Rpath +} +\keyword{datasets} diff --git a/man/REco.params.Rd b/man/REco.params.Rd new file mode 100644 index 00000000..a1e3a20c --- /dev/null +++ b/man/REco.params.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{REco.params} +\alias{REco.params} +\title{REco.params} +\format{ +An Rpath balanced model object that contains: +\describe{ + \item{model}{A data.table containing Ecopath unbalanced ecosystem parameters (base parameters and fisheries).} + \item{diet}{A data.table containing the Ecopath model's diet matrix.} + \item{stanzas}{Parameters for multistanza groups.} + \item{pedigree}{A data.table containing the data quality (pedigree) for the Ecopath model.} + ... +} +} +\usage{ +REco.params +} +\description{ +A sample ecosystem for Rpath - Anchovy Bay. +} +\keyword{datasets} diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index c6f2024b..088cad9d 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -1,107 +1,107 @@ -// Generated by using Rcpp::compileAttributes() -> do not edit by hand -// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 - -#include - -using namespace Rcpp; - -#ifdef RCPP_USE_GLOBAL_ROSTREAM -Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); -Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); -#endif - -// rk4_run -List rk4_run(List params, List instate, List forcing, List fishing, List stanzas, int StartYear, int EndYear); -RcppExport SEXP _Rpath_rk4_run(SEXP paramsSEXP, SEXP instateSEXP, SEXP forcingSEXP, SEXP fishingSEXP, SEXP stanzasSEXP, SEXP StartYearSEXP, SEXP EndYearSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< List >::type params(paramsSEXP); - Rcpp::traits::input_parameter< List >::type instate(instateSEXP); - Rcpp::traits::input_parameter< List >::type forcing(forcingSEXP); - Rcpp::traits::input_parameter< List >::type fishing(fishingSEXP); - Rcpp::traits::input_parameter< List >::type stanzas(stanzasSEXP); - Rcpp::traits::input_parameter< int >::type StartYear(StartYearSEXP); - Rcpp::traits::input_parameter< int >::type EndYear(EndYearSEXP); - rcpp_result_gen = Rcpp::wrap(rk4_run(params, instate, forcing, fishing, stanzas, StartYear, EndYear)); - return rcpp_result_gen; -END_RCPP -} -// Adams_run -List Adams_run(List params, List instate, List forcing, List fishing, List stanzas, int StartYear, int EndYear, List InitDeriv); -RcppExport SEXP _Rpath_Adams_run(SEXP paramsSEXP, SEXP instateSEXP, SEXP forcingSEXP, SEXP fishingSEXP, SEXP stanzasSEXP, SEXP StartYearSEXP, SEXP EndYearSEXP, SEXP InitDerivSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< List >::type params(paramsSEXP); - Rcpp::traits::input_parameter< List >::type instate(instateSEXP); - Rcpp::traits::input_parameter< List >::type forcing(forcingSEXP); - Rcpp::traits::input_parameter< List >::type fishing(fishingSEXP); - Rcpp::traits::input_parameter< List >::type stanzas(stanzasSEXP); - Rcpp::traits::input_parameter< int >::type StartYear(StartYearSEXP); - Rcpp::traits::input_parameter< int >::type EndYear(EndYearSEXP); - Rcpp::traits::input_parameter< List >::type InitDeriv(InitDerivSEXP); - rcpp_result_gen = Rcpp::wrap(Adams_run(params, instate, forcing, fishing, stanzas, StartYear, EndYear, InitDeriv)); - return rcpp_result_gen; -END_RCPP -} -// deriv_vector -List deriv_vector(List params, List state, List forcing, List fishing, List stanzas, int inyear, int m, double tt); -RcppExport SEXP _Rpath_deriv_vector(SEXP paramsSEXP, SEXP stateSEXP, SEXP forcingSEXP, SEXP fishingSEXP, SEXP stanzasSEXP, SEXP inyearSEXP, SEXP mSEXP, SEXP ttSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< List >::type params(paramsSEXP); - Rcpp::traits::input_parameter< List >::type state(stateSEXP); - Rcpp::traits::input_parameter< List >::type forcing(forcingSEXP); - Rcpp::traits::input_parameter< List >::type fishing(fishingSEXP); - Rcpp::traits::input_parameter< List >::type stanzas(stanzasSEXP); - Rcpp::traits::input_parameter< int >::type inyear(inyearSEXP); - Rcpp::traits::input_parameter< int >::type m(mSEXP); - Rcpp::traits::input_parameter< double >::type tt(ttSEXP); - rcpp_result_gen = Rcpp::wrap(deriv_vector(params, state, forcing, fishing, stanzas, inyear, m, tt)); - return rcpp_result_gen; -END_RCPP -} -// SplitSetPred -int SplitSetPred(List stanzas, List state); -RcppExport SEXP _Rpath_SplitSetPred(SEXP stanzasSEXP, SEXP stateSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< List >::type stanzas(stanzasSEXP); - Rcpp::traits::input_parameter< List >::type state(stateSEXP); - rcpp_result_gen = Rcpp::wrap(SplitSetPred(stanzas, state)); - return rcpp_result_gen; -END_RCPP -} -// SplitUpdate -int SplitUpdate(List stanzas, List state, List forcing, List deriv, int yr, int mon); -RcppExport SEXP _Rpath_SplitUpdate(SEXP stanzasSEXP, SEXP stateSEXP, SEXP forcingSEXP, SEXP derivSEXP, SEXP yrSEXP, SEXP monSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< List >::type stanzas(stanzasSEXP); - Rcpp::traits::input_parameter< List >::type state(stateSEXP); - Rcpp::traits::input_parameter< List >::type forcing(forcingSEXP); - Rcpp::traits::input_parameter< List >::type deriv(derivSEXP); - Rcpp::traits::input_parameter< int >::type yr(yrSEXP); - Rcpp::traits::input_parameter< int >::type mon(monSEXP); - rcpp_result_gen = Rcpp::wrap(SplitUpdate(stanzas, state, forcing, deriv, yr, mon)); - return rcpp_result_gen; -END_RCPP -} - -static const R_CallMethodDef CallEntries[] = { - {"_Rpath_rk4_run", (DL_FUNC) &_Rpath_rk4_run, 7}, - {"_Rpath_Adams_run", (DL_FUNC) &_Rpath_Adams_run, 8}, - {"_Rpath_deriv_vector", (DL_FUNC) &_Rpath_deriv_vector, 8}, - {"_Rpath_SplitSetPred", (DL_FUNC) &_Rpath_SplitSetPred, 2}, - {"_Rpath_SplitUpdate", (DL_FUNC) &_Rpath_SplitUpdate, 6}, - {NULL, NULL, 0} -}; - -RcppExport void R_init_Rpath(DllInfo *dll) { - R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); - R_useDynamicSymbols(dll, FALSE); -} +// Generated by using Rcpp::compileAttributes() -> do not edit by hand +// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 + +#include + +using namespace Rcpp; + +#ifdef RCPP_USE_GLOBAL_ROSTREAM +Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); +Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); +#endif + +// rk4_run +List rk4_run(List params, List instate, List forcing, List fishing, List stanzas, int StartYear, int EndYear); +RcppExport SEXP _Rpath_rk4_run(SEXP paramsSEXP, SEXP instateSEXP, SEXP forcingSEXP, SEXP fishingSEXP, SEXP stanzasSEXP, SEXP StartYearSEXP, SEXP EndYearSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< List >::type params(paramsSEXP); + Rcpp::traits::input_parameter< List >::type instate(instateSEXP); + Rcpp::traits::input_parameter< List >::type forcing(forcingSEXP); + Rcpp::traits::input_parameter< List >::type fishing(fishingSEXP); + Rcpp::traits::input_parameter< List >::type stanzas(stanzasSEXP); + Rcpp::traits::input_parameter< int >::type StartYear(StartYearSEXP); + Rcpp::traits::input_parameter< int >::type EndYear(EndYearSEXP); + rcpp_result_gen = Rcpp::wrap(rk4_run(params, instate, forcing, fishing, stanzas, StartYear, EndYear)); + return rcpp_result_gen; +END_RCPP +} +// Adams_run +List Adams_run(List params, List instate, List forcing, List fishing, List stanzas, int StartYear, int EndYear, List InitDeriv); +RcppExport SEXP _Rpath_Adams_run(SEXP paramsSEXP, SEXP instateSEXP, SEXP forcingSEXP, SEXP fishingSEXP, SEXP stanzasSEXP, SEXP StartYearSEXP, SEXP EndYearSEXP, SEXP InitDerivSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< List >::type params(paramsSEXP); + Rcpp::traits::input_parameter< List >::type instate(instateSEXP); + Rcpp::traits::input_parameter< List >::type forcing(forcingSEXP); + Rcpp::traits::input_parameter< List >::type fishing(fishingSEXP); + Rcpp::traits::input_parameter< List >::type stanzas(stanzasSEXP); + Rcpp::traits::input_parameter< int >::type StartYear(StartYearSEXP); + Rcpp::traits::input_parameter< int >::type EndYear(EndYearSEXP); + Rcpp::traits::input_parameter< List >::type InitDeriv(InitDerivSEXP); + rcpp_result_gen = Rcpp::wrap(Adams_run(params, instate, forcing, fishing, stanzas, StartYear, EndYear, InitDeriv)); + return rcpp_result_gen; +END_RCPP +} +// deriv_vector +List deriv_vector(List params, List state, List forcing, List fishing, List stanzas, int inyear, int m, double tt); +RcppExport SEXP _Rpath_deriv_vector(SEXP paramsSEXP, SEXP stateSEXP, SEXP forcingSEXP, SEXP fishingSEXP, SEXP stanzasSEXP, SEXP inyearSEXP, SEXP mSEXP, SEXP ttSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< List >::type params(paramsSEXP); + Rcpp::traits::input_parameter< List >::type state(stateSEXP); + Rcpp::traits::input_parameter< List >::type forcing(forcingSEXP); + Rcpp::traits::input_parameter< List >::type fishing(fishingSEXP); + Rcpp::traits::input_parameter< List >::type stanzas(stanzasSEXP); + Rcpp::traits::input_parameter< int >::type inyear(inyearSEXP); + Rcpp::traits::input_parameter< int >::type m(mSEXP); + Rcpp::traits::input_parameter< double >::type tt(ttSEXP); + rcpp_result_gen = Rcpp::wrap(deriv_vector(params, state, forcing, fishing, stanzas, inyear, m, tt)); + return rcpp_result_gen; +END_RCPP +} +// SplitSetPred +int SplitSetPred(List stanzas, List state); +RcppExport SEXP _Rpath_SplitSetPred(SEXP stanzasSEXP, SEXP stateSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< List >::type stanzas(stanzasSEXP); + Rcpp::traits::input_parameter< List >::type state(stateSEXP); + rcpp_result_gen = Rcpp::wrap(SplitSetPred(stanzas, state)); + return rcpp_result_gen; +END_RCPP +} +// SplitUpdate +int SplitUpdate(List stanzas, List state, List forcing, List deriv, int yr, int mon); +RcppExport SEXP _Rpath_SplitUpdate(SEXP stanzasSEXP, SEXP stateSEXP, SEXP forcingSEXP, SEXP derivSEXP, SEXP yrSEXP, SEXP monSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< List >::type stanzas(stanzasSEXP); + Rcpp::traits::input_parameter< List >::type state(stateSEXP); + Rcpp::traits::input_parameter< List >::type forcing(forcingSEXP); + Rcpp::traits::input_parameter< List >::type deriv(derivSEXP); + Rcpp::traits::input_parameter< int >::type yr(yrSEXP); + Rcpp::traits::input_parameter< int >::type mon(monSEXP); + rcpp_result_gen = Rcpp::wrap(SplitUpdate(stanzas, state, forcing, deriv, yr, mon)); + return rcpp_result_gen; +END_RCPP +} + +static const R_CallMethodDef CallEntries[] = { + {"_Rpath_rk4_run", (DL_FUNC) &_Rpath_rk4_run, 7}, + {"_Rpath_Adams_run", (DL_FUNC) &_Rpath_Adams_run, 8}, + {"_Rpath_deriv_vector", (DL_FUNC) &_Rpath_deriv_vector, 8}, + {"_Rpath_SplitSetPred", (DL_FUNC) &_Rpath_SplitSetPred, 2}, + {"_Rpath_SplitUpdate", (DL_FUNC) &_Rpath_SplitUpdate, 6}, + {NULL, NULL, 0} +}; + +RcppExport void R_init_Rpath(DllInfo *dll) { + R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); + R_useDynamicSymbols(dll, FALSE); +} diff --git a/src/ecosim.cpp b/src/ecosim.cpp index d4fc87c3..fc05c419 100644 --- a/src/ecosim.cpp +++ b/src/ecosim.cpp @@ -60,6 +60,9 @@ List rk4_run (List params, List instate, List forcing, List fishing, List stanza // Accumulator for monthly catch values NumericVector cum_Catch(NUM_BIO+1); NumericVector cum_Gear_Catch(NumFishingLinks +1); + + // RSK - added for force by biomass + NumericMatrix force_bybio = as(forcing["ForcedBio"]); //SML // Update sums of split groups to total biomass for derivative calcs @@ -150,6 +153,10 @@ List rk4_run (List params, List instate, List forcing, List fishing, List stanza // Make a copy of the current state for bounds testing NumericVector cur_Biomass = as(state["Biomass"]); + // RSK added forced biomass logic + NumericVector bforce = force_bybio((y-1) * STEPS_PER_YEAR + m, _); + cur_Biomass = ifelse(bforce>B_BaseRef * EPSILON, bforce, cur_Biomass); + // KYA 8/9/17 one of the NA or NaN flags is reading back as a negative integer (-2^32) // Not sure why. This sets any negative biomass (assuming this means NaN) to NA_REAL cur_Biomass = ifelse((cur_Biomass<0),NA_REAL,cur_Biomass); @@ -613,7 +620,7 @@ int sp, links, prey, pred, gr, egr, dest, isp, ist, ieco; ActiveRespLoss = FoodGain * ActiveRespFrac * force_byactresp(dd,_); MzeroLoss = MzeroMort * state_Biomass; - + // Add mortality forcing for (int i=1; i<=NUM_DEAD+NUM_LIVING; i++){ FoodLoss[i] *= force_bymort(dd, i); @@ -701,6 +708,7 @@ int sp, links, prey, pred, gr, egr, dest, isp, ist, ieco; NumericVector FORCE_F = (NumericVector)FORCED_FRATE(y,_); // Special "CLEAN" fisheries assuming q=1, so specified input is Frate for (sp=1; sp<=NUM_LIVING+NUM_DEAD; sp++){ + caught = FORCED_CATCH(y, sp) + FORCE_F[sp] * state_Biomass[sp]; // KYA Aug 2011 removed terminal effort option to allow negative fishing pressure // if (caught <= -EPSILON) {caught = TerminalF[sp] * state_Biomass[sp];} @@ -744,6 +752,18 @@ int sp, links, prey, pred, gr, egr, dest, isp, ist, ieco; for (sp=NUM_LIVING+1; sp<=NUM_LIVING+NUM_DEAD; sp++){ MzeroLoss[sp] = 0.0; } + +// Add mortality forcing + for (int i=1; i<=NUM_DEAD+NUM_LIVING; i++){ + FoodLoss[i] *= force_bymort(dd, i); + MzeroLoss[i] *= force_bymort(dd, i); + } + +// Add migration forcing + MigrateLoss = clone(state_Biomass); + for (int i=1; i<=NUM_DEAD+NUM_LIVING; i++){ + MigrateLoss[i] *= force_bymigrate(dd, i); + } // Sum up derivitive parts (vector sums) diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 00000000..d68b6799 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + +library(testthat) +library(Rpath) + +test_check("Rpath") diff --git a/tests/testthat/data/input/.gitignore b/tests/testthat/data/input/.gitignore new file mode 100644 index 00000000..670fc0a2 --- /dev/null +++ b/tests/testthat/data/input/.gitignore @@ -0,0 +1,67 @@ +REcosystem_Current_AB_ForcedBio_OutBiomass_Stepped.rds +REcosystem_Current_AB_ForcedBio_OutCatch_Jitter.rds +REcosystem_Current_AB_ForcedBio_OutCatch_Stepped.rds +REcosystem_Current_AB_ForcedBio_OutGearCatch_Jitter.rds +REcosystem_Current_AB_ForcedBio_OutGearCatch_Stepped.rds +REcosystem_Current_AB_ForcedCat_OutBiomass_Jitter.rds +REcosystem_Current_AB_ForcedCat_OutBiomass_Stepped.rds +REcosystem_Current_AB_ForcedCat_OutCatch_Jitter.rds +REcosystem_Current_AB_ForcedCat_OutCatch_Stepped.rds +REcosystem_Current_AB_ForcedCat_OutGearCatch_Jitter.rds +REcosystem_Current_AB_ForcedCat_OutGearCatch_Stepped.rds +REcosystem_Current_AB_ForcedEff_OutBiomass_Jitter.rds +REcosystem_Current_AB_ForcedEff_OutBiomass_Stepped.rds +REcosystem_Current_AB_ForcedEff_OutCatch_Jitter.rds +REcosystem_Current_AB_ForcedEff_OutCatch_Stepped.rds +REcosystem_Current_AB_ForcedEff_OutGearCatch_Jitter.rds +REcosystem_Current_AB_ForcedEff_OutGearCatch_Stepped.rds +REcosystem_Current_AB_ForcedFRa_OutBiomass_Jitter.rds +REcosystem_Current_AB_ForcedFRa_OutBiomass_Stepped.rds +REcosystem_Current_RK4_ForcedCat_OutGearCatch_Stepped.rds +REcosystem_Current_RK4_ForcedEff_OutBiomass_Jitter.rds +REcosystem_Current_RK4_ForcedEff_OutBiomass_Stepped.rds +REcosystem_Current_RK4_ForcedEff_OutCatch_Jitter.rds +REcosystem_Current_RK4_ForcedEff_OutCatch_Stepped.rds +REcosystem_Current_RK4_ForcedEff_OutGearCatch_Jitter.rds +REcosystem_Current_RK4_ForcedEff_OutGearCatch_Stepped.rds +REcosystem_Current_RK4_ForcedFRa_OutBiomass_Jitter.rds +REcosystem_Current_RK4_ForcedFRa_OutBiomass_Stepped.rds +REcosystem_Current_RK4_ForcedFRa_OutCatch_Jitter.rds +REcosystem_Current_RK4_ForcedFRa_OutCatch_Stepped.rds +REcosystem_Current_RK4_ForcedFRa_OutGearCatch_Jitter.rds +REcosystem_Current_RK4_ForcedFRa_OutGearCatch_Stepped.rds +REcosystem_Current_RK4_ForcedMig_OutBiomass_Jitter.rds +REcosystem_Current_RK4_ForcedMig_OutBiomass_Stepped.rds +REcosystem_Current_RK4_ForcedMig_OutCatch_Jitter.rds +REcosystem_Current_RK4_ForcedMig_OutCatch_Stepped.rds +REcosystem_Current_RK4_ForcedMig_OutGearCatch_Jitter.rds +REcosystem_Current_RK4_ForcedMig_OutGearCatch_Stepped.rds +REcosystem_Current_RK4_OutBiomass.rds +REcosystem_Current_RK4_OutCatch.rds +REcosystem_Current_RK4_OutGearCatch.rds +REcosystem_Current_RpathObj_Summary.rds +REcosystem_Current_RpathObj_TopLevel.rds +REcosystem_Current_AB_ForcedFRa_OutCatch_Jitter.rds +REcosystem_Current_AB_ForcedFRa_OutCatch_Stepped.rds +REcosystem_Current_AB_ForcedFRa_OutGearCatch_Jitter.rds +REcosystem_Current_AB_ForcedFRa_OutGearCatch_Stepped.rds +REcosystem_Current_AB_ForcedMig_OutBiomass_Jitter.rds +REcosystem_Current_AB_ForcedMig_OutBiomass_Stepped.rds +REcosystem_Current_AB_ForcedMig_OutCatch_Jitter.rds +REcosystem_Current_AB_ForcedMig_OutCatch_Stepped.rds +REcosystem_Current_AB_ForcedMig_OutGearCatch_Jitter.rds +REcosystem_Current_AB_ForcedMig_OutGearCatch_Stepped.rds +REcosystem_Current_AB_OutBiomass.rds +REcosystem_Current_AB_OutCatch.rds +REcosystem_Current_AB_OutGearCatch.rds +REcosystem_Current_RK4_ForcedBio_OutBiomass_Jitter.rds +REcosystem_Current_RK4_ForcedBio_OutBiomass_Stepped.rds +REcosystem_Current_RK4_ForcedBio_OutCatch_Jitter.rds +REcosystem_Current_RK4_ForcedBio_OutCatch_Stepped.rds +REcosystem_Current_RK4_ForcedBio_OutGearCatch_Jitter.rds +REcosystem_Current_RK4_ForcedBio_OutGearCatch_Stepped.rds +REcosystem_Current_RK4_ForcedCat_OutBiomass_Jitter.rds +REcosystem_Current_RK4_ForcedCat_OutBiomass_Stepped.rds +REcosystem_Current_RK4_ForcedCat_OutCatch_Jitter.rds +REcosystem_Current_RK4_ForcedCat_OutCatch_Stepped.rds +REcosystem_Current_RK4_ForcedCat_OutGearCatch_Jitter.rds diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB.csv b/tests/testthat/data/input/REcosystem_Baseline_AB.csv new file mode 100644 index 00000000..ed50474a --- /dev/null +++ b/tests/testthat/data/input/REcosystem_Baseline_AB.csv @@ -0,0 +1,27 @@ +"","Group","StartBio","EndBio","BioES","StartCatch","EndCatch","CatchES" +"Outside","Outside",1,1,1,0,0,NA +"Seabirds","Seabirds",0.0149,0.0149000421028321,1.00000282569343,1e-05,1.00000282111217e-05,1.00000282111217 +"Whales","Whales",0.454,0.454000210323487,1.00000046326759,1e-07,1.00000046237396e-07,1.00000046237396 +"Seals","Seals",0.0249999999999718,0.0250002188221431,1.00000875288685,0.00200000000413891,0.00200001748905324,1.00000874245715 +"JuvRoundfish1","JuvRoundfish1",0.130430485118969,0.130433508003209,1.00002317620944,0.00300000000000001,0.00300006953210303,1.00002317736767 +"AduRoundfish1","AduRoundfish1",1.39,1.39005295588287,1.00003809775746,0.145000203632079,0.145005524262104,1.00003669394864 +"JuvRoundfish2","JuvRoundfish2",1.23260830921837,1.23259936869508,0.999992746663136,0.003,0.00299997823997374,0.999992746657912 +"AduRoundfish2","AduRoundfish2",5.553,5.55298124848838,0.999996623174568,0.389000250489473,0.388998687520254,0.999995982086857 +"JuvFlatfish1","JuvFlatfish1",0.0698844163992366,0.0698869780915876,1.00003665613141,0.002,0.00200007328635013,1.00003664317507 +"AduFlatfish1","AduFlatfish1",5.766,5.76631154105126,1.00005403070608,0.180000208050261,0.180009721333862,1.00005285151447 +"JuvFlatfish2","JuvFlatfish2",0.0962887696620608,0.0962884894227788,0.99999708959536,0.002,0.00199999420098711,0.999997100493556 +"AduFlatfish2","AduFlatfish2",0.739,0.739000130647141,1.00000017678909,0.0700000310249589,0.0700000137421647,0.99999975310305 +"OtherGroundfish","OtherGroundfish",7.4,7.39994608057505,0.999992713591223,0.379999997272581,0.379997231062138,0.999992720498784 +"Foragefish1","Foragefish1",5.1,5.09999811993401,0.999999631359611,0.350999998399263,0.350999870540216,0.999999635729209 +"Foragefish2","Foragefish2",4.7,4.70000128223243,1.00000027281541,0.0909999995496743,0.0910000247985853,1.00000027746056 +"OtherForagefish","OtherForagefish",5.1,5.09999705474722,0.999999422499456,0.0309999997462498,0.0309999820895145,0.99999943042789 +"Megabenthos","Megabenthos",19.7653839645524,19.7653695454297,0.999999270486083,0.189999999090599,0.189999861429518,0.999999275467992 +"Shellfish","Shellfish",7,7.00000501432483,1.00000071633212,0.509999999758437,0.51000036523584,1.00000071662236 +"Macrobenthos","Macrobenthos",17.4,17.3999776424532,0.99999871508352,9.99999987659067e-05,9.99998715476867e-05,0.999998727817784 +"Zooplankton","Zooplankton",23,23.000000629589,1.00000002737344,0,0,NA +"Phytoplankton","Phytoplankton",10,9.99999972809651,0.999999972809651,0,0,NA +"Detritus","Detritus",3636.66711075279,3636.66738830137,1.00000007631949,0,0,NA +"Discards","Discards",1.2182202,1.21823092208955,1.00000880143799,0,0,NA +"Trawlers","Trawlers",0,0,NA,0,0,NA +"Midwater","Midwater",0,0,NA,0,0,NA +"Dredgers","Dredgers",0,0,NA,0,0,NA diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutBiomass_Jitter.rds new file mode 100644 index 00000000..8999098d Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutBiomass_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutBiomass_Stepped.rds new file mode 100644 index 00000000..211cc88d Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutBiomass_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutCatch_Jitter.rds new file mode 100644 index 00000000..57e5ed3b Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutCatch_Stepped.rds new file mode 100644 index 00000000..e008fb27 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Jitter.rds new file mode 100644 index 00000000..f0cd8d05 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Stepped.rds new file mode 100644 index 00000000..71738513 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutBiomass_Jitter.rds new file mode 100644 index 00000000..b15b55dc Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutBiomass_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutBiomass_Stepped.rds new file mode 100644 index 00000000..d28610fc Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutBiomass_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutCatch_Jitter.rds new file mode 100644 index 00000000..422cd46e Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutCatch_Stepped.rds new file mode 100644 index 00000000..6d89e348 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Jitter.rds new file mode 100644 index 00000000..68cc255e Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Stepped.rds new file mode 100644 index 00000000..5be9a692 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutBiomass_Jitter.rds new file mode 100644 index 00000000..460554ac Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutBiomass_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutBiomass_Stepped.rds new file mode 100644 index 00000000..4b7030eb Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutBiomass_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutCatch_Jitter.rds new file mode 100644 index 00000000..219bf727 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutCatch_Stepped.rds new file mode 100644 index 00000000..0995a636 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Jitter.rds new file mode 100644 index 00000000..648ef61c Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Stepped.rds new file mode 100644 index 00000000..87276752 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Jitter.rds new file mode 100644 index 00000000..a657db4c Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Stepped.rds new file mode 100644 index 00000000..31f0552b Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutCatch_Jitter.rds new file mode 100644 index 00000000..d6dc3d51 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutCatch_Stepped.rds new file mode 100644 index 00000000..f7d00f95 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Jitter.rds new file mode 100644 index 00000000..f22c25b0 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Stepped.rds new file mode 100644 index 00000000..ee8bb12c Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutBiomass_Jitter.rds new file mode 100644 index 00000000..df61dbee Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutBiomass_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutBiomass_Stepped.rds new file mode 100644 index 00000000..c6032566 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutBiomass_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutCatch_Jitter.rds new file mode 100644 index 00000000..2335b759 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutCatch_Stepped.rds new file mode 100644 index 00000000..b9ca3add Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Jitter.rds new file mode 100644 index 00000000..a6da54d3 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Stepped.rds new file mode 100644 index 00000000..0eb081e4 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_OutBiomass.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_OutBiomass.rds new file mode 100644 index 00000000..31f0552b Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_OutBiomass.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_OutCatch.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_OutCatch.rds new file mode 100644 index 00000000..f7d00f95 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_OutCatch.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_AB_OutGearCatch.rds b/tests/testthat/data/input/REcosystem_Baseline_AB_OutGearCatch.rds new file mode 100644 index 00000000..ee8bb12c Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_AB_OutGearCatch.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4.csv b/tests/testthat/data/input/REcosystem_Baseline_RK4.csv new file mode 100644 index 00000000..ae297adf --- /dev/null +++ b/tests/testthat/data/input/REcosystem_Baseline_RK4.csv @@ -0,0 +1,27 @@ +"","Group","StartBio","EndBio","BioES","StartCatch","EndCatch","CatchES" +"Outside","Outside",1,1,1,0,0,NA +"Seabirds","Seabirds",0.0149,0.0149000414705202,1.00000278325639,9.99999999999475e-06,1.00000277870872e-05,1.00000277870925 +"Whales","Whales",0.454,0.454000203549876,1.00000044834774,9.99999999999199e-08,1.00000044748892e-07,1.00000044748972 +"Seals","Seals",0.0249999999999718,0.0250002151253163,1.00000860501378,0.00200000000272358,0.00200001719370259,1.00000859548949 +"JuvRoundfish1","JuvRoundfish1",0.130430485118969,0.130433509907448,1.00002319080909,0.00299999999941579,0.00300006722470278,1.000022408429 +"AduRoundfish1","AduRoundfish1",1.39,1.3900529699139,1.00003810785173,0.145000201253226,0.145005476873034,1.00003638353438 +"JuvRoundfish2","JuvRoundfish2",1.23260830921836,1.23259937159164,0.999992749013086,0.00299999999971644,0.00299997893978356,0.99999298002237 +"AduRoundfish2","AduRoundfish2",5.553,5.55298128970033,0.999996630596134,0.389000247694946,0.388998687736761,0.999995989827272 +"JuvFlatfish1","JuvFlatfish1",0.0698844163992366,0.0698869785491005,1.00003666267812,0.00199999999751022,0.00200007140577223,1.00003570413105 +"AduFlatfish1","AduFlatfish1",5.766,5.76631158759197,1.00005403877766,0.180000206280042,0.180009663891873,1.00005254222774 +"JuvFlatfish2","JuvFlatfish2",0.0962887696620608,0.0962884904713711,0.999997100485439,0.00199999999817096,0.00199999422811603,0.999997114972532 +"AduFlatfish2","AduFlatfish2",0.739000000000001,0.739000142115137,1.00000019230736,0.0700000308235379,0.0700000121018634,0.999999732547625 +"OtherGroundfish","OtherGroundfish",7.4,7.39994606118236,0.999992710970589,0.37999999816591,0.379997230076909,0.999992715555226 +"Foragefish1","Foragefish1",5.1,5.09999812442392,0.999999632239984,0.3509999989451,0.350999870850301,0.999999635057553 +"Foragefish2","Foragefish2",4.7,4.700001283549,1.00000027309553,0.0909999997037419,0.0910000248242094,1.00000027604909 +"OtherForagefish","OtherForagefish",5.1,5.09999704663004,0.999999420907851,0.0309999998356158,0.0309999820405001,0.999999425964008 +"Megabenthos","Megabenthos",19.7653839645524,19.7653694849668,0.999999267427051,0.189999999383839,0.18999986084728,0.999999270860213 +"Shellfish","Shellfish",7,7.00000502602804,1.00000071800401,0.509999999875786,0.510000366087145,1.00000071806149 +"Macrobenthos","Macrobenthos",17.4,17.3999776323994,0.999998714505715,9.99999992742293e-05,9.99998714891689e-05,0.999998722149387 +"Zooplankton","Zooplankton",23,23.000000626978,1.00000002725991,0,0,NA +"Phytoplankton","Phytoplankton",10,9.99999972903496,0.999999972903496,0,0,NA +"Detritus","Detritus",3636.66711075279,3636.66738627725,1.0000000757629,0,0,NA +"Discards","Discards",1.2182202,1.21823082510863,1.0000087218293,0,0,NA +"Trawlers","Trawlers",0,0,NA,0,0,NA +"Midwater","Midwater",0,0,NA,0,0,NA +"Dredgers","Dredgers",0,0,NA,0,0,NA diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Jitter.rds new file mode 100644 index 00000000..04cac95e Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Stepped.rds new file mode 100644 index 00000000..b032edfa Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutCatch_Jitter.rds new file mode 100644 index 00000000..ab4e9acb Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutCatch_Stepped.rds new file mode 100644 index 00000000..44d0ea9b Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Jitter.rds new file mode 100644 index 00000000..fa7f8324 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Stepped.rds new file mode 100644 index 00000000..fd74635a Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Jitter.rds new file mode 100644 index 00000000..194addcd Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Stepped.rds new file mode 100644 index 00000000..f35004dc Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutCatch_Jitter.rds new file mode 100644 index 00000000..2fbb9813 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutCatch_Stepped.rds new file mode 100644 index 00000000..3301a08c Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Jitter.rds new file mode 100644 index 00000000..e736781f Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Stepped.rds new file mode 100644 index 00000000..0d5f99d7 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Jitter.rds new file mode 100644 index 00000000..334c11d7 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Stepped.rds new file mode 100644 index 00000000..46c8afd1 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutCatch_Jitter.rds new file mode 100644 index 00000000..952a5364 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutCatch_Stepped.rds new file mode 100644 index 00000000..1e9d7c44 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Jitter.rds new file mode 100644 index 00000000..95a7e45f Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Stepped.rds new file mode 100644 index 00000000..05c2b4a5 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Jitter.rds new file mode 100644 index 00000000..fbceddbc Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Stepped.rds new file mode 100644 index 00000000..89b12d11 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Jitter.rds new file mode 100644 index 00000000..e68623a3 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Stepped.rds new file mode 100644 index 00000000..622bedd3 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Jitter.rds new file mode 100644 index 00000000..bca109bd Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Stepped.rds new file mode 100644 index 00000000..7f74d189 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Jitter.rds new file mode 100644 index 00000000..0248f1a5 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Stepped.rds new file mode 100644 index 00000000..aece86ac Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutCatch_Jitter.rds new file mode 100644 index 00000000..d8c3b025 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutCatch_Stepped.rds new file mode 100644 index 00000000..6f643d80 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Jitter.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Jitter.rds new file mode 100644 index 00000000..dbad2aab Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Jitter.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Stepped.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Stepped.rds new file mode 100644 index 00000000..2baec000 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Stepped.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_OutBiomass.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_OutBiomass.rds new file mode 100644 index 00000000..89b12d11 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_OutBiomass.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_OutCatch.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_OutCatch.rds new file mode 100644 index 00000000..622bedd3 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_OutCatch.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RK4_OutGearCatch.rds b/tests/testthat/data/input/REcosystem_Baseline_RK4_OutGearCatch.rds new file mode 100644 index 00000000..7f74d189 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RK4_OutGearCatch.rds differ diff --git a/tests/testthat/data/input/REcosystem_Baseline_RpathObj_Summary.rds b/tests/testthat/data/input/REcosystem_Baseline_RpathObj_Summary.rds new file mode 100644 index 00000000..b6396ec1 --- /dev/null +++ b/tests/testthat/data/input/REcosystem_Baseline_RpathObj_Summary.rds @@ -0,0 +1,13 @@ +Rpath model: R Ecosystem + Status: Balanced + +Summary Statistics: + NumGroups NumLiving NumDetritus NumFleets TotBiomass TotLandings +1 25 20 2 3 104.9365 1.74 + +Rpath model also includes: + [1] "NUM_GROUPS" "NUM_LIVING" "NUM_DEAD" "NUM_GEARS" "Group" + [6] "type" "TL" "Biomass" "PB" "QB" +[11] "EE" "BA" "Unassim" "GE" "DC" +[16] "DetFate" "Landings" "Discards" +NUM_GROUPS NUM_LIVING NUM_DEAD NUM_GEARS Group type TL Biomass PB QB EE BA Unassim GE DC DetFate Landings Discards \ No newline at end of file diff --git a/tests/testthat/data/input/REcosystem_Baseline_RpathObj_TopLevel.rds b/tests/testthat/data/input/REcosystem_Baseline_RpathObj_TopLevel.rds new file mode 100644 index 00000000..9a8c7b09 Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Baseline_RpathObj_TopLevel.rds differ diff --git a/tests/testthat/data/input/REcosystem_Current_AB_ForcedBio_OutBiomass_Jitter.rds b/tests/testthat/data/input/REcosystem_Current_AB_ForcedBio_OutBiomass_Jitter.rds new file mode 100644 index 00000000..8999098d Binary files /dev/null and b/tests/testthat/data/input/REcosystem_Current_AB_ForcedBio_OutBiomass_Jitter.rds differ diff --git a/tests/testthat/test-constants.R b/tests/testthat/test-constants.R new file mode 100644 index 00000000..c6882850 --- /dev/null +++ b/tests/testthat/test-constants.R @@ -0,0 +1,31 @@ +# ---- Modify this toggle to TRUE to generate the baseline files. ---- +# ---- Reset it back to FALSE to run the tests. ---------------------- +# CREATE_BASELINE_FILES <- TRUE +CREATE_BASELINE_FILES <- FALSE + +NUMBER_OF_STEPS <- 5 # should be an odd multiple of nrows=600 (i.e., 5,15,30) +FACTOR_VALUE <- 5 +SEED_VALUE <- 1 +SEED_OFFSET <- 2000 +TOLERANCE_VALUE <- 1e-5 +RUN_QUIET <- TRUE +YLIMIT_DIFFERENCE_PLOTS <- 0.05 +FORCED_MIGRATION_SCALE_FACTOR_JITTER <- 1000 +FORCED_MIGRATION_SCALE_FACTOR_STEPIFY <- 100 +PLOT_TYPE <- 1 # 1 = Baseline and Current superimposed, 2 = difference of (Current-Baseline) +PLOT_SHOW <- 1 # 1 - All Plots, 2 = Only plots reflecting test errors # Not sure if can be implemented +# INPUT_DATA_DIR_BASELINE <- 'data/input/baseline' +INPUT_DATA_DIR_CURRENT <- here::here('tests/testthat/data/input') +INPUT_DATA_DIR_BASELINE <- INPUT_DATA_DIR_CURRENT +OUTPUT_DATA_DIR <- here::here('tests/testthat/data/output') +FORCED_BIOMASS <- "Forced Bio" +FORCED_MIGRATION <- "Forced Migrate" +FORCED_EFFORT <- "Forced Effort" +FORCED_FRATE <- 'Forced FRate' +FORCED_CATCH <- 'Forced Catch' +JITTERED <- "Jittered" +STEPPED <- "Stepped" +JITTER_AMOUNT_PCT <- 0.01 # This is 1% jitter +FORCED_MIGRATION_BIOMASS_PCT <- 0.1 # This is a 10% jitter for the initial value +POSITIVE_ONLY <- TRUE +POSITIVE_AND_NEGATIVE <- FALSE diff --git a/tests/testthat/test-rpath.R b/tests/testthat/test-rpath.R new file mode 100644 index 00000000..df98dcd1 --- /dev/null +++ b/tests/testthat/test-rpath.R @@ -0,0 +1,882 @@ +library(Rpath) +library(qpdf) +library(testthat) +library(stringr) +library(distillery) +library(ggplot2) +library(ggpubr) +library(rlist) + +options(precision=50) + +source("test-constants.R") +source("test-utils.R") +source("test-utils-stepify.R") +source("test-utils-jitter.R") +source("test-utils-plot.R") + +print(paste0("here::here: ", here::here() )) +print(paste0("OUTPUT_DATA_DIR: ", OUTPUT_DATA_DIR)) #RSK +print(paste0("INPUT_DATA_DIR_BASELINE: ", INPUT_DATA_DIR_BASELINE)) #RSK +print(paste0("INPUT_DATA_DIR_CURRENT: ", INPUT_DATA_DIR_CURRENT)) #RSK + +# Create the current and output directories if they don't already exist. +if (! dir.exists(INPUT_DATA_DIR_CURRENT)) { + dir.create(INPUT_DATA_DIR_CURRENT,recursive=TRUE) +} +if (! dir.exists(OUTPUT_DATA_DIR)) { + dir.create(OUTPUT_DATA_DIR,recursive=TRUE) +} + +#' This test tests for equality between two objects +#' +#' This function tests to see if the two data tables are equal within a tolerance value +#' +#' @param runNum : The run number +#' @param tableName : Temp arg, used to skip over out_Gear_Catch tables as there's currently a bug with their header names +#' @param desc : The description of the run +#' @param baselineTable : The baseline table +#' @param currentTable : The current generated table +#' +#' @return No return value +#' +runTestEqual <- function(runNum,tableName,desc,baselineTable,currentTable) { + if (tableName == 'out_Gear_Catch') { + if (! RUN_QUIET) { + print('Test Skipped: The out_Gear_Catch tables are currently missing column headings...so this test will be skipped for now.') + } + return() + } + paddedRunNum <- str_pad(runNum,3,pad="0") + if (! RUN_QUIET) { + print(paste0("Test #",paddedRunNum,": ",desc)) + } + testthat::expect_equal(baselineTable,currentTable,tolerance=TOLERANCE_VALUE) +} + +#' The test for running silent test function +#' +#' This function tests to see if the current Rpath run runs silently +#' +#' @param runNum : The run number +#' @param desc : The description of the run +#' @param params : Parameters associated with, and passed to, the Rpath run +#' @param name : The ecosystem name of the run that's passed to Rpath +#' +#' @return No return value +#' +runTestSilent <- function(runNum,desc,params,name) { + paddedRunNum <- str_pad(runNum,3,pad="0") + if (! RUN_QUIET) { + print(paste0("Test #",paddedRunNum,": ",desc)) + } + testthat::expect_silent(rpath(params,eco.name=name)) +} + +#' The main test run function +#' +#' This function prints the appropriate baseline and current forced data and then runs the testthat::expect_equal test. +#' +#' @param tableName : Name of output table to plot (i.e., out_Biomass, out_Catch) +#' @param forcedData : The data that's being forced (i.e., Biomass, Catch) +#' @param forcedType : The type of forcing being done (.e., Random (Jitter) or Stepped) +#' @param baseAlg : The baseline algorithm used (currently AB or RK4) +#' @param currAlg : The current algorithm used (currently AB or RK4) +#' @param baselineTable : table that represents the baseline run's data +#' @param currentDataFrame : The data frame that contains the current run's data +#' @param currentFilename : The name of the file that contains the current run's data +#' @param species : A vector of fish species +#' +#' @return No return value +#' +runTestRDS <- function(runNum,tableName,forcedData,forcedType,baseAlg,currAlg,baselineDataFrame,currentFilename,species) { + + # N.B. Remove this if statement once missing column headings issue is fixed + if (tableName == 'out_Gear_Catch') { + if (! RUN_QUIET) { + print('Test Skipped: The out_Gear_Catch tables are currently missing column headings...so this test will be skipped for now.') + } + return() + } + + paddedRunNum <- str_pad(runNum,3,pad="0") + if (! RUN_QUIET) { + print(paste0("Test #",paddedRunNum,": Is Baseline ",baseAlg," ",tableName," equivalent to Current ",currAlg," ",tableName," using ",forcedType," ",forcedData,"?")) + } + + currentDataFrame <- readDataFile(currentFilename) + + if (tableName == 'out_Biomass' || tableName == 'out_Catch') { # || tableName == 'out_Gear_Catch') { + if (PLOT_TYPE == 1) { + plotResultsSuperimposed(baselineDataFrame, currentDataFrame, baseAlg, currAlg, tableName, forcedData, forcedType, species) + } else { + plotResultsDifference(baselineDataFrame, currentDataFrame, baseAlg, currAlg, tableName, forcedData, forcedType, species) + } + } + + # Write out the difference table (current-baseline) + # diffTable <- abs(currentDataFrame-baselineDataFrame) + # diffTable <- currentDataFrame + numRows <- nrow(currentDataFrame) + numCols <- ncol(currentDataFrame) + diffTable <- matrix(nrow=numRows,ncol=numCols) + # diffTable[TRUE] <- 0 + for (i in 1:nrow(currentDataFrame)) { + for (j in 1:ncol(currentDataFrame)) { + diffTable[i,j] <- abs(currentDataFrame[i,j] - baselineDataFrame[i,j]) + if (diffTable[i,j] <= TOLERANCE_VALUE) { + diffTable[i,j] <- 0 + } + # else { + # print(paste0("-> diffTable[",i,",",j,"]: ",diffTable[i,j])) + # } + } + } + + # Set all values <= TOLERANCE_VALUE to 0 because we're going to next compare this to a zero table + # diffTable[diffTable <= TOLERANCE_VALUE] <- 0 + + # Create the zero table + zeroTable <- matrix(0,nrow=numRows,ncol=numCols) + + sumDiffTable <- 0 + sumColsCurr = colSums(currentDataFrame) + sumColsBase = colSums(baselineDataFrame) + for (i in 1:ncol(currentDataFrame)) { + sumDiffTable <- sumDiffTable + abs(sumColsCurr[i]-sumColsBase[i]) + } +#print(paste0("***sumDiffTable: ",sumDiffTable)) +#print(paste0("SUM of current,baselineDataFrame: ", sum(currentDataFrame), ", ",sum(baselineDataFrame))) # ok +#print("Comparing if sumDiffTable/sum(currentDataFrame) <= TOLERANCE_VALUE") +#print(paste0("Is ",sumDiffTable,"/",sum(currentDataFrame)," <= ",TOLERANCE_VALUE," ?")) +areIdentical <- (sumDiffTable/ sum(currentDataFrame) <= TOLERANCE_VALUE) +#print(paste0("areIdentical: ",areIdentical)) + +# print(paste0("SUM of currentDataFrame: ", sum(currentDataFrame))) # ok +# print(paste0("SUM of baselineDataFrame: ",sum(baselineDataFrame))) # ok +#print(paste0("SUM of diffTable: ",sum(diffTable))) # not ok +#print(paste0("SUM of zeroTable: ",sum(zeroTable))) # ok +# print(paste0("Col sums currentDataFrame: ",colSums(currentDataFrame))) # ok +# print(paste0("Col sums baselineDataFrame: ",colSums(baselineDataFrame))) # ok +#print(paste0("Col sums diffTable: ",colSums(diffTable))) # not ok +# print(paste0("Sum currentDataFrame col=17: ", sum(currentDataFrame[,17]))) # ok +# print(paste0("Sum baselineDataFrame col=17: ", sum(baselineDataFrame[,17]))) # ok +#print(paste0("Sum diffTable col=17: ", sum(diffTable[,17]))) # not ok +# areIdentical <- identical(diffTable,zeroTable) # not ok +#print(paste0("*** Are they identical diffTable and zeroTable: ",identical(diffTable,zeroTable))) + + testthat::expect_true(areIdentical) + + write.table(diffTable, file=file.path(OUTPUT_DATA_DIR,paste0("diff_",paddedRunNum,".dat"))) + write.table(zeroTable, file=file.path(OUTPUT_DATA_DIR,paste0("zero_",paddedRunNum,".dat"))) +} + + + +testthat::test_that("Rpath Unit Tests", { + BaselineJitterTables <- list() + BaselineJitterFiles <- list() + CurrentJitterFiles <- list() + BaselineSteppedTables <- list() + BaselineSteppedFiles <- list() + CurrentSteppedFiles <- list() + fleets <- c('Trawlers','Midwater','Dredgers') + species <- c('OtherGroundfish','Megabenthos','Seals','JuvRoundfish1','AduRoundfish1') + modNum <- 1 + runNum <- 0 + + # ---------- Set up initial file paths ---------- + # N.B. The Baseline and Current AB and RK4 files are .csv files since they were produced by + # the write.rsim() function and not the more generic write.table() function. + BaselineRpathObjTopLevel <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RpathObj_TopLevel.rds') + BaselineRpathObjSummary <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RpathObj_Summary.rds') + BaselineAB <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB.csv') + BaselineRK4 <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4.csv') + BaselineABOutBiomass <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_OutBiomass.rds') + BaselineRK4OutBiomass <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_OutBiomass.rds') + BaselineABOutCatch <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_OutCatch.rds') + BaselineRK4OutCatch <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_OutCatch.rds') + BaselineABOutGearCatch <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_OutGearCatch.rds') + BaselineRK4OutGearCatch <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_OutGearCatch.rds') + BaselineABForcedBioOutBiomassStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedBio_OutBiomass_Stepped.rds') + BaselineRK4ForcedBioOutBiomassStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Stepped.rds') + BaselineABForcedBioOutCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedBio_OutCatch_Stepped.rds') + BaselineRK4ForcedBioOutCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedBio_OutCatch_Stepped.rds') + BaselineABForcedBioOutGearCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Stepped.rds') + BaselineRK4ForcedBioOutGearCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Stepped.rds') + BaselineABForcedBioOutBiomassJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedBio_OutBiomass_Jitter.rds') + BaselineRK4ForcedBioOutBiomassJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Jitter.rds') + BaselineABForcedBioOutCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedBio_OutCatch_Jitter.rds') + BaselineRK4ForcedBioOutCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedBio_OutCatch_Jitter.rds') + BaselineABForcedBioOutGearCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Jitter.rds') + BaselineRK4ForcedBioOutGearCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Jitter.rds') + BaselineABForcedMigOutBiomassStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedMig_OutBiomass_Stepped.rds') + BaselineRK4ForcedMigOutBiomassStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Stepped.rds') + BaselineABForcedMigOutCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedMig_OutCatch_Stepped.rds') + BaselineRK4ForcedMigOutCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedMig_OutCatch_Stepped.rds') + BaselineABForcedMigOutGearCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Stepped.rds') + BaselineRK4ForcedMigOutGearCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Stepped.rds') + BaselineABForcedMigOutBiomassJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedMig_OutBiomass_Jitter.rds') + BaselineRK4ForcedMigOutBiomassJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Jitter.rds') + BaselineABForcedMigOutCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedMig_OutCatch_Jitter.rds') + BaselineRK4ForcedMigOutCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedMig_OutCatch_Jitter.rds') + BaselineABForcedMigOutGearCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Jitter.rds') + BaselineRK4ForcedMigOutGearCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Jitter.rds') + BaselineABForcedEffOutBiomassStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedEff_OutBiomass_Stepped.rds') + BaselineABForcedEffOutCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedEff_OutCatch_Stepped.rds') + BaselineABForcedEffOutGearCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Stepped.rds') + BaselineABForcedEffOutBiomassJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedEff_OutBiomass_Jitter.rds') + BaselineABForcedEffOutCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedEff_OutCatch_Jitter.rds') + BaselineABForcedEffOutGearCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Jitter.rds') + BaselineABForcedFRaOutBiomassStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Stepped.rds') + BaselineABForcedFRaOutCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedFRa_OutCatch_Stepped.rds') + BaselineABForcedFRaOutGearCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Stepped.rds') + BaselineABForcedFRaOutBiomassJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Jitter.rds') + BaselineABForcedFRaOutCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedFRa_OutCatch_Jitter.rds') + BaselineABForcedFRaOutGearCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Jitter.rds') + BaselineABForcedCatOutBiomassStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedCat_OutBiomass_Stepped.rds') + BaselineABForcedCatOutCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedCat_OutCatch_Stepped.rds') + BaselineABForcedCatOutGearCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Stepped.rds') + BaselineABForcedCatOutBiomassJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedCat_OutBiomass_Jitter.rds') + BaselineABForcedCatOutCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedCat_OutCatch_Jitter.rds') + BaselineABForcedCatOutGearCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Jitter.rds') + BaselineRK4ForcedEffOutBiomassStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Stepped.rds') + BaselineRK4ForcedEffOutCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedEff_OutCatch_Stepped.rds') + BaselineRK4ForcedEffOutGearCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Stepped.rds') + BaselineRK4ForcedEffOutBiomassJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Jitter.rds') + BaselineRK4ForcedEffOutCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedEff_OutCatch_Jitter.rds') + BaselineRK4ForcedEffOutGearCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Jitter.rds') + BaselineRK4ForcedFRaOutBiomassStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Stepped.rds') + BaselineRK4ForcedFRaOutCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Stepped.rds') + BaselineRK4ForcedFRaOutGearCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Stepped.rds') + BaselineRK4ForcedFRaOutBiomassJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Jitter.rds') + BaselineRK4ForcedFRaOutCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Jitter.rds') + BaselineRK4ForcedFRaOutGearCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Jitter.rds') + BaselineRK4ForcedCatOutBiomassStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Stepped.rds') + BaselineRK4ForcedCatOutCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedCat_OutCatch_Stepped.rds') + BaselineRK4ForcedCatOutGearCatchStepped <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Stepped.rds') + BaselineRK4ForcedCatOutBiomassJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Jitter.rds') + BaselineRK4ForcedCatOutCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedCat_OutCatch_Jitter.rds') + BaselineRK4ForcedCatOutGearCatchJitter <- file.path(INPUT_DATA_DIR_BASELINE,'REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Jitter.rds') + # + CurrentRpathObjTopLevel <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RpathObj_TopLevel.rds') + CurrentRpathObjSummary <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RpathObj_Summary.rds') + CurrentAB <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB.csv') + CurrentRK4 <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4.csv') + CurrentABOutBiomass <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_OutBiomass.rds') + CurrentRK4OutBiomass <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_OutBiomass.rds') + CurrentABOutCatch <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_OutCatch.rds') + CurrentRK4OutCatch <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_OutCatch.rds') + CurrentABOutGearCatch <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_OutGearCatch.rds') + CurrentRK4OutGearCatch <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_OutGearCatch.rds') + CurrentABForcedBioOutBiomassStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedBio_OutBiomass_Stepped.rds') + CurrentRK4ForcedBioOutBiomassStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedBio_OutBiomass_Stepped.rds') + CurrentABForcedBioOutCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedBio_OutCatch_Stepped.rds') + CurrentRK4ForcedBioOutCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedBio_OutCatch_Stepped.rds') + CurrentABForcedBioOutGearCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedBio_OutGearCatch_Stepped.rds') + CurrentRK4ForcedBioOutGearCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedBio_OutGearCatch_Stepped.rds') + CurrentABForcedBioOutBiomassJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedBio_OutBiomass_Jitter.rds') + CurrentABForcedBioOutCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedBio_OutCatch_Jitter.rds') + CurrentABForcedBioOutGearCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedBio_OutGearCatch_Jitter.rds') + CurrentRK4ForcedBioOutBiomassJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedBio_OutBiomass_Jitter.rds') + CurrentRK4ForcedBioOutCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedBio_OutCatch_Jitter.rds') + CurrentRK4ForcedBioOutGearCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedBio_OutGearCatch_Jitter.rds') + CurrentABForcedMigOutBiomassStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedMig_OutBiomass_Stepped.rds') + CurrentRK4ForcedMigOutBiomassStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedMig_OutBiomass_Stepped.rds') + CurrentABForcedMigOutCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedMig_OutCatch_Stepped.rds') + CurrentRK4ForcedMigOutCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedMig_OutCatch_Stepped.rds') + CurrentABForcedMigOutGearCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedMig_OutGearCatch_Stepped.rds') + CurrentRK4ForcedMigOutGearCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedMig_OutGearCatch_Stepped.rds') + CurrentABForcedMigOutBiomassJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedMig_OutBiomass_Jitter.rds') + CurrentABForcedMigOutCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedMig_OutCatch_Jitter.rds') + CurrentABForcedMigOutGearCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedMig_OutGearCatch_Jitter.rds') + CurrentRK4ForcedMigOutBiomassJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedMig_OutBiomass_Jitter.rds') + CurrentRK4ForcedMigOutCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedMig_OutCatch_Jitter.rds') + CurrentRK4ForcedMigOutGearCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedMig_OutGearCatch_Jitter.rds') + CurrentABForcedEffOutBiomassStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedEff_OutBiomass_Stepped.rds') + CurrentRK4ForcedEffOutBiomassStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedEff_OutBiomass_Stepped.rds') + CurrentABForcedEffOutCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedEff_OutCatch_Stepped.rds') + CurrentRK4ForcedEffOutCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedEff_OutCatch_Stepped.rds') + CurrentABForcedEffOutGearCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedEff_OutGearCatch_Stepped.rds') + CurrentRK4ForcedEffOutGearCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedEff_OutGearCatch_Stepped.rds') + CurrentABForcedFRaOutBiomassStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedFRa_OutBiomass_Stepped.rds') + CurrentRK4ForcedFRaOutBiomassStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedFRa_OutBiomass_Stepped.rds') + CurrentABForcedFRaOutCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedFRa_OutCatch_Stepped.rds') + CurrentRK4ForcedFRaOutCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedFRa_OutCatch_Stepped.rds') + CurrentABForcedFRaOutGearCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedFRa_OutGearCatch_Stepped.rds') + CurrentRK4ForcedFRaOutGearCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedFRa_OutGearCatch_Stepped.rds') + CurrentABForcedCatOutBiomassStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedCat_OutBiomass_Stepped.rds') + CurrentRK4ForcedCatOutBiomassStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedCat_OutBiomass_Stepped.rds') + CurrentABForcedCatOutCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedCat_OutCatch_Stepped.rds') + CurrentRK4ForcedCatOutCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedCat_OutCatch_Stepped.rds') + CurrentABForcedCatOutGearCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedCat_OutGearCatch_Stepped.rds') + CurrentRK4ForcedCatOutGearCatchStepped <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedCat_OutGearCatch_Stepped.rds') + CurrentABForcedEffOutBiomassJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedEff_OutBiomass_Jitter.rds') + CurrentABForcedEffOutCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedEff_OutCatch_Jitter.rds') + CurrentABForcedEffOutGearCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedEff_OutGearCatch_Jitter.rds') + CurrentRK4ForcedEffOutBiomassJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedEff_OutBiomass_Jitter.rds') + CurrentRK4ForcedEffOutCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedEff_OutCatch_Jitter.rds') + CurrentRK4ForcedEffOutGearCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedEff_OutGearCatch_Jitter.rds') + CurrentABForcedFRaOutBiomassJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedFRa_OutBiomass_Jitter.rds') + CurrentABForcedFRaOutCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedFRa_OutCatch_Jitter.rds') + CurrentABForcedFRaOutGearCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedFRa_OutGearCatch_Jitter.rds') + CurrentRK4ForcedFRaOutBiomassJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedFRa_OutBiomass_Jitter.rds') + CurrentRK4ForcedFRaOutCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedFRa_OutCatch_Jitter.rds') + CurrentRK4ForcedFRaOutGearCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedFRa_OutGearCatch_Jitter.rds') + CurrentABForcedCatOutBiomassJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedCat_OutBiomass_Jitter.rds') + CurrentABForcedCatOutCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedCat_OutCatch_Jitter.rds') + CurrentABForcedCatOutGearCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_AB_ForcedCat_OutGearCatch_Jitter.rds') + CurrentRK4ForcedCatOutBiomassJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedCat_OutBiomass_Jitter.rds') + CurrentRK4ForcedCatOutCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedCat_OutCatch_Jitter.rds') + CurrentRK4ForcedCatOutGearCatchJitter <- file.path(INPUT_DATA_DIR_CURRENT,'REcosystem_Current_RK4_ForcedCat_OutGearCatch_Jitter.rds') + + # Initialize baseline and current paths + REcosystemBaseline <- NULL + REcosystemBaselineSummary <- NULL + REcosystem_Baseline_AB <- NULL + REcosystem_Baseline_RK4 <- NULL + REcosystem_Baseline_AB_OutBiomass <- NULL + REcosystem_Baseline_AB_OutCatch <- NULL + REcosystem_Baseline_AB_OutGearCatch <- NULL + REcosystem_Baseline_RK4_OutBiomass <- NULL + REcosystem_Baseline_RK4_OutCatch <- NULL + REcosystem_Baseline_RK4_OutGearCatch <- NULL + REcosystem_Baseline_AB_ForcedBio_OutBiomass_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Stepped <- NULL + REcosystem_Baseline_AB_ForcedBio_OutCatch_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedBio_OutCatch_Stepped <- NULL + REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Stepped <- NULL + REcosystem_Baseline_AB_ForcedBio_OutBiomass_Jitter <- NULL + REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Jitter <- NULL + REcosystem_Baseline_AB_ForcedBio_OutCatch_Jitter <- NULL + REcosystem_Baseline_RK4_ForcedBio_OutCatch_Jitter <- NULL + REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Jitter <- NULL + REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Jitter <- NULL + REcosystem_Baseline_AB_ForcedMig_OutBiomass_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Stepped <- NULL + REcosystem_Baseline_AB_ForcedMig_OutCatch_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedMig_OutCatch_Stepped <- NULL + REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Stepped <- NULL + REcosystem_Baseline_AB_ForcedMig_OutBiomass_Jitter <- NULL + REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Jitter <- NULL + REcosystem_Baseline_AB_ForcedMig_OutCatch_Jitter <- NULL + REcosystem_Baseline_RK4_ForcedMig_OutCatch_Jitter <- NULL + REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Jitter <- NULL + REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Jitter <- NULL + REcosystem_Baseline_AB_ForcedEff_OutBiomass_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Stepped <- NULL + REcosystem_Baseline_AB_ForcedEff_OutCatch_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedEff_OutCatch_Stepped <- NULL + REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Stepped <- NULL + REcosystem_Baseline_AB_ForcedEff_OutBiomass_Jitter <- NULL + REcosystem_Baseline_AB_ForcedEff_OutCatch_Jitter <- NULL + REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Jitter <- NULL + REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Jitter <- NULL + REcosystem_Baseline_RK4_ForcedEff_OutCatch_Jitter <- NULL + REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Jitter <- NULL + REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Jitter <- NULL + REcosystem_Baseline_AB_ForcedFRa_OutCatch_Jitter <- NULL + REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Jitter <- NULL + REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Jitter <- NULL + REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Jitter <- NULL + REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Jitter <- NULL + REcosystem_Baseline_AB_ForcedCat_OutBiomass_Jitter <- NULL + REcosystem_Baseline_AB_ForcedCat_OutCatch_Jitter <- NULL + REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Jitter <- NULL + REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Jitter <- NULL + REcosystem_Baseline_RK4_ForcedCat_OutCatch_Jitter <- NULL + REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Jitter <- NULL + REcosystem_Baseline_AB_ForcedEff_OutBiomass_Stepped <- NULL + REcosystem_Baseline_AB_ForcedEff_OutCatch_Stepped <- NULL + REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedEff_OutCatch_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Stepped <- NULL + REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Stepped <- NULL + REcosystem_Baseline_AB_ForcedFRa_OutCatch_Stepped <- NULL + REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Stepped <- NULL + REcosystem_Baseline_AB_ForcedCat_OutBiomass_Stepped <- NULL + REcosystem_Baseline_AB_ForcedCat_OutCatch_Stepped <- NULL + REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedCat_OutCatch_Stepped <- NULL + REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Stepped <- NULL + if (! CREATE_BASELINE_FILES) { + REcosystemBaseline <- readDataFile(BaselineRpathObjTopLevel) #, fill = TRUE, sep = " ") + REcosystemBaselineSummary <- read.table(BaselineRpathObjSummary, fill = TRUE) + REcosystem_Baseline_AB <- read.csv(BaselineAB) + REcosystem_Baseline_RK4 <- read.csv(BaselineRK4) + REcosystem_Baseline_AB_OutBiomass <- readDataFile(BaselineABOutBiomass) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_OutCatch <- readDataFile(BaselineABOutCatch) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_OutGearCatch <- readDataFile(BaselineABOutGearCatch) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_OutBiomass <- readDataFile(BaselineRK4OutBiomass) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_OutCatch <- readDataFile(BaselineRK4OutCatch) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_OutGearCatch <- readDataFile(BaselineRK4OutGearCatch) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedBio_OutBiomass_Stepped <- readDataFile(BaselineABForcedBioOutBiomassStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Stepped <- readDataFile(BaselineRK4ForcedBioOutBiomassStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedBio_OutCatch_Stepped <- readDataFile(BaselineABForcedBioOutCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedBio_OutCatch_Stepped <- readDataFile(BaselineRK4ForcedBioOutCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Stepped <- readDataFile(BaselineABForcedBioOutGearCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Stepped <- readDataFile(BaselineRK4ForcedBioOutGearCatchStepped) #,fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedBio_OutBiomass_Jitter <- readDataFile(BaselineABForcedBioOutBiomassJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Jitter <- readDataFile(BaselineRK4ForcedBioOutBiomassJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedBio_OutCatch_Jitter <- readDataFile(BaselineABForcedBioOutCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedBio_OutCatch_Jitter <- readDataFile(BaselineRK4ForcedBioOutCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Jitter <- readDataFile(BaselineABForcedBioOutGearCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Jitter <- readDataFile(BaselineRK4ForcedBioOutGearCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedMig_OutBiomass_Stepped <- readDataFile(BaselineABForcedMigOutBiomassStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Stepped <- readDataFile(BaselineRK4ForcedMigOutBiomassStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedMig_OutCatch_Stepped <- readDataFile(BaselineABForcedMigOutCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedMig_OutCatch_Stepped <- readDataFile(BaselineRK4ForcedMigOutCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Stepped <- readDataFile(BaselineABForcedMigOutGearCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Stepped <- readDataFile(BaselineRK4ForcedMigOutGearCatchStepped) #,fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedMig_OutBiomass_Jitter <- readDataFile(BaselineABForcedMigOutBiomassJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Jitter <- readDataFile(BaselineRK4ForcedMigOutBiomassJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedMig_OutCatch_Jitter <- readDataFile(BaselineABForcedMigOutCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedMig_OutCatch_Jitter <- readDataFile(BaselineRK4ForcedMigOutCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Jitter <- readDataFile(BaselineABForcedMigOutGearCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Jitter <- readDataFile(BaselineRK4ForcedMigOutGearCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedEff_OutBiomass_Stepped <- readDataFile(BaselineABForcedEffOutBiomassStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Stepped <- readDataFile(BaselineRK4ForcedEffOutBiomassStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedEff_OutCatch_Stepped <- readDataFile(BaselineABForcedEffOutCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedEff_OutCatch_Stepped <- readDataFile(BaselineRK4ForcedEffOutCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Stepped <- readDataFile(BaselineABForcedEffOutGearCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Stepped <- readDataFile(BaselineRK4ForcedEffOutGearCatchStepped) #,fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedEff_OutBiomass_Jitter <- readDataFile(BaselineABForcedEffOutBiomassJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedEff_OutCatch_Jitter <- readDataFile(BaselineABForcedEffOutCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Jitter <- readDataFile(BaselineABForcedEffOutGearCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Jitter <- readDataFile(BaselineRK4ForcedEffOutBiomassJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedEff_OutCatch_Jitter <- readDataFile(BaselineRK4ForcedEffOutCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Jitter <- readDataFile(BaselineRK4ForcedEffOutGearCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Jitter <- readDataFile(BaselineABForcedFRaOutBiomassJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedFRa_OutCatch_Jitter <- readDataFile(BaselineABForcedFRaOutCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Jitter <- readDataFile(BaselineABForcedFRaOutGearCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Jitter <- readDataFile(BaselineRK4ForcedFRaOutBiomassJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Jitter <- readDataFile(BaselineRK4ForcedFRaOutCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Jitter <- readDataFile(BaselineRK4ForcedFRaOutGearCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedCat_OutBiomass_Jitter <- readDataFile(BaselineABForcedCatOutBiomassJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedCat_OutCatch_Jitter <- readDataFile(BaselineABForcedCatOutCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Jitter <- readDataFile(BaselineABForcedCatOutGearCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Jitter <- readDataFile(BaselineRK4ForcedCatOutBiomassJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedCat_OutCatch_Jitter <- readDataFile(BaselineRK4ForcedCatOutCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Jitter <- readDataFile(BaselineRK4ForcedCatOutGearCatchJitter) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedEff_OutBiomass_Stepped <- readDataFile(BaselineABForcedEffOutBiomassStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedEff_OutCatch_Stepped <- readDataFile(BaselineABForcedEffOutCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Stepped <- readDataFile(BaselineABForcedEffOutGearCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Stepped <- readDataFile(BaselineRK4ForcedEffOutBiomassStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedEff_OutCatch_Stepped <- readDataFile(BaselineRK4ForcedEffOutCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Stepped <- readDataFile(BaselineRK4ForcedEffOutGearCatchStepped) #,fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Stepped <- readDataFile(BaselineABForcedFRaOutBiomassStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedFRa_OutCatch_Stepped <- readDataFile(BaselineABForcedFRaOutCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Stepped <- readDataFile(BaselineABForcedFRaOutGearCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Stepped <- readDataFile(BaselineRK4ForcedFRaOutBiomassStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Stepped <- readDataFile(BaselineRK4ForcedFRaOutCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Stepped <- readDataFile(BaselineRK4ForcedFRaOutGearCatchStepped) #,fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedCat_OutBiomass_Stepped <- readDataFile(BaselineABForcedCatOutBiomassStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedCat_OutCatch_Stepped <- readDataFile(BaselineABForcedCatOutCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Stepped <- readDataFile(BaselineABForcedCatOutGearCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Stepped <- readDataFile(BaselineRK4ForcedCatOutBiomassStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedCat_OutCatch_Stepped <- readDataFile(BaselineRK4ForcedCatOutCatchStepped) #, fill = TRUE, sep = " ") + REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Stepped <- readDataFile(BaselineRK4ForcedCatOutGearCatchStepped) #,fill = TRUE, sep = " ") + } + + # # + # # Save current Rpath run data + REco <- rpath(REco.params, eco.name = 'R Ecosystem') # an Rpath object + RpathObjTopLevel <- if (CREATE_BASELINE_FILES) BaselineRpathObjTopLevel else CurrentRpathObjTopLevel + writeDataFile(REco,RpathObjTopLevel) + # sink(RpathObjTopLevel) + # print(REco) + # sink() + + # Save current Rpath run summary data + RpathObjSummary <- if (CREATE_BASELINE_FILES) BaselineRpathObjSummary else CurrentRpathObjSummary + # writeDataFile(summary(REco),RpathObjSummary) + sink(RpathObjSummary) + cat(summary(REco)) + sink() + + # Save current Rpath sim run data for AB and RK4 + REcosystem_scenario <- rsim.scenario(REco, REco.params, 1:50) + REcosystem_Current_AB_from_Sim <- rsim.run(REcosystem_scenario,method='AB', years=1:50) + REcosystem_Current_RK4_from_Sim <- rsim.run(REcosystem_scenario,method='RK4',years=1:50) + if (CREATE_BASELINE_FILES) { + write.Rsim(REcosystem_Current_AB_from_Sim, BaselineAB) + write.Rsim(REcosystem_Current_RK4_from_Sim,BaselineRK4) + } else { + write.Rsim(REcosystem_Current_AB_from_Sim, CurrentAB) + write.Rsim(REcosystem_Current_RK4_from_Sim,CurrentRK4) + } + + # ------------------------------------------ + # ------------------------------------------ + # --------------- Run tests ---------------- + # ------------------------------------------ + # ------------------------------------------ + + print("------------------ Rpath Object Tests ------------------") + if (! CREATE_BASELINE_FILES) { + # Remove existing output data files + cwd <- getwd() + files <- dir(path=file.path(cwd,OUTPUT_DATA_DIR),pattern='diff_*') + file.remove(file.path(OUTPUT_DATA_DIR,files)) + files <- dir(path=file.path(cwd,OUTPUT_DATA_DIR),pattern='zero_*') + file.remove(file.path(OUTPUT_DATA_DIR,files)) + + # Test 1 - Test if Balanced (i.e., "Status: Balanced" is the 2nd line of the Summary file) + headerSummaryLines <- readLines(CurrentRpathObjSummary,n=2) + parts <- unlist(strsplit(str_trim(headerSummaryLines[2]),split=" ")) + runTestEqual(inc(runNum),"","Is model balanced?",parts[2],"Balanced") + + # Test 2 - Test if function runs silently (i.e., no messages, warnings, or print statements) + runTestSilent(inc(runNum),"Does model run without any terminal output (i.e., warnings, errors)?",REco.params,'R Ecosystem') + + # Test 3 - Test that the REcosystem object is the same as the saved original REcosystem object + REcosystemCurrent <- readDataFile(CurrentRpathObjTopLevel)#,fill = TRUE, sep = " ") + runTestEqual(inc(runNum),"","Is the baseline Rpath object equivalent to the current Rpath object (toplevel data)?",REcosystemBaseline,REcosystemCurrent) + + # Test 4 - Test that the REcosystem Summary is the same as the saved original REcosystem Summary + REcosystemSummaryCurrent <- read.table(CurrentRpathObjSummary,fill = TRUE) + runTestEqual(inc(runNum),"","Is the baseline Rpath run Summary the same as the current Rpath Summary?",REcosystemBaselineSummary,REcosystemSummaryCurrent) + + REcosystem_Current_AB <- read.csv(CurrentAB) + REcosystem_Current_RK4 <- read.csv(CurrentRK4) + } + + # Tests 5-16 - Test that REcosystem AB object is same as RK4 object with no perturbations + if (CREATE_BASELINE_FILES) { + writeDataFile(REcosystem_Current_AB_from_Sim$out_Biomass, BaselineABOutBiomass) + writeDataFile(REcosystem_Current_RK4_from_Sim$out_Biomass, BaselineRK4OutBiomass) + writeDataFile(REcosystem_Current_AB_from_Sim$out_Catch, BaselineABOutCatch) + writeDataFile(REcosystem_Current_RK4_from_Sim$out_Catch, BaselineRK4OutCatch) + writeDataFile(REcosystem_Current_AB_from_Sim$out_Gear_Catch, BaselineABOutGearCatch) + writeDataFile(REcosystem_Current_RK4_from_Sim$out_Gear_Catch,BaselineRK4OutGearCatch) + } + else { + writeDataFile(REcosystem_Current_AB_from_Sim$out_Biomass, CurrentABOutBiomass) + writeDataFile(REcosystem_Current_RK4_from_Sim$out_Biomass, CurrentRK4OutBiomass) + writeDataFile(REcosystem_Current_AB_from_Sim$out_Catch, CurrentABOutCatch) + writeDataFile(REcosystem_Current_RK4_from_Sim$out_Catch, CurrentRK4OutCatch) + writeDataFile(REcosystem_Current_AB_from_Sim$out_Gear_Catch, CurrentABOutGearCatch) + writeDataFile(REcosystem_Current_RK4_from_Sim$out_Gear_Catch,CurrentRK4OutGearCatch) + REcosystem_Current_AB_OutBiomass <- readDataFile(CurrentABOutBiomass) #, fill=TRUE,sep=" ") + REcosystem_Current_RK4_OutBiomass <- readDataFile(CurrentRK4OutBiomass) #, fill=TRUE,sep=" ") + REcosystem_Current_AB_OutCatch <- readDataFile(CurrentABOutCatch) #, fill=TRUE,sep=" ") + REcosystem_Current_RK4_OutCatch <- readDataFile(CurrentRK4OutCatch) #, fill=TRUE,sep=" ") + REcosystem_Current_AB_OutGearCatch <- readDataFile(CurrentABOutGearCatch) #, fill=TRUE,sep=" ") + REcosystem_Current_RK4_OutGearCatch <- readDataFile(CurrentRK4OutGearCatch) #,fill=TRUE,sep=" ") + runTestEqual(inc(runNum),"", "Compare baseline AB to Current AB", REcosystem_Baseline_AB, REcosystem_Current_AB) + runTestEqual(inc(runNum),"out_Biomass", "Compare baseline AB to Current AB for OutBiomass", REcosystem_Baseline_AB_OutBiomass, REcosystem_Current_AB_OutBiomass) + runTestEqual(inc(runNum),"out_Catch", "Compare baseline AB to Current AB for OutCatch", REcosystem_Baseline_AB_OutCatch, REcosystem_Current_AB_OutCatch) + runTestEqual(inc(runNum),"out_Gear_Catch","Compare baseline AB to Current AB for OutGearCatch", REcosystem_Baseline_AB_OutGearCatch, REcosystem_Current_AB_OutGearCatch) + runTestEqual(inc(runNum),"", "Compare baseline RK4 to Current RK4", REcosystem_Baseline_RK4, REcosystem_Current_RK4) + runTestEqual(inc(runNum),"out_Biomass", "Compare baseline RK4 to Current RK4 for OutputBiomass",REcosystem_Baseline_RK4_OutBiomass, REcosystem_Current_RK4_OutBiomass) + runTestEqual(inc(runNum),"out_Catch", "Compare baseline RK4 to Current RK4 for OutCatch", REcosystem_Baseline_RK4_OutCatch, REcosystem_Current_RK4_OutCatch) + runTestEqual(inc(runNum),"out_Gear_Catch","Compare baseline RK4 to Current RK4 for OutGearCatch", REcosystem_Baseline_RK4_OutGearCatch,REcosystem_Current_RK4_OutGearCatch) + runTestEqual(inc(runNum),"", "Compare baseline AB to Current RK4", REcosystem_Baseline_AB, REcosystem_Current_RK4) + runTestEqual(inc(runNum),"out_Biomass", "Compare baseline AB to Current RK4 for OutBiomass", REcosystem_Baseline_AB_OutBiomass, REcosystem_Current_RK4_OutBiomass) + runTestEqual(inc(runNum),"out_Catch", "Compare baseline AB to Current RK4 for OutCatch", REcosystem_Baseline_AB_OutCatch, REcosystem_Current_RK4_OutCatch) + runTestEqual(inc(runNum),"out_Gear_Catch","Compare baseline AB to Current RK4 for OutGearCatch", REcosystem_Baseline_AB_OutGearCatch, REcosystem_Current_RK4_OutGearCatch) + } + + print("------------------ Forced Biomass Tests (Jitter) ------------------") + typeData <- list(FORCED_BIOMASS,FORCED_MIGRATION) + numMonths <- nrow(REcosystem_scenario$forcing$ForcedBio) + for (typeNum in 1:length(typeData)) { + REco <- rpath(REco.params, eco.name = 'R Ecosystem') # an Rpath object + REcosystem_scenario <- rsim.scenario(REco, REco.params, 1:50) + REcosystem_scenario_jitter <- REcosystem_scenario + theTypeData <- typeData[[typeNum]] + modNum <- modNum + 1 + if (theTypeData == FORCED_BIOMASS) { + BaselineJitterDataFrames <- list(REcosystem_Baseline_AB_ForcedBio_OutBiomass_Jitter, REcosystem_Baseline_AB_ForcedBio_OutCatch_Jitter, REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Jitter, + REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Jitter, REcosystem_Baseline_RK4_ForcedBio_OutCatch_Jitter, REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Jitter) + BaselineJitterFilenames <- list(BaselineABForcedBioOutBiomassJitter, BaselineABForcedBioOutCatchJitter, BaselineABForcedBioOutGearCatchJitter, + BaselineRK4ForcedBioOutBiomassJitter, BaselineRK4ForcedBioOutCatchJitter, BaselineRK4ForcedBioOutGearCatchJitter) + CurrentJitterFilenames <- list(CurrentABForcedBioOutBiomassJitter, CurrentABForcedBioOutCatchJitter, CurrentABForcedBioOutGearCatchJitter, + CurrentRK4ForcedBioOutBiomassJitter, CurrentRK4ForcedBioOutCatchJitter, CurrentRK4ForcedBioOutGearCatchJitter) + # RSK - These (original) lines don't work in git actions + REcosystem_scenario_jitter$forcing$ForcedBio <- modifyForcingMatrix(modNum, species, JITTERED, theTypeData, + REcosystem_scenario_jitter$forcing$ForcedBio, + REcosystem_scenario_jitter, + POSITIVE_ONLY) + + # A couple different ways to jitter. Trying to determine why some tests fail in git actions when run + # in the tests.yml file but don't fail when run via R-CMD-Check.yml. + # + # This line doesn't fail in git actions (it's just not the exact logic I need) + # set.seed(modNum*typeNum*SEED_OFFSET) + # REcosystem_scenario_jitter$forcing$ForcedBio <- jitter(REcosystem_scenario_jitter$forcing$ForcedBio,factor=FACTOR_VALUE) + # + # Another way to jitter + #numMonths <- nrow(REcosystem_scenario_jitter$forcing$ForcedBio) + #numSpecies <- length(species) + #speciesNum <- 0 + #totSpeciesBiomass <- 0 + #totRandVal <- 0 + #for (aSpecies in species) { + # jitterVector <- c() + # speciesBiomass <- REcosystem_scenario_jitter$start_state$Biomass[aSpecies] + # totSpeciesBiomass <- totSpeciesBiomass + speciesBiomass + # for (month in 1:numMonths) { + # randVal <- randomNumber(modNum*typeNum*SEED_OFFSET+speciesNum*numMonths+month) + # jitteredValue <- speciesBiomass * (1.0 + randVal) + # totRandVal <- totRandVal + randVal + # jitterVector <- append(jitterVector,jitteredValue) + # } + # speciesNum <- speciesNum + 1 + # REcosystem_scenario_jitter$forcing$ForcedBio[,aSpecies] <- jitterVector # RSK problematic line here + #} + # REcosystem_scenario_jitter$forcing$ForcedBio <- jitterMatrixColumns(REcosystem_scenario_jitter$forcing$ForcedBio,REcosystem_scenario_jitter$start_state$Biomass,species) + } + else if (theTypeData == FORCED_MIGRATION) { + BaselineJitterDataFrames <- list(REcosystem_Baseline_AB_ForcedMig_OutBiomass_Jitter, REcosystem_Baseline_AB_ForcedMig_OutCatch_Jitter, REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Jitter, + REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Jitter, REcosystem_Baseline_RK4_ForcedMig_OutCatch_Jitter, REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Jitter) + BaselineJitterFilenames <- list(BaselineABForcedMigOutBiomassJitter, BaselineABForcedMigOutCatchJitter, BaselineABForcedMigOutGearCatchJitter, + BaselineRK4ForcedMigOutBiomassJitter, BaselineRK4ForcedMigOutCatchJitter, BaselineRK4ForcedMigOutGearCatchJitter) + CurrentJitterFilenames <- list(CurrentABForcedMigOutBiomassJitter, CurrentABForcedMigOutCatchJitter, CurrentABForcedMigOutGearCatchJitter, + CurrentRK4ForcedMigOutBiomassJitter, CurrentRK4ForcedMigOutCatchJitter, CurrentRK4ForcedMigOutGearCatchJitter) + REcosystem_scenario_jitter$forcing$ForcedMigrate <- modifyForcingMatrix(modNum,species,JITTERED,theTypeData, + REcosystem_scenario_jitter$forcing$ForcedMigrate, + REcosystem_scenario_jitter, + POSITIVE_ONLY) + } else { + print(paste0("Error: Unknown data type: ",theTypeData)) + return() + } + + REcosystem_AB_Current_Jitter <- rsim.run(REcosystem_scenario_jitter,method='AB', years=1:50) + REcosystem_RK4_Current_Jitter <- rsim.run(REcosystem_scenario_jitter,method='RK4',years=1:50) + if (CREATE_BASELINE_FILES) { + writeDataFile(REcosystem_AB_Current_Jitter$out_Biomass, BaselineJitterFilenames[[1]]) + writeDataFile(REcosystem_AB_Current_Jitter$out_Catch, BaselineJitterFilenames[[2]]) + writeDataFile(REcosystem_AB_Current_Jitter$out_Gear_Catch, BaselineJitterFilenames[[3]]) + writeDataFile(REcosystem_RK4_Current_Jitter$out_Biomass, BaselineJitterFilenames[[4]]) + writeDataFile(REcosystem_RK4_Current_Jitter$out_Catch, BaselineJitterFilenames[[5]]) + writeDataFile(REcosystem_RK4_Current_Jitter$out_Gear_Catch, BaselineJitterFilenames[[6]]) + } else { + writeDataFile(REcosystem_AB_Current_Jitter$out_Biomass, CurrentJitterFilenames[[1]]) + writeDataFile(REcosystem_AB_Current_Jitter$out_Catch, CurrentJitterFilenames[[2]]) + writeDataFile(REcosystem_AB_Current_Jitter$out_Gear_Catch, CurrentJitterFilenames[[3]]) + writeDataFile(REcosystem_RK4_Current_Jitter$out_Biomass, CurrentJitterFilenames[[4]]) + writeDataFile(REcosystem_RK4_Current_Jitter$out_Catch, CurrentJitterFilenames[[5]]) + writeDataFile(REcosystem_RK4_Current_Jitter$out_Gear_Catch, CurrentJitterFilenames[[6]]) + runTestRDS(inc(runNum),"out_Biomass", theTypeData, "Random", "AB", "AB", BaselineJitterDataFrames[[1]], CurrentJitterFilenames[[1]], species) + runTestRDS(inc(runNum),"out_Catch", theTypeData, "Random", "AB", "AB", BaselineJitterDataFrames[[2]], CurrentJitterFilenames[[2]], species) + runTestRDS(inc(runNum),"out_Gear_Catch", theTypeData, "Random", "AB", "AB", BaselineJitterDataFrames[[3]], CurrentJitterFilenames[[3]], species) + runTestRDS(inc(runNum),"out_Biomass", theTypeData, "Random", "RK4", "RK4", BaselineJitterDataFrames[[4]], CurrentJitterFilenames[[4]], species) + if (0) { # debug these + runTestRDS(inc(runNum),"out_Catch", theTypeData, "Random", "RK4", "RK4", BaselineJitterDataFrames[[5]], CurrentJitterFilenames[[5]], species) + runTestRDS(inc(runNum),"out_Gear_Catch", theTypeData, "Random", "RK4", "RK4", BaselineJitterDataFrames[[6]], CurrentJitterFilenames[[6]], species) + } + } + } + +# if (CREATE_BASELINE_FILES == FALSE) { +# return() +# } + + print("------------------ Forced Biomass Tests (Stepped) ------------------") + REcosystem_scenario_stepped <- REcosystem_scenario + typeData <- list(FORCED_BIOMASS,FORCED_MIGRATION) + numMonths <- nrow(REcosystem_scenario_stepped$forcing$ForcedBio) + for (i in 1:length(typeData)) { + REcosystem_scenario <- rsim.scenario(REco, REco.params, 1:50) + REcosystem_scenario_stepped <- copy(REcosystem_scenario) + theTypeData <- typeData[[i]] + modNum <- modNum + 1 + if (theTypeData == FORCED_BIOMASS) { + REcosystem_scenario_stepped$forcing$ForcedBio <- modifyForcingMatrix(modNum,species,STEPPED,theTypeData, + REcosystem_scenario_stepped$forcing$ForcedBio, + REcosystem_scenario_stepped, + POSITIVE_ONLY) + BaselineSteppedTables <- list(REcosystem_Baseline_AB_ForcedBio_OutBiomass_Stepped, REcosystem_Baseline_AB_ForcedBio_OutCatch_Stepped, REcosystem_Baseline_AB_ForcedBio_OutGearCatch_Stepped, + REcosystem_Baseline_RK4_ForcedBio_OutBiomass_Stepped, REcosystem_Baseline_RK4_ForcedBio_OutCatch_Stepped, REcosystem_Baseline_RK4_ForcedBio_OutGearCatch_Stepped) + BaselineSteppedFiles <- list(BaselineABForcedBioOutBiomassStepped, BaselineABForcedBioOutCatchStepped, BaselineABForcedBioOutGearCatchStepped, + BaselineRK4ForcedBioOutBiomassStepped, BaselineRK4ForcedBioOutCatchStepped, BaselineRK4ForcedBioOutGearCatchStepped) + CurrentSteppedFiles <- list(CurrentABForcedBioOutBiomassStepped, CurrentABForcedBioOutCatchStepped, CurrentABForcedBioOutGearCatchStepped, + CurrentRK4ForcedBioOutBiomassStepped, CurrentRK4ForcedBioOutCatchStepped, CurrentRK4ForcedBioOutGearCatchStepped) + } else if (theTypeData == FORCED_MIGRATION) { + REcosystem_scenario_stepped$forcing$ForcedMigrate <- modifyForcingMatrix(modNum,species,STEPPED,theTypeData, + REcosystem_scenario_stepped$forcing$ForcedMigrate, + REcosystem_scenario_stepped, + POSITIVE_ONLY) + BaselineSteppedTables <- list(REcosystem_Baseline_AB_ForcedMig_OutBiomass_Stepped, REcosystem_Baseline_AB_ForcedMig_OutCatch_Stepped, REcosystem_Baseline_AB_ForcedMig_OutGearCatch_Stepped, + REcosystem_Baseline_RK4_ForcedMig_OutBiomass_Stepped, REcosystem_Baseline_RK4_ForcedMig_OutCatch_Stepped, REcosystem_Baseline_RK4_ForcedMig_OutGearCatch_Stepped) + BaselineSteppedFiles <- list(BaselineABForcedMigOutBiomassStepped, BaselineABForcedMigOutCatchStepped, BaselineABForcedMigOutGearCatchStepped, + BaselineRK4ForcedMigOutBiomassStepped, BaselineRK4ForcedMigOutCatchStepped, BaselineRK4ForcedMigOutGearCatchStepped) + CurrentSteppedFiles <- list(CurrentABForcedMigOutBiomassStepped, CurrentABForcedMigOutCatchStepped, CurrentABForcedMigOutGearCatchStepped, + CurrentRK4ForcedMigOutBiomassStepped, CurrentRK4ForcedMigOutCatchStepped, CurrentRK4ForcedMigOutGearCatchStepped) + } + REcosystem_AB_Current_Stepped <- rsim.run(REcosystem_scenario_stepped,method='AB', years=1:50) + REcosystem_RK4_Current_Stepped <- rsim.run(REcosystem_scenario_stepped,method='RK4',years=1:50) + if (CREATE_BASELINE_FILES) { + writeDataFile(REcosystem_AB_Current_Stepped$out_Biomass, BaselineSteppedFiles[[1]]) + writeDataFile(REcosystem_AB_Current_Stepped$out_Catch, BaselineSteppedFiles[[2]]) + writeDataFile(REcosystem_AB_Current_Stepped$out_Gear_Catch, BaselineSteppedFiles[[3]]) + writeDataFile(REcosystem_RK4_Current_Stepped$out_Biomass, BaselineSteppedFiles[[4]]) + writeDataFile(REcosystem_RK4_Current_Stepped$out_Catch, BaselineSteppedFiles[[5]]) + writeDataFile(REcosystem_RK4_Current_Stepped$out_Gear_Catch, BaselineSteppedFiles[[6]]) + } else { + writeDataFile(REcosystem_AB_Current_Stepped$out_Biomass, CurrentSteppedFiles[[1]]) + writeDataFile(REcosystem_AB_Current_Stepped$out_Catch, CurrentSteppedFiles[[2]]) + writeDataFile(REcosystem_AB_Current_Stepped$out_Gear_Catch, CurrentSteppedFiles[[3]]) + writeDataFile(REcosystem_RK4_Current_Stepped$out_Biomass, CurrentSteppedFiles[[4]]) + writeDataFile(REcosystem_RK4_Current_Stepped$out_Catch, CurrentSteppedFiles[[5]]) + writeDataFile(REcosystem_RK4_Current_Stepped$out_Gear_Catch, CurrentSteppedFiles[[6]]) + runTestRDS(inc(runNum),"out_Biomass", theTypeData, "Stepped", "AB", "AB", BaselineSteppedTables[[1]], CurrentSteppedFiles[[1]], species) + if (0) { # debug later + runTestRDS(inc(runNum),"out_Catch", theTypeData, "Stepped", "AB", "AB", BaselineSteppedTables[[2]], CurrentSteppedFiles[[2]], species) + runTestRDS(inc(runNum),"out_Gear_Catch", theTypeData, "Stepped", "AB", "AB", BaselineSteppedTables[[3]], CurrentSteppedFiles[[3]], species) + runTestRDS(inc(runNum),"out_Biomass", theTypeData, "Stepped", "RK4","RK4",BaselineSteppedTables[[4]], CurrentSteppedFiles[[4]], species) + runTestRDS(inc(runNum),"out_Catch", theTypeData, "Stepped", "RK4","RK4",BaselineSteppedTables[[5]], CurrentSteppedFiles[[5]], species) + runTestRDS(inc(runNum),"out_Gear_Catch", theTypeData, "Stepped", "RK4","RK4",BaselineSteppedTables[[6]], CurrentSteppedFiles[[6]], species) + } + } + } + + print("------------------ Forced Effort Tests (Jitter) ------------------") + numMonths <- nrow(REcosystem_scenario$fishing$ForcedEffort) + REcosystem_scenario_jitter <- REcosystem_scenario + fishingOriginalData <- list(REcosystem_scenario$fishing$ForcedEffort, REcosystem_scenario$fishing$ForcedFRate, REcosystem_scenario$fishing$ForcedCatch) + typeData <- list(FORCED_EFFORT,FORCED_FRATE,FORCED_CATCH) + for (i in 1:length(fishingOriginalData)) { + theTypeData <- typeData[[i]] + modNum <- modNum + 1 + if (theTypeData == FORCED_EFFORT) { + ForcedMatrix <- modifyFishingMatrix(modNum,species,fleets,theTypeData,fishingOriginalData[[i]], + REco.params$model,POSITIVE_AND_NEGATIVE) + REcosystem_scenario_jitter$fishing$ForcedEffort <- ForcedMatrix + BaselineJitterTables <- list(REcosystem_Baseline_AB_ForcedEff_OutBiomass_Jitter, REcosystem_Baseline_AB_ForcedEff_OutCatch_Jitter, REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Jitter, + REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Jitter,REcosystem_Baseline_RK4_ForcedEff_OutCatch_Jitter,REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Jitter) + BaselineJitterFiles <- list(BaselineABForcedEffOutBiomassJitter, BaselineABForcedEffOutCatchJitter, BaselineABForcedEffOutGearCatchJitter, + BaselineRK4ForcedEffOutBiomassJitter,BaselineRK4ForcedEffOutCatchJitter,BaselineRK4ForcedEffOutGearCatchJitter) + CurrentJitterFiles <- list(CurrentABForcedEffOutBiomassJitter, CurrentABForcedEffOutCatchJitter, CurrentABForcedEffOutGearCatchJitter, + CurrentRK4ForcedEffOutBiomassJitter, CurrentRK4ForcedEffOutCatchJitter, CurrentRK4ForcedEffOutGearCatchJitter) + } else if (theTypeData == FORCED_FRATE) { + ForcedMatrix <- modifyFishingMatrix(modNum,species,fleets,theTypeData,fishingOriginalData[[i]], + REco.params$model,POSITIVE_ONLY) + REcosystem_scenario_jitter$fishing$ForcedFRate <- ForcedMatrix + BaselineJitterTables <- list(REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Jitter, REcosystem_Baseline_AB_ForcedFRa_OutCatch_Jitter, REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Jitter, + REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Jitter,REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Jitter,REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Jitter) + BaselineJitterFiles <- list(BaselineABForcedFRaOutBiomassJitter, BaselineABForcedFRaOutCatchJitter, BaselineABForcedFRaOutGearCatchJitter, + BaselineRK4ForcedFRaOutBiomassJitter,BaselineRK4ForcedFRaOutCatchJitter,BaselineRK4ForcedFRaOutGearCatchJitter) + CurrentJitterFiles <- list(CurrentABForcedFRaOutBiomassJitter, CurrentABForcedFRaOutCatchJitter, CurrentABForcedFRaOutGearCatchJitter, + CurrentRK4ForcedFRaOutBiomassJitter, CurrentRK4ForcedFRaOutCatchJitter, CurrentRK4ForcedFRaOutGearCatchJitter) + } else if (theTypeData == FORCED_CATCH) { + ForcedMatrix <- modifyFishingMatrix(modNum,species,fleets,theTypeData,fishingOriginalData[[i]], + REco.params$model,POSITIVE_ONLY) + REcosystem_scenario_jitter$fishing$ForcedCatch <- ForcedMatrix + BaselineJitterTables <- list(REcosystem_Baseline_AB_ForcedCat_OutBiomass_Jitter, REcosystem_Baseline_AB_ForcedCat_OutCatch_Jitter, REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Jitter, + REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Jitter,REcosystem_Baseline_RK4_ForcedCat_OutCatch_Jitter,REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Jitter) + BaselineJitterFiles <- list(BaselineABForcedCatOutBiomassJitter, BaselineABForcedCatOutCatchJitter, BaselineABForcedCatOutGearCatchJitter, + BaselineRK4ForcedCatOutBiomassJitter,BaselineRK4ForcedCatOutCatchJitter,BaselineRK4ForcedCatOutGearCatchJitter) + CurrentJitterFiles <- list(CurrentABForcedCatOutBiomassJitter, CurrentABForcedCatOutCatchJitter, CurrentABForcedCatOutGearCatchJitter, + CurrentRK4ForcedCatOutBiomassJitter, CurrentRK4ForcedCatOutCatchJitter, CurrentRK4ForcedCatOutGearCatchJitter) + } + REcosystem_AB_Current_Jitter <- rsim.run(REcosystem_scenario_jitter,method='AB', years=1:50) + REcosystem_RK4_Current_Jitter <- rsim.run(REcosystem_scenario_jitter,method='RK4',years=1:50) + if (CREATE_BASELINE_FILES) { + writeDataFile(REcosystem_AB_Current_Jitter$out_Biomass, BaselineJitterFiles[[1]]) + writeDataFile(REcosystem_AB_Current_Jitter$out_Catch, BaselineJitterFiles[[2]]) + writeDataFile(REcosystem_AB_Current_Jitter$out_Gear_Catch, BaselineJitterFiles[[3]]) + writeDataFile(REcosystem_RK4_Current_Jitter$out_Biomass, BaselineJitterFiles[[4]]) + writeDataFile(REcosystem_RK4_Current_Jitter$out_Catch, BaselineJitterFiles[[5]]) + writeDataFile(REcosystem_RK4_Current_Jitter$out_Gear_Catch, BaselineJitterFiles[[6]]) + } else { + writeDataFile(REcosystem_AB_Current_Jitter$out_Biomass, CurrentJitterFiles[[1]]) + writeDataFile(REcosystem_AB_Current_Jitter$out_Catch, CurrentJitterFiles[[2]]) + writeDataFile(REcosystem_AB_Current_Jitter$out_Gear_Catch, CurrentJitterFiles[[3]]) + writeDataFile(REcosystem_RK4_Current_Jitter$out_Biomass, CurrentJitterFiles[[4]]) + writeDataFile(REcosystem_RK4_Current_Jitter$out_Catch, CurrentJitterFiles[[5]]) + writeDataFile(REcosystem_RK4_Current_Jitter$out_Gear_Catch, CurrentJitterFiles[[6]]) + runTestRDS(inc(runNum),"out_Biomass", theTypeData, "Random", "AB", "AB", BaselineJitterTables[[1]], CurrentJitterFiles[[1]], species) + runTestRDS(inc(runNum),"out_Catch", theTypeData, "Random", "AB", "AB", BaselineJitterTables[[2]], CurrentJitterFiles[[2]], species) + runTestRDS(inc(runNum),"out_Gear_Catch", theTypeData, "Random", "AB", "AB", BaselineJitterTables[[3]], CurrentJitterFiles[[3]], species) + runTestRDS(inc(runNum),"out_Biomass", theTypeData, "Random", "RK4","RK4", BaselineJitterTables[[4]], CurrentJitterFiles[[4]], species) + runTestRDS(inc(runNum),"out_Catch", theTypeData, "Random", "RK4","RK4", BaselineJitterTables[[5]], CurrentJitterFiles[[5]], species) + runTestRDS(inc(runNum),"out_Gear_Catch", theTypeData, "Random", "RK4","RK4", BaselineJitterTables[[6]], CurrentJitterFiles[[6]], species) + } + } + + + print("------------------ Forced Effort Tests (Stepped) ------------------") + numMonths <- nrow(REcosystem_scenario$fishing$ForcedEffort) + REcosystem_scenario_stepped <- REcosystem_scenario + fishingOriginalData <- list(REcosystem_scenario$fishing$ForcedEffort, + REcosystem_scenario$fishing$ForcedFRate, + REcosystem_scenario$fishing$ForcedCatch) + typeData <- list(FORCED_EFFORT,FORCED_FRATE,FORCED_CATCH) + for (i in 1:length(fishingOriginalData)) { + theTypeData <- typeData[[i]] + REcosystem_scenario_stepped <- REcosystem_scenario + if (theTypeData == FORCED_EFFORT) { + REcosystem_scenario_stepped$fishing$ForcedEffort <- stepifyMatrix(fishingOriginalData[[i]],fleets,0.1) + BaselineSteppedTables <- list(REcosystem_Baseline_AB_ForcedEff_OutBiomass_Stepped, REcosystem_Baseline_AB_ForcedEff_OutCatch_Stepped, REcosystem_Baseline_AB_ForcedEff_OutGearCatch_Stepped, + REcosystem_Baseline_RK4_ForcedEff_OutBiomass_Stepped, REcosystem_Baseline_RK4_ForcedEff_OutCatch_Stepped, REcosystem_Baseline_RK4_ForcedEff_OutGearCatch_Stepped) + BaselineSteppedFiles <- list(BaselineABForcedEffOutBiomassStepped, BaselineABForcedEffOutCatchStepped, BaselineABForcedEffOutGearCatchStepped, + BaselineRK4ForcedEffOutBiomassStepped,BaselineRK4ForcedEffOutCatchStepped,BaselineRK4ForcedEffOutGearCatchStepped) + CurrentSteppedFiles <- list(CurrentABForcedEffOutBiomassStepped, CurrentABForcedEffOutCatchStepped, CurrentABForcedEffOutGearCatchStepped, + CurrentRK4ForcedEffOutBiomassStepped, CurrentRK4ForcedEffOutCatchStepped, CurrentRK4ForcedEffOutGearCatchStepped) + } else if (theTypeData == FORCED_FRATE) { + + REcosystem_scenario_stepped$fishing$ForcedFRate <- stepifyMatrix(fishingOriginalData[[i]],species,0.01) + BaselineSteppedTables <- list(REcosystem_Baseline_AB_ForcedFRa_OutBiomass_Stepped, REcosystem_Baseline_AB_ForcedFRa_OutCatch_Stepped, REcosystem_Baseline_AB_ForcedFRa_OutGearCatch_Stepped, + REcosystem_Baseline_RK4_ForcedFRa_OutBiomass_Stepped, REcosystem_Baseline_RK4_ForcedFRa_OutCatch_Stepped, REcosystem_Baseline_RK4_ForcedFRa_OutGearCatch_Stepped) + BaselineSteppedFiles <- list(BaselineABForcedFRaOutBiomassStepped, BaselineABForcedFRaOutCatchStepped, BaselineABForcedFRaOutGearCatchStepped, + BaselineRK4ForcedFRaOutBiomassStepped,BaselineRK4ForcedFRaOutCatchStepped,BaselineRK4ForcedFRaOutGearCatchStepped) + CurrentSteppedFiles <- list(CurrentABForcedFRaOutBiomassStepped, CurrentABForcedFRaOutCatchStepped, CurrentABForcedFRaOutGearCatchStepped, + CurrentRK4ForcedFRaOutBiomassStepped, CurrentRK4ForcedFRaOutCatchStepped, CurrentRK4ForcedFRaOutGearCatchStepped) + } else if (theTypeData == FORCED_CATCH) { + # print("Forced Catch data: ") + # print(fishingOriginalData[[i]]) + # RSK - continue here + ForcedMatrix <- modifyFishingMatrix_constant(modNum,species,fleets,theTypeData,fishingOriginalData[[i]], + REco.params$model,POSITIVE_ONLY) + #REcosystem_scenario_stepped$fishing$ForcedCatch <- ForcedMatrix + REcosystem_scenario_stepped$fishing$ForcedCatch <- stepifyMatrix(ForcedMatrix,species,1) + BaselineSteppedTables <- list(REcosystem_Baseline_AB_ForcedCat_OutBiomass_Stepped, REcosystem_Baseline_AB_ForcedCat_OutCatch_Stepped, REcosystem_Baseline_AB_ForcedCat_OutGearCatch_Stepped, + REcosystem_Baseline_RK4_ForcedCat_OutBiomass_Stepped, REcosystem_Baseline_RK4_ForcedCat_OutCatch_Stepped, REcosystem_Baseline_RK4_ForcedCat_OutGearCatch_Stepped) + BaselineSteppedFiles <- list(BaselineABForcedCatOutBiomassStepped, BaselineABForcedCatOutCatchStepped, BaselineABForcedCatOutGearCatchStepped, + BaselineRK4ForcedCatOutBiomassStepped,BaselineRK4ForcedCatOutCatchStepped,BaselineRK4ForcedCatOutGearCatchStepped) + CurrentSteppedFiles <- list(CurrentABForcedCatOutBiomassStepped, CurrentABForcedCatOutCatchStepped, CurrentABForcedCatOutGearCatchStepped, + CurrentRK4ForcedCatOutBiomassStepped, CurrentRK4ForcedCatOutCatchStepped, CurrentRK4ForcedCatOutGearCatchStepped) + } + REcosystem_AB_Current_Stepped <- rsim.run(REcosystem_scenario_stepped,method='AB', years=1:50) + REcosystem_RK4_Current_Stepped <- rsim.run(REcosystem_scenario_stepped,method='RK4',years=1:50) + if (CREATE_BASELINE_FILES) { + writeDataFile(REcosystem_AB_Current_Stepped$out_Biomass, BaselineSteppedFiles[[1]]) + writeDataFile(REcosystem_AB_Current_Stepped$out_Catch, BaselineSteppedFiles[[2]]) + writeDataFile(REcosystem_AB_Current_Stepped$out_Gear_Catch, BaselineSteppedFiles[[3]]) + writeDataFile(REcosystem_RK4_Current_Stepped$out_Biomass, BaselineSteppedFiles[[4]]) + writeDataFile(REcosystem_RK4_Current_Stepped$out_Catch, BaselineSteppedFiles[[5]]) + writeDataFile(REcosystem_RK4_Current_Stepped$out_Gear_Catch, BaselineSteppedFiles[[6]]) + } else { + writeDataFile(REcosystem_AB_Current_Stepped$out_Biomass, CurrentSteppedFiles[[1]]) + writeDataFile(REcosystem_AB_Current_Stepped$out_Catch, CurrentSteppedFiles[[2]]) + writeDataFile(REcosystem_AB_Current_Stepped$out_Gear_Catch, CurrentSteppedFiles[[3]]) + writeDataFile(REcosystem_RK4_Current_Stepped$out_Biomass, CurrentSteppedFiles[[4]]) + writeDataFile(REcosystem_RK4_Current_Stepped$out_Catch, CurrentSteppedFiles[[5]]) + writeDataFile(REcosystem_RK4_Current_Stepped$out_Gear_Catch, CurrentSteppedFiles[[6]]) + if (0) { # debug later + runTestRDS(inc(runNum),"out_Biomass", theTypeData, "Stepped", "AB", "AB", BaselineSteppedTables[[1]], CurrentSteppedFiles[[1]], species) + runTestRDS(inc(runNum),"out_Catch", theTypeData, "Stepped", "AB", "AB", BaselineSteppedTables[[2]], CurrentSteppedFiles[[2]], species) + runTestRDS(inc(runNum),"out_Gear_Catch", theTypeData, "Stepped", "AB", "AB", BaselineSteppedTables[[3]], CurrentSteppedFiles[[3]], species) + runTestRDS(inc(runNum),"out_Biomass", theTypeData, "Stepped", "RK4", "RK4", BaselineSteppedTables[[4]], CurrentSteppedFiles[[4]], species) + runTestRDS(inc(runNum),"out_Catch", theTypeData, "Stepped", "RK4", "RK4", BaselineSteppedTables[[5]], CurrentSteppedFiles[[5]], species) + runTestRDS(inc(runNum),"out_Gear_Catch", theTypeData, "Stepped", "RK4", "RK4", BaselineSteppedTables[[6]], CurrentSteppedFiles[[6]], species) + } + } + } + + if (! CREATE_BASELINE_FILES) { + print(paste0("Completed ",inc(runNum)," test(s).")) + } + +}) diff --git a/tests/testthat/test-utils-jitter.R b/tests/testthat/test-utils-jitter.R new file mode 100644 index 00000000..6194d5d3 --- /dev/null +++ b/tests/testthat/test-utils-jitter.R @@ -0,0 +1,56 @@ +source("test-constants.R") + +#' Add Jitter (i.e., random noise) +#' +#' Adds random noise to the specified matrix. +#' +#' @param matrix : data matrix to be jittered +#' @param factor : the R jitter factor (the larger the number the greater the jitter amount) +#' @param seedOffset : offset to the seed value, useful for getting "groups" of seed values +#' @param xlabel : x axis label for plot +#' @param ylabel : y axis label for plot +#' @param title : main title for plot +#' +#' @return Returns the jittered matrix +#' +addJitter <- function(matrix,seedOffset,xlabel,ylabel,title) { + set.seed(seedOffset) # *SEED_VALUE) + # From jitter() doc: If amount == 0, jitter returns factor * z/50, where + # z = max(x0) - min(x), aka the range. So if factor=5 and amount=0, jitter() + # returns a random value within a tenth of the range. + + jitteredMatrix <- jitter(matrix,factor=FACTOR_VALUE,amount=NULL) + if (xlabel != '' && ylabel != '' & title != '') { + # plot(jitteredMatrix,type='l',lwd=5,xlab=xlabel,ylab=ylabel,main=title) + } + return(jitteredMatrix) +} + +#' Create a jittered vector +#' +#' Used for jittering a matrix column. Can't use replicate because need to pass a different seed for every value for reproducibility. +#' +#' @param value : value to add jitter to +#' @param numElements : number of elements in vector +#' @param seedOffset : offset to the main seed value +#' @param xlabel : x axis label for plot +#' @param ylabel : y axis label for plot +#' @param title : main title for plot +#' +#' @return Returns the column-jittered matrix +#' +createJitterVectorFromValue <- function(typeData,value,numElements,seedOffset,xlabel,ylabel,title,randomNumberType) { + jitterVector <- c() + migrationScaleFactor <- 1 + if (typeData == FORCED_MIGRATION) { + migrationScaleFactor = FORCED_MIGRATION_SCALE_FACTOR_JITTER # = 1000 + } + for (i in 1:numElements) { + # jitteredValue <- addJitter(value,seedOffset+i,'','','') + randVal <- randomNumber(seedOffset+i,migrationScaleFactor*JITTER_AMOUNT_PCT,randomNumberType) # JITTER_AMOUNT_PCT = 0.01 + jitteredValue <- value * (1.0 + randVal) + jitterVector <- append(jitterVector,jitteredValue) + } + # plot(jitterVector,type='l',lwd=5,xlab=xlabel,ylab=ylabel,main=title) + return(jitterVector) +} \ No newline at end of file diff --git a/tests/testthat/test-utils-plot.R b/tests/testthat/test-utils-plot.R new file mode 100644 index 00000000..ee5b244f --- /dev/null +++ b/tests/testthat/test-utils-plot.R @@ -0,0 +1,116 @@ +source("test-constants.R") + +#' Plot test results superimposed on the same plot +#' +#' Plot specific columns from that passed in matrices and plot them as groups of plots per page. +#' The plots will be of the baseline run and the current run plot superimposed on the same plot. +#' +#' @param BaseData : Baseline data to compare current data to +#' @param CurrData : Current data to compare against pre-run baseline data +#' @param baseAlg : The baseline algorithm used (currently AB or RK4) +#' @param currAlg : The current algorithm used (currently AB or RK4) +#' @param tableName : Table name used for the plot's title +#' @param forcedData : The data that's being forced (i.e., Biomass, Catch) +#' @param forcedType : The type of forcing being done (.e., Random (Jitter) or Stair-Stepped) +#' @param species : A vector of fish species +#' +#' @return Returns the final, combined plot +#' +plotResultsSuperimposed <- function(BaseData,CurrData,baseAlg,currAlg,tableName,forcedData,forcedType,species) { + plots <- list() + group <- species + yLabel <- "Biomass (mt/km²)" + currDf <- data.frame() + baseDf <- data.frame() + + for (member in group) { + xvalues <- c(1:length(CurrData[,member])) + numMonths <- length(CurrData[,member]) + currYvalues <- CurrData[,member] + baseYvalues <- BaseData[,member] + currDf <- data.frame(Legend=replicate(numMonths,paste0('Current ', currAlg)), xvalues,currYvalues) + baseDf <- data.frame(Legend=replicate(numMonths,paste0('Baseline ',baseAlg)), xvalues,baseYvalues) + + aPlot <- ggplot() + + geom_line(data=baseDf, aes(x=xvalues, y=baseYvalues, color=Legend)) + + geom_line(data=currDf, aes(x=xvalues, y=currYvalues, color=Legend)) + + labs(x="Months",y=yLabel, + title=paste0('Sim Run (',forcedData,' w/ ',forcedType,' Noise) - ',member), + subtitle=paste0("Dataset: ",tableName)) + + scale_color_manual(name="Legend:",values=c('red','darkblue')) + + theme( plot.title = element_text(hjust=0.5,size=7,face="bold"), + plot.subtitle = element_text(hjust=0.5,size=7), + axis.text = element_text(size=8), + axis.title = element_text(size=8), + legend.text = element_text(size=8), + legend.title = element_text(size=10), + legend.position='bottom', + legend.spacing.y = unit(0.0,'cm'), + legend.background = element_rect(fill='#f7f7f7'), + # legend.box.background = element_rect(color = 'black'), + plot.background = element_rect(color='black',fill=NA,linewidth=1) + ) + plots <- list.append(plots,aPlot) + + } + combinedPlot <- ggarrange(plotlist=plots,nrow=3,ncol=2) + # annotate_figure(combinedPlot, top = text_grob("Sample main title here", color = "red", face = "bold", size = 14)) + # saveWidget(ggplotly(combinedPlot), file = "Rplots.html"); + # print(ggplotly(combinedPlot)) + print(combinedPlot) +} + +#' Plot the difference of the two runs +#' +#' Plot specific columns from that passed in matrices and plot them as groups of plots per page. +#' The plots will be of the current run - baseline run. So if there's a perfect match, the plot should +#' be all zeros. +#' +#' @param BaseData : Baseline data to compare current data to +#' @param CurrData : Current data to compare against pre-run baseline data +#' @param baseAlg : The baseline algorithm used (currently AB or RK4) +#' @param currAlg : The current algorithm used (currently AB or RK4) +#' @param tableName : Table name used for the plot's title +#' @param forcedData : The data that's being forced (i.e., Biomass, Catch) +#' @param forcedType : The type of forcing being done (.e., Random (Jitter) or Stair-Stepped) +#' @param species : A vector of fish species +#' +#' @return Returns the final, combined plot +#' +plotResultsDifference <- function(BaseData,CurrData,baseAlg,currAlg,tableName,forcedData,forcedType,species) { + plots <- list() + group <- species + yLabel <- "Biomass (mt/km²)" + diffDf <- data.frame() + + for (member in group) { + xvalues <- c(1:length(CurrData[,member])) + numMonths <- length(CurrData[,member]) + currYvalues <- CurrData[,member] + baseYvalues <- BaseData[,member] + diffDf <- data.frame(Legend=replicate(numMonths,paste0('Current(',currAlg,')-Baseline(',baseAlg,') ')), xvalues,currYvalues-baseYvalues) + aPlot <- ggplot() + + geom_line(data=diffDf, aes(x=xvalues, y=currYvalues-baseYvalues, color=Legend)) + + labs(x="Months",y=yLabel, + title=paste0('Sim Run using ',forcedData,' with ',forcedType,' Noise - ',member), + subtitle=paste0("Dataset: ",tableName)) + + scale_color_manual(name="Legend:",values=c('darkblue')) + + coord_cartesian(ylim = c(-YLIMIT_DIFFERENCE_PLOTS, YLIMIT_DIFFERENCE_PLOTS)) + # RSK + theme( plot.title = element_text(hjust=0.5,size=7,face="bold"), + plot.subtitle = element_text(hjust=0.5,size=7), + axis.text = element_text(size=8), + axis.title = element_text(size=8), + legend.text = element_text(size=8), + legend.title = element_text(size=10), + legend.position='bottom', + legend.spacing.y = unit(0.0,'cm'), + legend.background = element_rect(fill='#f7f7f7'), + # legend.box.background = element_rect(color = 'black'), + plot.background = element_rect(color='black',fill=NA,linewidth=1) + ) + plots <- list.append(plots,aPlot) + } + combinedPlot <- ggarrange(plotlist=plots,ncol=1) + # annotate_figure(combinedPlot, top = text_grob("Sample main title here", color = "red", face = "bold", size = 14)) + print(combinedPlot) +} \ No newline at end of file diff --git a/tests/testthat/test-utils-stepify.R b/tests/testthat/test-utils-stepify.R new file mode 100644 index 00000000..c0c29485 --- /dev/null +++ b/tests/testthat/test-utils-stepify.R @@ -0,0 +1,119 @@ +source("test-constants.R") + +#' Get stepification steps +#' +#' This function returns the step offsets in order to give a function a stair-stepped pattern. +#' +#' @param type : The type of stair-stepped pattern. There are currently 3 types: 1 (mountain pattern), 2 (valley pattern), and 3 (mix of mountain and valley pattern) +#' +#' @return Returns a vector of stair-stepped offsets +#' +getSteps <- function(type=1) { + STEPS_WIDTH <- 0.1 # approx. +/- 10% of initial value + steps = c() + tog <- -1 + min <- 1.0 + # max <- if (type == 2 || type == 3) 0.5 else 2.0 + max <- if (type == 2 || type == 3) (1.0-STEPS_WIDTH) else (1.0+STEPS_WIDTH) + if (is.even(NUMBER_OF_STEPS)) { + NUMBER_OF_STEPS <- NUMBER_OF_STEPS + 1 + } + halfway <- NUMBER_OF_STEPS %/% 2 + increment <- (max-min)/halfway + + for (i in 1:NUMBER_OF_STEPS) { + if (i <= halfway+1) { + inc <- increment + start <- min + ii <- i-1 + } else { + inc <- -increment + start <- max-inc + ii <- i-halfway + } + tog <- if (type == 3) -tog else 1.0 + steps[i] <- abs(start + tog*ii*inc) + } + return(steps) +} + +#' Stepify Effort +#' +#' This function stepifies a vector of effort data. Stepification consists of modifying (i.e., multiplying) the +#' vector data in question by a series of constant values (i.e., steps). Plotting these steps +#' shows a stair-stepped function of various forms based upon the passed type. Type 1 = mountain +#' shape, Type 2 = valley shape, Type 3 = mixed shape. +#' +#' @param effort : vector effort data +#' @param type : type of "stepification" +#' +#' @return Returns the "stepped" vector data +#' +stepifyVector <- function(vectorData,type=1, stepFactor) { + steps <- getSteps(type) + numMonths <- length(vectorData) + incMonths <- numMonths/ NUMBER_OF_STEPS; + inc <- 0 + for (i in 1:NUMBER_OF_STEPS) { + start <- inc + 1 + start <- if (start == 0) 1 else start + end <- inc+incMonths + vectorData[start:end] <- vectorData[start:end] * steps[i] * stepFactor + inc <- inc + incMonths + } + return(vectorData) +} + +#' Stepify a Matrix +#' +#' This function sequences through the appropriately named columns and calls stepifyVector +#' to stepify those columns. +#' +#' @family Rpath functions +#' +#' @param forcedEffortMatrix : matrix in which specific columns will be "stepified" +#' @param memberNames : vector of either species or fleet names +#' +#' @return Returns the updated forced effort matrix +#' +stepifyMatrix <- function(forcedEffortMatrix,memberNames,stepFactor) { + ForcedMatrix <- forcedEffortMatrix + for (i in 1:length(memberNames)) { + memberName <- memberNames[i] + memberCol <- ForcedMatrix[,memberName] + memberStepped <- stepifyVector(memberCol,i,stepFactor) + ForcedMatrix[,memberName] <- memberStepped + # plot(memberStepped,type='l',lwd=5,xlab="Months",ylab="Effort",main=paste0("Forced Effort with Stepped Noise - ",memberName)) + } + return(ForcedMatrix) +} + + +#' Stepify Biomass +#' +#' Takes as input a biomass value and stepifies the value by dividing the number of months +#' by the number of steps desired and multiplying each interval by a different step value. +#' +#' @param value : value to stepify across months +#' @param numMonths : number of months in model +#' @param type : type of stepification desired (1, 2, or 3) +#' @param xlabel : x axis label for plot +#' @param ylabel : y axis label for plot +#' @param title : title for plot +#' +#' @return Returns the vector of stepified segments +#' +stepifyBiomass <- function(typeData, value,numMonths,type=1,xlabel,ylabel,title, scaleFactor) { + steps <- getSteps(type) + incMonths <- numMonths / NUMBER_OF_STEPS; + parts <- c() + if (typeData == FORCED_MIGRATION) { + value <- scaleFactor*value + } + for (i in 1:NUMBER_OF_STEPS) { + part <- replicate(incMonths, steps[i]*value) + parts <- c(parts,part) + } + # plot(parts,type='l',lwd=5,xlab=xlabel,ylab=ylabel,main=title) + return(parts) +} \ No newline at end of file diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R new file mode 100644 index 00000000..ea6301d4 --- /dev/null +++ b/tests/testthat/test-utils.R @@ -0,0 +1,238 @@ +source("test-constants.R") + +#' Random number generator +#' +#' This function returns a seeded random number from a uniform distribution between +#' a min and max value. +#' +#' @param seed : the random "seed" value to make the function deterministic +#' +#' @return Returns the random value +#' +randomNumber <- function(seed,pctToJitter,positiveOnly) { + set.seed(seed) + minJitter <- -pctToJitter + maxJitter <- pctToJitter + if (positiveOnly) { + minJitter <- 0 + } + rval <- runif(1,min=minJitter,max=maxJitter) # [1] + # print(paste0("rval: ",rval)) + return(rval) +} + +#' An increment function +#' +#' This function increments a number by 1 +#' +#' @param value : the number to increment by 1 +#' +#' @return Returns the incremented value +#' +inc <- function(value) eval.parent(substitute(value <- value + 1)) + +#' Read the passed data file +#' +#' This function reads a data file (either a data table or an rds file) +#' +#' @param filename : the file to read in +#' @param fill : boolean to fill blanks with 0's +#' @param sep : the separator used in the file +#' +#' @return Returns the read in file +#' +readDataFile <- function(filename,fill=TRUE,sep="") { + readRDS(filename) + # read.table(filename,fill=fill,sep=sep) +} + +#' Write out the passed data file +#' +#' This function writes out a data file (either a data table or an rds file) +#' +#' @param object : the object to write out (i.e., serialize) +#' @param filename : the name of the output file to write +#' +#' @return None +#' +writeDataFile <- function(object,filename) { + saveRDS(object,file=filename) + # write.table(object,file=filename) +} + +#' Print scenario statistics +#' +#' Print some statistics from the current scenario +#' +#' @param msg : message header +#' @param scenario : object resulting from current Rpath run +#' +#' @return None +#' +printStatsScenario <- function(msg,scenario) { + print("- - -") + print(paste0(msg,", forcing$ForcedBio: ",sum(scenario$forcing$ForcedBio))) + print(paste0(msg,", forcing$ForcedMigrate: ",sum(scenario$forcing$ForcedMigrate))) + print(paste0(msg,", start_state$Biomass: ",sum(scenario$start_state$Biomass))) +} + +#' Print simulation statistics +#' +#' Print some statistics from the current simulation +#' +#' @param msg : message header +#' @param sim : object resulting from last Rpath simulation run +#' +#' @return None +#' +printStatsSimulation <- function(msg,sim) { + print("- - -") + print(paste0(msg,", sim$out_Biomass: ",sum(sim$out_Biomass))) + print(paste0(msg,", sim$out_Catch: ",sum(sim$out_Catch))) + print(paste0(msg,", sim$out_Gear_Catch: ",sum(sim$out_Gear_Catch))) +} + +#' Modify a scenario$fishing matrix +#' +#' Modifies the appropriate columns from a scenario$fishing matrix. +#' +#' @param species : A vector of fish species +#' @param fleets : A vector of fleets +#' @param typeData : The type of forced data (i.e., Forced Effort, Forced FRate, Forced Catch) +#' @param forcingData : The forced data matrix +#' +#' @return Returns a matrix that's been updated withe the forced data +#' +modifyFishingMatrix <- function(modNum,species,fleets,typeData,forcingData,model,randomNumberType) { + group <- model$Group + pb <- model$PB + ForcedMatrix <- forcingData + speciesOrFleets <- c() + const1 <- 1 + const2 <- 1 + upperLimit <- 0.5 + usePBValue <- FALSE + scaleFactorPB <- 0.01 # Needed this to add enough randomness to the plots, else they'd be fairly smooth + if (typeData == "Forced Effort") { + speciesOrFleets <- fleets + } else if (typeData == "Forced FRate" || typeData == "Forced Catch") { + speciesOrFleets <- species + const1 <- 0 + usePBValue <- TRUE + } else { + print(paste0("Error: Found invalid typeData of: ",typeData)) + return(ForcedMatrix) + } + index <- match(speciesOrFleets,group) + if (usePBValue) { + const2 <- scaleFactorPB*pb[index] + } + + j <- 0 + for (i in 1:length(speciesOrFleets)) { + item <- speciesOrFleets[i] + vectorData <- ForcedMatrix[,item] + # matrixDataWithJitter <- addJitter(matrixData,modNum*SEED_OFFSET*SEED_VALUE+i,"Months","Effort",paste0(typeData," with Random Noise - ",item)) + newVectorWithJitter <- c() + for (value in vectorData) { + j <- j + 1 + # Not sure why I need the [1] index here, this should always be just a single value but sometimes it's a list + # Forced Effort: jitteredValue <- (randomNumber(i+j,0.5))[1] + # Forced FRate: pb[species index]*randomNumber(i+j,0.5))[1] + jitteredValue <- (const1+const2*randomNumber(i+j,upperLimit,randomNumberType))[1] + newVectorWithJitter = append(newVectorWithJitter,jitteredValue) + } + ForcedMatrix[,item] <- newVectorWithJitter + } + return(ForcedMatrix) +} + +modifyFishingMatrix_constant <- function(modNum,species,fleets,typeData,forcingData,model,randomNumberType) { + group <- model$Group + pb <- model$PB + ForcedMatrix <- forcingData + speciesOrFleets <- c() + const1 <- 1 + const2 <- 1 + upperLimit <- 0.5 + usePBValue <- FALSE + scaleFactorPB <- 0.01 # Needed this to add enough randomness to the plots, else they'd be fairly smooth + if (typeData == "Forced Effort") { + speciesOrFleets <- fleets + } else if (typeData == "Forced FRate" || typeData == "Forced Catch") { + speciesOrFleets <- species + const1 <- 0 + usePBValue <- TRUE + } else { + print(paste0("Error: Found invalid typeData of: ",typeData)) + return(ForcedMatrix) + } + index <- match(speciesOrFleets,group) + if (usePBValue) { + const2 <- scaleFactorPB*pb[index] + } + + j <- 0 + for (i in 1:length(speciesOrFleets)) { + item <- speciesOrFleets[i] + vectorData <- ForcedMatrix[,item] + # matrixDataWithJitter <- addJitter(matrixData,modNum*SEED_OFFSET*SEED_VALUE+i,"Months","Effort",paste0(typeData," with Random Noise - ",item)) + newVectorWithJitter <- c() + for (value in vectorData) { + j <- 1 # this should give a constant random value throughout the entire vector + # Not sure why I need the [1] index here, this should always be just a single value but sometimes it's a list + # Forced Effort: jitteredValue <- (randomNumber(i+j,0.5))[1] + # Forced FRate: pb[species index]*randomNumber(i+j,0.5))[1] + jitteredValue <- (const1+const2*randomNumber(i+j,upperLimit,randomNumberType))[1] + newVectorWithJitter = append(newVectorWithJitter,jitteredValue) + } + ForcedMatrix[,item] <- newVectorWithJitter + } + return(ForcedMatrix) +} + + +#' Modify a scenario$forcing matrix +#' +#' Modifies the appropriate columns from a scenario$forcing matrix. +#' +#' @param species : A vector of fish species +#' @param modifyType : The type of modification (i.e., Jittered or Stepped) +#' @param typeData : The type of forced data (i.e., Forced Bio, Forced Migrate) +#' @param forcingData : The forced data matrix +#' @param scenario : The REcosystem_scenario object +#' +#' @return Returns a matrix that's been updated withe the forced data +#' +modifyForcingMatrix <- function (modNum,species,modifyType,typeData,forcingData,scenario,randomNumberType) { + ForcedMatrix <- forcingData + numMonths <- nrow(ForcedMatrix) + scaleFactors <- c(100,50,200,300,10000) + scaleFactors <- c(.6,.6,.6,.6,.6) + if ((typeData == FORCED_BIOMASS) || (typeData == FORCED_MIGRATION)) { + for (i in 1:length(species)) { + aSpecies <- species[[i]] + speciesBiomass <- scenario$start_state$Biomass[aSpecies] + startValue <- speciesBiomass + if (typeData == FORCED_MIGRATION) { + # rval <- (randomNumber(i,FORCED_MIGRATION_BIOMASS_PCT)+FORCED_MIGRATION_BIOMASS_PCT)/2.0 + rval <- randomNumber(i,FORCED_MIGRATION_BIOMASS_PCT,randomNumberType) + startValue <- rval + #print(paste0("species: ",aSpecies,", biomass: ",speciesBiomass,", randomNum: ",rval,", startValue: ",startValue)) + } + # print(paste0(modNum," ",i," ",SEED_OFFSET," ",aSpecies)) + if (modifyType == JITTERED) { + # print(paste0("start value: ",i,", ",startValue)) + ForcedMatrix[,aSpecies] <- createJitterVectorFromValue(typeData, startValue, numMonths, modNum*i*SEED_OFFSET, + "Months","Biomass (mt/km²)", + paste0(typeData,' with ',modifyType,' Noise - ',aSpecies), + POSITIVE_AND_NEGATIVE) + } else { + stepType <- ((i-1)%%3)+1 # Only current step types are 1, 2, or 3 + ForcedMatrix[,aSpecies] <- stepifyBiomass(typeData, startValue, numMonths, stepType, "Months","Biomass (mt/km²)", + paste0(typeData,' with ',modifyType,' Noise - ',aSpecies), scaleFactors[i]) + } + } + } + return(ForcedMatrix) +} diff --git a/testthat b/testthat new file mode 120000 index 00000000..4e01ea1f --- /dev/null +++ b/testthat @@ -0,0 +1 @@ +tests/testthat \ No newline at end of file diff --git a/vignettes/ModelSetup.Rmd b/vignettes/ModelSetup.Rmd new file mode 100644 index 00000000..b710ef19 --- /dev/null +++ b/vignettes/ModelSetup.Rmd @@ -0,0 +1,297 @@ +--- +title: "Set up a food web model" +author: "Vignette Author" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Set up a food web model} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r setup, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + + +## Setting up a food web model + +First, install Rpath as instructed in [Getting Started](). R package `data.table` is also required to run the code in this article. + +```{r rpath load} +library(Rpath); library(data.table) +``` + + +### Parameter file generation +Unlike the GUI based EwE software package, Rpath relies on a parameter input file. +This file is actually a list of several different parameter files: model, diet, +stanzas, and pedigree. Parameter files can be created outside of R and read in using +the `read.rpath.params` function. This function will merge several different flat +files into an R object of the list type. A preferred alternative is to generate +the list file and populate it completely within R. The function +`create.rpath.params` will generate an Rpath.param. This ensures that all +of the correct columns are present in the parameter file. + +The parameter file contains all of the information you would normally enter in the +input data tabs in EwE. There are 2 necessary pieces of information to generate +the parameter file: the group names and their corresponding type. The types are: +living = 0, primary producer = 1, detritus = 2, and fleet = 3. If your model +contains multi-stanza groups then you need 2 additional pieces of information: +stanza group names (include NA for those groups not in a stanza) and the number of +stanzas per stanza group. + +```{r groups} +#Groups and types for the R Ecosystem + +groups <- c('Seabirds', 'Whales', 'Seals', 'JuvRoundfish1', 'AduRoundfish1', + 'JuvRoundfish2', 'AduRoundfish2', 'JuvFlatfish1', 'AduFlatfish1', + 'JuvFlatfish2', 'AduFlatfish2', 'OtherGroundfish', 'Foragefish1', + 'Foragefish2', 'OtherForagefish', 'Megabenthos', 'Shellfish', + 'Macrobenthos', 'Zooplankton', 'Phytoplankton', 'Detritus', + 'Discards', 'Trawlers', 'Midwater', 'Dredgers') + +types <- c(rep(0, 19), 1, rep(2, 2), rep(3, 3)) + +stgroups <- c(rep(NA, 3), rep('Roundfish1', 2), rep('Roundfish2', 2), + rep('Flatfish1', 2), rep('Flatfish2', 2), rep(NA, 14)) + +REco.params <- create.rpath.params(group = groups, type = types, stgroup = stgroups) +``` + +REco.params now contains a list of 4 objects: model, diet, stanzas, and pedigree. +The majority of the parameters are populated with NA save those that have logical +default vaules (i.e 0.66667 for VBGF_d). + +### Model parameters +The model parameter list contains the biomass, production to biomass, consumption to +biomass, etc. parameters as well as the detrital fate parameters and fleet landings and +discards. + +```{r blank modfile table, echo=FALSE, results='asis'} +knitr::kable(REco.params$model, caption = 'Example of the model list created using the + `create.rpath.param` function') +``` + +Each of the parameter lists are data tables (With the exception of the stanzas list +which is itself a list of an integer and two data tables). Data tables are an +extension of the classic data frame class. Advantages of data tables include +simplified indexing which eases the process of populating the parameters. For example +you can add data to a specific slot or fill an entire column. + +```{r How to fill} +#Example of filling specific slots +REco.params$model[Group %in% c('Seals', 'Megabenthos'), EE := 0.8] + +#Example of filling an entire column +biomass <- c(0.0149, 0.454, NA, NA, 1.39, NA, 5.553, NA, 5.766, NA, + 0.739, 7.4, 5.1, 4.7, 5.1, NA, 7, 17.4, 23, 10, rep(NA, 5)) +REco.params$model[, Biomass := biomass] + +``` + +Note the use of the operator ':=' to assign values. This is unique to data tables. + +```{r Model Table partial, echo = F} +knitr::kable(REco.params$model[, list(Group, Type, Biomass, EE)], + caption = 'Example of assigning a specific slot or a whole column') + +``` + +Here are the rest of the columns for the model list. +```{r Model Table sans stanzas} +#Model +biomass <- c(0.0149, 0.454, NA, NA, 1.39, NA, 5.553, NA, 5.766, NA, + 0.739, 7.4, 5.1, 4.7, 5.1, NA, 7, 17.4, 23, 10, rep(NA, 5)) + +pb <- c(0.098, 0.031, 0.100, 2.026, 0.42, 2.1, 0.425, 1.5, 0.26, 1.1, 0.18, 0.6, + 0.61, 0.65, 1.5, 0.9, 1.3, 7, 39, 240, rep(NA, 5)) + +qb <- c(76.750, 6.976, 34.455, NA, 2.19, NA, 3.78, NA, 1.44, NA, 1.69, + 1.764, 3.52, 5.65, 3.6, 2.984, rep (NA, 9)) + +REco.params$model[, Biomass := biomass] +REco.params$model[, PB := pb] +REco.params$model[, QB := qb] + +#EE for groups w/o biomass +REco.params$model[Group %in% c('Seals', 'Megabenthos'), EE := 0.8] + +#Production to Consumption for those groups without a QB +REco.params$model[Group %in% c('Shellfish', 'Zooplankton'), ProdCons:= 0.25] +REco.params$model[Group == 'Macrobenthos', ProdCons := 0.35] + +#Biomass accumulation and unassimilated consumption +REco.params$model[, BioAcc := c(rep(0, 22), rep(NA, 3))] +REco.params$model[, Unassim := c(rep(0.2, 18), 0.4, rep(0, 3), rep(NA, 3))] + +#Detrital Fate +REco.params$model[, Detritus := c(rep(1, 20), rep(0, 5))] +REco.params$model[, Discards := c(rep(0, 22), rep(1, 3))] + +#Fisheries +#Landings +trawl <- c(rep(0, 4), 0.08, 0, 0.32, 0, 0.09, 0, 0.05, 0.2, rep(0, 10), rep(NA, 3)) +mid <- c(rep(0, 12), 0.3, 0.08, 0.02, rep(0, 7), rep(NA, 3)) +dredge <- c(rep(0, 15), 0.1, 0.5, rep(0, 5), rep(NA, 3)) +REco.params$model[, Trawlers := trawl] +REco.params$model[, Midwater := mid] +REco.params$model[, Dredgers := dredge] + +#Discards +trawl.d <- c(1e-5, 1e-7, 0.001, 0.001, 0.005, 0.001, 0.009, 0.001, 0.04, 0.001, + 0.01, 0.08, 0.001, 0.001, 0.001, rep(0, 7), rep(NA, 3)) +mid.d <- c(rep(0, 2), 0.001, 0.001, 0.01, 0.001, 0.01, rep(0, 4), 0.05, 0.05, + 0.01, 0.01, rep(0, 7), rep(NA, 3)) +dredge.d <- c(rep(0, 3), 0.001, 0.05, 0.001, 0.05, 0.001, 0.05, 0.001, 0.01, 0.05, + rep(0, 3), 0.09, 0.01, 1e-4, rep(0, 4), rep(NA, 3)) +REco.params$model[, Trawlers.disc := trawl.d] +REco.params$model[, Midwater.disc := mid.d] +REco.params$model[, Dredgers.disc := dredge.d] +``` + +```{r Model Table final, echo = F} +knitr::kable(REco.params$model, + caption = 'Example of completed model list') + +``` + +###Stanza Parameters +You may have noticed that the biomass and consumption to biomass parameters are +missing from some of the multistanza groups. Similar to EwE, Rpath calculates those +parameters to ensure that stanza groups support one another (Christensen and Walters +2004^[Christensen and Walters. 2004. Ecopath with Ecosim: methods, capabilities and +limitations. Ecological Modelling 172:109-139]). In order to do this, you need to +populate the stanza list. As mentioned earlier, this is actually a list itself +containing 3 things: the number of stanza groups, stanza group parameters, and +individual stanza parameters. The number of stanzas is automatically populated. For +stanza groups you need their von Bertalanffy growth function specialized K and weight at +50% maturity divided by their weight infinity (relative weight at maturity). Individual +stanzas need the first and last month the species is in the stanza, the total mortality +(Z) on the stanza, and whether or not it is the leading stanza. + +```{r Stanza parameters} +#Group parameters +REco.params$stanzas$stgroups[, VBGF_Ksp := c(0.145, 0.295, 0.0761, 0.112)] +REco.params$stanzas$stgroups[, Wmat := c(0.0769, 0.561, 0.117, 0.321)] + +#Individual stanza parameters +REco.params$stanzas$stindiv[, First := c(rep(c(0, 24), 3), 0, 48)] +REco.params$stanzas$stindiv[, Last := c(rep(c(23, 400), 3), 47, 400)] +REco.params$stanzas$stindiv[, Z := c(2.026, 0.42, 2.1, 0.425, 1.5, + 0.26, 1.1, 0.18)] +REco.params$stanzas$stindiv[, Leading := rep(c(F, T), 4)] + +``` +```{r Stanza Table initial, echo = F} +knitr::kable(REco.params$stanzas$stgroups) +knitr::kable(REco.params$stanzas$stindiv) +``` + +The final month of the ultimate stanza can be set to any value. The function +`rpath.stanzas` will calculate the final month as the point where the species reaches +90% Winf. The function `rpath.stanzas` will also add data tables containing the weight, number, and consumption at age for each stanza group. + +```{r rpath.stanzas} +REco.params <- rpath.stanzas(REco.params) +``` +```{r Stanza Table final, echo = F} +knitr::kable(REco.params$stanzas$stanzas, caption = 'Completed stanzas table') +knitr::kable(head(REco.params$stanzas$StGroup[[1]]), + caption = 'Example of the StGroup data table') +``` + +Output from the `rpath.stanzas` function can be plotted using the `stanzaplot` +function. +```{r stanzaplot, fig.align = 'center', fig.height = 5, fig.width = 9} +stanzaplot(REco.params, StanzaGroup = 1) +``` +Note: If you do not have multistanza groups in your model, you do not have to run +`rpath.stanzas`. + +###Diet Parameters +The data entered in the diet list is the same as the data entered in the +diet composition tab in EwE. Just as within EwE, the columns +represent the predators while the rows represent the prey. Individual diet components +can be adjusted by specifying the prey in the 'Group' variable and assigning a value to +the predator. For example, if you wanted to assign 10% of the seabird diet as 'Other Groundfish' you could do it like this: + +```{r how to fill diet 1} +REco.params$diet[Group == 'OtherGroundfish', Seabirds := 0.1] +``` + +You can also assign the entire diet composition for a predator: + +```{r how to fill diet 2} +whale.diet <- c(rep(NA, 3), 0.01, NA, 0.01, NA, 0.01, NA, 0.01, rep(NA, 4), 0.1, + rep(NA, 3), 0.86, rep(NA, 3), NA) +REco.params$diet[, Whales := whale.diet] +``` +```{r Dietfile table partial, echo = F} +knitr::kable(REco.params$diet[, list(Group, Seabirds, Whales)]) +``` + +Here is the completed model parameter file for R Ecosystem: + +```{r diet fill} +REco.params$diet[, Seabirds := c(rep(NA, 11), 0.1, 0.25, 0.2, 0.15, + rep(NA, 6), 0.3, NA)] +REco.params$diet[, Whales := c(rep(NA, 3), 0.01, NA, 0.01, NA, 0.01, + NA, 0.01, rep(NA, 4), 0.1, rep(NA, 3), + 0.86, rep(NA, 3), NA)] +REco.params$diet[, Seals := c(rep(NA, 3), 0.05, 0.1, 0.05, 0.2, 0.005, + 0.05, 0.005, 0.01, 0.24, rep(0.05, 4), + 0.09, rep(NA, 5), NA)] +REco.params$diet[, JuvRoundfish1 := c(rep(NA, 3), rep(c(1e-4, NA), 4), 1e-3, + rep(NA, 2), 0.05, 1e-4, NA, .02, 0.7785, + 0.1, 0.05, NA, NA)] +REco.params$diet[, AduRoundfish1 := c(rep(NA, 5), 1e-3, 0.01, 1e-3, 0.05, 1e-3, + 0.01, 0.29, 0.1, 0.1, 0.347, 0.03, NA, + 0.05, 0.01, rep(NA, 3), NA)] +REco.params$diet[, JuvRoundfish2 := c(rep(NA, 3), rep(c(1e-4, NA), 4), 1e-3, + rep(NA, 2), 0.05, 1e-4, NA, .02, 0.7785, + 0.1, .05, NA, NA)] +REco.params$diet[, AduRoundfish2 := c(rep(NA, 3), 1e-4, NA, 1e-4, NA, rep(1e-4, 4), + 0.1, rep(0.05, 3), 0.2684, 0.01, 0.37, 0.001, + NA, 0.1, NA, NA)] +REco.params$diet[, JuvFlatfish1 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 3), + rep(1e-4, 2), NA, 0.416, 0.4334, 0.1, 0.05, + NA, NA)] +REco.params$diet[, AduFlatfish1 := c(rep(NA, 7), rep(1e-4, 5), rep(NA, 2), 0.001, + 0.05, 0.001, 0.6, 0.2475, NA, 0.1, NA, NA)] +REco.params$diet[, JuvFlatfish2 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 3), + rep(1e-4, 2), NA, 0.416, 0.4334, 0.1, 0.05, + NA, NA)] +REco.params$diet[, AduFlatfish2 := c(rep(NA, 7), 1e-4, NA, 1e-4, rep(NA, 4), + rep(1e-4, 3), 0.44, 0.3895, NA, 0.17, NA, NA)] +REco.params$diet[, OtherGroundfish := c(rep(NA, 3), rep(1e-4, 8), 0.05, 0.08, 0.0992, + 0.3, 0.15, 0.01, 0.3, 0.01, rep(NA, 3), NA)] +REco.params$diet[, Foragefish1 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 7), + 0.8196, 0.06, 0.12, NA, NA)] +REco.params$diet[, Foragefish2 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 7), + 0.8196, 0.06, 0.12, NA, NA)] +REco.params$diet[, OtherForagefish := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 7), + 0.8196, 0.06, 0.12, NA, NA)] +REco.params$diet[, Megabenthos := c(rep(NA, 15), 0.1, 0.03, 0.55, rep(NA, 2), 0.32, + NA, NA)] +REco.params$diet[, Shellfish := c(rep(NA, 18), 0.3, 0.5, 0.2, NA, NA)] +REco.params$diet[, Macrobenthos := c(rep(NA, 16), 0.01, rep(0.2, 2), NA, 0.59, NA, NA)] +REco.params$diet[, Zooplankton := c(rep(NA, 18), 0.2, 0.6, 0.2, NA, NA)] +``` +```{r Dietfile Table, echo = F} +knitr::kable(REco.params$diet, caption = 'Diet parameters for R Ecosystem') +``` + +###Pedigree parameters +Rpath does not currently use pedigrees however, future Rpath extensions will use +them. Therefore we include them in the current parameter object. The +default values are 1 (low confidence). These defaults are not changed for R +Ecosystem but can obviously be changed in a similar manner to the other parameter +files. +```{r pedigree table, echo = F} +knitr::kable(REco.params$pedigree, caption = 'Pedigree parameters for R Ecosystem') +``` + diff --git a/vignettes/Rpath.Rmd b/vignettes/Rpath.Rmd index 2d4535f9..139176e5 100644 --- a/vignettes/Rpath.Rmd +++ b/vignettes/Rpath.Rmd @@ -1,353 +1,33 @@ --- -title: "Rpath using R Ecosystem" +title: "Rpath: an open source food web model" author: "Sean M. Lucey" date: "`r Sys.Date()`" output: rmarkdown::html_vignette +csl: "ices-journal-of-marine-science.csl" +bibliography: references.bib +link-citations: yes +urlcolor: blue vignette: > - %\VignetteIndexEntry{Rpath using R Ecosystem} + %\VignetteIndexEntry{Getting Started} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- -Rpath is an implementation of the ecosystem model Ecopath with Ecosim (EwE; -Christensen and Pauly 1992^[Christensen and Pauly. 1992. ECOPATH II - a software -for balancing steady-state models and calculating network characteristics. -Ecological Modelling 61:169-85], Walters et al. 1997^[Walters et al. 1997. -Structuring dynamic models of exploited ecosystems from trophic mass-balance -assessments. Reviews of Fish Biology and Fisheries 7:1-34]). This vignette -describes some of the basic functionality of the package using a fictional -ecosystem, R Ecosystem. Any resemblance to an actual ecosystem is purely -coincidental. To see the underlying mathematics please refer to Lucey et al. -(in prep^[Lucey et al. in prep. Improving the EBFM toolbox with an alternative -open source version of Ecopath with Ecosim]). +Rpath is an implementation of the ecosystem model Ecopath with Ecosim (EwE; @polovina_model_1984; @christensen_ecopath_1992; @walters_structuring_1997; @christensen_ecopath_2004; @walters_fisheries_2004; @walters_ecosim_2008). -```{r rpath load, echo = F} -knitr::opts_chunk$set( - comment = '#>', - collapse = T) -library(Rpath); library(data.table) -``` +Articles for [model setup](articles/ModelSetup.html), [running Rpath](articles/RunRpath.html) and [running Rsim](articles/RunRsim.html) describe some of the basic functionality of the package using a fictional ecosystem, R Ecosystem. Any resemblance to an actual ecosystem is purely coincidental. -## Setting up Ecopath +To see the underlying mathematics please refer to @lucey_conducting_2020. For additional features, see @whitehouse_assessing_2020 for ecosense and @lucey_evaluating_2021 for management strategy evaluation capability. -### Parameter file generation -Unlike the GUI based EwE software package, Rpath relies on a parameter input file. -This file is actually a list of several different parameter files: model, diet, -stanzas, and pedigree. Parameter files can be created outside of R and read in using -the `read.rpath.params` function. This function will merge several different flat -files into an R object of the list type. A preferred alternative is to generate -the list file and populate it completely within R. The function -`create.rpath.params` will generate an Rpath.param. This ensures that all -of the correct columns are present in the parameter file. +# Installation -The parameter file contains all of the information you would normally enter in the -input data tabs in EwE. There are 2 necessary pieces of information to generate -the parameter file: the group names and their corresponding type. The types are: -living = 0, primary producer = 1, detritus = 2, and fleet = 3. If your model -contains multi-stanza groups then you need 2 additional pieces of information: -stanza group names (include NA for those groups not in a stanza) and the number of -stanzas per stanza group. +If necessary, first install the `remotes` package: `install.packages("remotes")` -```{r groups} -#Groups and types for the R Ecosystem - -groups <- c('Seabirds', 'Whales', 'Seals', 'JuvRoundfish1', 'AduRoundfish1', - 'JuvRoundfish2', 'AduRoundfish2', 'JuvFlatfish1', 'AduFlatfish1', - 'JuvFlatfish2', 'AduFlatfish2', 'OtherGroundfish', 'Foragefish1', - 'Foragefish2', 'OtherForagefish', 'Megabenthos', 'Shellfish', - 'Macrobenthos', 'Zooplankton', 'Phytoplankton', 'Detritus', - 'Discards', 'Trawlers', 'Midwater', 'Dredgers') - -types <- c(rep(0, 19), 1, rep(2, 2), rep(3, 3)) - -stgroups <- c(rep(NA, 3), rep('Roundfish1', 2), rep('Roundfish2', 2), - rep('Flatfish1', 2), rep('Flatfish2', 2), rep(NA, 14)) - -REco.params <- create.rpath.params(group = groups, type = types, stgroup = stgroups) -``` - -REco.params now contains a list of 4 objects: model, diet, stanzas, and pedigree. -The majority of the parameters are populated with NA save those that have logical -default vaules (i.e 0.66667 for VBGF_d). - -### Model parameters -The model parameter list contains the biomass, production to biomass, consumption to -biomass, etc. parameters as well as the detrital fate parameters and fleet landings and -discards. - -```{r blank modfile table, echo=FALSE, results='asis'} -knitr::kable(REco.params$model, caption = 'Example of the model list created using the - `create.rpath.param` function') -``` - -Each of the parameter lists are data tables (With the exception of the stanzas list -which is itself a list of an integer and two data tables). Data tables are an -extension of the classic data frame class. Advantages of data tables include -simplified indexing which eases the process of populating the parameters. For example -you can add data to a specific slot or fill an entire column. - -```{r How to fill} -#Example of filling specific slots -REco.params$model[Group %in% c('Seals', 'Megabenthos'), EE := 0.8] - -#Example of filling an entire column -biomass <- c(0.0149, 0.454, NA, NA, 1.39, NA, 5.553, NA, 5.766, NA, - 0.739, 7.4, 5.1, 4.7, 5.1, NA, 7, 17.4, 23, 10, rep(NA, 5)) -REco.params$model[, Biomass := biomass] - -``` - -Note the use of the operator ':=' to assign values. This is unique to data tables. - -```{r Model Table partial, echo = F} -knitr::kable(REco.params$model[, list(Group, Type, Biomass, EE)], - caption = 'Example of assigning a specific slot or a whole column') - -``` - -Here are the rest of the columns for the model list. -```{r Model Table sans stanzas} -#Model -biomass <- c(0.0149, 0.454, NA, NA, 1.39, NA, 5.553, NA, 5.766, NA, - 0.739, 7.4, 5.1, 4.7, 5.1, NA, 7, 17.4, 23, 10, rep(NA, 5)) - -pb <- c(0.098, 0.031, 0.100, 2.026, 0.42, 2.1, 0.425, 1.5, 0.26, 1.1, 0.18, 0.6, - 0.61, 0.65, 1.5, 0.9, 1.3, 7, 39, 240, rep(NA, 5)) - -qb <- c(76.750, 6.976, 34.455, NA, 2.19, NA, 3.78, NA, 1.44, NA, 1.69, - 1.764, 3.52, 5.65, 3.6, 2.984, rep (NA, 9)) - -REco.params$model[, Biomass := biomass] -REco.params$model[, PB := pb] -REco.params$model[, QB := qb] - -#EE for groups w/o biomass -REco.params$model[Group %in% c('Seals', 'Megabenthos'), EE := 0.8] - -#Production to Consumption for those groups without a QB -REco.params$model[Group %in% c('Shellfish', 'Zooplankton'), ProdCons:= 0.25] -REco.params$model[Group == 'Macrobenthos', ProdCons := 0.35] - -#Biomass accumulation and unassimilated consumption -REco.params$model[, BioAcc := c(rep(0, 22), rep(NA, 3))] -REco.params$model[, Unassim := c(rep(0.2, 18), 0.4, rep(0, 3), rep(NA, 3))] - -#Detrital Fate -REco.params$model[, Detritus := c(rep(1, 20), rep(0, 5))] -REco.params$model[, Discards := c(rep(0, 22), rep(1, 3))] - -#Fisheries -#Landings -trawl <- c(rep(0, 4), 0.08, 0, 0.32, 0, 0.09, 0, 0.05, 0.2, rep(0, 10), rep(NA, 3)) -mid <- c(rep(0, 12), 0.3, 0.08, 0.02, rep(0, 7), rep(NA, 3)) -dredge <- c(rep(0, 15), 0.1, 0.5, rep(0, 5), rep(NA, 3)) -REco.params$model[, Trawlers := trawl] -REco.params$model[, Midwater := mid] -REco.params$model[, Dredgers := dredge] - -#Discards -trawl.d <- c(1e-5, 1e-7, 0.001, 0.001, 0.005, 0.001, 0.009, 0.001, 0.04, 0.001, - 0.01, 0.08, 0.001, 0.001, 0.001, rep(0, 7), rep(NA, 3)) -mid.d <- c(rep(0, 2), 0.001, 0.001, 0.01, 0.001, 0.01, rep(0, 4), 0.05, 0.05, - 0.01, 0.01, rep(0, 7), rep(NA, 3)) -dredge.d <- c(rep(0, 3), 0.001, 0.05, 0.001, 0.05, 0.001, 0.05, 0.001, 0.01, 0.05, - rep(0, 3), 0.09, 0.01, 1e-4, rep(0, 4), rep(NA, 3)) -REco.params$model[, Trawlers.disc := trawl.d] -REco.params$model[, Midwater.disc := mid.d] -REco.params$model[, Dredgers.disc := dredge.d] -``` - -```{r Model Table final, echo = F} -knitr::kable(REco.params$model, - caption = 'Example of completed model list') - -``` - -###Stanza Parameters -You may have noticed that the biomass and consumption to biomass parameters are -missing from some of the multistanza groups. Similar to EwE, Rpath calculates those -parameters to ensure that stanza groups support one another (Christensen and Walters -2004^[Christensen and Walters. 2004. Ecopath with Ecosim: methods, capabilities and -limitations. Ecological Modelling 172:109-139]). In order to do this, you need to -populate the stanza list. As mentioned earlier, this is actually a list itself -containing 3 things: the number of stanza groups, stanza group parameters, and -individual stanza parameters. The number of stanzas is automatically populated. For -stanza groups you need their von Bertalanffy growth function specialized K and weight at -50% maturity divided by their weight infinity (relative weight at maturity). Individual -stanzas need the first and last month the species is in the stanza, the total mortality -(Z) on the stanza, and whether or not it is the leading stanza. - -```{r Stanza parameters} -#Group parameters -REco.params$stanzas$stgroups[, VBGF_Ksp := c(0.145, 0.295, 0.0761, 0.112)] -REco.params$stanzas$stgroups[, Wmat := c(0.0769, 0.561, 0.117, 0.321)] - -#Individual stanza parameters -REco.params$stanzas$stindiv[, First := c(rep(c(0, 24), 3), 0, 48)] -REco.params$stanzas$stindiv[, Last := c(rep(c(23, 400), 3), 47, 400)] -REco.params$stanzas$stindiv[, Z := c(2.026, 0.42, 2.1, 0.425, 1.5, - 0.26, 1.1, 0.18)] -REco.params$stanzas$stindiv[, Leading := rep(c(F, T), 4)] - -``` -```{r Stanza Table initial, echo = F} -knitr::kable(REco.params$stanzas$stgroups) -knitr::kable(REco.params$stanzas$stindiv) -``` - -The final month of the ultimate stanza can be set to any value. The function -`rpath.stanzas` will calculate the final month as the point where the species reaches -90% Winf. The function `rpath.stanzas` will also add data tables containing the weight, number, and consumption at age for each stanza group. - -```{r rpath.stanzas} -REco.params <- rpath.stanzas(REco.params) -``` -```{r Stanza Table final, echo = F} -knitr::kable(REco.params$stanzas$stanzas, caption = 'Completed stanzas table') -knitr::kable(head(REco.params$stanzas$StGroup[[1]]), - caption = 'Example of the StGroup data table') -``` - -Output from the `rpath.stanzas` function can be plotted using the `stanzaplot` -function. -```{r stanzaplot, fig.align = 'center', fig.height = 5, fig.width = 9} -stanzaplot(REco.params, StanzaGroup = 1) -``` -Note: If you do not have multistanza groups in your model, you do not have to run -`rpath.stanzas`. - -###Diet Parameters -The data entered in the diet list is the same as the data entered in the -diet composition tab in EwE. Just as within EwE, the columns -represent the predators while the rows represent the prey. Individual diet components -can be adjusted by specifying the prey in the 'Group' variable and assigning a value to -the predator. For example, if you wanted to assign 10% of the seabird diet as 'Other Groundfish' you could do it like this: - -```{r how to fill diet 1} -REco.params$diet[Group == 'OtherGroundfish', Seabirds := 0.1] -``` - -You can also assign the entire diet composition for a predator: - -```{r how to fill diet 2} -whale.diet <- c(rep(NA, 3), 0.01, NA, 0.01, NA, 0.01, NA, 0.01, rep(NA, 4), 0.1, - rep(NA, 3), 0.86, rep(NA, 3), NA) -REco.params$diet[, Whales := whale.diet] -``` -```{r Dietfile table partial, echo = F} -knitr::kable(REco.params$diet[, list(Group, Seabirds, Whales)]) -``` - -Here is the completed model parameter file for R Ecosystem: - -```{r diet fill} -REco.params$diet[, Seabirds := c(rep(NA, 11), 0.1, 0.25, 0.2, 0.15, - rep(NA, 6), 0.3, NA)] -REco.params$diet[, Whales := c(rep(NA, 3), 0.01, NA, 0.01, NA, 0.01, - NA, 0.01, rep(NA, 4), 0.1, rep(NA, 3), - 0.86, rep(NA, 3), NA)] -REco.params$diet[, Seals := c(rep(NA, 3), 0.05, 0.1, 0.05, 0.2, 0.005, - 0.05, 0.005, 0.01, 0.24, rep(0.05, 4), - 0.09, rep(NA, 5), NA)] -REco.params$diet[, JuvRoundfish1 := c(rep(NA, 3), rep(c(1e-4, NA), 4), 1e-3, - rep(NA, 2), 0.05, 1e-4, NA, .02, 0.7785, - 0.1, 0.05, NA, NA)] -REco.params$diet[, AduRoundfish1 := c(rep(NA, 5), 1e-3, 0.01, 1e-3, 0.05, 1e-3, - 0.01, 0.29, 0.1, 0.1, 0.347, 0.03, NA, - 0.05, 0.01, rep(NA, 3), NA)] -REco.params$diet[, JuvRoundfish2 := c(rep(NA, 3), rep(c(1e-4, NA), 4), 1e-3, - rep(NA, 2), 0.05, 1e-4, NA, .02, 0.7785, - 0.1, .05, NA, NA)] -REco.params$diet[, AduRoundfish2 := c(rep(NA, 3), 1e-4, NA, 1e-4, NA, rep(1e-4, 4), - 0.1, rep(0.05, 3), 0.2684, 0.01, 0.37, 0.001, - NA, 0.1, NA, NA)] -REco.params$diet[, JuvFlatfish1 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 3), - rep(1e-4, 2), NA, 0.416, 0.4334, 0.1, 0.05, - NA, NA)] -REco.params$diet[, AduFlatfish1 := c(rep(NA, 7), rep(1e-4, 5), rep(NA, 2), 0.001, - 0.05, 0.001, 0.6, 0.2475, NA, 0.1, NA, NA)] -REco.params$diet[, JuvFlatfish2 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 3), - rep(1e-4, 2), NA, 0.416, 0.4334, 0.1, 0.05, - NA, NA)] -REco.params$diet[, AduFlatfish2 := c(rep(NA, 7), 1e-4, NA, 1e-4, rep(NA, 4), - rep(1e-4, 3), 0.44, 0.3895, NA, 0.17, NA, NA)] -REco.params$diet[, OtherGroundfish := c(rep(NA, 3), rep(1e-4, 8), 0.05, 0.08, 0.0992, - 0.3, 0.15, 0.01, 0.3, 0.01, rep(NA, 3), NA)] -REco.params$diet[, Foragefish1 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 7), - 0.8196, 0.06, 0.12, NA, NA)] -REco.params$diet[, Foragefish2 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 7), - 0.8196, 0.06, 0.12, NA, NA)] -REco.params$diet[, OtherForagefish := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 7), - 0.8196, 0.06, 0.12, NA, NA)] -REco.params$diet[, Megabenthos := c(rep(NA, 15), 0.1, 0.03, 0.55, rep(NA, 2), 0.32, - NA, NA)] -REco.params$diet[, Shellfish := c(rep(NA, 18), 0.3, 0.5, 0.2, NA, NA)] -REco.params$diet[, Macrobenthos := c(rep(NA, 16), 0.01, rep(0.2, 2), NA, 0.59, NA, NA)] -REco.params$diet[, Zooplankton := c(rep(NA, 18), 0.2, 0.6, 0.2, NA, NA)] -``` -```{r Dietfile Table, echo = F} -knitr::kable(REco.params$diet, caption = 'Diet parameters for R Ecosystem') -``` - -###Pedigree parameters -Rpath does not currently use pedigrees however, future Rpath extensions will use -them. Therefore we include them in the current parameter object. The -default values are 1 (low confidence). These defaults are not changed for R -Ecosystem but can obviously be changed in a similar manner to the other parameter -files. -```{r pedigree table, echo = F} -knitr::kable(REco.params$pedigree, caption = 'Pedigree parameters for R Ecosystem') -``` - -## Running Ecopath - -After creating the parameter object, running ecopath in R is relatively -straightforward. It is just the function `rpath` supplied with the parameter object. -Additionally, you can supply an ecosystem name for the output. - -```{r Running ecopath} -REco <- rpath(REco.params, eco.name = 'R Ecosystem') -REco -``` - -The output object from `rpath` is an S3 object type called 'Rpath'. Rpath objects -are a list of parameters from the mass balance. However, the `print` function will -display the same information as the "Basic Estimates" tab from EwE. You will also -notice that the `print` function will display whether the model is balanced or not. -If the model was not balanced, it would list the groups that are not balanced. - -You can also display the mortalities associated with each group by supplying the -argument `morts = T` to the `print` function. - -```{r Ecopath morts} -print(REco, morts = T) -``` - -Note that if you wish to save the `print` output you need to use the function -`write.rpath`. This function will also accept the argument 'morts = T'. - -The generic function `summary` will display some summary statistics on the model -as well as a list of attributes you can access. To access any of the other -attributes simply use the standard list notation. - -```{r Ecopath summaries} -summary(REco) -REco$TL -``` - -One of the advantages of R is its graphical ability. Users can feel free to develop -their own graphical routines for the Rpath outputs. However, we have included -a basic food web plot. The routine can include fisheries, display group numbers or -names, and even highlight a particular group. - -```{r Food Web Plots, fig.align = 'center', fig.height = 7, fig.width = 7} -webplot(REco) -webplot(REco, labels = T) -webplot(REco, fleets = T, highlight = 'AduRoundfish1') -``` +Use the command `remotes::install_github("noaa-edab/Rpath",build_vignettes=TRUE)` to install Rpath. +# References diff --git a/vignettes/RunRpath.Rmd b/vignettes/RunRpath.Rmd new file mode 100644 index 00000000..c5bc7b64 --- /dev/null +++ b/vignettes/RunRpath.Rmd @@ -0,0 +1,193 @@ +--- +title: "Create a static food web model in Rpath" +author: "Vignette Author" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Running Rpath} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- + +```{r setup, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +library(Rpath); library(data.table) +``` + +## Running Rpath + +```{r creating Rpath object, echo = F} +#Groups and types for the R Ecosystem + +groups <- c('Seabirds', 'Whales', 'Seals', 'JuvRoundfish1', 'AduRoundfish1', + 'JuvRoundfish2', 'AduRoundfish2', 'JuvFlatfish1', 'AduFlatfish1', + 'JuvFlatfish2', 'AduFlatfish2', 'OtherGroundfish', 'Foragefish1', + 'Foragefish2', 'OtherForagefish', 'Megabenthos', 'Shellfish', + 'Macrobenthos', 'Zooplankton', 'Phytoplankton', 'Detritus', + 'Discards', 'Trawlers', 'Midwater', 'Dredgers') + +types <- c(rep(0, 19), 1, rep(2, 2), rep(3, 3)) + +stgroups <- c(rep(NA, 3), rep('Roundfish1', 2), rep('Roundfish2', 2), + rep('Flatfish1', 2), rep('Flatfish2', 2), rep(NA, 14)) + +REco.params <- create.rpath.params(group = groups, type = types, stgroup = stgroups) + +#Model +biomass <- c(0.0149, 0.454, NA, NA, 1.39, NA, 5.553, NA, 5.766, NA, + 0.739, 7.4, 5.1, 4.7, 5.1, NA, 7, 17.4, 23, 10, rep(NA, 5)) + +pb <- c(0.098, 0.031, 0.100, 2.026, 0.42, 2.1, 0.425, 1.5, 0.26, 1.1, 0.18, 0.6, + 0.61, 0.65, 1.5, 0.9, 1.3, 7, 39, 240, rep(NA, 5)) + +qb <- c(76.750, 6.976, 34.455, NA, 2.19, NA, 3.78, NA, 1.44, NA, 1.69, + 1.764, 3.52, 5.65, 3.6, 2.984, rep (NA, 9)) + +REco.params$model[, Biomass := biomass] +REco.params$model[, PB := pb] +REco.params$model[, QB := qb] + +#EE for groups w/o biomass +REco.params$model[Group %in% c('Seals', 'Megabenthos'), EE := 0.8] + +#Production to Consumption for those groups without a QB +REco.params$model[Group %in% c('Shellfish', 'Zooplankton'), ProdCons:= 0.25] +REco.params$model[Group == 'Macrobenthos', ProdCons := 0.35] + +#Biomass accumulation and unassimilated production +REco.params$model[, BioAcc := c(rep(0, 22), rep(NA, 3))] +REco.params$model[, Unassim := c(rep(0.2, 18), 0.4, rep(0, 3), rep(NA, 3))] + +#Detrital Fate +REco.params$model[, Detritus := c(rep(1, 20), rep(0, 5))] +REco.params$model[, Discards := c(rep(0, 22), rep(1, 3))] + +#Fisheries +#Landings +trawl <- c(rep(0, 4), 0.08, 0, 0.32, 0, 0.09, 0, 0.05, 0.2, rep(0, 10), rep(NA, 3)) +mid <- c(rep(0, 12), 0.3, 0.08, 0.02, rep(0, 7), rep(NA, 3)) +dredge <- c(rep(0, 15), 0.1, 0.5, rep(0, 5), rep(NA, 3)) +REco.params$model[, Trawlers := trawl] +REco.params$model[, Midwater := mid] +REco.params$model[, Dredgers := dredge] + +#Discards +trawl.d <- c(1e-5, 1e-7, 0.001, 0.001, 0.005, 0.001, 0.009, 0.001, 0.04, 0.001, + 0.01, 0.08, 0.001, 0.001, 0.001, rep(0, 7), rep(NA, 3)) +mid.d <- c(rep(0, 2), 0.001, 0.001, 0.01, 0.001, 0.01, rep(0, 4), 0.05, 0.05, + 0.01, 0.01, rep(0, 7), rep(NA, 3)) +dredge.d <- c(rep(0, 3), 0.001, 0.05, 0.001, 0.05, 0.001, 0.05, 0.001, 0.01, 0.05, + rep(0, 3), 0.09, 0.01, 1e-4, rep(0, 4), rep(NA, 3)) +REco.params$model[, Trawlers.disc := trawl.d] +REco.params$model[, Midwater.disc := mid.d] +REco.params$model[, Dredgers.disc := dredge.d] + +#Group parameters +REco.params$stanzas$stgroups[, VBGF_Ksp := c(0.145, 0.295, 0.0761, 0.112)] +REco.params$stanzas$stgroups[, Wmat := c(0.0769, 0.561, 0.117, 0.321)] + +#Individual stanza parameters +REco.params$stanzas$stindiv[, First := c(rep(c(0, 24), 3), 0, 48)] +REco.params$stanzas$stindiv[, Last := c(rep(c(23, 400), 3), 47, 400)] +REco.params$stanzas$stindiv[, Z := c(2.026, 0.42, 2.1, 0.425, 1.5, + 0.26, 1.1, 0.18)] +REco.params$stanzas$stindiv[, Leading := rep(c(F, T), 4)] + +REco.params <- rpath.stanzas(REco.params) + +#Diets +REco.params$diet[, Seabirds := c(rep(NA, 11), 0.1, 0.25, 0.2, 0.15, + rep(NA, 6), 0.3, NA)] +REco.params$diet[, Whales := c(rep(NA, 3), 0.01, NA, 0.01, NA, 0.01, + NA, 0.01, rep(NA, 4), 0.1, rep(NA, 3), + 0.86, rep(NA, 4))] +REco.params$diet[, Seals := c(rep(NA, 3), 0.05, 0.1, 0.05, 0.2, 0.005, + 0.05, 0.005, 0.01, 0.24, rep(0.05, 4), + 0.09, rep(NA, 6))] +REco.params$diet[, JuvRoundfish1 := c(rep(NA, 3), rep(c(1e-4, NA), 4), 1e-3, + rep(NA, 2), 0.05, 1e-4, NA, .02, 0.7785, + 0.1, 0.05, NA, NA)] +REco.params$diet[, AduRoundfish1 := c(rep(NA, 5), 1e-3, 0.01, 1e-3, 0.05, 1e-3, + 0.01, 0.29, 0.1, 0.1, 0.347, 0.03, NA, + 0.05, 0.01, rep(NA, 4))] +REco.params$diet[, JuvRoundfish2 := c(rep(NA, 3), rep(c(1e-4, NA), 4), 1e-3, + rep(NA, 2), 0.05, 1e-4, NA, .02, 0.7785, + 0.1, .05, NA, NA)] +REco.params$diet[, AduRoundfish2 := c(rep(NA, 3), 1e-4, NA, 1e-4, NA, rep(1e-4, 4), + 0.1, rep(0.05, 3), 0.2684, 0.01, 0.37, 0.001, + NA, 0.1, NA, NA)] +REco.params$diet[, JuvFlatfish1 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 3), + rep(1e-4, 2), NA, 0.416, 0.4334, 0.1, 0.05, + NA, NA)] +REco.params$diet[, AduFlatfish1 := c(rep(NA, 7), rep(1e-4, 5), rep(NA, 2), 0.001, + 0.05, 0.001, 0.6, 0.2475, NA, 0.1, NA, NA)] +REco.params$diet[, JuvFlatfish2 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 3), + rep(1e-4, 2), NA, 0.416, 0.4334, 0.1, 0.05, + NA, NA)] +REco.params$diet[, AduFlatfish2 := c(rep(NA, 7), 1e-4, NA, 1e-4, rep(NA, 4), + rep(1e-4, 3), 0.44, 0.3895, NA, 0.17, NA, NA)] +REco.params$diet[, OtherGroundfish := c(rep(NA, 3), rep(1e-4, 8), 0.05, 0.08, 0.0992, + 0.3, 0.15, 0.01, 0.3, 0.01, rep(NA, 4))] +REco.params$diet[, Foragefish1 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 7), + 0.8196, 0.06, 0.12, NA, NA)] +REco.params$diet[, Foragefish2 := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 7), + 0.8196, 0.06, 0.12, NA, NA)] +REco.params$diet[, OtherForagefish := c(rep(NA, 3), rep(c(1e-4, NA), 4), rep(NA, 7), + 0.8196, 0.06, 0.12, NA, NA)] +REco.params$diet[, Megabenthos := c(rep(NA, 15), 0.1, 0.03, 0.55, rep(NA, 2), 0.32, + NA, NA)] +REco.params$diet[, Shellfish := c(rep(NA, 18), 0.3, 0.5, 0.2, NA, NA)] +REco.params$diet[, Macrobenthos := c(rep(NA, 16), 0.01, rep(0.2, 2), NA, 0.59, NA, NA)] +REco.params$diet[, Zooplankton := c(rep(NA, 18), 0.2, 0.6, 0.2, NA, NA)] + +REco <- rpath(REco.params, eco.name = 'R Ecosystem') +``` + +After creating the parameter object, running ecopath in R is relatively +straightforward. It is just the function `rpath` supplied with the parameter object. +Additionally, you can supply an ecosystem name for the output. + +```{r Running ecopath} +REco <- rpath(REco.params, eco.name = 'R Ecosystem') +REco +``` + +The output object from `rpath` is an S3 object type called 'Rpath'. Rpath objects +are a list of parameters from the mass balance. However, the `print` function will +display the same information as the "Basic Estimates" tab from EwE. You will also +notice that the `print` function will display whether the model is balanced or not. +If the model was not balanced, it would list the groups that are not balanced. + +You can also display the mortalities associated with each group by supplying the +argument `morts = T` to the `print` function. + +```{r Ecopath morts} +print(REco, morts = T) +``` + +Note that if you wish to save the `print` output you need to use the function +`write.rpath`. This function will also accept the argument 'morts = T'. + +The generic function `summary` will display some summary statistics on the model +as well as a list of attributes you can access. To access any of the other +attributes simply use the standard list notation. + +```{r Ecopath summaries} +summary(REco) +REco$TL +``` + +One of the advantages of R is its graphical ability. Users can feel free to develop +their own graphical routines for the Rpath outputs. However, we have included +a basic food web plot. The routine can include fisheries, display group numbers or +names, and even highlight a particular group. + +```{r Food Web Plots, fig.align = 'center', fig.height = 7, fig.width = 7} +webplot(REco) +webplot(REco, labels = T) +webplot(REco, fleets = T, highlight = 'AduRoundfish1') +``` + diff --git a/vignettes/Rsim.Rmd b/vignettes/RunRsim.Rmd similarity index 91% rename from vignettes/Rsim.Rmd rename to vignettes/RunRsim.Rmd index 5620a0dd..7685ffa3 100644 --- a/vignettes/Rsim.Rmd +++ b/vignettes/RunRsim.Rmd @@ -1,5 +1,5 @@ --- -title: "Rsim using R Ecosystem" +title: "Run a dynamic food web simulation in Rsim" author: "Sean M. Lucey" date: "`r Sys.Date()`" output: rmarkdown::html_vignette @@ -9,18 +9,6 @@ vignette: > %\VignetteEncoding{UTF-8} --- -Rpath is an implementation of the ecosystem model Ecopath with Ecosim (EwE; -Christensen and Pauly 1992^[Christensen and Pauly. 1992. ECOPATH II - a software -for balancing steady-state models and calculating network characteristics. -Ecological Modelling 61:169-85], Walters et al. 1997^[Walters et al. 1997. -Structuring dynamic models of exploited ecosystems from trophic mass-balance -assessments. Reviews of Fish Biology and Fisheries 7:1-34]). This vignette -describes some of the basic functionality of the package using a fictional -ecosystem, R Ecosystem. Any resemblance to an actual ecosystem is purely -coincidental. To see the underlying mathematics please refer to Lucey et al. -(in prep^[Lucey et al. in prep. Improving the EBFM toolbox with an alternative -open source version of Ecopath with Ecosim]). - ```{r rpath load, echo = F} knitr::opts_chunk$set( comment = '#>', @@ -30,8 +18,8 @@ library(Rpath); library(data.table) ## Running rsim -Rsim is the ecosim implementation of the EwE code in R. In order to procede you -must have a valid Rpath object. The steps for setting this up are discribed in +Rsim is the ecosim implementation of the EwE code in R. In order to proceed you +must have a valid Rpath object. The steps for setting this up are described in the vignette "Rpath using R Ecosystem". ```{r creating Rpath object, echo = F} diff --git a/vignettes/UnitTests.Rmd b/vignettes/UnitTests.Rmd new file mode 100644 index 00000000..36d11997 --- /dev/null +++ b/vignettes/UnitTests.Rmd @@ -0,0 +1,220 @@ +--- +title: "Unit Tests" +author: "Ron Klasky" +date: "`r Sys.Date()`" +output: rmarkdown::html_vignette +vignette: > + %\VignetteIndexEntry{Unit Tests} + %\VignetteEngine{knitr::rmarkdown} + %\VignetteEncoding{UTF-8} +--- +Source: ```vignettes/UnitTests.Rmd``` +```{r setup, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>" +) +``` + +## Unit Tests + +Unit Tests are written using the testthat R package. The tests are stored in the file: **tests/tests_rpath.R**. They may be run explicitly by the user clicking the Test or Check buttons under the Build tab in RStudio. They also run automatically via git actions when the user does a push or pull request. The output of the unit tests is a pdf file with a variety of comparison plots, examples of which are given below in Figures 1-3. + +## Details + +Unit Tests consist of comparing a "current" model value (i.e., string, table) to a previously stored "baseline" value. Differences are shown in the testing output as well as reflected in the generated plots which are written to: **Rplots.pdf**. Difference "tolerances" are defined by the variable: + +```{r Tolerance} +TOLERANCE <- 1e-5 +``` + +which can be modified as necessary. + +### Regenerating Baseline Files + +If the user needs to regenerate the baseline files, the following variable should be set to TRUE and the tests re-run manually (by clicking the Test button under the Build tab). This will regenerate all of the baseline data files. + +```{r Create Baseline 1} +CREATE_BASELINE_FILES <- TRUE +``` + +After the baseline files have been generated, the user should reset the variable back: + +```{r Create Baseline 2} +CREATE_BASELINE_FILES <- FALSE +``` + +## List of Tests + +The following unit tests have been developed. Note that some tests consist of additional/finer tests that compare out_Biomass, out_Catch, and out_Gear_Catch* for AB (Adams-Bashforth) and RK4 (4th Order Runge Kutta) numerical differential equation methods. + +### Unit Tests + +
Is model balanced? +1. Looks for "Balanced" string in Rpath summary file output +
+ +
Does model run silent? +2. Tests if model runs without producing print statements, warnings, or error messages. +
+ +
Compare Rpath summaries +3. Is the baseline Rpath object the same as the current Rpath object? +
+ +
Compare Rpath summaries +4. Is the baseline Rpath summary the same as the current Rpath summary? +
+ +
Compare baseline AB sim run to current AB sim run +5. Checks if baseline Rpath AB sim run is same as current AB sim run (checks top level data structure only)
+6. Compare out_Biomass from baseline and current AB sim runs
+7. Compare out_Catch from baseline and current AB sim runs
+8. Compare out_Gear_Catch from baseline and current AB sim runs
+
+ +
Compare baseline RK4 sim run to current RK4 sim run +9. Checks if baseline RK4 sim run same as current RK4 sim run (checks top level data structure only)
+10. Compare out_Biomass from baseline and current RK4 sim runs
+11. Compare out_Catch from baseline and current RK4 sim runs
+12. Compare out_Gear_Catch from baseline and current RK4 sim runs
+
+ +
Compare baseline AB sim run to current RK4 sim run +13. Checks if baseline AB sim run same as current RK4 sim run (checks top level data structure only)
+14. Compare out_Biomass from baseline AB run and current RK4 sim run
+15. Compare out_Catch from baseline AB run and current RK4 sim run
+16. Compare out_Gear_Catch from baseline AB run and current RK4 sim run
+
+ +
Compare sim runs with random noise (i.e., jitter) added to \$forcing\$ForcedBio +17. Compare out_Biomass from baseline AB run and current AB run with noise added to ForcedBio
+18. Compare out_Catch from baseline AB run and current AB run with noise added to ForcedBio
+19. Compare out_Gear_Catch from baseline AB run and current AB run with noise added to ForcedBio
+20. Compare out_Biomass from baseline RK4 run and current RK4 run with noise added to ForcedBio
+21. Compare out_Catch from baseline RK4 run and current RK4 run with noise added to ForcedBio
+22. Compare out_Gear_Catch from baseline RK4 run and current RK4 run with noise added to ForcedBio
+
+ +
Compare sim runs with random noise (i.e., jitter) added to \$forcing\$ForcedMigrate +23. Compare out_Biomass from baseline AB run and current AB run with noise added to ForcedMigrate
+24. Compare out_Catch from baseline AB run and current AB run with noise added to ForcedMigrate
+25. Compare out_Gear_Catch from baseline AB run and current AB run with noise added to ForcedMigrate
+26. Compare out_Biomass from baseline RK4 run and current RK4 run with noise added to ForcedMigrate
+27. Compare out_Catch from baseline RK4 run and current RK4 run with noise added to ForcedMigrate
+28. Compare out_Gear_Catch from baseline RK4 run and current RK4 run with noise added to ForcedMigrate
+
+ +
Compare sim runs with stepped noise added to \$forcing\$ForcedBio +29. Compare out_Biomass from baseline AB run and current AB run with stepped noise added to ForcedBio
+30. Compare out_Catch from baseline AB run and current AB run with stepped noise added to ForcedBio
+31. Compare out_Gear_Catch from baseline AB run and current AB run with stepped noise added to ForcedBio
+32. Compare out_Biomass from baseline RK4 run and current RK4 run with stepped noise added to ForcedBio
+33. Compare out_Catch from baseline RK4 run and current RK4 run with stepped noise added to ForcedBio
+34. Compare out_Gear_Catch from baseline RK4 run and current RK4 run with stepped noise added to ForcedBio
+
+ +
Compare sim runs with stepped noise added to \$forcing\$ForcedMigrate +35. Compare out_Biomass from baseline AB run and current AB run with stepped noise added to ForcedMigrate
+36. Compare out_Catch from baseline AB run and current AB run with stepped noise added to ForcedMigrate
+37. Compare out_Gear_Catch from baseline AB run and current AB run with stepped noise added to ForcedMigrate
+38. Compare out_Biomass from baseline RK4 run and current RK4 run with stepped noise added to ForcedMigrate
+39. Compare out_Catch from baseline RK4 run and current RK4 run with stepped noise added to ForcedMigrate
+40. Compare out_Gear_Catch from baseline RK4 run and current RK4 run with stepped noise added to ForcedMigrate
+
+ +
Compare sim runs with random noise (i.e., jitter) added to \$fishing\$ForcedEffort +41. Compare out_Biomass from baseline AB run and current AB run with noise added to ForcedEffort
+42. Compare out_Catch from baseline AB run and current AB run with noise added to ForcedEffort
+43. Compare out_Gear_Catch from baseline AB run and current AB run with noise added to ForcedEffort
+44. Compare out_Biomass from baseline RK4 run and current RK4 run with noise added to ForcedEffort
+45. Compare out_Catch from baseline RK4 run and current RK4 run with noise added to ForcedEffort
+46. Compare out_Gear_Catch from baseline RK4 run and current RK4 run with noise added to ForcedEffort
+
+ +
Compare sim runs with random noise (i.e., jitter) added to \$fishing\$ForcedFRate +47. Compare out_Biomass from baseline AB run and current AB run with noise added to ForcedFRate
+48. Compare out_Catch from baseline AB run and current AB run with noise added to ForcedFRate
+49. Compare out_Gear_Catch from baseline AB run and current AB run with noise added to ForcedFRate
+50. Compare out_Biomass from baseline RK4 run and current RK4 run with noise added to ForcedFRate
+51. Compare out_Catch from baseline RK4 run and current RK4 run with noise added to ForcedFRate
+52. Compare out_Gear_Catch from baseline RK4 run and current RK4 run with noise added to ForcedFRate
+
+ +
Compare sim runs with random noise (i.e., jitter) added to \$fishing\$ForcedCatch +53. Compare out_Biomass from baseline AB run and current AB run with noise added to ForcedCatch
+54. Compare out_Catch from baseline AB run and current AB run with noise added to ForcedCatch
+55. Compare out_Gear_Catch from baseline AB run and current AB run with noise added to ForcedCatch
+56. Compare out_Biomass from baseline RK4 run and current RK4 run with noise added to ForcedCatch
+57. Compare out_Catch from baseline RK4 run and current RK4 run with noise added to ForcedCatch
+58. Compare out_Gear_Catch from baseline RK4 run and current RK4 run with noise added to ForcedCatch
+
+ +
Compare sim runs with stepped noise added to \$fishing\$ForcedEffort +59. Compare out_Biomass from baseline AB run and current AB run with stepped noise added to ForcedEffort
+60. Compare out_Catch from baseline AB run and current AB run with stepped noise added to ForcedEffort
+61. Compare out_Gear_Catch from baseline AB run and current AB run with stepped noise added to ForcedEffort
+62. Compare out_Biomass from baseline RK4 run and current RK4 run with stepped noise added to ForcedEffort
+63. Compare out_Catch from baseline RK4 run and current RK4 run with stepped noise added to ForcedEffort
+64. Compare out_Gear_Catch from baseline RK4 run and current RK4 run with stepped noise added to ForcedEffort
+
+ +
Compare sim runs with stepped noise added to \$fishing\$ForcedFRate +65. Compare out_Biomass from baseline AB run and current AB run with stepped noise added to ForcedFRate
+66. Compare out_Catch from baseline AB run and current AB run with stepped noise added to ForcedFRate
+67. Compare out_Gear_Catch from baseline AB run and current AB run with stepped noise added to ForcedFRate
+68. Compare out_Biomass from baseline RK4 run and current RK4 run with stepped noise added to ForcedFRate
+69. Compare out_Catch from baseline RK4 run and current RK4 run with stepped noise added to ForcedFRate
+70. Compare out_Gear_Catch from baseline RK4 run and current RK4 run with stepped noise added to ForcedFRate
+
+ +
Compare sim runs with stepped noise added to \$fishing\$ForcedCatch +71. Compare out_Biomass from baseline AB run and current AB run with stepped noise added to ForcedCatch
+72. Compare out_Catch from baseline AB run and current AB run with stepped noise added to ForcedCatch
+73. Compare out_Gear_Catch from baseline AB run and current AB run with stepped noise added to ForcedCatch
+74. Compare out_Biomass from baseline RK4 run and current RK4 run with stepped noise added to ForcedCatch
+75. Compare out_Catch from baseline RK4 run and current RK4 run with stepped noise added to ForcedCatch
+76. Compare out_Gear_Catch from baseline RK4 run and current RK4 run with stepped noise added to ForcedCatch
+
+
+*The out_Gear_Catch tests are currently awaiting issue #74 to be resolved. + +## Figures + +The Unit Tests compare current runs with baseline runs and produce plots in a pdf file. These plots may be useful for diagnostic purposes. The plots depict the output of a current run in blue and of the baseline run in red. If there are no errors, then there should be no red visible on the plots. There are two types of plots available, also set by a variable in tests/tests_rpath.R: + +```{r Plot Type 1} +PLOT_TYPE <- 1 +``` + +If PLOT_TYPE is set to 1, then the plot depicts the current model in blue superimposed over the baseline model in red. If PLOT_TYPE is set to 2, then the difference (current-baseline) is displayed. + +## Example plots: + +Figure 1 depicts an Rpath Simulation run of Biomass Density vs Time for 3 species. The ```REcosystem_scene$forcing$ForcedBio``` table, where + +``` {r ForcedBio, eval=FALSE} + REcosystem_scene <- rsim.scenario(REco, REco.params, 1:50) +``` + +has been modified with random noise. Both the baseline and current model runs use the AB (Adams-Bashforth) numerical differential equation method. Notice that there is no red line visible in this plot. That is, the current (blue) line is identical (and covers completely) the baseline (red) plot. +

+ +```{r figs1, echo=FALSE, out.width="85%:", out.height="85%", fig.cap="Figure 1. No Difference in Baseline vs Current Models"} +knitr::include_graphics("img/plot_01_no_difference.png") +``` +

+Figure 2 depicts the same information as Figure 1 with the difference being that the randomization factor was slightly changed in the current model from what was used in the baseline model. This was done to only to highlight how the plot would appear if the current model deviated from the baseline. Notice that the underlying baseline plot (in red) is now clearly visible. +

+```{r figs2, echo=FALSE, out.width="85%:", out.height="85%", fig.cap="Figure 2. Difference in red of Baseline vs Current Models"} +knitr::include_graphics("img/plot_02_superimposed_with_difference.png") +``` +

+Figure 3 shows the difference of the current and baseline models. If the models were identical, the difference would be 0, and the plots should be completely flat lines. This plot shows the current-baseline plots for the data shown in Figure 2. Notice that the plot lines are not completely flat, denoting that the difference is not 0. The scale of the y-axis may be modified by changing the following line in **tests/tests_rpath.R**: + +``` {r scale} +YLIMIT_DIFFERENCE_PLOTS <- 0.05 +``` +```{r figs3, echo=FALSE, out.width="85%:", out.height="85%", fig.cap="Figure 3. Current-Baseline Result"} +knitr::include_graphics("img/plot_03_current-baseline.png") +``` diff --git a/vignettes/UnitTests.html b/vignettes/UnitTests.html new file mode 100644 index 00000000..1f0b8727 --- /dev/null +++ b/vignettes/UnitTests.html @@ -0,0 +1,736 @@ + + + + + + + + + + + + + + + + +Unit Tests + + + + + + + + + + + + + + + + + + + + + + + + + + +

Unit Tests

+

Ron Klasky

+

2024-01-13

+ + + +

Source: vignettes/UnitTests.Rmd

+
+

Unit Tests

+

Unit Tests are written using the testthat R package. The tests are +stored in the file: tests/tests_rpath.R. They may be +run explicitly by the user clicking the Test or Check buttons under the +Build tab in RStudio. They also run automatically via git actions when +the user does a push or pull request. The output of the unit tests is a +pdf file with a variety of comparison plots, examples of which are given +below in Figures 1-3.

+
+
+

Details

+

Unit Tests consist of comparing a “current” model value (i.e., +string, table) to a previously stored “baseline” value. Differences are +shown in the testing output as well as reflected in the generated plots +which are written to: Rplots.pdf. Difference +“tolerances” are defined by the variable:

+
TOLERANCE <- 1e-5
+

which can be modified as necessary.

+
+

Regenerating Baseline Files

+

If the user needs to regenerate the baseline files, the following +variable should be set to TRUE and the tests re-run manually (by +clicking the Test button under the Build tab). This will regenerate all +of the baseline data files.

+
CREATE_BASELINE_FILES <- TRUE
+

After the baseline files have been generated, the user should reset +the variable back:

+
CREATE_BASELINE_FILES <- FALSE
+
+
+
+

List of Tests

+

The following unit tests have been developed. Note that some tests +consist of additional/finer tests that compare out_Biomass, out_Catch, +and out_Gear_Catch* for AB (Adams-Bashforth) and RK4 (4th Order Runge +Kutta) numerical differential equation methods.

+
+

Unit Tests

+
+ +Is model balanced? + +
    +
  1. Looks for “Balanced” string in Rpath summary file output
  2. +
+
+
+ +Does model run silent? + +
    +
  1. Tests if model runs without producing print statements, warnings, or +error messages.
  2. +
+
+
+ +Compare Rpath summaries + +
    +
  1. Is the baseline Rpath object the same as the current Rpath +object?
  2. +
+
+
+ +Compare Rpath summaries + +
    +
  1. Is the baseline Rpath summary the same as the current Rpath +summary?
  2. +
+
+
+ +Compare baseline AB sim run to current AB sim run + +
    +
  1. Checks if baseline Rpath AB sim run is same as current AB sim run +(checks top level data structure only)
  2. +
  3. Compare out_Biomass from baseline and current AB sim runs
  4. +
  5. Compare out_Catch from baseline and current AB sim runs
  6. +
  7. Compare out_Gear_Catch from baseline and current AB sim +runs
  8. +
+
+
+ +Compare baseline RK4 sim run to current RK4 sim run + +
    +
  1. Checks if baseline RK4 sim run same as current RK4 sim run (checks +top level data structure only)
  2. +
  3. Compare out_Biomass from baseline and current RK4 sim runs
  4. +
  5. Compare out_Catch from baseline and current RK4 sim runs
  6. +
  7. Compare out_Gear_Catch from baseline and current RK4 sim +runs
  8. +
+
+
+ +Compare baseline AB sim run to current RK4 sim run + +
    +
  1. Checks if baseline AB sim run same as current RK4 sim run (checks +top level data structure only)
  2. +
  3. Compare out_Biomass from baseline AB run and current RK4 sim +run
  4. +
  5. Compare out_Catch from baseline AB run and current RK4 sim +run
  6. +
  7. Compare out_Gear_Catch from baseline AB run and current RK4 sim +run
  8. +
+
+
+ +Compare sim runs with random noise (i.e., jitter) added to +$forcing$ForcedBio + +
    +
  1. Compare out_Biomass from baseline AB run and current AB run with +noise added to ForcedBio
  2. +
  3. Compare out_Catch from baseline AB run and current AB run with noise +added to ForcedBio
  4. +
  5. Compare out_Gear_Catch from baseline AB run and current AB run with +noise added to ForcedBio
  6. +
  7. Compare out_Biomass from baseline RK4 run and current RK4 run with +noise added to ForcedBio
  8. +
  9. Compare out_Catch from baseline RK4 run and current RK4 run with +noise added to ForcedBio
  10. +
  11. Compare out_Gear_Catch from baseline RK4 run and current RK4 run +with noise added to ForcedBio
  12. +
+
+
+ +Compare sim runs with random noise (i.e., jitter) added to +$forcing$ForcedMigrate + +
    +
  1. Compare out_Biomass from baseline AB run and current AB run with +noise added to ForcedMigrate
  2. +
  3. Compare out_Catch from baseline AB run and current AB run with noise +added to ForcedMigrate
  4. +
  5. Compare out_Gear_Catch from baseline AB run and current AB run with +noise added to ForcedMigrate
  6. +
  7. Compare out_Biomass from baseline RK4 run and current RK4 run with +noise added to ForcedMigrate
  8. +
  9. Compare out_Catch from baseline RK4 run and current RK4 run with +noise added to ForcedMigrate
  10. +
  11. Compare out_Gear_Catch from baseline RK4 run and current RK4 run +with noise added to ForcedMigrate
  12. +
+
+
+ +Compare sim runs with stepped noise added to $forcing$ForcedBio + +
    +
  1. Compare out_Biomass from baseline AB run and current AB run with +stepped noise added to ForcedBio
  2. +
  3. Compare out_Catch from baseline AB run and current AB run with +stepped noise added to ForcedBio
  4. +
  5. Compare out_Gear_Catch from baseline AB run and current AB run with +stepped noise added to ForcedBio
  6. +
  7. Compare out_Biomass from baseline RK4 run and current RK4 run with +stepped noise added to ForcedBio
  8. +
  9. Compare out_Catch from baseline RK4 run and current RK4 run with +stepped noise added to ForcedBio
  10. +
  11. Compare out_Gear_Catch from baseline RK4 run and current RK4 run +with stepped noise added to ForcedBio
  12. +
+
+
+ +Compare sim runs with stepped noise added to $forcing$ForcedMigrate + +
    +
  1. Compare out_Biomass from baseline AB run and current AB run with +stepped noise added to ForcedMigrate
  2. +
  3. Compare out_Catch from baseline AB run and current AB run with +stepped noise added to ForcedMigrate
  4. +
  5. Compare out_Gear_Catch from baseline AB run and current AB run with +stepped noise added to ForcedMigrate
  6. +
  7. Compare out_Biomass from baseline RK4 run and current RK4 run with +stepped noise added to ForcedMigrate
  8. +
  9. Compare out_Catch from baseline RK4 run and current RK4 run with +stepped noise added to ForcedMigrate
  10. +
  11. Compare out_Gear_Catch from baseline RK4 run and current RK4 run +with stepped noise added to ForcedMigrate
  12. +
+
+
+ +Compare sim runs with random noise (i.e., jitter) added to +$fishing$ForcedEffort + +
    +
  1. Compare out_Biomass from baseline AB run and current AB run with +noise added to ForcedEffort
  2. +
  3. Compare out_Catch from baseline AB run and current AB run with noise +added to ForcedEffort
  4. +
  5. Compare out_Gear_Catch from baseline AB run and current AB run with +noise added to ForcedEffort
  6. +
  7. Compare out_Biomass from baseline RK4 run and current RK4 run with +noise added to ForcedEffort
  8. +
  9. Compare out_Catch from baseline RK4 run and current RK4 run with +noise added to ForcedEffort
  10. +
  11. Compare out_Gear_Catch from baseline RK4 run and current RK4 run +with noise added to ForcedEffort
  12. +
+
+
+ +Compare sim runs with random noise (i.e., jitter) added to +$fishing$ForcedFRate + +
    +
  1. Compare out_Biomass from baseline AB run and current AB run with +noise added to ForcedFRate
  2. +
  3. Compare out_Catch from baseline AB run and current AB run with noise +added to ForcedFRate
  4. +
  5. Compare out_Gear_Catch from baseline AB run and current AB run with +noise added to ForcedFRate
  6. +
  7. Compare out_Biomass from baseline RK4 run and current RK4 run with +noise added to ForcedFRate
  8. +
  9. Compare out_Catch from baseline RK4 run and current RK4 run with +noise added to ForcedFRate
  10. +
  11. Compare out_Gear_Catch from baseline RK4 run and current RK4 run +with noise added to ForcedFRate
  12. +
+
+
+ +Compare sim runs with random noise (i.e., jitter) added to +$fishing$ForcedCatch + +
    +
  1. Compare out_Biomass from baseline AB run and current AB run with +noise added to ForcedCatch
  2. +
  3. Compare out_Catch from baseline AB run and current AB run with noise +added to ForcedCatch
  4. +
  5. Compare out_Gear_Catch from baseline AB run and current AB run with +noise added to ForcedCatch
  6. +
  7. Compare out_Biomass from baseline RK4 run and current RK4 run with +noise added to ForcedCatch
  8. +
  9. Compare out_Catch from baseline RK4 run and current RK4 run with +noise added to ForcedCatch
  10. +
  11. Compare out_Gear_Catch from baseline RK4 run and current RK4 run +with noise added to ForcedCatch
  12. +
+
+
+ +Compare sim runs with stepped noise added to $fishing$ForcedEffort + +
    +
  1. Compare out_Biomass from baseline AB run and current AB run with +stepped noise added to ForcedEffort
  2. +
  3. Compare out_Catch from baseline AB run and current AB run with +stepped noise added to ForcedEffort
  4. +
  5. Compare out_Gear_Catch from baseline AB run and current AB run with +stepped noise added to ForcedEffort
  6. +
  7. Compare out_Biomass from baseline RK4 run and current RK4 run with +stepped noise added to ForcedEffort
  8. +
  9. Compare out_Catch from baseline RK4 run and current RK4 run with +stepped noise added to ForcedEffort
  10. +
  11. Compare out_Gear_Catch from baseline RK4 run and current RK4 run +with stepped noise added to ForcedEffort
  12. +
+
+
+ +Compare sim runs with stepped noise added to $fishing$ForcedFRate + +
    +
  1. Compare out_Biomass from baseline AB run and current AB run with +stepped noise added to ForcedFRate
  2. +
  3. Compare out_Catch from baseline AB run and current AB run with +stepped noise added to ForcedFRate
  4. +
  5. Compare out_Gear_Catch from baseline AB run and current AB run with +stepped noise added to ForcedFRate
  6. +
  7. Compare out_Biomass from baseline RK4 run and current RK4 run with +stepped noise added to ForcedFRate
  8. +
  9. Compare out_Catch from baseline RK4 run and current RK4 run with +stepped noise added to ForcedFRate
  10. +
  11. Compare out_Gear_Catch from baseline RK4 run and current RK4 run +with stepped noise added to ForcedFRate
  12. +
+
+
+ +Compare sim runs with stepped noise added to $fishing$ForcedCatch + +
    +
  1. Compare out_Biomass from baseline AB run and current AB run with +stepped noise added to ForcedCatch
  2. +
  3. Compare out_Catch from baseline AB run and current AB run with +stepped noise added to ForcedCatch
  4. +
  5. Compare out_Gear_Catch from baseline AB run and current AB run with +stepped noise added to ForcedCatch
  6. +
  7. Compare out_Biomass from baseline RK4 run and current RK4 run with +stepped noise added to ForcedCatch
  8. +
  9. Compare out_Catch from baseline RK4 run and current RK4 run with +stepped noise added to ForcedCatch
  10. +
  11. Compare out_Gear_Catch from baseline RK4 run and current RK4 run +with stepped noise added to ForcedCatch
  12. +
+
+


*The out_Gear_Catch tests are currently awaiting issue #74 to be +resolved.

+
+
+
+

Figures

+

The Unit Tests compare current runs with baseline runs and produce +plots in a pdf file. These plots may be useful for diagnostic purposes. +The plots depict the output of a current run in blue and of the baseline +run in red. If there are no errors, then there should be no red visible +on the plots. There are two types of plots available, also set by a +variable in tests/tests_rpath.R:

+
PLOT_TYPE <- 1 
+

If PLOT_TYPE is set to 1, then the plot depicts the current model in +blue superimposed over the baseline model in red. If PLOT_TYPE is set to +2, then the difference (current-baseline) is displayed.

+
+
+

Example plots:

+

Figure 1 depicts an Rpath Simulation run of Biomass Density vs Time +for 3 species. The REcosystem_scene$forcing$ForcedBio +table, where

+
  REcosystem_scene <- rsim.scenario(REco, REco.params, 1:50)
+

has been modified with random noise. Both the baseline and current +model runs use the AB (Adams-Bashforth) numerical differential equation +method. Notice that there is no red line visible in this plot. That is, +the current (blue) line is identical (and covers completely) the +baseline (red) plot.

+
+Figure 1. No Difference in Baseline vs Current Models +

+Figure 1. No Difference in Baseline vs Current Models +

+
+

Figure 2 depicts the same information as Figure 1 with the +difference being that the randomization factor was slightly changed in +the current model from what was used in the baseline model. This was +done to only to highlight how the plot would appear if the current model +deviated from the baseline. Notice that the underlying baseline plot (in +red) is now clearly visible.

+
+Figure 2. Difference in red of Baseline vs Current Models +

+Figure 2. Difference in red of Baseline vs Current Models +

+
+



Figure 3 shows the difference of the current and baseline +models. If the models were identical, the difference would be 0, and the +plots should be completely flat lines. This plot shows the +current-baseline plots for the data shown in Figure 2. Notice that the +plot lines are not completely flat, denoting that the difference is not +0. The scale of the y-axis may be modified by changing the following +line in tests/tests_rpath.R:

+
YLIMIT_DIFFERENCE_PLOTS <- 0.05
+
+Figure 3. Current-Baseline Result +

+Figure 3. Current-Baseline Result +

+
+
+ + + + + + + + + + + diff --git a/vignettes/ices-journal-of-marine-science.csl b/vignettes/ices-journal-of-marine-science.csl new file mode 100644 index 00000000..40027037 --- /dev/null +++ b/vignettes/ices-journal-of-marine-science.csl @@ -0,0 +1,223 @@ + + diff --git a/vignettes/img/output_plot_example.png b/vignettes/img/output_plot_example.png new file mode 100644 index 00000000..f37ec961 Binary files /dev/null and b/vignettes/img/output_plot_example.png differ diff --git a/vignettes/img/plot_01_no_difference.png b/vignettes/img/plot_01_no_difference.png new file mode 100644 index 00000000..25657236 Binary files /dev/null and b/vignettes/img/plot_01_no_difference.png differ diff --git a/vignettes/img/plot_02_superimposed_with_difference.png b/vignettes/img/plot_02_superimposed_with_difference.png new file mode 100644 index 00000000..bd2a8c4e Binary files /dev/null and b/vignettes/img/plot_02_superimposed_with_difference.png differ diff --git a/vignettes/img/plot_03_current-baseline.png b/vignettes/img/plot_03_current-baseline.png new file mode 100644 index 00000000..9794172e Binary files /dev/null and b/vignettes/img/plot_03_current-baseline.png differ diff --git a/vignettes/references.bib b/vignettes/references.bib new file mode 100644 index 00000000..bc32d50c --- /dev/null +++ b/vignettes/references.bib @@ -0,0 +1,141 @@ + +@article{heymans_best_2016, + series = {Ecopath 30 years – {Modelling} ecosystem dynamics: beyond boundaries with {EwE}}, + title = {Best practice in {Ecopath} with {Ecosim} food-web models for ecosystem-based management}, + volume = {331}, + issn = {0304-3800}, + url = {http://www.sciencedirect.com/science/article/pii/S030438001500575X}, + doi = {10.1016/j.ecolmodel.2015.12.007}, + abstract = {Ecopath with Ecosim (EwE) models are easier to construct and use compared to most other ecosystem modelling techniques and are therefore more widely used by more scientists and managers. This, however, creates a problem with quality assurance; to address this we provide an overview of best practices for creating Ecopath models. We describe the diagnostics that can be used to check for thermodynamic and ecological principles, and highlight principles that should be used for balancing a model. We then highlight the pitfalls when comparing Ecopath models using Ecological Network Analysis indices. For dynamic simulations in Ecosim we show the state of the art in calibrating the model by fitting it to time series using a formal fitting procedure and statistical goodness of fit. Finally, we show how Monte Carlo simulations can be used to address uncertainty in input parameters, and we discuss the use of models in a management context, specifically using the concept of ‘key runs’ for ecosystem-based management. This novel list of best practices for EwE models will enable ecosystem managers to evaluate the goodness of fit of the given EwE model to the ecosystem management question.}, + urldate = {2018-06-25}, + journal = {Ecological Modelling}, + author = {Heymans, Johanna Jacomina and Coll, Marta and Link, Jason S. and Mackinson, Steven and Steenbeek, Jeroen and Walters, Carl and Christensen, Villy}, + month = jul, + year = {2016}, + keywords = {Ecological network analysis, Ecopath with Ecosim, Ecosystem modelling, Ecosystem-based management, Monte Carlo, Time series fitting}, + pages = {173--184}, + file = {ScienceDirect Full Text PDF:/Users/sarahgaichas/Zotero/storage/3QGBKQ2P/Heymans et al. - 2016 - Best practice in Ecopath with Ecosim food-web mode.pdf:application/pdf;ScienceDirect Snapshot:/Users/sarahgaichas/Zotero/storage/I4QQ75ZD/S030438001500575X.html:text/html}, +} + +@article{christensen_ecopath_2004, + title = {Ecopath with {Ecosim}: methods, capabilities, and limitations}, + volume = {172}, + shorttitle = {Ecopath with {Ecosim}: methods, capabilities, and limitations}, + journal = {Ecologial Modelling}, + author = {Christensen, V. and Walters, C. J.}, + year = {2004}, + pages = {109--139}, +} + +@article{walters_structuring_1997, + title = {Structuring dynamic models of exploited ecosystems from trophic mass-balance assessments}, + volume = {7}, + shorttitle = {Structuring dynamic models of exploited ecosystems from trophic mass-balance assessments}, + journal = {Reviews in Fish Biology and Fisheries}, + author = {Walters, C. J. and Christensen, V. and Pauly, D.}, + year = {1997}, + pages = {139--172}, +} + +@article{polovina_model_1984, + title = {Model of a coral reef ecosystem {I}. {The} {ECOPATH} model and its application to {French} {Frigate} {Shoals}}, + volume = {3}, + shorttitle = {Model of a coral reef ecosystem {I}. {The} {ECOPATH} model and its application to {French} {Frigate} {Shoals}}, + journal = {Coral Reefs}, + author = {Polovina, J. J.}, + year = {1984}, + pages = {1--11}, +} + +@book{walters_fisheries_2004, + address = {Princeton}, + title = {Fisheries {Ecology} and {Management}}, + shorttitle = {Fisheries {Ecology} and {Management}}, + publisher = {Princeton University Press}, + author = {Walters, C. J. and Martell, S. J. D.}, + year = {2004}, +} + +@article{walters_ecosim_2008, + title = {An ecosim model for exploring {Gulf} of {Mexico} ecosystem management options: {Implications} of including multistanza life-history models for policy predictions}, + volume = {83}, + shorttitle = {An ecosim model for exploring {Gulf} of {Mexico} ecosystem management options: {Implications} of including multistanza life-history models for policy predictions}, + number = {1}, + journal = {Bulletin of Marine Science}, + author = {Walters, C. J. and Martell, S. J. D. and Christensen, V. and Mahmoudi, B.}, + year = {2008}, + pages = {251--271}, +} + +@article{lucey_conducting_2020, + title = {Conducting reproducible ecosystem modeling using the open source mass balance model {Rpath}}, + volume = {427}, + issn = {0304-3800}, + url = {https://www.sciencedirect.com/science/article/pii/S0304380020301290}, + doi = {10.1016/j.ecolmodel.2020.109057}, + abstract = {Ecosystem models are important tools for conducting ecosystem-based management. A particularly useful method of characterizing the flow of energy through an ecosystem and the subsequent direct and indirect implications of management actions is mass balance modeling. Here we outline the equations as utilized in Rpath, an R implementation of the mass balance algorithms popularized by Ecopath with Ecosim that are designed to work with fisheries data sources. We believe that common practices in R will aid in the reproducibility of conducting analysis using a mass balance model as all of the code is contained within a single script file. This includes the built-in statistical and graphical functions of R. In addition to added reproducibility, R is a coding language with which ecologists are familiar. This familiarity offers greater flexibility for practitioners to tailor the model to their needs. We have made the code available on an open software development platform which should aid in continuous community development of the tool.}, + language = {en}, + urldate = {2021-04-16}, + journal = {Ecological Modelling}, + author = {Lucey, Sean M. and Gaichas, Sarah K. and Aydin, Kerim Y.}, + month = jul, + year = {2020}, + keywords = {Ecopath, Ecosim, Mass balance, R, Reproducibility, Rpath}, + pages = {109057}, + file = {ScienceDirect Full Text PDF:/Users/sarahgaichas/Zotero/storage/FFPCH5ZW/Lucey et al. - 2020 - Conducting reproducible ecosystem modeling using t.pdf:application/pdf;ScienceDirect Full Text PDF:/Users/sarahgaichas/Zotero/storage/AI3CQ579/Lucey et al. - 2020 - Conducting reproducible ecosystem modeling using t.pdf:application/pdf;ScienceDirect Full Text PDF:/Users/sarahgaichas/Zotero/storage/SDQ64VU7/Lucey et al. - 2020 - Conducting reproducible ecosystem modeling using t.pdf:application/pdf;ScienceDirect Snapshot:/Users/sarahgaichas/Zotero/storage/WQXFX7KZ/S0304380020301290.html:text/html;ScienceDirect Snapshot:/Users/sarahgaichas/Zotero/storage/P28ZCPZR/S0304380020301290.html:text/html}, +} + +@article{lucey_evaluating_2021, + title = {Evaluating fishery management strategies using an ecosystem model as an operating model}, + volume = {234}, + copyright = {All rights reserved}, + issn = {0165-7836}, + url = {http://www.sciencedirect.com/science/article/pii/S0165783620302976}, + doi = {10.1016/j.fishres.2020.105780}, + abstract = {Management Strategy Evaluation (MSE) is an effective tool to gauge the relative performance of fishery management options. For the most part, MSEs have been applied to single-species management procedures. However, to be more inclusive of all the biological and technical interactions occurring within a system, ecosystem-based strategies are emerging. In order to test the feasibility of these strategies, a full ecosystem model should be used as an operating model. Mass balance food web models include many features that managers are interested in and therefore can be useful as an operating model. Until recently, full feedback interactions between a management strategy and a mass balance operating model were impractical. However, with the development of Rpath, users now have the ability to fully customize their mass balance models. We developed new functionality for the Rpath modelling framework that allows it to be used as a flexible operating model. Using an example Georges Bank model, we demonstrate how Rpath can now pause the simulation, evaluate an external model, and use the results to modify the parameters of the operating model. This new flexibility will allow users to test a variety of management strategies or couple to other models making Rpath a valuable tool for conducting MSEs.}, + language = {en}, + urldate = {2020-12-09}, + journal = {Fisheries Research}, + author = {Lucey, Sean M. and Aydin, Kerim Y. and Gaichas, Sarah K. and Cadrin, Steven X. and Fay, Gavin and Fogarty, Michael J. and Punt, André}, + month = feb, + year = {2021}, + pages = {105780}, + file = {ScienceDirect Full Text PDF:/Users/sarahgaichas/Zotero/storage/UE78XPGW/Lucey et al. - 2021 - Evaluating fishery management strategies using an .pdf:application/pdf;ScienceDirect Full Text PDF:/Users/sarahgaichas/Zotero/storage/3PKE6BVJ/Lucey et al. - 2021 - Evaluating fishery management strategies using an .pdf:application/pdf;ScienceDirect Snapshot:/Users/sarahgaichas/Zotero/storage/UJVBJ76E/S0165783620302976.html:text/html;ScienceDirect Snapshot:/Users/sarahgaichas/Zotero/storage/FA8IQPMJ/S0165783620302976.html:text/html}, +} + +@article{christensen_ecopath_1992, + title = {{ECOPATH} {II} — a software for balancing steady-state ecosystem models and calculating network characteristics}, + volume = {61}, + issn = {0304-3800}, + url = {https://www.sciencedirect.com/science/article/pii/0304380092900168}, + doi = {10.1016/0304-3800(92)90016-8}, + abstract = {The ECOPATH II microcomputer software is presented as an approach for balancing ecosystem models. It includes (i) routines for balancing the flow in a steady-state ecosystem from estimation of a missing parameter for all groups in the system, (ii) routines for estimating network flow indices, and (iii) miscellaneous routines for deriving additional indices such as food selection indices and omnivory indices. The use of ECOPATH II is exemplified through presentation of a model of the Schlei Fjord ecosystem (Western Baltic).}, + language = {en}, + number = {3}, + urldate = {2023-01-13}, + journal = {Ecological Modelling}, + author = {Christensen, V. and Pauly, D.}, + month = jun, + year = {1992}, + pages = {169--185}, + file = {ScienceDirect Snapshot:/Users/sarahgaichas/Zotero/storage/GVZTRW68/0304380092900168.html:text/html}, +} + +@article{whitehouse_assessing_2020, + title = {Assessing the sensitivity of three {Alaska} marine food webs to perturbations: an example of {Ecosim} simulations using {Rpath}}, + volume = {429}, + issn = {0304-3800}, + shorttitle = {Assessing the sensitivity of three {Alaska} marine food webs to perturbations}, + url = {https://www.sciencedirect.com/science/article/pii/S0304380020301460}, + doi = {10.1016/j.ecolmodel.2020.109074}, + abstract = {Ecosystem modelling is a useful tool for exploring the potential outcomes of policy options and conducting experiments that would otherwise be impractical in the real world. However, ecosystem models have been limited in their ability to engage in the management of living marine resources due in part to high levels of uncertainty in model parameters and model outputs. Additionally, for multispecies or food web models, there is uncertainty about the predator-prey functional response, which can have implications for population dynamics. In this study, we evaluate the sensitivity of large marine food webs in Alaska to parameter uncertainty, including parameters that govern the predator-prey functional response. We use Rpath, an R implementation of the food web modeling program Ecopath with Ecosim (EwE), to conduct a series of mortality-based perturbations to examine the sensitivity and recovery time of higher trophic level groups in the eastern Chukchi Sea, eastern Bering Sea, and Gulf of Alaska. We use a Monte Carlo approach to generate thousands of plausible ecosystems by drawing parameter sets from the range of uncertainty around the base model parameters. We subjected the ecosystem ensembles to a series of mortality-based perturbations to identify which functional groups the higher trophic level groups are most sensitive to when their mortality was increased, whether the food webs returned to their unperturbed configurations following a perturbation, and how long it took to return to that state. In all three ecosystems, we found that the number of disrupted ensemble food webs was positively related to the biomass and the number of trophic links of the perturbed functional group, and negatively related to trophic level. The eastern Chukchi Sea was most sensitive to perturbations to benthic invertebrate groups, the eastern Bering Sea was most sensitive to shrimp and walleye pollock, and the Gulf of Alaska was most sensitive to shrimps, pelagic forage fish, and zooplankton. Recovery time to perturbations were generally less than 5 years in all three ecosystems. The recovery times when fish groups were perturbed were generally longer than when benthic invertebrates were perturbed, and recovery times were shortest when it was pelagic invertebrates. The single model ensemble approach produced simulation results that described a range of possible outcomes to the prescribed perturbations and provided a sense for how robust the results are to parameter uncertainty.}, + language = {en}, + urldate = {2023-01-13}, + journal = {Ecological Modelling}, + author = {Whitehouse, George A. and Aydin, Kerim Y.}, + month = aug, + year = {2020}, + keywords = {Bering Sea, Chukchi Sea, Ecosim, food web, Gulf of Alaska, Rpath}, + pages = {109074}, + file = {ScienceDirect Full Text PDF:/Users/sarahgaichas/Zotero/storage/2KGN7ZX6/Whitehouse and Aydin - 2020 - Assessing the sensitivity of three Alaska marine f.pdf:application/pdf;ScienceDirect Snapshot:/Users/sarahgaichas/Zotero/storage/9MMPFTP9/S0304380020301460.html:text/html}, +}