Skip to content

Commit

Permalink
Merge pull request #85 from PredictiveEcology/LandRAssertionFix
Browse files Browse the repository at this point in the history
2 cohorts become identical ... cohort 1 = 14 B and 2 = 15 B at start of yr
  • Loading branch information
eliotmcintire authored Jun 6, 2024
2 parents 07c9664 + 29b1222 commit 0c277e3
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions Biomass_core.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defineModule(sim, list(
person("Jean", "Marchal", email = "[email protected]", role = "ctb")
),
childModules = character(0),
version = list(Biomass_core = numeric_version("1.4.1.9003")),
version = list(Biomass_core = numeric_version("1.4.2")),
timeframe = as.POSIXlt(c(NA, NA)),
timeunit = "year",
citation = list("citation.bib"),
Expand Down Expand Up @@ -1311,8 +1311,17 @@ MortalityAndGrowth <- compiler::cmpfun(function(sim) {
sim$cohortData[age == 1, age := age + 1L]

if (isTRUE(getOption("LandR.assertions"))) {
if (!identical(NROW(sim$cohortData), NROW(unique(sim$cohortData, by = P(sim)$cohortDefinitionCols)))) {
stop("sim$cohortData has duplicated rows, i.e., multiple rows with the same pixelGroup, speciesCode and age")
byCols <- P(sim)$cohortDefinitionCols
if (!identical(NROW(sim$cohortData), NROW(unique(sim$cohortData, by = byCols)))) {
whPGduplicated <- sim$cohortData[duplicated(sim$cohortData, by = byCols) %in% TRUE]
cd1 <- sim$cohortData[whPGduplicated[, ..byCols], on = byCols]
byColsNoB <- setdiff(byCols, "B")
sumCols <- c("B", "mortality", "aNPPAct")
cd1 <- cd1[, lapply(.SD, sum), .SDcols = sumCols, by = byColsNoB]
cd2 <- sim$cohortData[!whPGduplicated, on = byCols]
sim$cohortData <- rbindlist(list(cd1, cd2), use.names = TRUE)
message("sim$cohortData has duplicated rows, i.e., multiple rows with the same pixelGroup, speciesCode and age.\n",
"These identical cohorts were summed together")
}
}

Expand Down

0 comments on commit 0c277e3

Please sign in to comment.