diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 3cf51dbf..1c242c6f 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -4,7 +4,7 @@ name: R CI/CD test #R-CMD-check on: push: - branches: [main, master, develop] + # branches: [main, master, develop] paths-ignore: - '**.md' # prevent md files (e.g., README.md) in any repo dir from trigering workflow - '**.bib' @@ -73,7 +73,6 @@ jobs: devtools::load_all() m <- useeior::buildModel("USEEIOv2.0-411") useeior::printValidationResults(m) - shell: Rscript {0} - name: Build and validate models - USEEIOv2.0-i-411 detail industry model with waste disaggregation @@ -83,7 +82,6 @@ jobs: devtools::load_all() m <- useeior::buildModel("USEEIOv2.0-i-411") useeior::printValidationResults(m) - shell: Rscript {0} - name: Build and validate models - USEEIOv2.0 industry model @@ -93,7 +91,6 @@ jobs: devtools::load_all() m <- useeior::buildModel("USEEIOv2.0-i-GHG") useeior::printValidationResults(m) - shell: Rscript {0} - name: Build and validate models - USEEIOv2.0 summary model @@ -103,7 +100,6 @@ jobs: devtools::load_all() m <- useeior::buildModel("USEEIOv2.0-s-GHG") useeior::printValidationResults(m) - shell: Rscript {0} - name: Build and validate models - USEEIOv2.0.1-411 detail model with waste disaggregation @@ -122,7 +118,15 @@ jobs: devtools::load_all() m <- useeior::buildModel("USEEIOv2.0-GHG-NGCombustion") useeior::printValidationResults(m) + shell: Rscript {0} + - name: Build and validate models - GAEEIOv1.0-s-WAT-12 summary two-region model + if: always() + run: | + require(devtools) + devtools::load_all() + m <- useeior::buildModel("GAEEIOv1.0-s-WAT-12") + useeior::print2RValidationResults(m) shell: Rscript {0} #- name: Show testthat output diff --git a/.github/workflows/generate-2R-model.yaml b/.github/workflows/generate-2R-model.yaml index 8b7bd9b3..ab884acd 100644 --- a/.github/workflows/generate-2R-model.yaml +++ b/.github/workflows/generate-2R-model.yaml @@ -8,7 +8,7 @@ on: model: description: "Model" required: true - default: "GAEEIOv2.0-s-WAT" + default: "GAEEIOv1.0-s-WAT-12" jobs: build: diff --git a/.zenodo.json b/.zenodo.json index a68d4c45..14db31e8 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -4,16 +4,6 @@ "title": "useeior", "upload_type": "software", "creators": [ - { - "affiliation": "General Dynamics Information Technology, Inc.", - "name": "Mo Li" - "orcid": "https://orcid.org/0000-0002-3672-1622" - }, - { - "affiliation": "US Environmental Protection Agency", - "name": "Wesley Ingwersen" - "orcid": "https://orcid.org/0000-0002-9614-701X" - }, { "affiliation": "Eastern Research Group", "name": "Ben Young" @@ -23,16 +13,16 @@ "affiliation": "Eastern Research Group", "name": "Jorge Vendries" "orcid": "https://orcid.org/0000-0002-8452-229X" - }, - { - "affiliation": "US Environmental Protection Agency", - "name": "Catherine Birney", - "orcid": "https://orcid.org/0000-0003-4467-9927" + }, + { + "affiliation": "General Dynamics Information Technology, Inc.", + "name": "Mo Li" + "orcid": "https://orcid.org/0000-0002-3672-1622" }, { - "affiliation": "Eastern Research Group", - "name": "Andrew Beck", - "orcid": "https://orcid.org/0000-0003-4051-6901" + "affiliation": "US Environmental Protection Agency", + "name": "Wesley Ingwersen" + "orcid": "https://orcid.org/0000-0002-9614-701X" } ], "access_right": "open" diff --git a/DESCRIPTION b/DESCRIPTION index 8e1932ed..183fb7cb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,13 +1,13 @@ Package: useeior Type: Package Title: USEEIO R modeling software -Version: 1.3.0 -Date: 2023-7-21 +Version: 1.4.0 +Date: 2024-1-19 Authors@R: c( - person("Mo","Li", email="mo.li@gdit.com", role="aut"), - person("Wesley","Ingwersen", email="ingwersen.wesley@epa.gov", role= c("aut", "cre")), person("Ben","Young", email="ben.young@erg.com", role="aut"), - person("Jorge","Vendries", email="jvendries@gmail.com", role="aut")) + person("Jorge","Vendries", email="jvendries@gmail.com", role="aut"), + person("Mo","Li", email="mo.li@gdit.com", role="aut"), + person("Wesley","Ingwersen", email="ingwersen.wesley@epa.gov", role= c("aut", "cre"))) Description: The United States Environmentally-Extended Input-Output model is a model used to estimate potential environmental and economic impacts associated with the production and consumption of goods and services in the US. @@ -23,6 +23,7 @@ Imports: ggplot2 (>= 3.0), jsonlite (>= 1.6), logging (>= 0.10), + Matrix (>= 1.4), rappdirs (>= 0.3), readxl (>= 1.3.1), reshape2 (>= 1.4.3), diff --git a/NAMESPACE b/NAMESPACE index c964feb9..2518e067 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -6,11 +6,13 @@ export(aggregateResultMatrixbyRow) export(barplotFloworImpactFractionbyRegion) export(barplotIndicatorScoresbySector) export(buildModel) +export(buildTwoRegionModels) export(calculateEEIOModel) export(calculateFlowContributiontoImpact) export(calculateMarginSectorImpacts) export(calculateSectorContributiontoImpact) export(calculateSectorPurchasedbySectorSourcedImpact) +export(compare2RCommodityTotals) export(compareCommodityOutputXMarketShareandIndustryOutputwithCPITransformation) export(compareCommodityOutputandDomesticUseplusProductionDemand) export(compareEandLCIResult) @@ -18,13 +20,16 @@ export(compareFlowTotals) export(compareOutputandLeontiefXDemand) export(disaggregateTotalToDirectAndTier1) export(extractAndFormatDemandVector) +export(formatDemandVector) export(generateModelIdentifier) export(heatmapSatelliteTableCoverage) export(heatmapSectorRanking) export(normalizeResultMatrixByTotalImpacts) export(plotMatrixCoefficient) +export(print2RValidationResults) export(printValidationResults) export(seeAvailableModels) +export(validate2RCommodityTotals) export(writeModelMatrices) export(writeModelforAPI) export(writeModeltoXLSX) diff --git a/R/BuildModel.R b/R/BuildModel.R index bfb7a0a0..b2020ef2 100644 --- a/R/BuildModel.R +++ b/R/BuildModel.R @@ -46,8 +46,15 @@ constructEEIOMatrices <- function(model) { colnames(model$U_d) <- colnames(model$U) model[c("U", "U_d")] <- lapply(model[c("U", "U_d")], function(x) ifelse(is.na(x), 0, x)) - model$U_n <- generateDirectRequirementsfromUse(model, domestic = FALSE) #normalized Use - model$U_d_n <- generateDirectRequirementsfromUse(model, domestic = TRUE) #normalized DomesticUse + + if (model$specs$IODataSource=="stateior") { + model$U_n <- generate2RDirectRequirementsfromUseWithTrade(model, domestic = FALSE) + model$U_d_n <- generate2RDirectRequirementsfromUseWithTrade(model, domestic = TRUE) + } else { + model$U_n <- generateDirectRequirementsfromUse(model, domestic = FALSE) #normalized Use + model$U_d_n <- generateDirectRequirementsfromUse(model, domestic = TRUE) #normalized DomesticUse + } + model$q <- model$CommodityOutput model$x <- model$IndustryOutput model$mu <- model$InternationalTradeAdjustment @@ -227,6 +234,57 @@ createCfromFactorsandBflows <- function(factors,B_flows) { return(C) } +#' Build two-region models for all 50 states based on a single config reference file. +#' @param modelname Name of the model from a config file. +#' @param configpaths str vector, paths (including file name) of model configuration file +#' and optional agg/disagg configuration file(s). If NULL, built-in config files are used. +#' @param validate bool, if TRUE print validation results for each model +#' @param year int, indicating for which year to run the models +#' @return A list of EEIO models for each state with complete components and attributes +#' @export +buildTwoRegionModels <- function(modelname, configpaths = NULL, validate = FALSE, year = NULL) { + model_ls <- list() + q_comparison_failures_ls <- list() + basemodel <- initializeModel(modelname, configpaths) + + if(!is.null(year)){ + basemodel$specs$IOYear <- year + } + + for (s in state.abb){ + model <- basemodel + state <- paste("US", s, sep="-") + model$specs$ModelRegionAcronyms[1] <- state + cat("\n") + logging::loginfo(paste0("Building two-region model for ", + paste(state, model$specs$ModelRegionAcronyms[2], sep="/"), + "...")) + cat("\n") + + model_ls[[state]] <- tryCatch( + { + model <- loadIOData(model, configpaths) + model <- loadandbuildSatelliteTables(model) + model <- loadandbuildIndicators(model) + model <- loadDemandVectors(model) + model <- constructEEIOMatrices(model) + if (validate) { + print2RValidationResults(model) + } + model_ls[[state]] <- model + }, + error=function(e) + { + message(paste0("Error for ", state, " model.")) + return(NA) + } + )# end of try catch + + + } + return(model_ls) +} + #' Build an EIO model with economic components only. #' @param modelname Name of the model from a config file. #' @param configpaths str vector, paths (including file name) of model configuration file diff --git a/R/CalculationFunctions.R b/R/CalculationFunctions.R index cde03515..626e018f 100644 --- a/R/CalculationFunctions.R +++ b/R/CalculationFunctions.R @@ -3,21 +3,28 @@ #' Calculate total emissions/resources (LCI) and total impacts (LCIA) for an EEIO model #' for a given perspective and demand vector. #' @param model A complete EEIO model: a list with USEEIO model components and attributes. -#' @param perspective Perspective of the model, can be "DIRECT", "INTERMEDIATE", or "FINAL". -#' @param demand A demand vector, can be name of a built-in model demand vector, e.g. "Production", +#' @param perspective Perspective of the model, can be "DIRECT" or "FINAL". "DIRECT" perspective +#' aligns results with the sectors in which they are produced, while "FINAL" perspective aligns +#' results with the sectors consumed by the final user. +#' @param demand A demand vector, can be name of a built-in model demand vector, e.g. "Production" or "Consumption", #' or an actual demand vector with names as one or more model sectors and #' numeric values in USD with the same dollar year as model. +#' @param location, str optional location code for demand vector, required for two-region models #' @param use_domestic_requirements A logical value: if TRUE, use domestic demand and L_d matrix; #' if FALSE, use complete demand and L matrix. #' @export #' @return A list with LCI and LCIA results (in data.frame format) of the EEIO model. -calculateEEIOModel <- function(model, perspective, demand = "Production", use_domestic_requirements = FALSE) { +calculateEEIOModel <- function(model, perspective, demand = "Production", location = NULL, use_domestic_requirements = FALSE) { result <- list() # Generate Total Requirements (L or L_d) matrix based on whether "use_domestic" if (use_domestic_requirements) { L <- model$L_d + M <- model$M_d + N <- model$N_d } else { L <- model$L + M <- model$M + N <- model$N } # Prepare demand vector @@ -30,7 +37,15 @@ calculateEEIOModel <- function(model, perspective, demand = "Production", use_do paste0("Domestic", demand), paste0("Complete", demand)) # Get vector name (ID) from the meta table - id <- meta[which(meta$Name==demand_name),"ID"] + if(is.null(location)) { + id <- meta[which(meta$Name==demand_name),"ID"] + if(length(id)>1) { + stop("Unique demand vector not found, consider passing location") + } + } else { + id <- meta[which(meta$Name==demand_name & + meta$Location==location),"ID"] + } d <- model$DemandVectors$vectors[[id]] } else { stop(paste0("'", demand, "' is not a valid demand vector name in model.")) @@ -58,10 +73,10 @@ calculateEEIOModel <- function(model, perspective, demand = "Production", use_do } else if (perspective=="FINAL") { # Calculate Final Perspective LCI (a matrix with total impacts in form of sector x flows) logging::loginfo("Calculating Final Perspective LCI...") - result$LCI_f <- calculateFinalPerspectiveLCI(model$M, f) + result$LCI_f <- calculateFinalPerspectiveLCI(M, f) # Calculate Final Perspective LCIA (matrix with total impacts in form of sector x impacts) logging::loginfo("Calculating Final Perspective LCIA...") - result$LCIA_f <- calculateFinalPerspectiveLCIA(model$N, f) + result$LCIA_f <- calculateFinalPerspectiveLCIA(N, f) } logging::loginfo("Result calculation complete.") diff --git a/R/ConfigurationFunctions.R b/R/ConfigurationFunctions.R index 006f839e..f1884143 100644 --- a/R/ConfigurationFunctions.R +++ b/R/ConfigurationFunctions.R @@ -5,11 +5,12 @@ #' @param configtype str, configuration type, can be "model", "disagg", or "agg" #' @param configpaths str vector, paths (including file name) of model configuration file #' and optional agg/disagg configuration file(s). If NULL, built-in config files are used. +#' @param pkg str, indicate package for access to config, either "useeior" or "stateior" #' @return A list of model specifications. -getConfiguration <- function(configname, configtype, configpaths = NULL) { +getConfiguration <- function(configname, configtype, configpaths = NULL, pkg="useeior") { configfile <- paste0(configname, ".yml") if (is.null(configpaths)) { - configpath <- system.file(paste0("extdata/", configtype, "specs/"), configfile, package = "useeior") + configpath <- system.file(paste0("extdata/", configtype, "specs/"), configfile, package = pkg) } else { configpath <- configpaths[endsWith(configpaths, configfile)] if (length(configpath) == 0) { diff --git a/R/DemandFunctions.R b/R/DemandFunctions.R index aab3f83e..7fe8b27b 100644 --- a/R/DemandFunctions.R +++ b/R/DemandFunctions.R @@ -30,9 +30,11 @@ sumDemandCols <- function(Y,codes) { #' Domestic portion of national consumption: y_dc <- Y_dh + Y_dv + Y_dg #' @param model An EEIO model object with model specs and IO tables loaded #' @param Y, a model Demand df. +#' @param location, str of location code for demand vector #' @return A named vector with model sectors and demand amounts -sumforConsumption <- function(model, Y) { - codes <- model$FinalDemandMeta[model$FinalDemandMeta$Group%in%c("Household", "Investment", "Government"), +sumforConsumption <- function(model, Y, location) { + codes <- model$FinalDemandMeta[model$FinalDemandMeta$Group%in%c("Household", "Investment", "Government") & + grepl(location, model$FinalDemandMeta$Code_Loc), "Code_Loc"] y_c <- sumDemandCols(Y, codes) return (y_c) @@ -43,56 +45,82 @@ sumforConsumption <- function(model, Y) { #' where y_c = consumption, y_e = exports, y_m = imports, y_delta = change in inventories #' y_m values are generally negative in the BEA data and thus are added (whereas when positive they are subtracted) #' @param model An EEIO model object with model specs and IO tables loaded +#' @param location, str of location code for demand vector #' @return A named vector with demand -prepareProductionDemand <- function(model) { - export_code <- model$FinalDemandMeta[model$FinalDemandMeta$Group=="Export", "Code_Loc"] - changeinventories_code <- model$FinalDemandMeta[model$FinalDemandMeta$Group=="ChangeInventories", "Code_Loc"] - import_code <- model$FinalDemandMeta[model$FinalDemandMeta$Group=="Import", "Code_Loc"] - y_c <- sumforConsumption(model, model$FinalDemand) - y_e <- sumDemandCols(model$FinalDemand, export_code) - y_m <- sumDemandCols(model$FinalDemand, import_code) - y_delta <- sumDemandCols(model$FinalDemand, changeinventories_code) - y_p <- y_c + y_e + y_m + y_delta +prepareProductionDemand <- function(model, location) { + if (model$specs$IODataSource == "stateior") { + y_p <- prepare2RDemand(model, location, domestic = FALSE) + } else { + loc <- grepl(location, model$FinalDemandMeta$Code_Loc) + export_code <- model$FinalDemandMeta[model$FinalDemandMeta$Group=="Export" & loc, "Code_Loc"] + changeinventories_code <- model$FinalDemandMeta[model$FinalDemandMeta$Group=="ChangeInventories" & loc, "Code_Loc"] + import_code <- model$FinalDemandMeta[model$FinalDemandMeta$Group=="Import" & loc, "Code_Loc"] + y_c <- sumforConsumption(model, model$FinalDemand, location) + y_e <- sumDemandCols(model$FinalDemand, export_code) + y_m <- sumDemandCols(model$FinalDemand, import_code) + y_delta <- sumDemandCols(model$FinalDemand, changeinventories_code) + y_p <- y_c + y_e + y_m + y_delta + } return(y_p) } #' Prepares a demand vector representing domestic production #' Formula for production vector: y_p <- y_dc + y_e + y_d_delta + mu #' @param model An EEIO model object with model specs and IO tables loaded +#' @param location, str of location code for demand vector #' @return A named vector with demand -prepareDomesticProductionDemand <- function(model) { - export_code <- model$FinalDemandMeta[model$FinalDemandMeta$Group=="Export", "Code_Loc"] - changeinventories_code <- model$FinalDemandMeta[model$FinalDemandMeta$Group=="ChangeInventories", "Code_Loc"] - y_d_c <- sumforConsumption(model, model$DomesticFinalDemand) - y_d_e <- sumDemandCols(model$DomesticFinalDemand, export_code) - y_d_delta <- sumDemandCols(model$DomesticFinalDemand, changeinventories_code) - mu <- model$InternationalTradeAdjustment - y_d_p <- y_d_c + y_d_e + y_d_delta + mu +prepareDomesticProductionDemand <- function(model, location) { + if (model$specs$IODataSource == "stateior") { + # This calls the same function as non-domestic demand since for 2R models the non-domestic Use table is replaced with + # domestic Use table with trade, meaning the model$U and model$U_d objects are equal. + y_d_p <- prepare2RDemand(model, location, domestic = TRUE) + } else { + loc <- grepl(location, model$FinalDemandMeta$Code_Loc) + export_code <- model$FinalDemandMeta[model$FinalDemandMeta$Group=="Export" & loc, "Code_Loc"] + changeinventories_code <- model$FinalDemandMeta[model$FinalDemandMeta$Group=="ChangeInventories" & loc, "Code_Loc"] + y_d_c <- sumforConsumption(model, model$DomesticFinalDemand, location) + y_d_e <- sumDemandCols(model$DomesticFinalDemand, export_code) + y_d_delta <- sumDemandCols(model$DomesticFinalDemand, changeinventories_code) + mu <- model$InternationalTradeAdjustment + y_d_p <- y_d_c + y_d_e + y_d_delta + mu + } return(y_d_p) } #' Prepares a demand vector representing consumption #' @param model An EEIO model object with model specs and IO tables loaded +#' @param location, str of location code for demand vector #' @return a named vector with demand -prepareConsumptionDemand <- function(model) { - y_c <- sumforConsumption(model, model$FinalDemand) +prepareConsumptionDemand <- function(model, location) { + if (model$specs$IODataSource == "stateior") { + y_c <- prepare2RDemand(model, location, domestic = FALSE, demand_type = "Consumption") + } else { + y_c <- sumforConsumption(model, model$FinalDemand, location) + } return(y_c) } #' Prepares a demand vector representing domestic consumption #' @param model An EEIO model object with model specs and IO tables loaded +#' @param location, str of location code for demand vector #' @return A named vector with demand -prepareDomesticConsumptionDemand <- function(model) { - y_c_d <- sumforConsumption(model, model$DomesticFinalDemand) +prepareDomesticConsumptionDemand <- function(model, location) { + if (model$specs$IODataSource == "stateior") { + y_c_d <- prepare2RDemand(model, location, domestic = TRUE, demand_type = "Consumption") + } else { + y_c_d <- sumforConsumption(model, model$DomesticFinalDemand, location) + } return(y_c_d) } #' Prepares a demand vector representing household consumption #' @param model An EEIO model object with model specs and IO tables loaded +#' @param location, str of location code for demand vector #' @return A named vector with demand -prepareHouseholdDemand <- function(model) { +prepareHouseholdDemand <- function(model, location) { Y <- model$FinalDemand - household_code <- model$FinalDemandMeta[model$FinalDemandMeta$Group=="Household", "Code_Loc"] + household_code <- model$FinalDemandMeta[model$FinalDemandMeta$Group=="Household" & + grepl(location, model$FinalDemandMeta$Code_Loc), "Code_Loc"] y_h <- sumDemandCols(Y, household_code) return(y_h) } @@ -112,6 +140,7 @@ isDemandVectorValid <- function(dv, L){ #' @param dv, a user provided demand vector. See calculateEEIOModel() #' @param L, the L matrix for the given model, used as a reference #' @return A named vector with values for all names in L and ordered like L +#' @export formatDemandVector <- function(dv,L) { #create a named vector using the first col of L d <- c(L[,1]) diff --git a/R/DisaggregateFunctions.R b/R/DisaggregateFunctions.R index e097a18f..e3140d9a 100644 --- a/R/DisaggregateFunctions.R +++ b/R/DisaggregateFunctions.R @@ -11,51 +11,53 @@ disaggregateModel <- function (model){ model$Commodities <- disaggregateSectorDFs(model, disagg, "Commodity") model$Industries <- disaggregateSectorDFs(model, disagg, "Industry") - #Disaggregating main model components - model$UseTransactions <- disaggregateUseTable(model, disagg) - model$MakeTransactions <- disaggregateMakeTable(model, disagg) - model$UseValueAdded <- disaggregateVA(model, disagg) - model$DomesticUseTransactions <- disaggregateUseTable(model, disagg, domestic = TRUE) - - if(model$specs$CommodityorIndustryType=="Commodity") { - model$FinalDemand <- disaggregateFinalDemand(model, disagg, domestic = FALSE) - model$DomesticFinalDemand <- disaggregateFinalDemand(model, disagg, domestic = TRUE) - } else { - model$FinalDemandbyCommodity <- disaggregateFinalDemand(model, disagg, domestic = FALSE) - model$DomesticFinalDemandbyCommodity <- disaggregateFinalDemand(model, disagg, domestic = TRUE) - model$InternationalTradeAdjustmentbyCommodity <- disaggregateInternationalTradeAdjustment(model, disagg, NULL, adjustmentByCommodity = TRUE) - } - - #Balancing model - if(disagg$DisaggregationType == "Userdefined"){ - model <- balanceDisagg(model, disagg) - } - - #Recalculate model$CommodityOutput and model$IndustryOutput objects. This if else has to be separate from the one above because - #the calculateIndustryCommodityOutput function is used prior to the creation of model$FinalDemandbyCommodity object, - #and we can't recalculate the commodity and industry totals before balancing. - if(model$specs$CommodityorIndustryType=="Commodity") { - model <- calculateIndustryCommodityOutput(model) + if(model$specs$IODataSource != "stateior"){ + #Disaggregating main model components + model$UseTransactions <- disaggregateUseTable(model, disagg) + model$MakeTransactions <- disaggregateMakeTable(model, disagg) + model$UseValueAdded <- disaggregateVA(model, disagg) + model$DomesticUseTransactions <- disaggregateUseTable(model, disagg, domestic = TRUE) - } else{ - model$IndustryOutput <- colSums(model$UseTransactions) + colSums(model$UseValueAdded) - model$CommodityOutput <- rowSums(model$UseTransactions) + rowSums(model$FinalDemandbyCommodity) + if(model$specs$CommodityorIndustryType=="Commodity") { + model$FinalDemand <- disaggregateFinalDemand(model, disagg, domestic = FALSE) + model$DomesticFinalDemand <- disaggregateFinalDemand(model, disagg, domestic = TRUE) + } else { + model$FinalDemandbyCommodity <- disaggregateFinalDemand(model, disagg, domestic = FALSE) + model$DomesticFinalDemandbyCommodity <- disaggregateFinalDemand(model, disagg, domestic = TRUE) + model$InternationalTradeAdjustmentbyCommodity <- disaggregateInternationalTradeAdjustment(model, disagg, NULL, adjustmentByCommodity = TRUE) + } + + #Balancing model + if(disagg$DisaggregationType == "Userdefined"){ + model <- balanceDisagg(model, disagg) + } + + #Recalculate model$CommodityOutput and model$IndustryOutput objects. This if else has to be separate from the one above because + #the calculateIndustryCommodityOutput function is used prior to the creation of model$FinalDemandbyCommodity object, + #and we can't recalculate the commodity and industry totals before balancing. + if(model$specs$CommodityorIndustryType=="Commodity") { + model <- calculateIndustryCommodityOutput(model) + + } else{ + model$IndustryOutput <- colSums(model$UseTransactions) + colSums(model$UseValueAdded) + model$CommodityOutput <- rowSums(model$UseTransactions) + rowSums(model$FinalDemandbyCommodity) + } + + #Disaggregating MultiyearIndustryOutput and MultiYearCommodityOutput + model$MultiYearCommodityOutput <- disaggregateMultiYearOutput(model, disagg, output_type = "Commodity") + model$MultiYearIndustryOutput <- disaggregateMultiYearOutput(model, disagg, output_type = "Industry") + + #Disaggregating CPI model objects. Assumption is that the disaggregated sectors have the same CPI values as the original sector. + model$MultiYearCommodityCPI <- disaggregateCols(model$MultiYearCommodityCPI, disagg, duplicate = TRUE) + model$MultiYearIndustryCPI <- disaggregateCols(model$MultiYearIndustryCPI, disagg, duplicate = TRUE) + + model$InternationalTradeAdjustment <- disaggregateInternationalTradeAdjustment(model, disagg) } - - #Disaggregating MultiyearIndustryOutput and MultiYearCommodityOutput - model$MultiYearCommodityOutput <- disaggregateMultiYearOutput(model, disagg, output_type = "Commodity") - model$MultiYearIndustryOutput <- disaggregateMultiYearOutput(model, disagg, output_type = "Industry") - - #Disaggregating CPI model objects. Assumption is that the disaggregated sectors have the same CPI values as the original sector. - model$MultiYearCommodityCPI <- disaggregateCols(model$MultiYearCommodityCPI, disagg, duplicate = TRUE) - model$MultiYearIndustryCPI <- disaggregateCols(model$MultiYearIndustryCPI, disagg, duplicate = TRUE) - #Disaggregating Crosswalk model$crosswalk <- disaggregateMasterCrosswalk(model, disagg) #Disaggregate Margins model$Margins <- disaggregateMargins(model, disagg) - model$InternationalTradeAdjustment <- disaggregateInternationalTradeAdjustment(model, disagg) model$TaxLessSubsidies <- disaggregateTaxLessSubsidies(model, disagg) # Transform model FinalDemand, DomesticFinalDemand, and InternationalTradeAdjustment to by-industry form @@ -75,13 +77,14 @@ disaggregateModel <- function (model){ #' @param model An EEIO model object with model specs and IO tables loaded #' @param configpaths str vector, paths (including file name) of disagg configuration file(s). #' If NULL, built-in config files are used. +#' @param pkg str, indicate package for access to config, either "useeior" or "stateior" #' @return A model with the specified aggregation and disaggregation specs. -getDisaggregationSpecs <- function (model, configpaths = NULL){ +getDisaggregationSpecs <- function (model, configpaths = NULL, pkg = "useeior"){ model$DisaggregationSpecs <- vector(mode='list') for (configFile in model$specs$DisaggregationSpecs){ logging::loginfo(paste0("Loading disaggregation specification file for ", configFile, "...")) - config <- getConfiguration(configFile, "disagg", configpaths) + config <- getConfiguration(configFile, "disagg", configpaths, pkg=pkg) if('Disaggregation' %in% names(config)){ model$DisaggregationSpecs <- append(model$DisaggregationSpecs, config$Disaggregation) @@ -101,7 +104,11 @@ getDisaggregationSpecs <- function (model, configpaths = NULL){ disaggregateSetup <- function (model, configpaths = NULL){ for (disagg in model$DisaggregationSpecs){ - filename <- getInputFilePath(configpaths, "extdata/disaggspecs", disagg$SectorFile) + if(is.null(disagg$package)){ + disagg$package = "useeior" + } + filename <- getInputFilePath(configpaths, "extdata/disaggspecs", disagg$SectorFile, + package = disagg$package) disagg$NAICSSectorCW <- utils::read.table(filename, sep = ",", header = TRUE, stringsAsFactors = FALSE, @@ -125,7 +132,8 @@ disaggregateSetup <- function (model, configpaths = NULL){ # Load Make table disaggregation file if(!is.null(disagg$MakeFile)){ - filename <- getInputFilePath(configpaths, "extdata/disaggspecs", disagg$MakeFile) + filename <- getInputFilePath(configpaths, "extdata/disaggspecs", disagg$MakeFile, + package = disagg$package) disagg$MakeFileDF <- utils::read.table(filename, sep = ",", header = TRUE, stringsAsFactors = FALSE, @@ -134,7 +142,8 @@ disaggregateSetup <- function (model, configpaths = NULL){ # Load Use table disaggregation file if(!is.null(disagg$UseFile)){ - filename <- getInputFilePath(configpaths, "extdata/disaggspecs", disagg$UseFile) + filename <- getInputFilePath(configpaths, "extdata/disaggspecs", disagg$UseFile, + package = disagg$package) disagg$UseFileDF <- utils::read.table(filename, sep = ",", header = TRUE, stringsAsFactors = FALSE, @@ -143,7 +152,8 @@ disaggregateSetup <- function (model, configpaths = NULL){ # Load Environment flows table if(!is.null(disagg$EnvFile)){ - filename <- getInputFilePath(configpaths, "extdata/disaggspecs", disagg$EnvFile) + filename <- getInputFilePath(configpaths, "extdata/disaggspecs", disagg$EnvFile, + package = disagg$package) disagg$EnvFileDF <- utils::read.table(filename, sep = ",", header = TRUE, stringsAsFactors = FALSE, @@ -305,7 +315,7 @@ disaggregateInternationalTradeAdjustment <- function(model, disagg, ratios = NUL #' @return newMargins A dataframe which contain the margins for the disaggregated sectors disaggregateMargins <- function(model, disagg) { originalMargins <- model$Margins - originalIndex <- grep(disagg$OriginalSectorCode, model$Margins$Code_Loc)#get row index of the original aggregate sector in the model$Margins object + originalIndex <- grep(paste0("^", disagg$OriginalSectorCode), model$Margins$Code_Loc)#get row index of the original aggregate sector in the model$Margins object originalRow <- model$Margins[originalIndex,]#copy row containing the Margins information for the original aggregate sector disaggMargins <-originalRow[rep(seq_len(nrow(originalRow)), length(disagg$DisaggregatedSectorCodes)),,drop=FALSE]#replicate the original a number of times equal to the number of disaggregate sectors disaggRatios <- unname(disaggregatedRatios(model, disagg, model$specs$CommodityorIndustryType))#ratios needed to calculate the margins for the disaggregated sectors. Need to unname for compatibility with Rho matrix later in the model build process. @@ -455,7 +465,7 @@ disaggregateSectorDFs <- function(model, disagg, list_type) { #assume industry if not specified originalList <- model$Industries } - originalIndex <- grep(disagg$OriginalSectorCode, originalList$Code_Loc) + originalIndex <- grep(paste0("^",disagg$OriginalSectorCode), originalList$Code_Loc) newSectors <- data.frame(matrix(ncol = ncol(originalList), nrow = length(disagg$DisaggregatedSectorCodes))) names(newSectors) <- names(originalList) #rename columns for the df diff --git a/R/IOFunctions.R b/R/IOFunctions.R index bc8bf308..097edc29 100644 --- a/R/IOFunctions.R +++ b/R/IOFunctions.R @@ -32,8 +32,9 @@ adjustOutputbyCPI <- function (outputyear, referenceyear, location_acronym, IsRo #' @return A matrix. normalizeIOTransactions <- function (IO_transactions_df, IO_output_df) { # Replace 0 in IO_transactions_df and IO_output_df with 1E-3 to avoid errors in solve(x_hat) - IO_transactions_df[names(IO_output_df[IO_output_df == 0]), - names(IO_output_df[IO_output_df == 0])] <- 1E-3 + for (s in names(IO_output_df[IO_output_df == 0])){ + IO_transactions_df[s, s] <- 1E-3 + } IO_output_df[IO_output_df == 0] <- 1E-3 Z <- as.matrix(IO_transactions_df) x <- unname(unlist(IO_output_df)) diff --git a/R/LoadDemandVectors.R b/R/LoadDemandVectors.R index a1d27b94..291f9a16 100644 --- a/R/LoadDemandVectors.R +++ b/R/LoadDemandVectors.R @@ -29,8 +29,12 @@ loadDemandVectors <- function(model) { logging::loginfo(paste("Loading", i["Location"], i["Name"], "demand vector...")) func_to_eval <- DemandVectorFunctionRegistry[[i$Type]][[i$System]] demandFunction <- as.name(func_to_eval) - dv <- do.call(eval(demandFunction), list(model)) - model$DemandVectors$vectors[[i$ID]] <- dv[grepl(i$Location, names(dv))] + dv <- do.call(eval(demandFunction), list(model, location = i[1,"Location"])) + if(model$specs$IODataSource=="stateior") { + model$DemandVectors$vectors[[i$ID]] <- dv + } else { + model$DemandVectors$vectors[[i$ID]] <- dv[grepl(i$Location, names(dv))] + } } else { stop(paste(i$Type,i$System,"not found in registered demand vector functions. This vector must be registered or removed from the model spec.")) } diff --git a/R/LoadIOTables.R b/R/LoadIOTables.R index b7a13703..286c5243 100644 --- a/R/LoadIOTables.R +++ b/R/LoadIOTables.R @@ -12,6 +12,7 @@ loadIOData <- function(model, configpaths = NULL) { model <- loadIOmeta(model) # Define IO table names io_table_names <- c("MakeTransactions", "UseTransactions", "DomesticUseTransactions", + "DomesticUseTransactionswithTrade", "UseTransactionswithTrade", "UseValueAdded", "FinalDemand", "DomesticFinalDemand", "InternationalTradeAdjustment") # Load IO data @@ -46,8 +47,14 @@ loadIOData <- function(model, configpaths = NULL) { # Add Chain Price Index (CPI) to model model$MultiYearIndustryCPI <- loadChainPriceIndexTable(model$specs)[model$Industries$Code, ] rownames(model$MultiYearIndustryCPI) <- model$Industries$Code_Loc + + ## if Disaggregated two-region model, adjust CPI data frame + if(model$specs$IODataSource == "stateior" && !is.null(model$specs$DisaggregationSpecs)){ + model$MultiYearIndustryCPI <- disaggregateCPI(model$MultiYearIndustryCPI, model) + } + # Transform industry CPI to commodity CPI - model$MultiYearCommodityCPI <- as.data.frame(model$Commodities, row.names = model$Commodities$Code_Loc)[, FALSE] + model$MultiYearCommodityCPI <- as.data.frame(model$CommodityOutput, row.names = names(model$CommodityOutput))[, FALSE] for (year_col in colnames(model$MultiYearIndustryCPI)) { model$MultiYearCommodityCPI[, year_col] <- transformIndustryCPItoCommodityCPIforYear(as.numeric(year_col), model) } @@ -60,7 +67,8 @@ loadIOData <- function(model, configpaths = NULL) { # Check for disaggregation if(!is.null(model$specs$DisaggregationSpecs)){ - model <- getDisaggregationSpecs(model, configpaths) + pkg <- ifelse(model$specs$IODataSource=="stateior", "stateior", "useeior") + model <- getDisaggregationSpecs(model, configpaths, pkg) model <- disaggregateModel(model) } @@ -280,8 +288,10 @@ loadTwoRegionStateIOtables <- function(model) { # Load IO tables from stateior StateIO$MakeTransactions <- getTwoRegionIOData(model, "Make") StateIO$UseTransactions <- getTwoRegionIOData(model, "UseTransactions") + StateIO$UseTransactionswithTrade <- getTwoRegionIOData(model, "UseTransactionswithTrade") StateIO$FinalDemand <- getTwoRegionIOData(model, "FinalDemand") StateIO$DomesticUseTransactions <- getTwoRegionIOData(model, "DomesticUseTransactions") + StateIO$DomesticUseTransactionswithTrade <- getTwoRegionIOData(model, "DomesticUseTransactionswithTrade") StateIO$DomesticFinalDemand <- getTwoRegionIOData(model, "DomesticFinalDemand") StateIO$UseValueAdded <- getTwoRegionIOData(model, "ValueAdded") StateIO$InternationalTradeAdjustment <- getTwoRegionIOData(model, "InternationalTradeAdjustment") @@ -316,7 +326,7 @@ loadCommodityandIndustryOutput <- function(model) { model$IndustryOutput <- getTwoRegionIOData(model, "IndustryOutput") model$CommodityOutput <- getTwoRegionIOData(model, "CommodityOutput") # Load multi-year industry and commodity output - years <- as.character(2012:2017) + years <- as.character(2012:2020) tmpmodel <- model model$MultiYearIndustryOutput <- as.data.frame(model$IndustryOutput)[, FALSE] model$MultiYearCommodityOutput <- as.data.frame(model$CommodityOutput)[, FALSE] diff --git a/R/LoadSatellites.R b/R/LoadSatellites.R index df8d32ff..77a2956e 100644 --- a/R/LoadSatellites.R +++ b/R/LoadSatellites.R @@ -137,8 +137,9 @@ conformTbStoIOSchema <- function(tbs, sat_spec, model) { tbs <- disaggregateSatelliteTable(disagg, tbs, sat_spec) } } - # Change Location if model is a state model - if (all(model$specs$ModelRegionAcronyms!="US", model$specs$IODataSource=="stateior")) { + # Change Location if model is a state model and not already using acronyms + if (all(model$specs$ModelRegionAcronyms!="US", model$specs$IODataSource=="stateior", + all(!unique(tbs$Location) %in% model$specs$ModelRegionAcronyms))) { # Format location in tbs tbs$Location <- formatLocationforStateModels(tbs$Location) } diff --git a/R/SatelliteFunctions.R b/R/SatelliteFunctions.R index f13accec..0285ddd6 100644 --- a/R/SatelliteFunctions.R +++ b/R/SatelliteFunctions.R @@ -126,7 +126,7 @@ aggregateSatelliteTable <- function(sattable, from_level, model) { #' @return aggregated totals by sector collapseTBS <- function(tbs, model) { # Add in BEA industry names - sectornames <- model$Industries[, c("Code", "Name")] + sectornames <- unique(model$Industries[, c("Code", "Name")]) colnames(sectornames) <- c("Sector", "SectorName") # Add F01000 or F010 to sectornames if (model$specs$BaseIOLevel=="Detail") { @@ -194,16 +194,21 @@ getValueAddedTotalsbySector <- function(model) { df[, c("Row.names", "Code_Loc")] <- NULL # Convert to standard totals_by_sector format df <- reshape2::melt(df, id.vars = "Name") - colnames(df) <- c("Flowable", "Sector", "FlowAmount") + colnames(df) <- c("Flowable", "Code_Loc", "FlowAmount") + df <- merge(df, model$Industries[, c("Code_Loc", "Name")], + by.x = "Code_Loc", by.y = "Code_Loc", all.x = TRUE) + colnames(df)[colnames(df) == "Name"] ="SectorName" # Add columns to convert to standard totals_by_sector format - df[, "Sector"] <- gsub("/.*", "", df$Sector) - df <- merge(df, model$Industries[, c("Code", "Name")], - by.x = "Sector", by.y = "Code", all.x = TRUE) + if (length(model$specs$ModelRegionAcronyms) == 1) { + df[, "Sector"] <- gsub("/.*", "", df$Code_Loc) + df[, "Location"] <- model$specs$SatelliteTable$VADD$Locations + } else { + df[, c("Sector", "Location")] <- do.call(rbind, strsplit(as.character(df$Code_Loc),'/')) + } df[, "Context"] <- "Economic" df[, "Unit"] <- "USD" - df[, "Year"] <- model$specs$SatelliteTable$VADD$SectorListYear + df[, "Year"] <- model$specs$SatelliteTable$VADD$DataYears df[, "MetaSources"] <- model$specs$SatelliteTable$VADD$SectorListSource - df[, "Location"] <- model$specs$SatelliteTable$VADD$Locations df[, c("DataReliability", "TemporalCorrelation", "GeographicalCorrelation", "TechnologicalCorrelation", "DataCollection")] <- 1 rownames(df) <- NULL diff --git a/R/StateiorFunctions.R b/R/StateiorFunctions.R index 795c4951..5fa533db 100644 --- a/R/StateiorFunctions.R +++ b/R/StateiorFunctions.R @@ -12,33 +12,291 @@ #' @return A list of two-region IO data of model iolevel and year. getTwoRegionIOData <- function(model, dataname) { # Define state, year and iolevel - if (!"US-DC" %in% model$specs$ModelRegionAcronyms) { + if(!"US-DC" %in% model$specs$ModelRegionAcronyms) { state <- state.name[state.abb == gsub(".*-", "", model$specs$ModelRegionAcronyms[1])] } else { state <- "District of Columbia" } # Define data file name - filename <- paste("TwoRegion", model$specs$BaseIOLevel, dataname, model$specs$IOYear, - model$specs$IODataVersion, sep = "_") + filename <- paste(lapply(c("TwoRegion", model$specs$BaseIOLevel, dataname, + model$specs$DisaggregationSpecs, model$specs$IOYear, + model$specs$IODataVersion), + function(x) x[!is.na(x)]), collapse = "_") # Adjust filename to fit what is on the Data Commons - if (dataname %in% c("UseTransactions", "FinalDemand")) { + if(dataname %in% c("UseTransactions", "FinalDemand")) { filename <- gsub(dataname, "Use", filename) - } else if (dataname %in% c("DomesticUseTransactions", "DomesticFinalDemand")) { + } else if(dataname %in% c("DomesticUseTransactions", "DomesticFinalDemand")) { filename <- gsub(dataname, "DomesticUse", filename) + } else if(dataname %in% c("DomesticUseTransactionswithTrade")){ + filename <- gsub(dataname, "DomesticUsewithTrade", filename) + } else if(dataname %in% c("UseTransactionswithTrade")){ + filename <- gsub(dataname, "UsewithTrade", filename) } # Load data TwoRegionIOData <- readRDS(loadDataCommonsfile(paste0("stateio/", filename, ".rds"))) # Keep SoI and RoUS only TwoRegionIOData <- TwoRegionIOData[[state]] - if (dataname %in% c("UseTransactions", "DomesticUseTransactions")) { - TwoRegionIOData <- TwoRegionIOData[model$Commodities$Code_Loc, - model$Industries$Code_Loc] - } else if (dataname %in% c("FinalDemand", "DomesticFinalDemand")) { - TwoRegionIOData <- TwoRegionIOData[model$Commodities$Code_Loc, - model$FinalDemandMeta$Code_Loc] - } else if (dataname == "ValueAdded") { - TwoRegionIOData <- TwoRegionIOData[model$ValueAddedMeta$Code_Loc, - model$Industries$Code_Loc] + if(dataname %in% c("UseTransactions", "DomesticUseTransactions")) { + TwoRegionIOData <- TwoRegionIOData[, !(colnames(TwoRegionIOData) + %in% model$FinalDemandMeta$Code_Loc)] + } else if(dataname %in% c("FinalDemand", "DomesticFinalDemand")) { + TwoRegionIOData <- TwoRegionIOData[, model$FinalDemandMeta$Code_Loc] + } else if(dataname == "ValueAdded") { + TwoRegionIOData <- TwoRegionIOData[model$ValueAddedMeta$Code_Loc, ] } return(TwoRegionIOData) } + +#' @description Disaggregate CPI table to ensure the correct dimensions +#' @param df, CPI table +#' @param model An EEIO form USEEIO model object with model specs and IO meta data loaded. +#' @return An expanded CPI table with values replicated for disaggregated sectors. +disaggregateCPI <- function(df, model){ + ## Find rows in IndustryCPI not in IndustryOutput, and duplicate them + sector_index <- !(rownames(df) %in% names(model$IndustryOutput)) + disagg_sectors <- rownames(df)[sector_index] + + numNewSectors <- (length(model$IndustryOutput) - nrow(df)) / 2 + for (row in disagg_sectors){ + originalIndex <- which(rownames(df)==row) + originalRowVector <- df[originalIndex,] + disaggRows <-originalRowVector[rep(seq_len(nrow(originalRowVector)), numNewSectors + 1),,drop=FALSE] + + df <- rbind(df[1:originalIndex-1,,drop=FALSE], #from 1st row to row right before disaggregation + disaggRows, + df[-(1:originalIndex),,drop=FALSE]) + } + return(df) +} + + +#' @description Generate direct requirements Use table for 2 region models using domestic +#' Use table with trade data generated by stateior +#' @param model An EEIO form USEEIO model object with model specs and IO meta data loaded. +#' @param domestic A logical parameter indicating whether to DR or Domestic DR. +#' @return A 2-region direct requirements table generated using the domestic Use table with trade +generate2RDirectRequirementsfromUseWithTrade <- function(model, domestic){ + # This function contains code adapted from stateior's validateTwoRegionLagainstOutput() + # function adapted to work within the useeior package. + iolevel <- model$specs$BaseIOLevel + ioschema <- model$specs$BaseIOSchema + year <- model$specs$IOYear + state_abb <- sub(".*-","",model$specs$ModelRegionAcronyms[1]) ## Extract characters after - + + # Define industries and commodities + industries <- getVectorOfCodes(ioschema, iolevel, "Industry") + commodities <- getVectorOfCodes(ioschema, iolevel, "Commodity") + ita_column <- ifelse(iolevel == "Detail", "F05100", "F051") + + if(domestic) { + ls <- model$DomesticUseTransactionswithTrade + name <- "Domestic Use table" + } else { + ls <- model$UseTransactionswithTrade + name <- "Use table" + } + TwoRegionIndustryOutput <- model$IndustryOutput + SoI_Industry_Output <- TwoRegionIndustryOutput[endsWith(names(TwoRegionIndustryOutput), + state_abb)] + RoUS_Industry_Output <- TwoRegionIndustryOutput[endsWith(names(TwoRegionIndustryOutput), + "RoUS")] + # If industry/comm output == 0, it's not viable to generate A matrix, hence set it to 1. + SoI_Industry_Output[SoI_Industry_Output == 0] <- 1 + + logging::loginfo(paste0("Generating A matrix of SoI2SoI ", name, " ...")) + SoI2SoI_A <- normalizeIOTransactions(ls[["SoI2SoI"]][, industries], + SoI_Industry_Output) + + logging::loginfo(paste0("Generating A matrix of RoUS2SoI ", name, " ...")) + RoUS2SoI_A <- normalizeIOTransactions(ls[["RoUS2SoI"]][, industries], + SoI_Industry_Output) + + logging::loginfo(paste0("Generating A matrix of SoI2RoUS ", name, " ...")) + SoI2RoUS_A <- normalizeIOTransactions(ls[["SoI2RoUS"]][, industries], + RoUS_Industry_Output) + + logging::loginfo(paste0("Generating A matrix of RoUS2RoUS ", name, " ...")) + RoUS2RoUS_A <- normalizeIOTransactions(ls[["RoUS2RoUS"]][, industries], + RoUS_Industry_Output) + + U_n_w_trade <- cbind(rbind(SoI2SoI_A, RoUS2SoI_A), rbind(SoI2RoUS_A, RoUS2RoUS_A)) + colnames(U_n_w_trade) <- colnames(model$UseTransactions) + rownames(U_n_w_trade) <- rownames(model$UseTransactions) + return(U_n_w_trade) +} + + +#' Prepares a production demand vector representing production for two region models +#' Demand for SoI = SoI2SoI + RoUS2SoI +#' Demand for RoUS = SoI2RoUS + RoUS2RoUS +#' @param model An EEIO model object with model specs and IO tables loaded +#' @param location, str of location code for demand vector +#' @param domestic A logical parameter indicating whether to generate domestic demand vector. +#' @param demand_type A str indicating whether demand is Production or Consumption +#' @return A named vector with demand +prepare2RDemand <- function(model, location, domestic, demand_type = "Production") { + # Get state abbreviations, e.g., "US-ME" and "RoUS" + state_abb <- sub(".*/","",model$FinalDemandMeta$Code_Loc) ## Extract characters after / + state_abb <- unique(state_abb) + iolevel <- model$specs$BaseIOLevel + + if(domestic){ + use_table <- model$DomesticUseTransactionswithTrade + } else { + use_table <- model$UseTransactionswithTrade + } + # Getting list of final demand columns used for the appropriate demand + if(demand_type == "Production") { + FD_columns <- unlist(sapply(list("HouseholdDemand", "InvestmentDemand", + "ChangeInventories", "Export", "Import", + "GovernmentDemand"), + getVectorOfCodes, ioschema = model$specs$BaseIOSchema, + iolevel = iolevel)) + FD_columns <- FD_columns[FD_columns %in% gsub("/.*", "", colnames(model$FinalDemand))] + # Calculate production demand for both regions + ita_column <- ifelse(iolevel == "Detail", "F05100", "F051") + if(location == state_abb[1]) { + # calculate production final demand for SoI + if(domestic) { + SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, ita_column, "ExportResidual")]) + } else { + SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, "ExportResidual")]) + } + RoUS2SoI_y <- rowSums(use_table[["RoUS2SoI"]][, c(FD_columns, ita_column)]) + y_p <- c(SoI2SoI_y, RoUS2SoI_y) + + } else if(location == state_abb[2]) { + # calculate production final demand for RoUS + if(domestic) { + RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, ita_column, "ExportResidual")]) + } else { + RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, "ExportResidual")]) + } + SoI2RoUS_y <- rowSums(use_table[["SoI2RoUS"]][, c(FD_columns, ita_column)]) + y_p <- c(SoI2RoUS_y, RoUS2RoUS_y) + } + + } else if(demand_type == "Consumption") { + # Includes only household, investment, and government consumption as per Ingwersen et al. 2022 (USEEIOv2.0 paper) + FD_columns <- unlist(sapply(list("HouseholdDemand", "InvestmentDemand", "GovernmentDemand"), + getVectorOfCodes, ioschema = model$specs$BaseIOSchema, iolevel = iolevel)) + + # Calculate consumption demand for both regions + if(location == state_abb[1]) { + # calculate production final demand for SoI + SoI2SoI_y <- rowSums(use_table[["SoI2SoI"]][, c(FD_columns, "ExportResidual")]) + RoUS2SoI_y <- rowSums(use_table[["RoUS2SoI"]][, c(FD_columns)]) + y_p <- c(SoI2SoI_y, RoUS2SoI_y) + } else if(location == state_abb[2]) { + # calculate production final demand for RoUS + SoI2RoUS_y <- rowSums(use_table[["SoI2RoUS"]][, c(FD_columns)]) + RoUS2RoUS_y <- rowSums(use_table[["RoUS2RoUS"]][, c(FD_columns, "ExportResidual")]) + y_p <- c(SoI2RoUS_y, RoUS2RoUS_y) + } + } + names(y_p) <- model$Commodities$Code_Loc + return(y_p) +} + + +#' Run validation checks for 2R models and print to console +#' @param model A complete 2R EEIO model: a list with USEEIO model components and attributes +#' @return A list with 2R model results. +#' @export +print2RValidationResults <- function(model) { + + # Check that Production demand can be run without errors + cat("Checking that production demand vectors do not produce errors for 2-R models, ", + "as well as validating model components.\n\n") + printValidationResults(model) + cat("\n") + + # Creating 2-R Production Complete demand vector + f <- model$DemandVectors$vectors[endsWith(names(model$DemandVectors$vectors), "Production_Complete")][[1]] + f <- (f + model$DemandVectors$vectors[endsWith(names(model$DemandVectors$vectors), "Production_Complete")][[2]]) + + cat("Calculating direct results using Production Complete final demand...\n") + directResultsProductionComplete <- calculateEEIOModel(model, perspective = "DIRECT", + demand = f, location = NULL, + use_domestic_requirements = FALSE) + + cat("\nCalculating final results using Production Complete final demand...\n\n") + finalResultsProductionComplete <- calculateEEIOModel(model, perspective = "FINAL", + demand = f, location = NULL, + use_domestic_requirements = FALSE) + + # Check that Consumption demand can be run without errors + cat("\n\nChecking that consumption demand vectors do not produce errors for 2-R models.\n\n") + + # Creating 2-R Consumption Complete demand vector + f <- model$DemandVectors$vectors[endsWith(names(model$DemandVectors$vectors), "Consumption_Complete")][[1]] + f <- (f + model$DemandVectors$vectors[endsWith(names(model$DemandVectors$vectors), "Consumption_Complete")][[2]]) + + cat("Calculating direct results using Consumption Complete final demand...\n") + directResultsConsumptionComplete <- calculateEEIOModel(model, perspective = "DIRECT", + demand = f, location = NULL, + use_domestic_requirements = FALSE) + + cat("\nCalculating final results using Consumption Complete final demand...\n") + finalResultsConsumptionComplete <- calculateEEIOModel(model, perspective = "FINAL", + demand = f, location = NULL, + use_domestic_requirements = FALSE) + + twoRegionResults_ls <- list() + twoRegionResults_ls$directResultsProductionComplete <- directResultsProductionComplete + twoRegionResults_ls$directResultsConsumptionComplete <- directResultsConsumptionComplete + twoRegionResults_ls$finalResultsProductionComplete <- finalResultsProductionComplete + twoRegionResults_ls$finalResultsConsumptionComplete <- finalResultsConsumptionComplete + + # return(twoRegionResults_ls) +} + + +#' Validate commodity totals between 2R Use table, Make table, and total commodity output objects +#' @param model A complete 2R EEIO model: a list with USEEIO model components and attributes +#' @return A list containing failures of commodity total comparisons between various model objects. +#' @export +validate2RCommodityTotals <- function(model) { + + failures_ls <- list() + + cat("Comparing commodity totals summed from Make and Use (with trade) tables.\n") + commodityNum <- dim(model$Commodities)[1] # Get number of commodities + q_make <- colSums(model$V) + q_use <- rowSums(model$U[1:commodityNum,])#excluding VA rows, including all columns + + failures_ls$Make_Use <- compare2RCommodityTotals(q_make, q_use) + + cat("Comparing commodity totals summed from Make and Domestic Use (with trade) tables.\n") + q_d_use <- rowSums(model$U_d[1:commodityNum,])#excluding VA rows, including all columns + failures_ls$Make_DUse <- compare2RCommodityTotals(q_make, q_d_use) + + + cat("Comparing commodity totals summed from Make and commodityTotal (model$q) object imported from stateior.\n\n") + failures_ls$Make_modelq <- compare2RCommodityTotals(q_make, model$q) + + return(failures_ls) + +} + +#' Compare commodity totals between the specified 2R model objects +#' @param q_One A vector of commodity totals derived from specific model object +#' @param q_Two A vector of commodity totals dervied from a different model object than q_One +#' @return A list of sectors that failed the comparison between the two specified q vectors. +#' @export +compare2RCommodityTotals <- function(q_One, q_Two) { + + # Calculate relative differences in q_One and q_Two + rel_diff_q <- (q_Two - q_One)/q_One + # Validate relative diff + validationResults <- formatValidationResult(rel_diff_q, abs_diff = TRUE, tolerance = 0.01) + failures <- validationResults$Failure + failuresIndex <- which(rownames(validationResults$RelativeDifference) %in% failures$rownames) + failures <- cbind(failures, validationResults$RelativeDifference[failuresIndex,1]) + colnames(failures)[1:3] <- c("Commodity", "Validation", "Relative Diff") + cat(paste(c("Number of failures: ",length(failures$Commodity)),"\n", collapse = " ")) + cat(paste(c("Failing commodities: ", failures$Commodity),"\n", collapse = " ")) + cat("\n") + return(failures) + +} diff --git a/R/UtilityFunctions.R b/R/UtilityFunctions.R index a576eedc..84c04d78 100644 --- a/R/UtilityFunctions.R +++ b/R/UtilityFunctions.R @@ -440,24 +440,23 @@ writeMetadatatoJSON <- function(package, #' @param location A text value of input location name #' @return A text value of formatted location for state models formatLocationforStateModels <- function(location) { - loc <- stringr::str_replace_all(string = tolower(location), - pattern = setNames(paste("US", state.abb, sep = "-"), - tolower(state.name))) + pattern <- setNames(paste("US", state.abb, sep = "-"), tolower(state.name)) + loc <- dplyr::recode(tolower(location), !!!pattern) return(loc) } #' Identify location of filepath for model input files #' @param configpaths str vector, paths (including file name) of configuration files. #' @param folderPath str local path to configuration type -#' @param filename str filename of model spec -getInputFilePath <- function(configpaths, folderPath="extdata", filename){ +#' @param filename str filename of model spec +#' @param package str name of package for location of input file +getInputFilePath <- function(configpaths, folderPath="extdata", filename, package="useeior"){ if(!is.null(configpaths)) { filepath <- file.path(dirname(configpaths)[1], filename) if(file.exists(filepath)) { return(filepath) } } - filepath <- system.file(folderPath, filename, package = "useeior") + filepath <- system.file(folderPath, filename, package = package) return(filepath) } - diff --git a/R/ValidateModel.R b/R/ValidateModel.R index 15b4fd4f..1e938597 100644 --- a/R/ValidateModel.R +++ b/R/ValidateModel.R @@ -56,10 +56,16 @@ compareEandLCIResult <- function(model, use_domestic = FALSE, tolerance = 0.05) calculateProductofLeontiefAndProductionDemand <- function (model, use_domestic) { if (use_domestic) { f <- model$DemandVectors$vectors[endsWith(names(model$DemandVectors$vectors), "Production_Domestic")][[1]] + if (model$specs$IODataSource=="stateior") { + f <- (f + model$DemandVectors$vectors[endsWith(names(model$DemandVectors$vectors), "Production_Domestic")][[2]]) + } y <- as.matrix(formatDemandVector(f, model$L_d)) c <- getScalingVector(model$L_d, y) } else { f <- model$DemandVectors$vectors[endsWith(names(model$DemandVectors$vectors), "Production_Complete")][[1]] + if (model$specs$IODataSource=="stateior") { + f <- (f + model$DemandVectors$vectors[endsWith(names(model$DemandVectors$vectors), "Production_Complete")][[2]]) + } y <- as.matrix(formatDemandVector(f, model$L)) c <- getScalingVector(model$L, y) } @@ -108,10 +114,13 @@ compareOutputandLeontiefXDemand <- function(model, use_domestic=FALSE, tolerance #' @export compareCommodityOutputandDomesticUseplusProductionDemand <- function(model, tolerance=0.05) { q <- removeHybridProcesses(model, model$q) + demand <- model$DemandVectors$vectors[endsWith(names(model$DemandVectors$vectors),"Production_Domestic")][[1]] + if (model$specs$IODataSource=="stateior") { + demand <- (demand + model$DemandVectors$vectors[endsWith(names(model$DemandVectors$vectors), "Production_Domestic")][[2]]) + } x <- rowSums(model$U_d[removeHybridProcesses(model, model$Commodities$Code_Loc), removeHybridProcesses(model, model$Industries$Code_Loc)]) + - removeHybridProcesses(model, model$DemandVectors$vectors[endsWith(names(model$DemandVectors$vectors), - "Production_Domestic")][[1]]) + removeHybridProcesses(model, demand) # Row names should be identical if (!identical(names(q), names(x))) { stop("Sectors not aligned in model ouput variable and calculation result") @@ -314,13 +323,13 @@ printValidationResults <- function(model) { print(paste("Number of flow totals by commodity failing:",q_x_val$N_Fail)) print(paste("Sectors with flow totals failing:", paste(unique(q_x_val$Failure$rownames), collapse = ", "))) -if (model$specs$CommodityorIndustryType=="Commodity") { - print("Validate that commodity output equals to domestic use plus production demand") - q_val <- compareCommodityOutputandDomesticUseplusProductionDemand(model, tolerance = 0.01) - print(paste("Number of flow totals by commodity passing:",q_val$N_Pass)) - print(paste("Number of flow totals by commodity failing:",q_val$N_Fail)) - print(paste("Sectors with flow totals failing:", paste(unique(q_val$Failure$rownames), collapse = ", "))) -} + if (model$specs$CommodityorIndustryType=="Commodity") { + print("Validate that commodity output equals to domestic use plus production demand") + q_val <- compareCommodityOutputandDomesticUseplusProductionDemand(model, tolerance = 0.01) + print(paste("Number of flow totals by commodity passing:",q_val$N_Pass)) + print(paste("Number of flow totals by commodity failing:",q_val$N_Fail)) + print(paste("Sectors with flow totals failing:", paste(unique(q_val$Failure$rownames), collapse = ", "))) + } } #' Removes hybrid processes form a model object for successful validation diff --git a/R/VisualizationFunctions.R b/R/VisualizationFunctions.R index 839875c0..3d0a29a0 100644 --- a/R/VisualizationFunctions.R +++ b/R/VisualizationFunctions.R @@ -33,6 +33,10 @@ plotMatrixCoefficient <- function(model_list, matrix_name, coefficient_name, sec rownames(matrix) <- Y_title matrix <- as.data.frame(reshape2::melt(matrix)) colnames(matrix) <- c("CoefficientName", "Sector", "Value") + # For two-region models assign model name based on region here + if (length(model$specs$ModelRegionAcronyms) > 1) { + matrix$modelname <- sapply(strsplit(as.character(matrix$Sector),"/"), "[", 2) + } matrix$Sector <- toupper(gsub("/.*", "", matrix$Sector)) # Convert matrix to df df_model <- data.frame() @@ -44,9 +48,14 @@ plotMatrixCoefficient <- function(model_list, matrix_name, coefficient_name, sec } else { SectorName <- model$Industries[, c("Code", "Name")] } + # Remove duplicate sector names for two-region models + SectorName <- SectorName[!duplicated(SectorName), ] colnames(SectorName) <- c("Sector", "SectorName") df_model <- merge(df_model, SectorName, by = "Sector") - df_model$modelname <- modelname + # Bypass this step for two-region models as modelname assigned above + if (!('modelname' %in% colnames(df_model))) { + df_model$modelname <- modelname + } # Remove certain sectors df_model <- df_model[!df_model$Sector%in%sector_to_remove, ] df_model <- df_model[order(df_model$GroupName), ] @@ -220,27 +229,34 @@ heatmapSatelliteTableCoverage <- function(model, form="Commodity") { #' SMM tool like heatmap showing ranking of sectors #' @param model A complete EEIO model: a list with USEEIO model components and attributes #' @param matrix A matrix from model result -#' @param indicators A vector of indicators to plot +#' @param indicators A vector of indicators to plot, use Codes if use_codes = TRUE, otherwise use Names #' @param sector_to_remove Code of one or more BEA sectors that will be removed from the plot. Can be "". #' @param N_sector A numeric value indicating number of sectors to show in the ranking #' @param x_title A string specifying desired title on the x-axis, default is NULL, the title will be "modelname indicators" +#' @param use_codes bool, indicate if figure should use indicator Code (TRUE) or Name (FALSE) #' @export -heatmapSectorRanking <- function(model, matrix, indicators, sector_to_remove, N_sector, x_title = NULL) { +heatmapSectorRanking <- function(model, matrix, indicators, sector_to_remove, N_sector, x_title = NULL, + use_codes = TRUE) { # Generate BEA sector color mapping mapping <- getBEASectorColorMapping(model) mapping$GroupName <- mapping$SectorName + if (length(model$specs$ModelRegionAcronyms) > 1) { + # For two-region models, aggregate locations + rownames(matrix) <- gsub("/.*", "", rownames(matrix)) + matrix <- t(sapply(by(matrix, rownames(matrix), colSums), identity)) + } # Prepare data frame for plot df <- as.data.frame(prop.table(matrix, margin = 2)) - if (model$specs$Model=="USEEIOv2.0") { + if (use_codes) { colnames(df) <- model$Indicators$meta[order(match(model$Indicators$meta$Name, colnames(df))), "Code"] } df$Sector <- toupper(gsub("/.*", "", rownames(df))) df <- merge(df, mapping[, c(paste0(model$specs$BaseIOLevel, "Code"), "color", "GroupName")], by.x = "Sector", by.y = paste0(model$specs$BaseIOLevel, "Code"), all.x = TRUE) if (model$specs$CommodityorIndustryType=="Commodity") { - SectorName <- model$Commodities[, c("Code", "Name")] + SectorName <- unique(model$Commodities[, c("Code", "Name")]) } else { - SectorName <- model$Industries[, c("Code", "Name")] + SectorName <- unique(model$Industries[, c("Code", "Name")]) } colnames(SectorName) <- c("Sector", "SectorName") df <- merge(df, SectorName, by = "Sector") diff --git a/R/WriteModel.R b/R/WriteModel.R index 2c7288ed..514cd550 100644 --- a/R/WriteModel.R +++ b/R/WriteModel.R @@ -110,7 +110,7 @@ writeModeltoXLSX <- function(model, outputfolder) { final_demand_meta <- model$FinalDemandMeta final_demand_meta$Index <- c(1:nrow(final_demand_meta)-1) final_demand_meta$ID <- final_demand_meta$Code_Loc - final_demand_meta$Location <- model$specs$ModelRegionAcronyms + final_demand_meta$Location <- gsub(".*/", "", final_demand_meta$Code_Loc) final_demand_meta$Description <- "" USEEIOtoXLSX_ls[["final_demand_meta"]] <- final_demand_meta[, demand_meta_fields] @@ -118,7 +118,7 @@ writeModeltoXLSX <- function(model, outputfolder) { value_added_meta <- model$ValueAddedMeta value_added_meta$Index <- c(1:nrow(value_added_meta)-1) value_added_meta$ID <- value_added_meta$Code_Loc - value_added_meta$Location <- model$specs$ModelRegionAcronyms + value_added_meta$Location <- gsub(".*/", "", value_added_meta$Code_Loc) value_added_meta$Description <- "" USEEIOtoXLSX_ls[["value_added_meta"]] <- value_added_meta[, demand_meta_fields] @@ -183,11 +183,6 @@ prepareWriteDirs <- function(model, dirs) { #' @param outputfolder A directory to write model demand vectors. #' @description Writes model demand vectors, including y and y_d for consumption and production. writeModelDemandstoJSON <- function(model, outputfolder) { - #!WARNING: Only works for single region model - if (model$specs$ModelRegionAcronyms!="US") { - stop("Currently only works for single region US models.") - } - for (n in names(model$DemandVectors$vectors)) { f <- model$DemandVectors$vectors[[n]] f <- data.frame(amount=f) @@ -206,11 +201,6 @@ writeModelDemandstoJSON <- function(model, outputfolder) { #' @param dirs A named list of directories with model and data directory paths #' @description Writes model metadata, including indicators and demands. writeModelMetadata <- function(model, dirs) { - #!WARNING: Only works for single region model - if (model$specs$ModelRegionAcronyms!="US") { - stop("Currently only works for single region US models.") - } - # Load metadata fields for API fields <- configr::read.config(system.file("extdata/USEEIO_API_fields.yml", package="useeior")) @@ -219,7 +209,7 @@ writeModelMetadata <- function(model, dirs) { model_desc <- file.path(dirs$data, "models.csv") ID <- model$specs$Model Name <- model$specs$Model - Location <- model$specs$ModelRegionAcronyms + Location <- model$specs$ModelRegionAcronyms[1] Description <- "" #Add in sector schema for model if (is.null(model$specs$DisaggregationSpecs)) { @@ -270,7 +260,7 @@ writeModelMetadata <- function(model, dirs) { # Write sectors to csv sectors <- model[[gsub("y", "ies", model$specs$CommodityorIndustryType)]] sectors$ID <- sectors$Code_Loc - sectors$Location <- model$specs$ModelRegionAcronyms + sectors$Location <- gsub(".*/", "", sectors$Code_Loc) sectors$Index <- c(1:nrow(sectors)-1) sectors$Category <- paste(sectors$Category, sectors$Subcategory, sep="/") sectors <- sectors[, fields$sectors] @@ -286,8 +276,8 @@ writeModelMetadata <- function(model, dirs) { flows <- flows[order(flows$ID),] flows$Index <- c(1:nrow(flows)-1) flows <- flows[, fields$flows] - checkNamesandOrdering(flows$ID, rownames(model$B), - "flows in flows.csv and rows in B matrix") + #checkNamesandOrdering(flows$ID, rownames(model$B), + # "flows in flows.csv and rows in B matrix") utils::write.csv(flows, paste0(dirs$model, "/flows.csv"), na = "", row.names = FALSE, fileEncoding = "UTF-8") diff --git a/format_specs/ModelSpecification.md b/format_specs/ModelSpecification.md index 51cbfe60..a9326897 100644 --- a/format_specs/ModelSpecification.md +++ b/format_specs/ModelSpecification.md @@ -7,11 +7,11 @@ Model specifications are assigned in a yml file based on the parameters shown be | BaseIOSchema | int | Y | The base IO schema (e.g. 2012) | | BaseIOLevel | str | Y | The base IO level of detail (e.g. `Detail`) | | IOYear | int | Y | The base IO year | -| PrimaryRegionAcronym | str | Y | The primary region acronym | | ModelRegionAcronyms | list | Y | The model region acronyms | | ModelType | str | Y | The [model type](#Model-Types) (e.g. `EEIO`) | -| ModelSource | str | Y | The model source | -| BasePriceType | str | Y | The model base price type (producer or purchaser) | +| IODataSource | str | Y | The model source (e.g. `BEA` or `stateior`) | +| IODataVersion | str | N | Required if IODataSource is `stateior`, [stateior model version number](https://github.com/USEPA/stateior/wiki/Planned-Package-Releases) | +| BasePriceType | str | Y | The model base price type (`PRO`: producer or `PUR`: purchaser) | | BasewithRedefinitions | bool | Y | Whether the model is based with redefinitions (TRUE or FALSE) | | CommodityorIndustryType | str | Y | Define if this is a commodity x commodity (`Commodity`) or industry x industry (`Industry`) model | | ScrapIncluded | bool | Y | Whether the model includes scrap (TRUE or FALSE) | diff --git a/inst/extdata/VisualizationEssentials.yml b/inst/extdata/VisualizationEssentials.yml index 5d0fa761..0f05bb05 100644 --- a/inst/extdata/VisualizationEssentials.yml +++ b/inst/extdata/VisualizationEssentials.yml @@ -94,3 +94,55 @@ Indicators: - "#428E55" # green, Eonomic & Social - "Jobs Supported": - "#428E55" + +# State color palette is from https://medialab.github.io/iwanthue/ +StateColorPalette: ["#d93762", +"#44c96a", +"#9969e4", +"#89c13d", +"#8b45b3", +"#43a132", +"#db4bb1", +"#c5ba34", +"#4d5ac6", +"#e09129", +"#6982ec", +"#919f35", +"#d974e1", +"#3d8339", +"#e43588", +"#56bd8a", +"#ac3e9b", +"#84b96b", +"#b13670", +"#5bcbb9", +"#d73440", +"#4ab4dd", +"#d04818", +"#406dac", +"#ee5e42", +"#3b9987", +"#af3733", +"#347c52", +"#e7699f", +"#5f7f24", +"#ba84d6", +"#c99e3b", +"#74569e", +"#bdb76b", +"#8a99dd", +"#e47d45", +"#a05e90", +"#596222", +"#d88bc1", +"#876c1d", +"#964969", +"#88894b", +"#e1646d", +"#b37e48", +"#e68c95", +"#a74f1b", +"#e6a573", +"#a64d54", +"#8c532c", +"#d07259"] diff --git a/inst/extdata/modelspecs/GAEEIOv2.0-s-WAT.yml b/inst/extdata/modelspecs/GAEEIOv1.0-s-WAT-12.yml similarity index 91% rename from inst/extdata/modelspecs/GAEEIOv2.0-s-WAT.yml rename to inst/extdata/modelspecs/GAEEIOv1.0-s-WAT-12.yml index a4a7910d..8dd56cc3 100644 --- a/inst/extdata/modelspecs/GAEEIOv2.0-s-WAT.yml +++ b/inst/extdata/modelspecs/GAEEIOv1.0-s-WAT-12.yml @@ -1,11 +1,11 @@ -Model: "GAEEIOv2.0-s-WAT" # 2012 Summary, Commodity +Model: "GAEEIOv1.0-s-WAT-12" # 2012 Summary, Commodity BaseIOSchema: 2012 BaseIOLevel: "Summary" IOYear: 2012 # Year for IO data ModelRegionAcronyms: ["US-GA", "RoUS"] ModelType: "EEIO" IODataSource: "stateior" -IODataVersion: "0.1.0" +IODataVersion: "0.2.1" BasePriceType: "PRO" #producer BasewithRedefinitions: FALSE CommodityorIndustryType: "Commodity" @@ -17,7 +17,7 @@ SatelliteTable: FullName: "Water withdrawals" Abbreviation: "WAT" StaticSource: TRUE - StaticFile: "flowsa/FlowBySector/Water_state_2015_m1_v1.1_b05ad38.parquet" + StaticFile: "flowsa/FlowBySector/Water_state_2015_m1_v1.2.4_7c15ea5.parquet" FileLocation: "DataCommons" DataYears: [2015] SectorListSource: "NAICS" diff --git a/inst/extdata/modelspecs/USEEIOv2.1-422.yml b/inst/extdata/modelspecs/USEEIOv2.1-422.yml deleted file mode 100644 index 42ba7621..00000000 --- a/inst/extdata/modelspecs/USEEIOv2.1-422.yml +++ /dev/null @@ -1,867 +0,0 @@ -Model: "USEEIOv2.1-422" -BaseIOSchema: 2012 -BaseIOLevel: &BaseIOLevel "Detail" -IOYear: 2012 # Year for IO data -ModelRegionAcronyms: ["US"] -ModelType: "EEIO" -IODataSource: "BEA" -BasePriceType: "PRO" #producer -BasewithRedefinitions: FALSE -CommodityorIndustryType: "Commodity" -ScrapIncluded: FALSE -DisaggregationSpecs: ["ElectricityDisaggregationDetail", "WasteDisaggregationDetail"] #Name of disaggregation yml file. -AggregationSpecs: ["ElectricityAggregationDetail"] - -SatelliteTable: - WAT: - FullName: "Water withdrawals" - Abbreviation: "WAT" - StaticSource: TRUE - StaticFile: "flowsa/FlowBySector/Water_national_2015_m3_v0.4.1_7c5071e.parquet" - FileLocation: "DataCommons" - DataYears: [2015] - Locations: ["US"] - SectorListSource: "NAICS" - SectorListYear: 2012 - SectorListLevel: "6" - OriginalFlowSource: "FEDEFLv1.0.6" - ScriptFunctionCall: "getFlowbySectorCollapsed" #function to call for script - ScriptFunctionParameters: null - DataSources: - USGS_NWIS_WU_2015: - Title: "Water Use in the US" - Author: "USGS" - DataYear: 2015 - URL: "https://waterdata.usgs.gov/" - Primary: TRUE - CHAIR: - FullName: "Criteria and Hazardous Air Emissions" - Abbreviation: "CHAIR" - StaticSource: TRUE - StaticFile: "flowsa/FlowBySector/CAP_HAP_national_2017_v0.3.1_f3cdf5b.parquet" - FileLocation: "DataCommons" - DataYears: [2017] - Locations: ["US"] - SectorListSource: "NAICS" - SectorListYear: 2012 - SectorListLevel: "6" - OriginalFlowSource: "FEDEFLv1.0.6" - ScriptFunctionCall: "getFlowbySectorCollapsed" #function to call for script - ScriptFunctionParameters: null - DataSources: - EPA_NEI_2017: - Title: "National Emissions Inventory" - Author: "EPA" - DataYear: 2017 - URL: "https://www.epa.gov/air-emissions-inventories/national-emissions-inventory-nei" - Primary: TRUE - EPA_TRI_2017: - Title: "Toxic Release Inventory" - Author: "EPA" - DataYear: 2017 - URL: "https://www.epa.gov/toxics-release-inventory-tri-program" - Primary: TRUE - GRDREL: - FullName: "Point source industrial releases to ground" - Abbreviation: "GRDREL" - StaticSource: TRUE - StaticFile: "flowsa/FlowBySector/GRDREL_national_2017_v0.3.1_f3cdf5b.parquet" - FileLocation: "DataCommons" - DataYears: [2017] - Locations: ["US"] - SectorListSource: "NAICS" - SectorListYear: 2012 - SectorListLevel: "6" - OriginalFlowSource: "FEDEFLv1.0.6" - ScriptFunctionCall: "getFlowbySectorCollapsed" #function to call for script - ScriptFunctionParameters: null - DataSources: - EPA_TRI_2017: - Title: "Toxic Release Inventory" - Author: "EPA" - DataYear: 2017 - URL: "https://www.epa.gov/toxics-release-inventory-tri-program" - Primary: TRUE - WATREL: - FullName: "Point source releases to water" - Abbreviation: "WATREL" - StaticSource: TRUE - StaticFile: "flowsa/FlowBySector/TRI_DMR_national_2017_v0.3.1_f3cdf5b.parquet" - FileLocation: "DataCommons" - DataYears: [2017] - Locations: ["US"] - SectorListSource: "NAICS" - SectorListYear: 2012 - SectorListLevel: "6" - OriginalFlowSource: "FEDEFLv1.0.6" - ScriptFunctionCall: "getFlowbySectorCollapsed" #function to call for script - ScriptFunctionParameters: null - DataSources: - EPA_TRI_2017: - Title: "Toxic Release Inventory" - Author: "EPA" - DataYear: 2017 - URL: "https://www.epa.gov/toxics-release-inventory-tri-program" - Primary: TRUE - EPA_DMR_2017: - Title: "Discharge Monitoring Report" - Author: "EPA" - DataYear: 2017 - URL: "https://echo.epa.gov/tools/data-downloads/icis-npdes-dmr-and-limit-data-set" - Primary: TRUE - GHG: - FullName: "Greenhouse Gases" - Abbreviation: "GHG" - StaticSource: TRUE - StaticFile: "useeior/NGHGIAM_GHG_TotalsBySector_wUUIDs.csv" - FileLocation: "DataCommons" - DataYears: [2016] - Locations: ["US"] - SectorListSource: "BEA" # or, NAICS - SectorListYear: 2012 - SectorListLevel: "Detail" - OriginalFlowSource: "FEDEFLv1.0.6" - DataSources: - USEPA_GHG_2018: - Title: "GHG Inventory" - Author: "USEPA" - DataYear: 2016 - URL: "https://www.epa.gov/ghgemissions/inventory-us-greenhouse-gas-emissions-and-sinks-1990-2016" - Primary: TRUE - LAND: - FullName: "Land use" - Abbreviation: "LAND" - StaticSource: TRUE - StaticFile: "flowsa/FlowBySector/Land_national_2012_v1.0.1_0470867.parquet" - FileLocation: "DataCommons" - DataYears: [2012] - Locations: ["US"] - SectorListSource: "NAICS" - SectorListYear: 2012 - SectorListLevel: "6" - OriginalFlowSource: "FEDEFLv1.0.6" - ScriptFunctionCall: "getFlowbySectorCollapsed" #function to call for script - ScriptFunctionParameters: null - DataSources: - BLM_PLS: - Title: "Public Land Statistics" - Author: "BLM" - DataYear: 2012 - URL: "https://www.blm.gov/about/data/public-land-statistics" - Primary: FALSE - EIA_CBECS_Land: - Title: "Commercial Building Energy Consumption Survey" - Author: "EIA" - DataYear: 2012 - URL: "https://www.eia.gov/consumption/commercial/data/2012/" - Primary: FALSE - EIA_MECS_Land: - Title: "Manufacturing Energy Consumption Survey" - Author: "EIA" - DataYear: 2014 - URL: "https://www.eia.gov/consumption/manufacturing/data/2014/" - Primary: FALSE - USDA_ERS_MLU: - Title: "Major Uses of Land in the United States" - Author: "USDA" - DataYear: 2012 - URL: "https://www.ers.usda.gov/data-products/major-land-uses/" - Primary: TRUE - MINE: - FullName: "Mineral extraction" - Abbreviation: "MINE" - StaticSource: TRUE - StaticFile: "useeior/USEEIOv1.1_MINE_TotalsBySector_FEDEFL_wUUIDs.csv" - FileLocation: "DataCommons" - DataYears: [2014] - Locations: ["US"] - SectorListSource: "BEA" - SectorListYear: 2007 - SectorListLevel: "Detail" - OriginalFlowSource: "FEDEFLv1.0.6" - DataSources: - USGS_MCS: - Title: "Mineral Commodity Summary" - Author: "USGS" - DataYear: 2014 - URL: "https://www.usgs.gov/centers/nmic/mineral-commodity-summaries" - Primary: TRUE - ENERGY: - FullName: "Energy extraction" - Abbreviation: "ENERGY" - StaticSource: TRUE - StaticFile: "useeior/USEEIOv1.1_Energy_TotalsBySector_FEDEFL_wUUIDs.csv" - FileLocation: "DataCommons" - DataYears: [2014] - Locations: ["US"] - SectorListSource: "BEA" - SectorListYear: 2007 - SectorListLevel: "Detail" - OriginalFlowSource: "FEDEFLv1.0.6" - DataSources: - EIA_MER: - Title: "Monthly Energy Review" - Author: "EIA" - DataYear: 2014 - URL: "http://www.eia.gov/totalenergy/data/monthly/" - Primary: TRUE - EIA_923: - Title: "Form EIA-923 Detailed" - Author: "EIA" - DataYear: 2014 - URL: "https://www.eia.gov/electricity/data/eia923/" - Primary: TRUE - NPAG: - FullName: "Nitrogen and Phosphorus Releases from Agriculture" - Abbreviation: "NPAG" - StaticSource: TRUE - StaticFile: "useeior/USEEIOv1.1_NPAG_TotalsBySector_wUUIDs.csv" - FileLocation: "DataCommons" - DataYears: [2013, 2015] - Locations: ["US"] - SectorListSource: "BEA" - SectorListYear: 2007 - SectorListLevel: "Detail" - OriginalFlowSource: "FEDEFLv1.0.6" - DataSources: - USDA_CUS_Corn_Potatoes: - Title: "Chemical Use Survey - Corn and Potatoes" - Author: "USDA" - DataYear: 2014 - URL: "https://www.nass.usda.gov/Data_and_Statistics/Pre-Defined_Queries/2014_Corn_and_Potatoes/" - Primary: FALSE - USDA_CUS_Cotton: - Title: "Chemical Use Survey - Cotton" - Author: "USDA" - DataYear: 2010 - URL: "https://www.nass.usda.gov/Data_and_Statistics/Pre-Defined_Queries/2010_Corn_Upland_Cotton_Fall_Potatoes/" - Primary: FALSE - USDA_CUS_Fruit: - Title: "Chemical Use Survey - Fruit" - Author: "USDA" - DataYear: 2011 - URL: "https://www.nass.usda.gov/Data_and_Statistics/Pre-Defined_Queries/2011_Fruit_Chem_Usage/" - Primary: FALSE - USDA_CUS_Peanuts_Rice: - Title: "Chemical Use Survey - Peanuts and Rice" - Author: "USDA" - DataYear: 2013 - URL: "https://www.nass.usda.gov/Data_and_Statistics/Pre-Defined_Queries/2013_Peanuts_and_Rice/" - Primary: FALSE - USDA_CUS_Soybeans_Wheat: - Title: "Chemical Use Survey - Soybeans and Wheat" - Author: "USDA" - DataYear: 2012 - URL: "https://www.nass.usda.gov/Data_and_Statistics/Pre-Defined_Queries/2012_Soybeans_and_Wheat/" - Primary: FALSE - USDA_CUS_Vegetables: - Title: "Chemical Use Survey - Vegetables" - Author: "USDA" - DataYear: 2014 - URL: "https://www.nass.usda.gov/Data_and_Statistics/Pre-Defined_Queries/2014_Vegetables/" - Primary: FALSE - PEST: - FullName: "Pesticide releases" - Abbreviation: "PEST" - StaticSource: TRUE - StaticFile: "useeior/USEEIOv1.1_PEST_TotalsBySector_wUUIDs.csv" - FileLocation: "DataCommons" - DataYears: [2004, 2005, 2010, 2011, 2012, 2013, 2014] - Locations: ["US"] - SectorListSource: "BEA" - SectorListYear: 2007 - SectorListLevel: "Detail" - OriginalFlowSource: "FEDEFLv1.0.6" - DataSources: - USDA_CUS_Corn_Potatoes: - Title: "Chemical Use Survey - Corn and Potatoes" - Author: "USDA" - DataYear: 2014 - URL: "https://www.nass.usda.gov/Data_and_Statistics/Pre-Defined_Queries/2014_Corn_and_Potatoes/" - Primary: FALSE - USDA_CUS_Cotton: - Title: "Chemical Use Survey - Cotton" - Author: "USDA" - DataYear: 2010 - URL: "https://www.nass.usda.gov/Data_and_Statistics/Pre-Defined_Queries/2010_Corn_Upland_Cotton_Fall_Potatoes/" - Primary: FALSE - USDA_CUS_Fruit: - Title: "Chemical Use Survey - Fruit" - Author: "USDA" - DataYear: 2011 - URL: "https://www.nass.usda.gov/Data_and_Statistics/Pre-Defined_Queries/2011_Fruit_Chem_Usage/" - Primary: FALSE - USDA_CUS_Peanuts_Rice: - Title: "Chemical Use Survey - Peanuts and Rice" - Author: "USDA" - DataYear: 2013 - URL: "https://www.nass.usda.gov/Data_and_Statistics/Pre-Defined_Queries/2013_Peanuts_and_Rice/" - Primary: FALSE - USDA_CUS_Soybeans_Wheat: - Title: "Chemical Use Survey - Soybeans and Wheat" - Author: "USDA" - DataYear: 2012 - URL: "https://www.nass.usda.gov/Data_and_Statistics/Pre-Defined_Queries/2012_Soybeans_and_Wheat/" - Primary: FALSE - USDA_CUS_Vegetables: - Title: "Chemical Use Survey - Vegetables" - Author: "USDA" - DataYear: 2014 - URL: "https://www.nass.usda.gov/Data_and_Statistics/Pre-Defined_Queries/2014_Vegetables/" - Primary: FALSE - CNHW: - FullName: "Commercial non-hazardous waste excluding construction activities" - Abbreviation: "CNHW" - StaticSource: TRUE - StaticFile: "useeior/USEEIOv1.1_CNHW_TotalsBySector.csv" - FileLocation: "DataCommons" - DataYears: [2015] - Locations: ["US"] - SectorListSource: "BEA" - SectorListYear: 2007 - SectorListLevel: "Detail" - OriginalFlowSource: "Waste Characterization Study 2014" - DataSources: - CalRecycle_CWCS: - Title: "2014 Generator-Based Characterization of Commercial Sector" - Author: "CalRecycle" - DataYear: 2014 - URL: "https://www2.calrecycle.ca.gov/WasteCharacterization/PubExtracts/2014/GenSummary.pdf" - Primary: TRUE - CNHWC: - FullName: "Commercial non-hazardous waste from construction activities" - Abbreviation: "CNHWC" - StaticSource: TRUE - StaticFile: "useeior/USEEIOv1.1_CNHWC_TotalsBySector.csv" - FileLocation: "DataCommons" - DataYears: [2014] - Locations: ["US"] - SectorListSource: "BEA" - SectorListYear: 2007 - SectorListLevel: "Detail" - OriginalFlowSource: "CDDPath" - DataSources: - USEPA_FF_2014: - Title: "Advancing Sustainable Materials Management: 2014 Fact Sheet" - Author: "USEPA" - DataYear: 2014 - URL: "https://www.epa.gov/sites/production/files/2016-11/documents/2014_smmfactsheet_508.pdf" - Primary: TRUE - CRHW: - FullName: "Commercial RCRA-defined hazardous waste" - Abbreviation: "CRHW" - StaticSource: TRUE - StaticFile: "flowsa/FlowBySector/CRHW_national_2017_v0.3.1_f3cdf5b.parquet" - FileLocation: "DataCommons" - DataYears: [2017] - Locations: ["US"] - SectorListSource: "NAICS" - SectorListYear: 2012 - SectorListLevel: "6" - ScriptFunctionCall: "getFlowbySectorCollapsed" #function to call for script - ScriptFunctionParameters: null - OriginalFlowSource: "RCRAInfo" - DataSources: - USEPA_RCRAInfo_2017: - Title: "National Biennial RCRA Hazardous Waste Report" - Author: "USEPA" - DataYear: 2017 - URL: "https://rcrapublic.epa.gov/rcrainfoweb/action/modules/br/main/broverview" - Primary: TRUE - EMP: - FullName: "Employment" - Abbreviation: "EMP" - StaticSource: TRUE - StaticFile: "flowsa/FlowBySector/Employment_national_2017_v0.3.1_f3cdf5b.parquet" - FileLocation: "DataCommons" - DataYears: [2017] - Locations: ["US"] - SectorListSource: "NAICS" - SectorListYear: 2012 - SectorListLevel: "6" - ScriptFunctionCall: "getFlowbySectorCollapsed" #function to call for script - ScriptFunctionParameters: null - OriginalFlowSource: "National Employment Matrix" - DataSources: - BLS_QCEW_2017: - Title: "Quarterly Census of Employment and Wages" - Author: "BLS" - DataYear: 2017 - URL: "https://www.bls.gov/cew/" - Primary: TRUE - VADD: - FullName: "Value Added" - Abbreviation: "VADD" - StaticSource: FALSE - StaticFile: null - FileLocation: None - DataYears: [2012] - Locations: ["US"] - SectorListSource: "BEA" - SectorListYear: 2012 - SectorListLevel: *BaseIOLevel - OriginalFlowSource: "Input-Output Tables" - ScriptFunctionCall: "getValueAddedTotalsbySector" #function to call for script - ScriptFunctionParameters: ["model"] #list of parameters - DataSources: - BEA_USE: - Title: "Detail Use Before Redefinitions" - Author: "BEA" - DataYear: 2012 - URL: "https://apps.bea.gov//industry/iTables%20Static%20Files/AllTablesIO.zip" - Primary: TRUE - -Indicators: - GreenhouseGases: - Name: "Greenhouse Gases" - Code: "GHG" - Group: "Impact Potential" - Unit: "kg CO2 eq" - SimpleUnit: "Kilograms Carbon Dioxide (CO2)" - SimpleName: "Greenhouse Gases" - StaticSource: TRUE - StaticFile: "lciafmt/traci/TRACI_2.1_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["Global warming"] - DataSources: - USEPA_TRACI_2.1: - Title: "TRACI 2.1" - Author: "USEPA" - DataYear: NA - URL: "https://www.epa.gov/chemical-research/tool-reduction-and-assessment-chemicals-and-other-environmental-impacts-traci" - Primary: TRUE - Acidification: - Name: "Acidification Potential" - Code: "ACID" - Group: "Impact Potential" - Unit: "kg SO2 eq" - SimpleUnit: "Kilograms Sulphur Dioxide (SO2)" - SimpleName: "Acid Rain" - StaticSource: TRUE - StaticFile: "lciafmt/traci/TRACI_2.1_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["Acidification"] - DataSources: - USEPA_TRACI_2.1: - Title: "TRACI 2.1" - Author: "USEPA" - DataYear: NA - URL: "https://www.epa.gov/chemical-research/tool-reduction-and-assessment-chemicals-and-other-environmental-impacts-traci" - Primary: TRUE - Eutrophication: - Name: "Eutrophication Potential" - Code: "EUTR" - Group: "Impact Potential" - Unit: "kg N eq" - SimpleUnit: "Kilograms Nitrogen (N)" - SimpleName: "Water Eutrophication" - StaticSource: TRUE - StaticFile: "lciafmt/traci/TRACI_2.1_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["Eutrophication"] - DataSources: - USEPA_TRACI_2.1: - Title: "TRACI 2.1" - Author: "USEPA" - DataYear: NA - URL: "https://www.epa.gov/chemical-research/tool-reduction-and-assessment-chemicals-and-other-environmental-impacts-traci" - Primary: TRUE - FreshwaterEcotox: - Name: "Freshwater Ecotoxicity Potential" - Code: "ETOX" - Group: "Impact Potential" - Unit: "CTUe" - SimpleUnit: "Comparative Toxic Unit for Ecosystem (CTUe)" - SimpleName: "Freshwater Ecotoxicity" - StaticSource: TRUE - StaticFile: "lciafmt/traci/TRACI_2.1_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["Freshwater ecotoxicity"] - DataSources: - USEPA_TRACI_2.1: - Title: "TRACI 2.1" - Author: "USEPA" - DataYear: NA - URL: "https://www.epa.gov/chemical-research/tool-reduction-and-assessment-chemicals-and-other-environmental-impacts-traci" - Primary: TRUE - HumanHealthCancer: - Name: "Human Health - Cancer" - Code: "HCAN" - Group: "Impact Potential" - Unit: "CTUh" - SimpleUnit: "Comparative Toxic Unit for Humans (CTUh)" - SimpleName: "Cancer Disease" - StaticSource: TRUE - StaticFile: "lciafmt/traci/TRACI_2.1_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["Human health - cancer"] - DataSources: - USEPA_TRACI_2.1: - Title: "TRACI 2.1" - Author: "USEPA" - DataYear: NA - URL: "https://www.epa.gov/chemical-research/tool-reduction-and-assessment-chemicals-and-other-environmental-impacts-traci" - Primary: TRUE - HumanHealthNonCancer: - Name: "Human Health - Noncancer" - Code: "HNCN" - Group: "Impact Potential" - Unit: "CTUh" - SimpleUnit: "Comparative Toxic Unit for Humans (CTUh)" - SimpleName: "Noncancer Disease" - StaticSource: TRUE - StaticFile: "lciafmt/traci/TRACI_2.1_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["Human health - non-cancer"] - DataSources: - USEPA_TRACI_2.1: - Title: "TRACI 2.1" - Author: "USEPA" - DataYear: NA - URL: "https://www.epa.gov/chemical-research/tool-reduction-and-assessment-chemicals-and-other-environmental-impacts-traci" - Primary: TRUE - HumanHealthToxicity: - Name: "Human Health Toxicity" - Code: "HTOX" - Group: "Impact Potential" - Unit: "CTUh" - SimpleUnit: "Comparative Toxic Unit for Humans (CTUh)" - SimpleName: "Toxic to Humans" - StaticSource: TRUE - StaticFile: "lciafmt/traci/TRACI_2.1_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getCombinedImpactMethods" #function to call for script - ScriptFunctionParameters: - indicators: ["Human health - cancer", "Human health - non-cancer"] - DataSources: - USEEIO_LCIA_Aggregation: - Title: "Aggregation of HNCN and HCAN" - Author: NA - DataYear: NA - URL: NA - Primary: TRUE - HumanHealthRespEffects: - Name: "Human Health - Respiratory Effects" - Code: "HRSP" - Group: "Impact Potential" - Unit: "kg PM2.5 eq" - SimpleUnit: "Kilograms Particulate Matter" - SimpleName: "Respiratory Effects" - StaticSource: TRUE - StaticFile: "lciafmt/traci/TRACI_2.1_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["Human health - particulate matter"] - DataSources: - USEPA_TRACI_2.1: - Title: "TRACI 2.1" - Author: "USEPA" - URL: "https://www.epa.gov/chemical-research/tool-reduction-and-assessment-chemicals-and-other-environmental-impacts-traci" - Primary: TRUE - Ozone: - Name: "Ozone Depletion" - Code: "OZON" - Group: "Impact Potential" - Unit: "kg CFC-11 eq" - SimpleUnit: "Kilograms ChloroFluoroCarbon-11" - SimpleName: "Ozone Depletion" - StaticSource: TRUE - StaticFile: "lciafmt/traci/TRACI_2.1_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["Ozone depletion"] - DataSources: - USEPA_TRACI_2.1: - Title: "TRACI 2.1" - Author: "USEPA" - DataYear: NA - URL: "https://www.epa.gov/chemical-research/tool-reduction-and-assessment-chemicals-and-other-environmental-impacts-traci" - Primary: TRUE - Smog: - Name: "Smog Formation Potential" - Code: "SMOG" - Group: "Impact Potential" - Unit: "kg O3 eq" - SimpleUnit: "Kilograms Ozone (O3)" - SimpleName: "Smog Formation" - StaticSource: TRUE - StaticFile: "lciafmt/traci/TRACI_2.1_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["Smog formation"] - DataSources: - USEPA_TRACI_2.1: - Title: "TRACI 2.1" - Author: "USEPA" - DataYear: NA - URL: "https://www.epa.gov/chemical-research/tool-reduction-and-assessment-chemicals-and-other-environmental-impacts-traci" - Primary: TRUE - freshwater_withdrawal: - Name: "Freshwater withdrawals" - Code: "WATR" - Group: "Resource Use" - Unit: "kg" - SimpleUnit: "Kilograms" - SimpleName: "Water Use" - StaticSource: TRUE - StaticFile: "lciafmt/fedefl/FEDEFL_Inventory_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["freshwater_resources"] - DataSources: - LCIAformatter: - Title: "LCIAformatter FEDEFL Inventory Methods" - Author: "USEPA" - DataYear: 2020 - URL: "https://github.com/USEPA/LCIAformatter" - Primary: TRUE - land_use: - Name: "Land use" - Code: "LAND" - Group: "Resource Use" - Unit: "m2*yr" - SimpleUnit: "Square Meters per Year" - SimpleName: "Land Use" - StaticSource: TRUE - StaticFile: "lciafmt/fedefl/FEDEFL_Inventory_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["land_use"] - DataSources: - LCIAformatter: - Title: "LCIAformatter FEDEFL Inventory Methods" - Author: "USEPA" - DataYear: 2020 - URL: "https://github.com/USEPA/LCIAformatter" - Primary: TRUE - HAP: - Name: "Hazardous Air Pollutants" - Code: "HAPS" - Group: "Chemical Releases" - Unit: "kg" - SimpleUnit: "Kilograms" - SimpleName: "Hazardous Air Pollutants" - StaticSource: TRUE - StaticFile: "lciafmt/fedefl/FEDEFL_Inventory_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["HAP"] - DataSources: - LCIAformatter: - Title: "LCIAformatter FEDEFL Inventory Methods" - Author: "USEPA" - DataYear: 2020 - URL: "https://github.com/USEPA/LCIAformatter" - Primary: TRUE - Pesticides: - Name: "Pesticides" - Code: "PEST" - Group: "Chemical Releases" - Unit: "kg" - SimpleUnit: "Kilograms" - SimpleName: "Pesticides" - StaticSource: TRUE - StaticFile: "lciafmt/fedefl/FEDEFL_Inventory_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["USDA_CUS_pesticides"] - DataSources: - LCIAformatter: - Title: "LCIAformatter FEDEFL Inventory Methods" - Author: "USEPA" - DataYear: 2020 - URL: "https://github.com/USEPA/LCIAformatter" - Primary: TRUE - NonRenewableEnergy: - Name: "Nonrenewable Energy Use" - Code: "NNRG" - Group: "Resource Use" - Unit: "MJ" - SimpleUnit: "Megajoules (MJ)" - SimpleName: "Nonrenewable Energy Use" - StaticSource: TRUE - FileLocation: "DataCommons" - StaticFile: "lciafmt/fedefl/FEDEFL_Inventory_v1.0.0_5555779.parquet" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["nonrenewable_energy"] - DataSources: - LCIAformatter: - Title: "LCIAformatter FEDEFL Inventory Methods" - Author: "USEPA" - DataYear: 2020 - URL: "https://github.com/USEPA/LCIAformatter" - Primary: TRUE - RenewableEnergy: - Name: "Renewable Energy Use" - Code: "RNRG" - Group: "Resource Use" - Unit: "MJ" - SimpleUnit: "Megajoules (MJ)" - SimpleName: "Renewable Energy Use" - StaticSource: TRUE - StaticFile: "lciafmt/fedefl/FEDEFL_Inventory_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["renewable_energy"] - DataSources: - LCIAformatter: - Title: "LCIAformatter FEDEFL Inventory Methods" - Author: "USEPA" - DataYear: 2020 - URL: "https://github.com/USEPA/LCIAformatter" - Primary: TRUE - Energy: - Name: "Energy Use" - Code: "ENRG" - Group: "Resource Use" - Unit: "MJ" - SimpleUnit: "Megajoules (MJ)" - SimpleName: "Energy Use" - StaticSource: TRUE - StaticFile: "lciafmt/fedefl/FEDEFL_Inventory_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["energy"] - DataSources: - LCIAformatter: - Title: "LCIAformatter FEDEFL Inventory Methods" - Author: "USEPA" - DataYear: 2020 - URL: "https://github.com/USEPA/LCIAformatter" - Primary: TRUE - MineralsMetals: - Name: "Minerals and Metals Use" - Code: "MNRL" - Group: "Resource Use" - Unit: "kg" - SimpleUnit: "Kilograms" - SimpleName: "Minerals and Metals Use" - StaticSource: TRUE - StaticFile: "lciafmt/fedefl/FEDEFL_Inventory_v1.0.0_5555779.parquet" - FileLocation: "DataCommons" - ScriptFunctionCall: "getImpactMethod" #function to call for script - ScriptFunctionParameters: - indicators: ["USGS_mineral_resources"] - DataSources: - LCIAformatter: - Title: "LCIAformatter FEDEFL Inventory Methods" - Author: "USEPA" - DataYear: 2020 - URL: "https://github.com/USEPA/LCIAformatter" - Primary: TRUE - ValueAdded: - Name: "Value Added" - Code: "VADD" - Group: "Economic & Social" - Unit: "$" - SimpleUnit: "US Dollars ($)" - SimpleName: "Value Added" - StaticSource: TRUE - StaticFile: "USEEIO_LCIA_Factors.csv" - FileLocation: "useeior" - DataSources: - ingwersen_useeiov11_2017: - Title: "USEEIOv1.1 - Elementary Flows and Life Cycle Impact Assessment (LCIA) Characterization Factors" - Author: "USEPA" - DataYear: 2020 - URL: "http://doi.org/10.23719/1368541" - Primary: TRUE - Jobs: - Name: "Jobs Supported" - Code: "JOBS" - Group: "Economic & Social" - Unit: "jobs" - SimpleUnit: "Employees" - SimpleName: "Jobs Supported" - StaticSource: TRUE - StaticFile: "USEEIO_LCIA_Factors.csv" - FileLocation: "useeior" - DataSources: - ingwersen_useeiov11_2017: - Title: "USEEIOv1.1 - Elementary Flows and Life Cycle Impact Assessment (LCIA) Characterization Factors" - Author: "USEPA" - DataYear: 2020 - URL: "http://doi.org/10.23719/1368541" - Primary: TRUE - RCRAHazWaste: - Name: "Commercial RCRA Hazardous Waste" - Code: "CRHW" - Group: "Waste Generated" - Unit: "kg" - SimpleUnit: "Kilograms" - SimpleName: "Hazardous Waste" - StaticSource: TRUE - StaticFile: "USEEIO_LCIA_Factors.csv" - FileLocation: "useeior" - DataSources: - meyer_analyzing_2020: - Title: "Analyzing economy-scale solid waste generation using the United States environmentally-extended input-output model" - Author: "USEPA" - DataYear: 2020 - URL: "http://doi.org/10.1016/j.resconrec.2020.104795" - Primary: TRUE - MunicipalWaste: - Name: "Commercial Municipal Solid Waste" - Code: "CMSW" - Group: "Waste Generated" - Unit: "kg" - SimpleUnit: "Kilograms" - SimpleName: "Municipal Solid Waste" - StaticSource: TRUE - StaticFile: "USEEIO_LCIA_Factors.csv" - FileLocation: "useeior" - DataSources: - meyer_analyzing_2020: - Title: "Analyzing economy-scale solid waste generation using the United States environmentally-extended input-output model" - Author: "USEPA" - DataYear: 2020 - URL: "http://doi.org/10.1016/j.resconrec.2020.104795" - Primary: TRUE - ConstructionDebris: - Name: "Commercial Construction and Demolition Debris" - Code: "CCDD" - Group: "Waste Generated" - Unit: "kg" - SimpleUnit: "Kilograms" - SimpleName: "Construction Debris" - StaticSource: TRUE - StaticFile: "USEEIO_LCIA_Factors.csv" - FileLocation: "useeior" - DataSources: - meyer_analyzing_2020: - Title: "Analyzing economy-scale solid waste generation using the United States environmentally-extended input-output model" - Author: "USEPA" - DataYear: 2020 - URL: "http://doi.org/10.1016/j.resconrec.2020.104795" - Primary: TRUE - -DemandVectors: - DefaultDemand: "DefaultDemandVectors" # Name of default demand vectors yml file -# Additional demand vectors beyond useeior defaults - HouseholdConsumption: - Type: "Consumption" - Year: 2012 - System: "Household" - Location: "US" diff --git a/man/buildTwoRegionModels.Rd b/man/buildTwoRegionModels.Rd new file mode 100644 index 00000000..1b60b9cf --- /dev/null +++ b/man/buildTwoRegionModels.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/BuildModel.R +\name{buildTwoRegionModels} +\alias{buildTwoRegionModels} +\title{Build two-region models for all 50 states based on a single config reference file.} +\usage{ +buildTwoRegionModels( + modelname, + configpaths = NULL, + validate = FALSE, + year = NULL +) +} +\arguments{ +\item{modelname}{Name of the model from a config file.} + +\item{configpaths}{str vector, paths (including file name) of model configuration file +and optional agg/disagg configuration file(s). If NULL, built-in config files are used.} + +\item{validate}{bool, if TRUE print validation results for each model} + +\item{year}{int, indicating for which year to run the models} +} +\value{ +A list of EEIO models for each state with complete components and attributes +} +\description{ +Build two-region models for all 50 states based on a single config reference file. +} diff --git a/man/calculateEEIOModel.Rd b/man/calculateEEIOModel.Rd index 142f7e39..ade7d8e3 100644 --- a/man/calculateEEIOModel.Rd +++ b/man/calculateEEIOModel.Rd @@ -9,18 +9,23 @@ calculateEEIOModel( model, perspective, demand = "Production", + location = NULL, use_domestic_requirements = FALSE ) } \arguments{ \item{model}{A complete EEIO model: a list with USEEIO model components and attributes.} -\item{perspective}{Perspective of the model, can be "DIRECT", "INTERMEDIATE", or "FINAL".} +\item{perspective}{Perspective of the model, can be "DIRECT" or "FINAL". "DIRECT" perspective +aligns results with the sectors in which they are produced, while "FINAL" perspective aligns +results with the sectors consumed by the final user.} -\item{demand}{A demand vector, can be name of a built-in model demand vector, e.g. "Production", +\item{demand}{A demand vector, can be name of a built-in model demand vector, e.g. "Production" or "Consumption", or an actual demand vector with names as one or more model sectors and numeric values in USD with the same dollar year as model.} +\item{location, }{str optional location code for demand vector, required for two-region models} + \item{use_domestic_requirements}{A logical value: if TRUE, use domestic demand and L_d matrix; if FALSE, use complete demand and L matrix.} } diff --git a/man/compare2RCommodityTotals.Rd b/man/compare2RCommodityTotals.Rd new file mode 100644 index 00000000..0caee01a --- /dev/null +++ b/man/compare2RCommodityTotals.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/StateiorFunctions.R +\name{compare2RCommodityTotals} +\alias{compare2RCommodityTotals} +\title{Compare commodity totals between the specified 2R model objects} +\usage{ +compare2RCommodityTotals(q_One, q_Two) +} +\arguments{ +\item{q_One}{A vector of commodity totals derived from specific model object} + +\item{q_Two}{A vector of commodity totals dervied from a different model object than q_One} +} +\value{ +A list of sectors that failed the comparison between the two specified q vectors. +} +\description{ +Compare commodity totals between the specified 2R model objects +} diff --git a/man/getConfiguration.Rd b/man/getConfiguration.Rd index 05bc2b20..b1b464d7 100644 --- a/man/getConfiguration.Rd +++ b/man/getConfiguration.Rd @@ -4,7 +4,7 @@ \alias{getConfiguration} \title{Gets a stored or user specified model or aggregation/disaggregation configuration file} \usage{ -getConfiguration(configname, configtype, configpaths = NULL) +getConfiguration(configname, configtype, configpaths = NULL, pkg = "useeior") } \arguments{ \item{configname}{str, name of the configuration file} @@ -13,6 +13,8 @@ getConfiguration(configname, configtype, configpaths = NULL) \item{configpaths}{str vector, paths (including file name) of model configuration file and optional agg/disagg configuration file(s). If NULL, built-in config files are used.} + +\item{pkg}{str, indicate package for access to config, either "useeior" or "stateior"} } \value{ A list of model specifications. diff --git a/man/getDisaggregationSpecs.Rd b/man/getDisaggregationSpecs.Rd index d2262d34..9062c039 100644 --- a/man/getDisaggregationSpecs.Rd +++ b/man/getDisaggregationSpecs.Rd @@ -4,13 +4,15 @@ \alias{getDisaggregationSpecs} \title{Obtain aggregation and disaggregation specs from input files} \usage{ -getDisaggregationSpecs(model, configpaths = NULL) +getDisaggregationSpecs(model, configpaths = NULL, pkg = "useeior") } \arguments{ \item{model}{An EEIO model object with model specs and IO tables loaded} \item{configpaths}{str vector, paths (including file name) of disagg configuration file(s). If NULL, built-in config files are used.} + +\item{pkg}{str, indicate package for access to config, either "useeior" or "stateior"} } \value{ A model with the specified aggregation and disaggregation specs. diff --git a/man/getInputFilePath.Rd b/man/getInputFilePath.Rd index 055e733e..b1e6ef1d 100644 --- a/man/getInputFilePath.Rd +++ b/man/getInputFilePath.Rd @@ -4,7 +4,12 @@ \alias{getInputFilePath} \title{Identify location of filepath for model input files} \usage{ -getInputFilePath(configpaths, folderPath = "extdata", filename) +getInputFilePath( + configpaths, + folderPath = "extdata", + filename, + package = "useeior" +) } \arguments{ \item{configpaths}{str vector, paths (including file name) of configuration files.} @@ -12,6 +17,8 @@ getInputFilePath(configpaths, folderPath = "extdata", filename) \item{folderPath}{str local path to configuration type} \item{filename}{str filename of model spec} + +\item{package}{str name of package for location of input file} } \description{ Identify location of filepath for model input files diff --git a/man/heatmapSectorRanking.Rd b/man/heatmapSectorRanking.Rd index df755cbf..14962683 100644 --- a/man/heatmapSectorRanking.Rd +++ b/man/heatmapSectorRanking.Rd @@ -10,7 +10,8 @@ heatmapSectorRanking( indicators, sector_to_remove, N_sector, - x_title = NULL + x_title = NULL, + use_codes = TRUE ) } \arguments{ @@ -18,13 +19,15 @@ heatmapSectorRanking( \item{matrix}{A matrix from model result} -\item{indicators}{A vector of indicators to plot} +\item{indicators}{A vector of indicators to plot, use Codes if use_codes = TRUE, otherwise use Names} \item{sector_to_remove}{Code of one or more BEA sectors that will be removed from the plot. Can be "".} \item{N_sector}{A numeric value indicating number of sectors to show in the ranking} \item{x_title}{A string specifying desired title on the x-axis, default is NULL, the title will be "modelname indicators"} + +\item{use_codes}{bool, indicate if figure should use indicator Code (TRUE) or Name (FALSE)} } \description{ SMM tool like heatmap showing ranking of sectors diff --git a/man/prepare2RDemand.Rd b/man/prepare2RDemand.Rd new file mode 100644 index 00000000..4f2d0e84 --- /dev/null +++ b/man/prepare2RDemand.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/StateiorFunctions.R +\name{prepare2RDemand} +\alias{prepare2RDemand} +\title{Prepares a production demand vector representing production for two region models +Demand for SoI = SoI2SoI + RoUS2SoI +Demand for RoUS = SoI2RoUS + RoUS2RoUS} +\usage{ +prepare2RDemand(model, location, domestic, demand_type = "Production") +} +\arguments{ +\item{model}{An EEIO model object with model specs and IO tables loaded} + +\item{location, }{str of location code for demand vector} + +\item{domestic}{A logical parameter indicating whether to generate domestic demand vector.} + +\item{demand_type}{A str indicating whether demand is Production or Consumption} +} +\value{ +A named vector with demand +} +\description{ +Prepares a production demand vector representing production for two region models +Demand for SoI = SoI2SoI + RoUS2SoI +Demand for RoUS = SoI2RoUS + RoUS2RoUS +} diff --git a/man/prepareConsumptionDemand.Rd b/man/prepareConsumptionDemand.Rd index 0d47bc3f..7d4dbf5e 100644 --- a/man/prepareConsumptionDemand.Rd +++ b/man/prepareConsumptionDemand.Rd @@ -4,10 +4,12 @@ \alias{prepareConsumptionDemand} \title{Prepares a demand vector representing consumption} \usage{ -prepareConsumptionDemand(model) +prepareConsumptionDemand(model, location) } \arguments{ \item{model}{An EEIO model object with model specs and IO tables loaded} + +\item{location, }{str of location code for demand vector} } \value{ a named vector with demand diff --git a/man/prepareDomesticConsumptionDemand.Rd b/man/prepareDomesticConsumptionDemand.Rd index 6493d1b8..2220c652 100644 --- a/man/prepareDomesticConsumptionDemand.Rd +++ b/man/prepareDomesticConsumptionDemand.Rd @@ -4,10 +4,12 @@ \alias{prepareDomesticConsumptionDemand} \title{Prepares a demand vector representing domestic consumption} \usage{ -prepareDomesticConsumptionDemand(model) +prepareDomesticConsumptionDemand(model, location) } \arguments{ \item{model}{An EEIO model object with model specs and IO tables loaded} + +\item{location, }{str of location code for demand vector} } \value{ A named vector with demand diff --git a/man/prepareDomesticProductionDemand.Rd b/man/prepareDomesticProductionDemand.Rd index e8fb6870..8acfdc30 100644 --- a/man/prepareDomesticProductionDemand.Rd +++ b/man/prepareDomesticProductionDemand.Rd @@ -5,10 +5,12 @@ \title{Prepares a demand vector representing domestic production Formula for production vector: y_p <- y_dc + y_e + y_d_delta + mu} \usage{ -prepareDomesticProductionDemand(model) +prepareDomesticProductionDemand(model, location) } \arguments{ \item{model}{An EEIO model object with model specs and IO tables loaded} + +\item{location, }{str of location code for demand vector} } \value{ A named vector with demand diff --git a/man/prepareHouseholdDemand.Rd b/man/prepareHouseholdDemand.Rd index f8eb2dfc..2e63aa49 100644 --- a/man/prepareHouseholdDemand.Rd +++ b/man/prepareHouseholdDemand.Rd @@ -4,10 +4,12 @@ \alias{prepareHouseholdDemand} \title{Prepares a demand vector representing household consumption} \usage{ -prepareHouseholdDemand(model) +prepareHouseholdDemand(model, location) } \arguments{ \item{model}{An EEIO model object with model specs and IO tables loaded} + +\item{location, }{str of location code for demand vector} } \value{ A named vector with demand diff --git a/man/prepareProductionDemand.Rd b/man/prepareProductionDemand.Rd index cb3d955b..d9435532 100644 --- a/man/prepareProductionDemand.Rd +++ b/man/prepareProductionDemand.Rd @@ -7,10 +7,12 @@ Formula for production vector: y_p <- y_c + y_e + y_m + y_delta where y_c = consumption, y_e = exports, y_m = imports, y_delta = change in inventories y_m values are generally negative in the BEA data and thus are added (whereas when positive they are subtracted)} \usage{ -prepareProductionDemand(model) +prepareProductionDemand(model, location) } \arguments{ \item{model}{An EEIO model object with model specs and IO tables loaded} + +\item{location, }{str of location code for demand vector} } \value{ A named vector with demand diff --git a/man/print2RValidationResults.Rd b/man/print2RValidationResults.Rd new file mode 100644 index 00000000..e2436d49 --- /dev/null +++ b/man/print2RValidationResults.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/StateiorFunctions.R +\name{print2RValidationResults} +\alias{print2RValidationResults} +\title{Run validation checks for 2R models and print to console} +\usage{ +print2RValidationResults(model) +} +\arguments{ +\item{model}{A complete 2R EEIO model: a list with USEEIO model components and attributes} +} +\value{ +A list with 2R model results. +} +\description{ +Run validation checks for 2R models and print to console +} diff --git a/man/sumforConsumption.Rd b/man/sumforConsumption.Rd index 4c547e0f..77bdb7d2 100644 --- a/man/sumforConsumption.Rd +++ b/man/sumforConsumption.Rd @@ -6,12 +6,14 @@ Complete national consumption formula: y_c <- Y_h + Y_v + Y_g Domestic portion of national consumption: y_dc <- Y_dh + Y_dv + Y_dg} \usage{ -sumforConsumption(model, Y) +sumforConsumption(model, Y, location) } \arguments{ \item{model}{An EEIO model object with model specs and IO tables loaded} \item{Y, }{a model Demand df.} + +\item{location, }{str of location code for demand vector} } \value{ A named vector with model sectors and demand amounts diff --git a/man/validate2RCommodityTotals.Rd b/man/validate2RCommodityTotals.Rd new file mode 100644 index 00000000..18366e60 --- /dev/null +++ b/man/validate2RCommodityTotals.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/StateiorFunctions.R +\name{validate2RCommodityTotals} +\alias{validate2RCommodityTotals} +\title{Validate commodity totals between 2R Use table, Make table, and total commodity output objects} +\usage{ +validate2RCommodityTotals(model) +} +\arguments{ +\item{model}{A complete 2R EEIO model: a list with USEEIO model components and attributes} +} +\value{ +A list containing failures of commodity total comparisons between various model objects. +} +\description{ +Validate commodity totals between 2R Use table, Make table, and total commodity output objects +}