Skip to content

Commit

Permalink
Pull request #333: SSP GDP, population, labor force update
Browse files Browse the repository at this point in the history
Merge in JGCRI/gcam-core from xz/feature/SSPv3_2024 to master

Squashed commit of the following:

commit 731c683d384dcf5a423af5022e6a54eef804933e
Author: Pralit Patel <[email protected]>
Date:   Fri Aug 23 13:45:07 2024 -0400

    Given the change in socio-economics we should commit an updated set of
    calibrated macro TFP

commit 3efcc7749c83d822210b2347919b1bded9e86e18
Author: Pralit Patel <[email protected]>
Date:   Fri Aug 23 13:44:37 2024 -0400

    Bump version number for public release

commit 6ad07affea665a370351a38474474dc96f77c794
Author: Pralit Patel <[email protected]>
Date:   Fri Aug 23 13:43:04 2024 -0400

    Increase max tax for SSP4_2p6 as it is close to reaching the old one and
    can cause the target finder trouble if it tries one that would exceed
    it.

commit 4b9001b9b6ab6791eb889f57bb72a50462edaa6d
Author: Pralit Patel <[email protected]>
Date:   Thu Aug 22 23:37:32 2024 -0400

    Fix some precursor statements and update the GCAM_DATA_MAP

commit f842c57a7d99932168763447720e44a8ef1dab12
Author: Pralit Patel <[email protected]>
Date:   Thu Aug 22 23:35:04 2024 -0400

    Include Matthew's fix to keep gas trade calibration flows from going
    negative which can throw of historical natural gas calibration

commit 41fa0c1651935d735a3ee4c4b94e6f7fc9037359
Author: Zhao, Xin <[email protected]>
Date:   Thu Aug 22 12:00:14 2024 -0400

    fix pop folder name case

commit 8aa3f3c44326a9c0455acbd21e1dae9c09654d8b
Author: Zhao, Xin <[email protected]>
Date:   Thu Aug 22 11:21:25 2024 -0400

    improve the use of constants; minor code updates

commit 2439d1b3a6c457cf5b066e9ced99cf2a6c614b35
Author: Zhao, Xin <[email protected]>
Date:   Wed Aug 21 17:14:32 2024 -0400

    clean up data and code for old SSPs

commit cea41330268eacc5f79953e86c88cef1bcf90623
Author: Pralit Patel <[email protected]>
Date:   Tue Aug 20 14:21:02 2024 -0400

    Fix energy balance issue which was stemming from the fact that
    industrial EFW calculations correctly calculated coefficients based off
    of industrial self supply (L132.water_km3_ctry_ind_Yh) + desal.
    However, the total water flow was in the water_td_ind sector was
    calculated from just self supply.  The latter was corrected to calculate
    coefficients from self supply + desal thus ensuring all water and energy
    flows are calculated as expected.

    Note: with this fix we can drop the temporary workaround in
    zwater_xml_electricity_water.R for adjusting 1990 Central Asia coal to
    avoid calibration errors.

commit 57f4357c97b50570d31891c3df6685247e903d0e
Author: Zhao, Xin <[email protected]>
Date:   Mon Aug 5 11:56:31 2024 -0400

    temp fix of 1990 Central Asia coal calibration

commit a46ab4cc3edfc62fdbfcfa75ab2e886fa3805d16
Author: Zhao, Xin <[email protected]>
Date:   Sat Aug 3 23:23:31 2024 -0400

    update TFP per labor force data updates

commit bba6416cbd181abd8843afb5cde04d7106a53c0e
Author: Zhao, Xin <[email protected]>
Date:   Fri Aug 2 17:33:30 2024 -0400

    update labor force and carbon price ceiling

commit 3de4b0a95afca1a49a9d6188601d641da9305d79
Author: Zhao, Xin <[email protected]>
Date:   Wed Jul 31 09:08:44 2024 -0400

    update tfp and filter years >1990 in national accounts queries

