Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update vignettes #67

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ 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)
40 changes: 40 additions & 0 deletions R/Data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#' Rpath parameter set for the fictitious Anchovy Bay
#'
#' This is a parameter set for the example fictitious ecosystem of Anchovy Bay.
#' Anchovy Bay is used as an introduction to Ecopath with Ecosim.
#'
#' @format An Rpath.params object
#' @family rpathParameters
#'
#' \describe{
#'\item{model}{Main model parameters including Biomass, PB, QB, EE, etc.}
#'\item{diet}{Diet composition matrix with predators as columns and prey as rows}
#'\item{stanzas}{List object containing necessary parameters for multistanza groups.
#' Note that Anchovy Bay does not have any multistanza groups.}
#'\item{pedigree}{Matrix of certainty surrounding parameter values. Defaulted to 1
#' for this fictitious system.}
#'
#' }
#'
#'
"AB.params"

#' Rpath parameter set for the fictitious R Ecosystem
#'
#' This is a parameter set for the example fictitious ecosystem of R Ecosystem.
#' R Ecosystem is used as an introduction to Rpath.
#'
#' @format An Rpath.params object
#' @family rpathParameters
#'
#' \describe{
#'\item{model}{Main model parameters including Biomass, PB, QB, EE, etc.}
#'\item{diet}{Diet composition matrix with predators as columns and prey as rows}
#'\item{stanzas}{List object containing necessary parameters for multistanza groups}
#'\item{pedigree}{Matrix of certainty surrounding parameter values. Defaulted to 1
#' for this fictitious system.}
#'
#' }
#'
#'
"REco.params"
60 changes: 60 additions & 0 deletions data_raw/Ancovy_Bay.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#Anchovy Bay
#SML

#Required packages
library(data.table); library(Rpath); library(here)

#Anchovy Bay----
groups <- c('whales', 'seals', 'cod', 'whiting', 'mackerel', 'anchovy', 'shrimp',
'benthos', 'zooplankton', 'phytoplankton', 'detritus', 'sealers',
'trawlers', 'seiners', 'bait boats', 'shrimpers')

types <- c(rep(0, 9), 1, 2, rep(3, 5))

AB.params <- create.rpath.params(groups, types)

#Biomass, Production, consumption
biomass <- c(0.08, 0.0609, 3, 1.8, 1.2, 7, 0.8, NA, 14.8, 9, 10, rep(NA, 5))

pb <- c(0.05, 0.164, 0.340, 0.581, 0.723, 1.140, 3, 3, 35, 240, rep(NA, 6))

qb <- c(9, 15, 2.58, 3.3, 4.4, 9.13, rep(NA, 10))

AB.params$model[, Biomass := biomass]
AB.params$model[, PB := pb]
AB.params$model[, QB := qb]

AB.params$model[Group == 'shrimp', ProdCons := 0.25]
AB.params$model[Group == 'benthos', ProdCons := 0.25]
AB.params$model[Group == 'zooplankton', ProdCons := 0.25]

#Add EE's for unknown biomasses
AB.params$model[Group == 'benthos', EE := 0.6]
#Biomass accumulation and unassimilated production
AB.params$model[, BioAcc := c(rep(0, 11), rep(NA, 5))]
AB.params$model[, Unassim := c(rep(0.2, 9), rep(0, 2), rep(NA, 5))]

#Detrital fate
AB.params$model[, detritus := c(rep(1, 10), rep(0, 6))]

#Landings/Discards
AB.params$model[Group == 'seals', sealers := .0045]
AB.params$model[Group == 'cod', trawlers := 0.45]
AB.params$model[Group == 'whiting', trawlers := 0.2]
AB.params$model[Group == 'mackerel', seiners := 0.4]
AB.params$model[Group == 'anchovy', seiners := 1.2]
AB.params$model[Group == 'anchovy', "bait boats" := 0.2]
AB.params$model[Group == 'shrimp', shrimpers := 0.05]

#Diet
AB.params$diet[, whales := c(rep(NA, 2), 0.1, 0.1, 0.2, 0.5, NA, 0.1, rep(NA, 4))]
AB.params$diet[, seals := c(NA, NA, 0.04, 0.05, NA, NA, 0.01, 0.9, rep(NA, 4))]
AB.params$diet[, cod := c(NA, NA, NA, 0.05, NA, 0.1, 0.01, 0.84, rep(NA, 4))]
AB.params$diet[, whiting := c(NA, NA, 0.05, 0.05, NA, 0.45, 0.01, 0.44, rep(NA, 4))]
AB.params$diet[, mackerel := c(rep(NA, 4), 0.05, 0.5, NA, NA, 0.45, rep(NA, 3))]
AB.params$diet[, anchovy := c(rep(NA, 8), 1, rep(NA, 3))]
AB.params$diet[, shrimp := c(rep(NA, 7), 1, rep(NA, 4))]
AB.params$diet[, benthos := c(rep(NA, 7), 0.1, 0.1, 0.1, 0.7, NA)]
AB.params$diet[, zooplankton := c(rep(NA, 9), 0.9, 0.1, NA)]

usethis::use_data(AB.params, overwrite = T)
135 changes: 135 additions & 0 deletions data_raw/REcosystem.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#R Ecosystem
#Tutorial ecosystem for teaching Rpath

library(Rpath); library(data.table); library(here)

#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)
5 changes: 5 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

using namespace Rcpp;

#ifdef RCPP_USE_GLOBAL_ROSTREAM
Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& 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) {
Expand Down
Loading