-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add .rmd script testing impacts of commit d188633
- Loading branch information
jvendries
committed
Jun 14, 2024
1 parent
94c5db2
commit 50fa6e0
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#useeior issue 298 - Testing removing export residual from consumption vector | ||
```{r Build state model from develop with export residual in consumption vector} | ||
devtools::load_all(".") | ||
# # Run the following from develop branch | ||
# modelname <- "GAEEIOv1.0-s-GHG-19" | ||
# cfg <- paste0("tests/modelspecs/", modelname, ".yml") | ||
# # Build "ogModel", i.e., original model with export residual included in consumption vector | ||
# ogModel <- buildModel(modelname, configpaths = file.path(cfg)) | ||
ogModel <- readRDS("tests/2019_GA_with_ExpRes.rds") #might need to modify path depending on setup | ||
printValidationResults(ogModel) | ||
``` | ||
|
||
|
||
```{r Build state model from develop WITHOUT export residual in consumption vector} | ||
# Run the same as above, but from issue_298 branch (after commit d1886338) | ||
# devtools::load_all(".") | ||
# modelname <- "GAEEIOv1.0-s-GHG-19" | ||
# cfg <- paste0("tests/modelspecs/", modelname, ".yml") | ||
# model <- buildModel(modelname, configpaths = file.path(cfg)) | ||
model <- readRDS("tests/2019_GA_NO_ExpRes.rds") | ||
printValidationResults(model) | ||
# Compare all model components | ||
print("Comparing model objects before and after removing export residual from consumption vector") | ||
all.equal(ogModel, model) | ||
## Output of above command: Removing export residual from the consumption vector results | ||
## in changes in the consumption vector, CbS, and B_h model objects. | ||
## CbS and B_h ultimately depend on final demand from line 227 in BuildModel.R | ||
``` | ||
|
||
|
||
```{r compare hh model results with and without export residuals in consumption vector} | ||
ogResults <- calculateEEIOModel(ogModel, perspective = "FINAL", demand = "Consumption", location = ogModel$specs$ModelRegionAcronyms[1], | ||
use_domestic_requirements = FALSE, household_emissions = TRUE) | ||
results <- calculateEEIOModel(model, perspective = "FINAL", demand = "Consumption", location = ogModel$specs$ModelRegionAcronyms[1], | ||
use_domestic_requirements = FALSE, household_emissions = TRUE) | ||
# Compare household results before and after modification | ||
# Rest of the results should be different because the y vector has changed, but | ||
# household results should be the same. | ||
hh_LCI_indexes <- which(rownames(results$LCI_f) %in% c("F010/US-GA", "F010/RoUS")) | ||
hh_LCIA_indexes <- which(rownames(results$LCIA_f) %in% c("F010/US-GA", "F010/RoUS")) | ||
print("Comparing LCI household model results before and after removing export residual from consumption vector") | ||
all.equal(ogResults$LCI_f[hh_LCI_indexes,], results$LCI_f[hh_LCI_indexes,]) | ||
print("Comparing LCIA household model results before and after removing export residual from consumption vector") | ||
all.equal(ogResults$LCIA_f[hh_LCIA_indexes,], results$LCIA_f[hh_LCIA_indexes,]) | ||
``` | ||
|
||
```{r compare SoI consumption vector from model final demand vs. model use rows} | ||
# Sum consumption fd vectors using model$U (See https://github.com/USEPA/StateCBEIdocs/issues/26#issue-2341639588) | ||
m <- model | ||
# Get columns in consumption FD | ||
FD_columns <- unlist(sapply(list("HouseholdDemand", "InvestmentDemand", "GovernmentDemand"), | ||
getVectorOfCodes, ioschema = m$specs$BaseIOSchema, iolevel = m$specs$BaseIOLevel)) | ||
# Add SoI region acronym | ||
SoI_FD_columns <- paste0(FD_columns, "/", m$specs$ModelRegionAcronyms[1]) | ||
# Get SoI FD Col indexes | ||
SoI_FD_indexes <- which(colnames(model$U) %in% SoI_FD_columns) | ||
# Sum rows of SoI consumption FD cols | ||
SoI_U_consumption_FD <- rowSums(m$U[1:dim(m$Commodities)[1],c(SoI_FD_indexes)]) | ||
# Create DF containing consumption vector from existing final demand vectors (vector_consumption) and U row sums (U_consumption) | ||
FD_comp <- cbind(m$DemandVectors$vectors$`2019_US-GA_Consumption_Complete`, SoI_U_consumption_FD) | ||
FD_comp <- data.frame(FD_comp) | ||
colnames(FD_comp) <- c("SoI_Vector_consumption","SoI_U_consumption") | ||
FD_comp$ConsumptionDiff <- FD_comp$SoI_Vector_consumption - FD_comp$SoI_U_consumption | ||
print("Comparing SOI consumption vectors from model$DemandVectors and derived from summing acrross model$U") | ||
all.equal(FD_comp$SoI_Vector_consumption, FD_comp$SoI_U_consumption) | ||
``` |