commit 99b15e02e5c27eeeae55eb3cc3c09c24a8b98a18
Author: Zhao, Xin <[email protected]>
Date:   Tue Jul 30 16:56:14 2024 -0400

    fix twn and south amer North

commit 5f0785285b410b8ef1aa079acaabfcd77f991489
Author: dsheng1026 <[email protected]>
Date:   Mon Jul 29 10:36:56 2024 -0400

    update TFP across SSP for open mode

commit 03e7aecc4c7177ace54067b01480d20664b1b5df
Author: Di Sheng <[email protected]>
Date:   Wed Jul 24 14:12:19 2024 -0700

    hector version 3.2.0

commit 6d5b498dc8b2bf43f67c75337cd2dd56f0714e74
Author: Zhao, Xin <[email protected]>
Date:   Wed Jul 24 15:58:59 2024 -0400

    Update historical GDP to use FAOSTAT (1971-2020 or -2023) and SSP database (future)

commit 495afea8c4465917fc946dee143fb9ccb2d22839
Author: Zhao, Xin <[email protected]>
Date:   Tue Jul 23 14:37:41 2024 -0400

    git data and code ready for hist GDP and SSP database updates

commit 2618067f74bb85025b1b91cba1727157270c999d
Author: Zhao, Xin <[email protected]>
Date:   Sat Jul 20 17:03:41 2024 -0400

    adding SSP_Database_Verion options to constants.R

commit 522a443164474fa48f130f2e9365e8868e448520
Author: Di Sheng <[email protected]>
Date:   Mon Jul 15 10:56:57 2024 -0700

    manually update hector version

... and 7 more commits
  • Loading branch information
realxinzhao authored and pralitp committed Aug 23, 2024
1 parent dc374cd commit bdcab96
Show file tree
Hide file tree
Showing 46 changed files with 31,613 additions and 198,812 deletions.
4 changes: 2 additions & 2 deletions cvs/objects/util/base/include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
* NOTE: ADD 1 TO LATEST SUBVERSION REVISION NUMBER
*/
//! The latest SVN revision number for identification of the build.
#define __REVISION_NUMBER__ "gcam-v7.1"
#define __REVISION_NUMBER__ "gcam-v7.2"
/*****************************************************************************/

//! GCAM model version.
#define __ObjECTS_VER__ "7.1"
#define __ObjECTS_VER__ "7.2"

#endif // _VERSION_H_
8 changes: 6 additions & 2 deletions input/gcamdata/R/constants.R
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,12 @@ energy.FOOD_PROCESSING.ENERGY_INFILL_MIN_EJ_PCAL_COEF <- 0.000413 # minimum valu

# Socioeconomics constants ======================================================================

socioeconomics.SSP_DB_BASEYEAR <- 2020 # base year of SSP data base v3.0.1
socioeconomics.GDP_Adj_Moving_Average_ISO <- c("ven")
socioeconomics.GDP_Adj_Moving_Average_Duration <- 15 # used for smoothing GDP for South_America_North
socioeconomics.GDP_Adj_No_Neg_Growth_ISO <- c("ven", "twn")
socioeconomics.GDP_Adj_No_Neg_Growth_Year <- 2025 # used for adjusting GDP projection to avoid negative GDP growth after this year (for Taiwan and South_America_North)

socioeconomics.CORE_GCAM_SCENARIO <- "gSSP2"

# Population years - note that these sequences shouldn't have any overlap,
Expand All @@ -643,8 +649,6 @@ socioeconomics.PWT_CONSTANT_CURRENCY_YEAR <- 2011 # Currency base year in Penn W
# we do the SSP scenarios if we update to UN 2015 population.)
socioeconomics.FINAL_HIST_YEAR <- 2015

