Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into sjs/feature/CEDS_Re…
Browse files Browse the repository at this point in the history
…lease_April21
  • Loading branch information
pralitp committed Jul 10, 2021
2 parents ef252cd + deae9d8 commit 544eff9
Show file tree
Hide file tree
Showing 30 changed files with 1,117 additions and 2 deletions.
554 changes: 554 additions & 0 deletions input/gcamdata/R/zchunk_L262.dac.R

Large diffs are not rendered by default.

31 changes: 30 additions & 1 deletion input/gcamdata/R/zchunk_L270.limits.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ module_energy_L270.limits <- function(command, ...) {
if(command == driver.DECLARE_INPUTS) {
return(c(FILE = "common/GCAM_region_names",
FILE = "energy/A23.globaltech_eff",
FILE = "emissions/A_CDRU",
"L102.gdp_mil90usd_GCAM3_R_Y",
"L102.gdp_mil90usd_Scen_R_Y",
"L221.GlobalTechCoef_en",
Expand Down Expand Up @@ -52,6 +53,7 @@ module_energy_L270.limits <- function(command, ...) {
# Load required inputs
GCAM_region_names <- get_data(all_data, "common/GCAM_region_names")
A23.globaltech_eff <- get_data(all_data, "energy/A23.globaltech_eff")
A_CDRU <- get_data(all_data, "emissions/A_CDRU")
L102.gdp_mil90usd_GCAM3_R_Y <- get_data(all_data, "L102.gdp_mil90usd_GCAM3_R_Y", strip_attributes = TRUE)
L102.gdp_mil90usd_Scen_R_Y <- get_data(all_data, "L102.gdp_mil90usd_Scen_R_Y")
L102.gdp_mil90usd_Scen_R_Y <- get_data(all_data, "L102.gdp_mil90usd_Scen_R_Y")
Expand Down Expand Up @@ -125,6 +127,31 @@ module_energy_L270.limits <- function(command, ...) {

L270.CTaxInput <- L270.CTaxInput[, c(LEVEL2_DATA_NAMES[["GlobalTechYr"]], "ctax.input", "fuel.C.coef")]


A_CDRU %>%
gather_years("coef") -> A_CDRU

#create a coefficient table for airCO2 only, analogous to L221.GlobalTechCoef_en (where we don't want airCO2 showing up), which will be appended to L270.CTaxInput
A_CDRU %>%
select(supplysector, subsector, technology) %>%
distinct %>%
# Interpolate to all years
repeat_add_columns(tibble(year = c(HISTORICAL_YEARS, MODEL_FUTURE_YEARS))) %>%
left_join(A_CDRU, by = c("supplysector", "subsector", "technology", "year")) %>%
group_by(supplysector, subsector, technology) %>%
mutate(coefficient = approx_fun(year, value = coef, rule = 1)) %>%
ungroup() %>%
filter(year %in% MODEL_YEARS) %>%
select(sector.name = supplysector, subsector.name = subsector, technology, year, coefficient) -> L270.GlobalTechCoef_cdr

L270.GlobalTechCoef_cdr %>%
mutate(ctax.input = energy.NEG_EMISS_POLICY_NAME) %>%
rename(fuel.C.coef = coefficient)-> L270.GlobalTechCoef_cdr

L270.CTaxInput %>%
bind_rows(L270.GlobalTechCoef_cdr) -> L270.CTaxInput


# L270.LandRootNegEmissMkt: set the negative emissions policy name into the LandAllocator root
# so it can make it available to all land leaves under a UCT
tibble(region = GCAM_region_names$region,
Expand Down Expand Up @@ -216,9 +243,11 @@ module_energy_L270.limits <- function(command, ...) {
add_comments("Add ctax-input to all of the bio-energy supply sectors") %>%
add_comments("by using L221.GlobalTechCoef_en filtered by biomass|ethanol") %>%
add_comments("and joining carbon coefficients from L202.CarbonCoef") %>%
add_comments("airCO2 is also appended for direct air capture (i.e. negative emissions not from biomass)") %>%
add_legacy_name("L270.CTaxInput") %>%
add_precursors("L221.GlobalTechCoef_en",
"L202.CarbonCoef") ->
"L202.CarbonCoef",
"emissions/A_CDRU") ->
L270.CTaxInput

L270.LandRootNegEmissMkt %>%
Expand Down
62 changes: 62 additions & 0 deletions input/gcamdata/R/zchunk_LA162.dac.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2019 Battelle Memorial Institute; see the LICENSE file.

#' module_energy_LA162.dac
#'
#' Sets up input, output, and IO coefficients for dac
#'
#' @param command API command to execute
#' @param ... other optional parameters, depending on command
#' @return Depends on \code{command}: either a vector of required inputs,
#' a vector of output names, or (if \code{command} is "MAKE") all
#' the generated outputs: \code{L162.out_Mt_R_dac_Yh},
#' @details This chunk defines historical demand for the climate engineering services sector, setting up structure for future competition.
#' For all historical years, is met entirely by "no DAC" technology
#' @importFrom assertthat assert_that
#' @importFrom dplyr arrange bind_rows filter group_by left_join mutate select semi_join summarise summarise_all
#' @importFrom tidyr complete gather nesting
#' @author JF March 2021
module_energy_LA162.dac <- function(command, ...) {
if(command == driver.DECLARE_INPUTS) {
return(c(FILE = "energy/A62.calibration"))
} else if(command == driver.DECLARE_OUTPUTS) {
return(c("L162.out_Mt_R_dac_Yh"))
} else if(command == driver.MAKE) {

# Silence global variable package check
. <- Biomass <- Biomass_EJ <- Coal <- Coal_EJ <- Country <- GCAM_region_ID <- Gas <- Gas_EJ <-
IEA_fuelshare_region <- IEA_intensity_region <- IOelec <- Oil <- Oil_EJ <- TPE_GJkg <-
Worrell_region <- cement_prod_Mt <- country_name <- elec_EJ <- elec_GJkg <-
emiss_ktC <- fuel <- heat_EJ <- heat_GJkg <- in.value <- ind.value <- iso <-
old.year <- out.value <- process_emissions_MtC <- process_emissions_ktC <-
prod_Mt <- prod_emiss_ratio <- reg_process_emissions <- region_GCAM3 <- sector <-
share <- value <- cement <- year <- value.y <- value.x <- NULL

all_data <- list(...)[[1]]

# Load required inputs

ces_calibration <- get_data(all_data, "energy/A62.calibration")


# ===================================================
# 2. Perform computations

# Set constants used for this chunk
# ---------------------------------

ces_calibration -> L162.out_Mt_R_dac_Yh


L162.out_Mt_R_dac_Yh %>%
add_units("Mt C") %>%
add_comments("Outputs are calculated by simply transposing the calibration matrix, which contains arbitrarily high values for dac+noDAC") %>%
add_legacy_name("L162.out_Mt_R_dac_Yh") %>%
add_precursors("energy/A62.calibration") ->
L162.out_Mt_R_dac_Yh


return_data(L162.out_Mt_R_dac_Yh)
} else {
stop("Unknown command")
}
}
125 changes: 125 additions & 0 deletions input/gcamdata/R/zchunk_batch_dac_xml.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Copyright 2019 Battelle Memorial Institute; see the LICENSE file.

#' module_energy_batch_dac_xml
#'
#' Construct XML data structure for \code{dac.xml}.
#'
#' @param command API command to execute
#' @param ... other optional parameters, depending on command
#' @return Depends on \code{command}: either a vector of required inputs,
#' a vector of output names, or (if \code{command} is "MAKE") all
#' the generated outputs: \code{dac.xml}. The corresponding file in the
#' original data system was \code{batch_dac_xml.R} (energy XML).
#' @author JF March 2021
module_energy_batch_dac_xml <- function(command, ...) {


TECH_PARAMETRIZATION_INPUTS <- paste0("ssp", 1:5)
if(command == driver.DECLARE_INPUTS) {
return(c("L262.Supplysector_dac",
"L262.FinalEnergyKeyword_dac",
"L262.SubsectorLogit_dac",
"L262.SubsectorShrwtFllt_dac",
"L262.SubsectorInterp_dac",
"L262.StubTech_dac",
"L262.GlobalTechShrwt_dac",
c(paste("L262.GlobalTechShrwt_dac", tolower(TECH_PARAMETRIZATION_INPUTS), sep = "_")),
c(paste("L262.GlobalTechCoef_dac", tolower(TECH_PARAMETRIZATION_INPUTS), sep = "_")),
c(paste("L262.GlobalTechCost_dac", tolower(TECH_PARAMETRIZATION_INPUTS), sep = "_")),
"L262.GlobalTechCapture_dac",
"L262.StubTechProd_dac",
"L262.PerCapitaBased_dac",
"L262.BaseService_dac",
"L262.PriceElasticity_dac",
"L262.GlobalTechSCurve_dac",
"L262.GlobalTechProfitShutdown_dac"))
} else if(command == driver.DECLARE_OUTPUTS) {
return(c(XML = "dac_ssp1.xml",
XML = "dac_ssp2.xml",
XML = "dac_ssp3.xml",
XML = "dac_ssp4.xml",
XML = "dac_ssp5.xml"))
} else if(command == driver.MAKE) {

all_data <- list(...)[[1]]

for(sce in TECH_PARAMETRIZATION_INPUTS){
# Load required inputs
L262.Supplysector_dac <- get_data(all_data, "L262.Supplysector_dac")
L262.FinalEnergyKeyword_dac <- get_data(all_data, "L262.FinalEnergyKeyword_dac")
L262.SubsectorLogit_dac <- get_data(all_data, "L262.SubsectorLogit_dac")
L262.SubsectorShrwtFllt_dac <- get_data(all_data, "L262.SubsectorShrwtFllt_dac")
L262.SubsectorInterp_dac <- get_data(all_data, "L262.SubsectorInterp_dac")
L262.StubTech_dac <- get_data(all_data, "L262.StubTech_dac")
L262.GlobalTechShrwt_dac <- get_data(all_data, "L262.GlobalTechShrwt_dac")

coef_name <- paste0("L262.GlobalTechCoef_dac_",tolower(sce))
cost_name <- paste0("L262.GlobalTechCost_dac_",tolower(sce))
shwt_name <- paste0("L262.GlobalTechShrwt_dac_",tolower(sce))

L262.GlobalTechCoef_dac <- get_data(all_data, coef_name)
L262.GlobalTechCost_dac <- get_data(all_data, cost_name)
L262.GlobalTechShrwt_dac <- get_data(all_data, shwt_name)

L262.GlobalTechCapture_dac <- get_data(all_data, "L262.GlobalTechCapture_dac")
L262.StubTechProd_dac <- get_data(all_data, "L262.StubTechProd_dac")
L262.PerCapitaBased_dac <- get_data(all_data, "L262.PerCapitaBased_dac")
L262.BaseService_dac <- get_data(all_data, "L262.BaseService_dac")
L262.PriceElasticity_dac <- get_data(all_data, "L262.PriceElasticity_dac")
L262.GlobalTechSCurve_dac <- get_data(all_data, "L262.GlobalTechSCurve_dac")
L262.GlobalTechProfitShutdown_dac <- get_data(all_data, "L262.GlobalTechProfitShutdown_dac")



xmlfn <- paste0("dac_",tolower(sce), '.xml')

# ===================================================
# Produce outputs
create_xml(xmlfn) %>%
add_logit_tables_xml(L262.Supplysector_dac, "Supplysector") %>%
add_xml_data(L262.FinalEnergyKeyword_dac, "FinalEnergyKeyword") %>%
add_logit_tables_xml(L262.SubsectorLogit_dac, "SubsectorLogit") %>%
add_xml_data(L262.SubsectorShrwtFllt_dac, "SubsectorShrwtFllt") %>%
add_xml_data(L262.SubsectorInterp_dac, "SubsectorInterp") %>%
add_xml_data(L262.StubTech_dac, "StubTech") %>%
add_xml_data(L262.GlobalTechShrwt_dac, "GlobalTechShrwt") %>%
add_xml_data(L262.GlobalTechCoef_dac, "GlobalTechCoef") %>%
add_xml_data(L262.GlobalTechCost_dac, "GlobalTechCost") %>%
add_xml_data(L262.GlobalTechCapture_dac, "GlobalTechCapture") %>%
add_xml_data(L262.StubTechProd_dac, "StubTechProd") %>%
add_xml_data(L262.PerCapitaBased_dac, "PerCapitaBased") %>%
add_xml_data(L262.BaseService_dac, "BaseService") %>%
add_xml_data(L262.PriceElasticity_dac, "PriceElasticity") %>%
add_xml_data(L262.GlobalTechSCurve_dac, "GlobalTechSCurve") %>%
add_xml_data(L262.GlobalTechProfitShutdown_dac, "GlobalTechProfitShutdown") %>%
add_precursors("L262.Supplysector_dac",
"L262.FinalEnergyKeyword_dac",
"L262.SubsectorLogit_dac",
"L262.SubsectorShrwtFllt_dac",
"L262.SubsectorInterp_dac",
"L262.StubTechProd_dac",
"L262.StubTech_dac",
"L262.GlobalTechShrwt_dac",
paste0("L262.GlobalTechShrwt_dac_",tolower(sce)),
paste0("L262.GlobalTechCoef_dac_",tolower(sce)),
paste0("L262.GlobalTechCost_dac_",tolower(sce)),
"L262.GlobalTechCapture_dac",
"L262.PerCapitaBased_dac",
"L262.BaseService_dac",
"L262.PriceElasticity_dac",
"L262.GlobalTechSCurve_dac",
"L262.GlobalTechProfitShutdown_dac") ->
xmlobj
assign(xmlfn, xmlobj)


}
return_data(dac_ssp1.xml,
dac_ssp2.xml,
dac_ssp3.xml,
dac_ssp4.xml,
dac_ssp5.xml)}
else {
stop("Unknown command")
}
}
8 changes: 8 additions & 0 deletions input/gcamdata/inst/extdata/emissions/A_CDRU.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# File: A_CDRU.csv
# Title: Primary energy handling default coefficients
# Units: Unitless
#Description: Defines dummy coefficient table for atmospheric carbon stocks
# Column types: ccccnnn
# ----------
supplysector,subsector,technology,minicam.energy.input,1971,2010,2100
airCO2,airCO2,airCO2,atmospheric carbon stocks,1,1,1
4 changes: 3 additions & 1 deletion input/gcamdata/inst/extdata/emissions/A_PrimaryFuelCCoef.csv
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Description: assumed global default emissions factors
# Units: kg C per GJ
# Source: CDIAC inventory IEA energy balance some manual adjustments
# Column types: cni
# Column types: cni
# ----------
PrimaryFuelCO2Coef.name,PrimaryFuelCO2Coef,traded
biomass,0,0
Expand All @@ -28,4 +28,6 @@ refining,19.6,0
refined liquids industrial,19.6,0
refined liquids enduse,19.6,0
limestone,0.08,0
airCO2,1,0
unconventional oil upscaling,1.5,0

38 changes: 38 additions & 0 deletions input/gcamdata/inst/extdata/energy/A62.calibration.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# File: A62.calibration.csv
# Title: Calibration values for the CO2 removal sector
# Units: MtC
# Column types: icin
# ----------
GCAM_region_ID,sector,year,value
1,CO2 removal,2015,2000
2,CO2 removal,2015,26.58921908
3,CO2 removal,2015,26.30296292
4,CO2 removal,2015,25.52156095
5,CO2 removal,2015,51.65929106
6,CO2 removal,2015,417.4775416
7,CO2 removal,2015,1012.357646
8,CO2 removal,2015,79.87707563
9,CO2 removal,2015,86.18576367
10,CO2 removal,2015,429.8246874
11,CO2 removal,2015,2116.541628
12,CO2 removal,2015,22.06217174
13,CO2 removal,2015,71.77458929
14,CO2 removal,2015,15.81592955
15,CO2 removal,2015,15.84963925
16,CO2 removal,2015,6.342950362
17,CO2 removal,2015,87.41423367
18,CO2 removal,2015,16.37849476
19,CO2 removal,2015,66.31417001
20,CO2 removal,2015,232.7632894
21,CO2 removal,2015,334.5848291
22,CO2 removal,2015,7.458686272
23,CO2 removal,2015,313.0929592
24,CO2 removal,2015,5.567627191
25,CO2 removal,2015,161.9684919
26,CO2 removal,2015,470.9671038
27,CO2 removal,2015,8.830836973
28,CO2 removal,2015,0
29,CO2 removal,2015,165.6920326
30,CO2 removal,2015,0.307808272
31,CO2 removal,2015,331.3724602
32,CO2 removal,2015,136.5132452
8 changes: 8 additions & 0 deletions input/gcamdata/inst/extdata/energy/A62.demand.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# File: A62.demand.csv
# Title: dac final demand perCapitaBased and price elasticity
# Units: NA for perCapitaBased; Unitless for price.elasticity
# Comments: perCapitaBased is a logical (Boolean) indicating whether to use a per-capita or per-GDP based demand function
# Column types: cin
# ----------
energy.final.demand,perCapitaBased,price.elasticity
CO2 removal,0,0
10 changes: 10 additions & 0 deletions input/gcamdata/inst/extdata/energy/A62.globaltech_co2capture.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# File: A62.globaltech_co2capture.csv
# Title: CO2 capture rates for dac and process heat dac technology
# Units: Unitless
# Column types: cccnn
# ----------
supplysector,subsector,technology,1971,2100
process heat dac,gas CCS,gas CCS,0.95,0.95
CO2 removal,dac,hightemp DAC NG,1,1
CO2 removal,dac,hightemp DAC elec,1,1
CO2 removal,dac,lowtemp DAC heatpump,1,1
21 changes: 21 additions & 0 deletions input/gcamdata/inst/extdata/energy/A62.globaltech_coef_ssp1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# File: A62.globaltech_coef_ssp1.csv
# Title: Default coefficients for DAC
# Units: airCO2 input is unitless (MtC from the atmosphere per Mt dac demand); all others are GJ per kg C (EJ of energy per Mt C)
# Column types: ccccnnnn
# ----------
supplysector,subsector,technology,minicam.energy.input,1971,2020,2050,2100
CO2 removal,dac,hightemp DAC NG,process heat dac,0.0297,0.0297,0.019433333,0.019433333
CO2 removal,dac,hightemp DAC NG,elect_td_ind,0.006526667,0.006526667,0.004766667,0.004766667
CO2 removal,dac,hightemp DAC NG,airCO2,1,1,1,1
CO2 removal,dac,hightemp DAC NG,water_td_ind_C,0.017233333,0.017233333,0.017233333,0.017233333
CO2 removal,dac,hightemp DAC NG,water_td_ind_W,0.017233333,0.017233333,0.017233333,0.017233333
CO2 removal,dac,no DAC,process heat dac,0,0,0,0
CO2 removal,dac,no DAC,elect_td_ind,0,0,0,0
CO2 removal,dac,no DAC,airCO2,0,0,0,0
process heat dac,gas CCS,gas CCS,wholesale gas,1,1,1,1
CO2 removal,dac,hightemp DAC elec,elect_td_ind,0.0220044,0.0220044,0.0186384,0.0186384
CO2 removal,dac,hightemp DAC elec,airCO2,1,1,1,1
CO2 removal,dac,hightemp DAC elec,water_td_ind_C,0.017233333,0.017233333,0.017233333,0.017233333
CO2 removal,dac,hightemp DAC elec,water_td_ind_W,0.017233333,0.017233333,0.017233333,0.017233333
CO2 removal,dac,lowtemp DAC heatpump,elect_td_ind,0.0200684,0.0200684,0.009320178,0.009320178
CO2 removal,dac,lowtemp DAC heatpump,airCO2,1,1,1,1
21 changes: 21 additions & 0 deletions input/gcamdata/inst/extdata/energy/A62.globaltech_coef_ssp2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# File: A62.globaltech_coef_ssp2.csv
# Title: Default coefficients for DAC
# Units: airCO2 input is unitless (MtC from the atmosphere per Mt dac demand); all others are GJ per kg C (EJ of energy per Mt C)
# Column types: ccccnnnn
# ----------
supplysector,subsector,technology,minicam.energy.input,1971,2020,2050,2100
CO2 removal,dac,hightemp DAC NG,process heat dac,0.0297,0.0297,0.019433333,0.019433333
CO2 removal,dac,hightemp DAC NG,elect_td_ind,0.006526667,0.006526667,0.004766667,0.004766667
CO2 removal,dac,hightemp DAC NG,airCO2,1,1,1,1
CO2 removal,dac,hightemp DAC NG,water_td_ind_C,0.017233333,0.017233333,0.017233333,0.017233333
CO2 removal,dac,hightemp DAC NG,water_td_ind_W,0.017233333,0.017233333,0.017233333,0.017233333
CO2 removal,dac,no DAC,process heat dac,0,0,0,0
CO2 removal,dac,no DAC,elect_td_ind,0,0,0,0
CO2 removal,dac,no DAC,airCO2,0,0,0,0
process heat dac,gas CCS,gas CCS,wholesale gas,1,1,1,1
CO2 removal,dac,hightemp DAC elec,elect_td_ind,0.0220044,0.0220044,0.0186384,0.0186384
CO2 removal,dac,hightemp DAC elec,airCO2,1,1,1,1
CO2 removal,dac,hightemp DAC elec,water_td_ind_C,0.017233333,0.017233333,0.017233333,0.017233333
CO2 removal,dac,hightemp DAC elec,water_td_ind_W,0.017233333,0.017233333,0.017233333,0.017233333
CO2 removal,dac,lowtemp DAC heatpump,elect_td_ind,0.0200684,0.0200684,0.009320178,0.009320178
CO2 removal,dac,lowtemp DAC heatpump,airCO2,1,1,1,1
21 changes: 21 additions & 0 deletions input/gcamdata/inst/extdata/energy/A62.globaltech_coef_ssp3.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# File: A62.globaltech_coef_ssp3.csv
# Title: Default coefficients for DAC
# Units: airCO2 input is unitless (MtC from the atmosphere per Mt dac demand); all others are GJ per kg C (EJ of energy per Mt C)
# Column types: ccccnnnn
# ----------
supplysector,subsector,technology,minicam.energy.input,1971,2020,2050,2100
CO2 removal,dac,hightemp DAC NG,process heat dac,0.0297,0.0297,0.0297,0.0297
CO2 removal,dac,hightemp DAC NG,elect_td_ind,0.006526667,0.006526667,0.006526667,0.006526667
CO2 removal,dac,hightemp DAC NG,airCO2,1,1,1,1
CO2 removal,dac,hightemp DAC NG,water_td_ind_C,0.017233333,0.017233333,0.017233333,0.017233333
CO2 removal,dac,hightemp DAC NG,water_td_ind_W,0.017233333,0.017233333,0.017233333,0.017233333
CO2 removal,dac,no DAC,process heat dac,0,0,0,0
CO2 removal,dac,no DAC,elect_td_ind,0,0,0,0
CO2 removal,dac,no DAC,airCO2,0,0,0,0
process heat dac,gas CCS,gas CCS,wholesale gas,1,1,1,1
CO2 removal,dac,hightemp DAC elec,elect_td_ind,0.0220044,0.0220044,0.0220044,0.0220044
CO2 removal,dac,hightemp DAC elec,airCO2,1,1,1,1
CO2 removal,dac,hightemp DAC elec,water_td_ind_C,0.017233333,0.017233333,0.017233333,0.017233333
CO2 removal,dac,hightemp DAC elec,water_td_ind_W,0.017233333,0.017233333,0.017233333,0.017233333
CO2 removal,dac,lowtemp DAC heatpump,elect_td_ind,0.0200684,0.0200684,0.0200684,0.0200684
CO2 removal,dac,lowtemp DAC heatpump,airCO2,1,1,1,1
Loading

0 comments on commit 544eff9

Please sign in to comment.