Skip to content

Commit

Permalink
move M matrix test to validation and print any failures
Browse files Browse the repository at this point in the history
  • Loading branch information
bl-young committed Sep 13, 2024
1 parent c9762f4 commit e232ca1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 0 additions & 9 deletions R/ExternalImportFactors.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,5 @@ deriveMMatrix <- function(model) {
M <- model$M_d %*% diag(as.vector(dr)) + model$M_m %*% diag(as.vector(mr))
colnames(M) <- colnames(model$M_d)

# Validate that M is between M_m and M_d
a <- signif(model$M_m, 6)
b <- signif(M, 6)
c <- signif(model$M_d, 6)
z <- ((b > a) & (b > c)) | ((b < a) & (b < c))
if(sum(z) > 0) {
stop("Error in deriving M matrix")
}

return(M)
}
13 changes: 13 additions & 0 deletions R/ValidateModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,19 @@ validateImportFactorsApproach <- function(model, demand = "Consumption"){
cat("assuming model$M = model$M_m.\n")
print(all.equal(LCIA_dm, LCIA))

cat("\nValidating that the derived M matrix has all values between M_d and M_m\n")

# Validate that M is between M_m and M_d
a <- signif(model$M_m, 6)
b <- signif(model$M, 6)
c <- signif(model$M_d, 6)
z <- ((b > a) & (b > c)) | ((b < a) & (b < c))
if(sum(z) == 0) {
print(TRUE)
} else {
comm <- colSums(z) > 0
print(paste0("Failures: ", names(comm)[comm == TRUE]))
}
}

#' Validate the calculation of household_emissions
Expand Down

0 comments on commit e232ca1

Please sign in to comment.