# Sets the years during which the IMF projections are used over-riding the default (generally SSP) assumptions.
socioeconomics.IMF_GDP_YEARS <- 2015:2024
# There will be an imblance of trade by region historically which is implicitly balanced by
# capital flows. We can phase this out by the year assumed below (linearly). Note, setting a value
# beyond the final model year will hold the final historical net capital flows constant. Either
Expand Down
2 changes: 1 addition & 1 deletion input/gcamdata/R/utils-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ get_units <- function(x) { attr(x, ATTR_UNITS) }
#' @param ... Names of precursor objects (character)
#' @return \code{x} with units appended to any existing comments.
add_precursors <- function(x, ...) {
pc <- as.character(list(...))
pc <- c(...)
attr(x, ATTR_PRECURSORS) <- c(attr(x, ATTR_PRECURSORS), pc)
x
}
Expand Down
1 change: 1 addition & 0 deletions input/gcamdata/R/zaglu_L162.ag_prodchange_R_C_Y_GLU_irr.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ module_aglu_L162.ag_prodchange_R_C_Y_GLU_irr <- function(command, ...) {
mutate(Irr_Rfd = "RFD") %>%
rename(yield_kgHa = Yield_kgHa_rainfed) %>%
bind_rows(L162.ag_irrYield_kgHa_Rcrs_Ccrs_Y) %>%
mutate(yield_kgHa = as.numeric(yield_kgHa)) %>%
group_by(CROSIT_ctry, CROSIT_crop, Irr_Rfd) %>%
mutate(tag1 = if_else(yield_kgHa[year == 2030] < yield_kgHa[year == 2005], 1, 0), # if 2030 < 2005, then AgProdChange1 = 0
yield_kgHa = if_else(tag1 == 1 & year == 2030, yield_kgHa[year == 2005], yield_kgHa),
Expand Down
2 changes: 1 addition & 1 deletion input/gcamdata/R/zaglu_L202.an_input.R
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ module_aglu_L202.an_input <- function(command, ...) {
left_join(L110.IO_Coefs_pulp%>% left_join_error_no_match(GCAM_region_names, by = c("GCAM_region_ID")), by = c("region","year")) %>%
mutate(coefficient = IO,
coefficient=if_else(stub.technology == "woodpulp",aglu.FOREST_PULP_CONVERSION,coefficient)) %>%
group_by(GCAM_region_ID,stub.technology) %>%
group_by(region, stub.technology) %>%
mutate(coefficient= if_else(is.na(coefficient),approx_fun(year, coefficient, rule = 1),coefficient)) %>%
ungroup() %>%
select(colnames(L202.StubTechCoef_an))->L202.StubTechCoef_an_Forest
Expand Down
16 changes: 8 additions & 8 deletions input/gcamdata/R/zenergy_L1327.paper.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' @author MMC July 2022
module_energy_L1327.paper <- function(command, ...) {
if(command == driver.DECLARE_INPUTS) {
return(c("L1011.en_bal_EJ_R_Si_Fi_Yh",
return(c("L1012.en_bal_EJ_R_Si_Fi_Yh",
FILE = "energy/A_regions",
FILE = "energy/mappings/enduse_fuel_aggregation",
"L1326.in_EJ_R_indenergy_F_Yh",
Expand Down Expand Up @@ -50,7 +50,7 @@ module_energy_L1327.paper <- function(command, ...) {
all_data <- list(...)[[1]]

# Load required inputs
L1011.en_bal_EJ_R_Si_Fi_Yh <- get_data(all_data, "L1011.en_bal_EJ_R_Si_Fi_Yh", strip_attributes = TRUE)
L1012.en_bal_EJ_R_Si_Fi_Yh <- get_data(all_data, "L1012.en_bal_EJ_R_Si_Fi_Yh", strip_attributes = TRUE)
A_regions <- get_data(all_data, "energy/A_regions",strip_attributes = TRUE)
enduse_fuel_aggregation <- get_data(all_data, "energy/mappings/enduse_fuel_aggregation", strip_attributes = TRUE)
L1326.in_EJ_R_indenergy_F_Yh <- get_data(all_data, "L1326.in_EJ_R_indenergy_F_Yh", strip_attributes = TRUE)
Expand Down Expand Up @@ -85,7 +85,7 @@ module_energy_L1327.paper <- function(command, ...) {


# Get pulp and paper energy use from IEA energy balances
L1011.en_bal_EJ_R_Si_Fi_Yh %>%
L1012.en_bal_EJ_R_Si_Fi_Yh %>%
filter(grepl("paper", sector)) ->
L1327.in_EJ_R_paper_F_Yh

Expand Down Expand Up @@ -414,7 +414,7 @@ module_energy_L1327.paper <- function(command, ...) {
add_units("EJ") %>%
add_comments("PAPERPRO sector from IEA energy balances aggregated to GCAM regions") %>%
add_legacy_name("L1327.in_EJ_R_paper_F_Yh") %>%
add_precursors("L1011.en_bal_EJ_R_Si_Fi_Yh", "energy/A_regions",
add_precursors("L1012.en_bal_EJ_R_Si_Fi_Yh", "energy/A_regions",
"common/iso_GCAM_regID", "energy/mappings/enduse_fuel_aggregation",
"L123.in_EJ_R_indchp_F_Yh", "energy/paper_food_TFE", "energy/A327.china_biomass") ->
L1327.in_EJ_R_paper_F_Yh
Expand All @@ -432,7 +432,7 @@ module_energy_L1327.paper <- function(command, ...) {
add_units("GJ/kg paper") %>%
add_legacy_name("L1327.IO_GJkg_R_paper_F_Yh") %>%
add_comments("IO coefficients for heat energy and electricity are calculated from IEA energy consumption and FAO paper production data") %>%
add_precursors("L1011.en_bal_EJ_R_Si_Fi_Yh", "aglu/FAO/FAO_Paper_Prod_t_FORESTAT", "aglu/AGLU_ctry", "energy/A_regions",
add_precursors("L1012.en_bal_EJ_R_Si_Fi_Yh", "aglu/FAO/FAO_Paper_Prod_t_FORESTAT", "aglu/AGLU_ctry", "energy/A_regions",
"common/iso_GCAM_regID","energy/mappings/enduse_fuel_aggregation", "L123.in_EJ_R_indchp_F_Yh",
"energy/paper_food_TFE", "energy/A327.globaltech_coef", "energy/A327.china_biomass") ->
L1327.IO_GJkg_R_paper_F_Yh
Expand All @@ -443,7 +443,7 @@ module_energy_L1327.paper <- function(command, ...) {
add_comments("Subtracted pulp and paper energy use from industrial energy use values in L1326.in_EJ_R_indenergy_F_Yh") %>%
add_comments("To determine adjusted input energy for industrial energy use") %>%
add_legacy_name("L1327.in_EJ_R_indenergy_F_Yh") %>%
add_precursors("L1011.en_bal_EJ_R_Si_Fi_Yh", "L1326.in_EJ_R_indenergy_F_Yh", "aglu/FAO/FAO_Paper_Prod_t_FORESTAT",
add_precursors("L1012.en_bal_EJ_R_Si_Fi_Yh", "L1326.in_EJ_R_indenergy_F_Yh", "aglu/FAO/FAO_Paper_Prod_t_FORESTAT",
"aglu/AGLU_ctry", "energy/A_regions", "common/iso_GCAM_regID","energy/mappings/enduse_fuel_aggregation") ->
L1327.in_EJ_R_indenergy_F_Yh

Expand All @@ -452,7 +452,7 @@ module_energy_L1327.paper <- function(command, ...) {
add_units("None") %>%
add_comments("Subsector share weights for process heat technologies will be reset from 0 to 1 for these regions") %>%
add_legacy_name("L1327.elec_noheat_adj_shwt_R") %>%
add_precursors("L1011.en_bal_EJ_R_Si_Fi_Yh", "energy/A_regions",
add_precursors("L1012.en_bal_EJ_R_Si_Fi_Yh", "energy/A_regions",
"common/iso_GCAM_regID","energy/mappings/enduse_fuel_aggregation") ->
L1327.elec_noheat_adj_shwt_R

Expand All @@ -470,7 +470,7 @@ module_energy_L1327.paper <- function(command, ...) {
add_units("GJ/kg") %>%
add_comments("Woodpulp in Mt divided by paper sector biomass energy in EJ") %>%
add_legacy_name("L1327.IO_woodpulp_energy") %>%
add_precursors("L1011.en_bal_EJ_R_Si_Fi_Yh", "energy/A_regions", "common/GCAM_region_names",
add_precursors("L1012.en_bal_EJ_R_Si_Fi_Yh", "energy/A_regions", "common/GCAM_region_names",
"common/iso_GCAM_regID", "energy/mappings/enduse_fuel_aggregation",
"L123.in_EJ_R_indchp_F_Yh", "energy/paper_food_TFE", "energy/A327.china_biomass",
"L110.For_ALL_bm3_R_Y") ->
Expand Down
20 changes: 18 additions & 2 deletions input/gcamdata/R/zenergy_L2391.gas_trade_flows.R
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,30 @@ module_energy_L2391.gas_trade_flows <- function(command, ...) {
mutate(value = abs(value)) -> L2391.NG_import_calOutput_statdiff

# Divide export difference for each region between LNG & pipelines according to historical shares,
# and then adjust the corresponding calOutputValues accordingly. Thiss will keep any region's
# and then adjust the corresponding calOutputValues accordingly. This will keep any region's
# exports from going negative and keep LNG / pipeline shares relatively constant.
# First, recalculate historical shares from adjusted data.
L2391.gas_flow_balances %>%
select(region, year, calExport_pipe, calExport_LNG) %>%
tidyr::gather(GCAM_Commodity_traded, value, -c(region, year)) %>%
mutate(GCAM_Commodity = "natural gas") %>%
mutate(GCAM_Commodity_traded = gsub("calExport_", "", GCAM_Commodity_traded),
GCAM_Commodity_traded = if_else(GCAM_Commodity_traded == "pipe", "gas pipeline", GCAM_Commodity_traded)) %>%
group_by(region, year, GCAM_Commodity, GCAM_Commodity_traded) %>%
summarise(value = sum(value)) %>%
ungroup() %>%
group_by(region, year) %>%
mutate(share = value / sum(value)) %>%
ungroup() %>%
mutate(share = if_else(is.nan(share), 0, share)) %>%
select(-value) -> L2391.NG_export_shares_adj

L2391.NG_import_calOutput_statdiff %>%
left_join_error_no_match(GCAM_region_pipeline_bloc_export, by = c("region" = "origin.region")) %>%
# L2391.NG_export_shares contains shares for LNG and pipeline
# join will duplicate rows by each carrier
# LJENM will error, left_join() is used
left_join(L2391.NG_export_shares, by = c("region", "year")) %>%
left_join(L2391.NG_export_shares_adj, by = c("region", "year")) %>%
mutate(value = value * share) %>%
select(-share) -> L2391.NG_import_calOutput_adj

Expand Down
80 changes: 55 additions & 25 deletions input/gcamdata/R/zsocio_L100.GDP_hist.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,73 @@
#' @importFrom dplyr filter mutate select
#' @author BBL February 2017
module_socio_L100.GDP_hist <- function(command, ...) {

MODULE_INPUTS <-
c(FILE = "aglu/AGLU_ctry",
FILE = "socioeconomics/GDP/GCAMFAOSTAT_GDP",
FILE = "socioeconomics/GDP/GDP_twn")

MODULE_OUTPUTS <-
c("L100.gdp_mil90usd_ctry_Yh")

if(command == driver.DECLARE_INPUTS) {
return(c(FILE = "socioeconomics/USDA_GDP_MER",
FILE = "socioeconomics/WB_ExtraCountries_GDP_MER"))
return(MODULE_INPUTS)
} else if(command == driver.DECLARE_OUTPUTS) {
return(c("L100.gdp_mil90usd_ctry_Yh"))
return(MODULE_OUTPUTS)
} else if(command == driver.MAKE) {

Country <- year <- value <- iso <- NULL # silence package checks.

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

# Load required inputs
usda_gdp_mer <- get_data(all_data, "socioeconomics/USDA_GDP_MER")
WB_ExtraCountries_GDP_MER <- get_data(all_data, "socioeconomics/WB_ExtraCountries_GDP_MER")
assert_that(tibble::is_tibble(usda_gdp_mer))
assert_that(tibble::is_tibble(WB_ExtraCountries_GDP_MER))

# bind qatar's GDP data to the USDA's nation-level data
usda_gdp_mer <- bind_rows(usda_gdp_mer, WB_ExtraCountries_GDP_MER) %>%
arrange(Country)

# Convert to long form, filter to historical years, convert units
usda_gdp_mer %>%
select(-Country) %>%
gather_years %>%
filter(!is.na(value), !is.na(iso)) %>%
mutate(value = value * CONV_BIL_MIL * gdp_deflator(1990, base_year = 2010),
year = as.integer(year)) %>%
add_title("Historical GDP downscaled to country (iso)") %>%
add_comments("Units converted to constant 1990 USD") %>%
add_precursors("socioeconomics/USDA_GDP_MER",
"socioeconomics/WB_ExtraCountries_GDP_MER") %>%
# Load required inputs ----
get_data_list(all_data, MODULE_INPUTS, strip_attributes = TRUE)

# Note that GCAMFAOSTAT_GDP has data in 2015$ so regional GDP deflators are not used
# But values are brought back to 1990$ using USA GDP deflators
# FAO_GDP_Deflators is added to this chunk for BYU uses
# see module_aglu_L100.regional_ag_an_for_prices for examples
# Note that historical regional values have been fixed using FAO_AREA_DISAGGREGATE_HIST_DISSOLUTION_ALL in gcamfaostat
GCAMFAOSTAT_GDP %>%
gather_years() %>%
filter(element_code == 6184, # 2015$
!is.na(value)) %>%
# ToDo: GCAMFAOSTAT_GDP is more recent than other GCAMFAOSTAT files
# FAOSTAT recent changed name of 2 countries
# next GCAMFAOSTAT update (ready already) will use area_code to avoid dealing with country name changes
mutate(area = if_else(grepl("Yemen ", area), "Yemen", area),
area = if_else(area == "Netherlands (Kingdom of the)", "Netherlands", area),
area = if_else(area == "Sint Maarten (Dutch part)", "Sint Maarten (Dutch Part)", area)) %>%
left_join_error_no_match(AGLU_ctry %>% select(area = FAO_country, iso), by = "area") %>%
select(iso, year, value) %>%
# agg two Yeman
group_by(iso, year) %>%
summarize(value = sum(value), .groups = "drop") %>%
mutate(value = value * gdp_deflator(1990, base_year = 2015) ) ->
L100.gdp_mil90usd_ctry_Yh_0

# Taiwan from pwt but also extend to recent years using Taiwan statistics
GDP_twn %>%
select(iso, year, value = gdp_2015USD) %>%
mutate(value = value * gdp_deflator(1990, base_year = 2015)) ->
L100.gdp_mil90usd_ctry_Yh_0_TWN

L100.gdp_mil90usd_ctry_Yh_0 %>%
bind_rows(
L100.gdp_mil90usd_ctry_Yh_0_TWN
) %>%
add_title("Historical GDP by country (iso) since 1970 per FAOSTAT") %>%
add_comments("Units 2015$ converted to constant 1990 USD using USA GDP deflators") %>%
add_precursors("socioeconomics/GDP/GCAMFAOSTAT_GDP",
"aglu/AGLU_ctry",
"socioeconomics/GDP/GDP_twn") %>%
add_units("Million 1990 USD") %>%
add_legacy_name("L100.gdp_mil90usd_ctry_Yh") ->
L100.gdp_mil90usd_ctry_Yh

return_data(L100.gdp_mil90usd_ctry_Yh)

return_data(MODULE_OUTPUTS)

} else {
stop("Unknown command")
}
Expand Down
Loading

0 comments on commit bdcab96

Please sign in to comment.