Skip to content

Commit eb84e1e

Browse files
author
WesIngwersen
committed
Adds test for aggregateMatrix
1 parent a7bcc1d commit eb84e1e

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Model: "USEEIOv2.2-s-ECON" # 2017 Summary, Commodity
2+
BaseIOSchema: 2017
3+
BaseIOLevel: "Summary"
4+
IOYear: 2017 # Year for IO data
5+
ModelRegionAcronyms: ["US"]
6+
ModelType: "EEIO"
7+
IODataSource: "BEA"
8+
BasePriceType: "PRO" #producer
9+
BasewithRedefinitions: FALSE
10+
CommodityorIndustryType: "Commodity"
11+
ScrapIncluded: FALSE
12+
DisaggregationSpecs: null
13+
ExternalImportFactors: FALSE
14+
15+
DemandVectors:
16+
DefaultDemand: "DefaultDemandVectors" # Name of default demand vectors yml file
17+
# Additional demand vectors beyond useeior defaults

tests/modelspecs/USEEIOv2.2-s-GHG.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
Model: "USEEIOv2.2-GHG" # 2017 Detail, Commodity
2+
BaseIOSchema: 2017
3+
BaseIOLevel: "Detail"
4+
IOYear: 2017 # Year for IO data
5+
ModelRegionAcronyms: ["US"]
6+
ModelType: "EEIO"
7+
IODataSource: "BEA"
8+
BasePriceType: "PRO" #producer
9+
BasewithRedefinitions: FALSE
10+
CommodityorIndustryType: "Commodity"
11+
ScrapIncluded: FALSE
12+
DisaggregationSpecs: null
13+
14+
SatelliteTable:
15+
GHG:
16+
FullName: "Greenhouse Gases"
17+
Abbreviation: "GHG"
18+
StaticSource: TRUE
19+
StaticFile: "flowsa/FlowBySector/GHG_national_2022_m2_v2.0.3_1cb504c.parquet"
20+
FileLocation: "DataCommons"
21+
DataYears: [2022]
22+
Locations: ["US"]
23+
SectorListSource: "NAICS"
24+
SectorListYear: 2017
25+
SectorListLevel: "6"
26+
OriginalFlowSource: "FEDEFLv1.2"
27+
ScriptFunctionCall: "getFlowbySectorCollapsed" #function to call for script
28+
ScriptFunctionParameters: null
29+
DataSources:
30+
USEPA_GHG_2024:
31+
Title: "GHG Inventory"
32+
Author: "USEPA"
33+
DataYear: 2022
34+
URL: "https://www.epa.gov/ghgemissions/inventory-us-greenhouse-gas-emissions-and-sinks-1990-2022"
35+
Primary: TRUE
36+
37+
Indicators:
38+
GreenhouseGases:
39+
Name: "Greenhouse Gases"
40+
Code: "GHG"
41+
Group: "Impact Potential"
42+
Unit: "kg CO2 eq"
43+
SimpleUnit: "Kilograms Carbon Dioxide (CO2)"
44+
SimpleName: "Greenhouse Gases"
45+
StaticSource: TRUE
46+
StaticFile: "lciafmt/ipcc/IPCC_v1.1.1_27ba917.parquet"
47+
FileLocation: "DataCommons"
48+
ScriptFunctionCall: "getImpactMethod" #function to call for script
49+
ScriptFunctionParameters:
50+
indicators: ["AR5-100"]
51+
DataSources:
52+
IPCC_AR5:
53+
Title: "IPCC Fifth Assessment Report: Direct Global Warming Potentials for 100 year time horizon"
54+
Author: "IPCC"
55+
DataYear: 2017
56+
URL: ""
57+
Primary: TRUE
58+
59+
DemandVectors:
60+
DefaultDemand: "DefaultDemandVectors" # Name of default demand vectors yml file
61+
# Additional demand vectors beyond useeior defaults

tests/test_aggregate_matrix.R

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
setwd("tests")
2+
library(devtools)
3+
load_all("../")
4+
5+
6+
#Build a detailed model that can be aggregated to summary
7+
## USEEIOv2.2-GHG Detail, commodity model (2017 Schema)
8+
modelname <- "USEEIOv2.2-GHG"
9+
cfg <- paste0("modelspecs/", modelname, ".yml")
10+
model <- buildModel(modelname, configpaths = file.path(cfg))
11+
12+
13+
# Set matrix to Use matrix
14+
m <- model$U
15+
from_level <- "Detail"
16+
to_level <- "Summary"
17+
18+
m_agg <- aggregateMatrix(m,from_level,to_level,model)
19+
20+
#Build a summary model with the same year
21+
#Check to see if the aggregated matrix is equivalent to a summary model matrix with the same data year
22+
23+
modelname <- "USEEIOv2.2-s-ECON"
24+
cfg <- paste0("modelspecs/", modelname, ".yml")
25+
sum_model <- buildIOModel(modelname, configpaths = file.path(cfg))
26+
27+
sum_m <- sum_model$U
28+
29+
30+
#Reorder to match dimensions
31+
m_agg <- m_agg[rownames(sum_m),colnames(sum_m)]
32+
33+
rel_diff <- compareMatrices(m_agg,sum_m,percentage_diff = TRUE)
34+
35+
validation <- formatValidationResult(rel_diff, abs_diff = FALSE, tolerance=0.01)
36+
validation
37+
#Fails for some cells
38+
39+
## Test on a multi-region EEIO model
40+
41+
modelname <- "GAEEIOv1.0-GHG-19" #this model is in the package modelspecs
42+
model <- buildModel(modelname)
43+
44+
m_2R <- model$U
45+
46+
from_level <- "Summary"
47+
to_level <- "Sector"
48+
49+
m_agg <- aggregateMatrix(m_2R,from_level,to_level,model)
50+
51+
# Fails for 2R
52+
53+

0 commit comments

Comments
 (0)