Skip to content

Commit f4f0c0d

Browse files
author
kerim aydin
committed
added/tested PB estimation feature to match EwE
1 parent 15b9ef1 commit f4f0c0d

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

R/ecopath.R

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#'@export
1919
rpath <- function(Rpath.params, eco.name = NA, eco.area = 1) {
2020
#Need to define variables to eliminate check() note about no visible binding
21-
Type <- Group <- DetInput <- ProdCons <- PB <- QB <- noB <- noEE <- alive <- NULL
21+
Type <- Group <- DetInput <- ProdCons <- PB <- QB <- noB <- noEE <- alive <- noPB <- NULL
2222
BEE <- Biomass <- Q <- BioAcc <- BioQB <- diag.a <- EEa <- B <- M0 <- NULL
2323
QBloss <- Unassim <- Ex <- NULL
2424

@@ -99,11 +99,13 @@ rpath <- function(Rpath.params, eco.name = NA, eco.area = 1) {
9999
model[, noEE := 0]
100100
model[, alive := 0]
101101
model[, BEE := 0]
102+
model[, noPB := 0]
102103
model[is.na(Biomass), noB := 1]
103104
model[is.na(EE), noEE := 1]
104105
model[Type < 2, alive := 1]
105-
model[noB == 0 & noEE == 0, BEE := 1]
106-
106+
model[noB == 0 & noEE == 0, BEE := 1]
107+
model[BEE == 1 & is.na(PB), noPB := 1]
108+
107109
# define detritus fate matrix
108110
detfate <- model[, (10 + 1):(10 + ndead), with = F]
109111
detdetfate <- model[Type==2, (10 + 1):(10 + ndead), with = F]
@@ -120,6 +122,7 @@ rpath <- function(Rpath.params, eco.name = NA, eco.area = 1) {
120122
#Set up A matrix
121123
living[noEE == 1, diag.a := Biomass * PB]
122124
living[noEE == 0, diag.a := PB * EE]
125+
living[noPB == 1, diag.a := Biomass * EE] # this needs to be after noEE==0 case
123126

124127
#Special case where B and EE are known then need to solve for BA
125128
#living[BEE == 1, b := b - (Biomass * PB * EE)]
@@ -148,6 +151,9 @@ rpath <- function(Rpath.params, eco.name = NA, eco.area = 1) {
148151
living[, B := x * noB]
149152
living[is.na(Biomass), Biomass := B]
150153

154+
living[, PBa := x * noPB]
155+
living[is.na(PB), PB := PBa]
156+
151157
# detritus EE calcs
152158
living[, M0 := PB * (1 - EE)]
153159
living[, QBloss := QB]
@@ -184,7 +190,7 @@ rpath <- function(Rpath.params, eco.name = NA, eco.area = 1) {
184190
inDetB <- model[(nliving + 1):(nliving + ndead), Biomass]
185191
DetPB <- ifelse(is.na(inDetPB), Default_Detrital_PB, inDetPB)
186192
DetB <- ifelse(is.na(inDetB), detinputs / DetPB, inDetB)
187-
DetPB <- detinputs / DetB
193+
DetPB <- as.numeric(detinputs) / DetB
188194

189195
# Trophic Level calcs
190196
b <- rep(1, ngroups)
@@ -219,16 +225,18 @@ rpath <- function(Rpath.params, eco.name = NA, eco.area = 1) {
219225
#to match header file format (replacing NAs with 0.0s)
220226
Bplus <- c(living[, Biomass], DetB, rep(0.0, ngear))
221227

222-
PBplus <- model[, PB]
223-
PBplus[(nliving + 1):(nliving + ndead)] <- DetPB
228+
#PBplus <- model[, PB]
229+
#PBplus[(nliving + 1):(nliving + ndead)] <- DetPB
230+
PBplus <- c(living[,PB],DetPB , rep(0.0, ngear))
224231
PBplus[is.na(PBplus)] <- 0.0
225232

226233
EEplus <- c(EE, rep(0.0, ngear))
227234

228235
QBplus <- model[, QB]
229236
QBplus[is.na(QBplus)] <- 0.0
230237

231-
GE[is.na(GE)] <- 0.0
238+
GE <- PBplus/QBplus
239+
GE[is.na(GE) | is.nan(GE) | is.infinite(GE)] <- 0.0
232240

233241
RemPlus <- model[, totcatch]
234242
RemPlus[is.na(RemPlus)] <- 0.0

R/param.R

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,14 @@ check.rpath.params <- function(Rpath.params) {
216216
w <- w + 1
217217
}
218218
if (length(Rpath.params$model[!is.na(Biomass) &
219-
!is.na(EE) & Type < 2, Group]) > 0) {
219+
!is.na(EE) &
220+
(!is.na(PB) | (is.na(PB) & !is.na(QB) & !is.na(ProdCons))) &
221+
Type < 2, Group]) > 0) {
220222
warning(
221223
paste(
222224
Rpath.params$model[!is.na(Biomass) & !is.na(EE) & Type < 2, Group],
223-
'have both Biomass and EE...Note that Rpath does not calculate BA
224-
please enter a value for BA if appropriate \n',
225+
'have all of Biomass, EE, and PB entered... Note that Rpath does
226+
not calculate BA, please enter a value for BA if appropriate \n',
225227
sep = ' '
226228
)
227229
)
@@ -255,7 +257,7 @@ check.rpath.params <- function(Rpath.params) {
255257
warning(
256258
paste(
257259
Rpath.params$model[Type > 1 & !is.na(QB), Group],
258-
'are not living and should not have a QB...set to NA \n',
260+
'are not living and should not have a QB... please set to NA \n',
259261
sep = ' '
260262
)
261263
)
@@ -265,7 +267,7 @@ check.rpath.params <- function(Rpath.params) {
265267
warning(
266268
paste(
267269
Rpath.params$model[Type > 1 & !is.na(EE), Group],
268-
'are not living and should not have a EE...set to NA \n',
270+
'are not living and should not have a EE... please set to NA \n',
269271
sep = ' '
270272
)
271273
)
@@ -276,7 +278,7 @@ check.rpath.params <- function(Rpath.params) {
276278
warning(
277279
paste(
278280
Rpath.params$model[Type > 1 & !is.na(ProdCons), Group],
279-
'are not living and should not have a ProdCons...set to NA \n',
281+
'are not living and should not have a ProdCons... please set to NA \n',
280282
sep = ' '
281283
)
282284
)
@@ -287,12 +289,14 @@ check.rpath.params <- function(Rpath.params) {
287289
if (length(Rpath.params$model[Type < 2 & is.na(PB), Group]) > 0) {
288290
no.pb <- Rpath.params$model[Type < 2 & is.na(PB), Group]
289291
if (length(Rpath.params$model[Group %in% no.pb &
290-
(is.na(QB) | is.na(ProdCons)), Group]) > 0) {
292+
(is.na(QB) | is.na(ProdCons)) &
293+
(is.na(Biomass) | is.na(EE)), Group]) > 0) {
291294
warning(
292295
paste(
293296
Rpath.params$model[Group %in% no.pb &
294-
(is.na(QB) | is.na(ProdCons)), Group],
295-
'are missing a PB without a QB and PQ...set to >= 0 \n',
297+
(is.na(QB) | is.na(ProdCons)) &
298+
(is.na(Biomass) | is.na(EE)), Group],
299+
'are missing a PB without either a (QB and ProdCons) or (EE and B) to estimate PB... please set to >= 0 \n',
296300
sep = ' '
297301
)
298302
)

0 commit comments

Comments
 (0)