Skip to content

Commit

Permalink
allow built in demands for import results
Browse files Browse the repository at this point in the history
  • Loading branch information
bl-young committed Mar 8, 2024
1 parent 582e210 commit a3f2256
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions R/CalculationFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,27 @@ prepareDemandVectorForStandardResults <- function(model, demand = "Production",
#' @param demand A demand vector, can be name of a built-in model demand vector, e.g. "Production" or "Consumption",
#' @param location, str optional location code for demand vector, required for two-region models
prepareDemandVectorForImportResults <- function(model, demand = "Production", location = NULL) {
if(is.null(location)) {
location <- "US"
}
# Calculate import demand vector y_m.
if(demand == "Production"){
# This option left in for validation purposes.
logging::loginfo("Warning: Production demand vector not recommended for estimating results for models with external Import Factors. ")
y_m <- prepareImportProductionDemand(model, location = location)
} else if(demand == "Consumption"){
y_m <- prepareImportConsumptionDemand(model, location = location)
if (is.character(demand)) {
# assume this is a built-in demand
if(is.null(location)) {
location <- "US"
}
# Calculate import demand vector y_m.
if(demand == "Production"){
# This option left in for validation purposes.
logging::loginfo("Warning: Production demand vector not recommended for estimating results for models with external Import Factors. ")
y_m <- prepareImportProductionDemand(model, location = location)
} else if(demand == "Consumption"){
y_m <- prepareImportConsumptionDemand(model, location = location)
}
} else {
# Assume this is a user-defined demand vector
if (isDemandVectorValid(demand, model$L)) {
y_m <- formatDemandVector(demand, model$L)
} else {
stop("Format of the demand vector is invalid. Cannot calculate result.")
}
}

return(as.matrix(y_m))

}
Expand Down Expand Up @@ -167,7 +176,7 @@ calculateResultsWithExternalFactors <- function(model, perspective = "FINAL", de
# Direct perspective implemented using the following steps:
# Imported_LCI = LCI_direct_domestic
# Calculate Direct Perspective LCI (a matrix with total impacts in form of sector x flows)
logging::loginfo("Calculating Direct Perspective LCI with external import factors...")
logging::loginfo("Calculating Direct + Imported Perspective LCI with external import factors...")
s <- getScalingVector(model$L_d, y_d)
domesticLCI_d <- calculateDirectPerspectiveLCI(model$B, s)

Expand Down

0 comments on commit a3f2256

Please sign in to comment.