Skip to content

Commit

Permalink
Merge pull request #120 from pik-piam/revert-119-gdp_update
Browse files Browse the repository at this point in the history
Revert "Gdp update"
  • Loading branch information
caviddhen authored Sep 3, 2024
2 parents 89ad7e7 + bf853ba commit b23d349
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 128 deletions.
4 changes: 2 additions & 2 deletions R/calcGTAPTotalTransportCosts.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ calcGTAPTotalTransportCosts <- function(costType = "transport", version = "9") {
totalTcosts <- (tcostInputs + tcostToSecondary) / 2

totalTcosts <- GDPuc::convertGDP(totalTcosts, unit_in = "current US$MER",
unit_out = "constant 2017 US$MER",
unit_out = "constant 2005 US$MER",
replace_NAs = "no_conversion")

return(list(x = totalTcosts,
weight = NULL,
unit = "million constant 2017 US$MER/yr",
unit = "million constant 2005 US$MER/yr",
description = "Costs for GTAP commodities (half of input to market and market to value"))
}
29 changes: 3 additions & 26 deletions R/calcIniFoodPrice.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @param year Specifies the year for the initialization of prices in MAgPIE. Default is `y2005`.
#' @param products subselection of products to be returned
#'
#' @return List with a magpie object with commodity prices on global level in $17/tDM.
#' @return List with a magpie object with commodity prices on global level in $05/tDM.
#' @author Mishko Stevanovic, Benjamin Leon Bodirsky
#' @seealso
#' [readIMPACT3.2.2World_Price()]
Expand All @@ -27,7 +27,7 @@ calcIniFoodPrice <- function(datasource = "FAO", year = "y2005", products = "kfo
dm <- collapseNames(dm)

if (datasource == "IMPACT3.2.2World_Price") {
out <- readSource("IMPACT3.2.2World_Price") #in 2017 prices now
out <- readSource("IMPACT3.2.2World_Price")
# select scenario and initial year
out <- collapseNames(out[, year, "SSP2-NoCC-NoCC-379"])
out <- setYears(out, NULL)
Expand Down Expand Up @@ -68,18 +68,6 @@ calcIniFoodPrice <- function(datasource = "FAO", year = "y2005", products = "kfo
out[, , "res_nonfibrous"] <- 50 # quick google search
out[, , "pasture"] <- 50 # quick google search
out[, , "scp"] <- 1500 # using upper end prices similar to fishmeal

#[DC] At some point probably better to do another 'quick google search',
#for now convert these to 2017 values using US inflation, also for consistency
conv <- c("sugr_cane", "sugr_beet", "alcohol", "fish", "oilpalm", "oilcakes", "cottn_pro", "foddr",
"brans", "distillers_grain", "ethanol", "fibres", "molasses", "wood", "woodfuel", "begr",
"betr", "res_cereals", "res_fibrous", "pasture", "scp")
getItems(out, dim = 1) <- "USA"
out[, , conv] <- GDPuc::convertGDP(out[, , conv],
unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")
getItems(out, dim = 1) <- "GLO"

# correct the prices for dry matter values
out <- out[, , ] / dm[, , ]
Expand Down Expand Up @@ -118,17 +106,6 @@ calcIniFoodPrice <- function(datasource = "FAO", year = "y2005", products = "kfo
out[, , "foddr"] <- 50 # quick google search
out[, , "sugar"] <- 250 # quick google search

conv <- c("fish", "oilcakes", "brans", "distillers_grain", "ethanol", "alcohol",
"molasses", "wood", "woodfuel", "begr",
"betr", "res_cereals", "res_fibrous", "pasture", "scp",
"foddr", "sugar")
getItems(out, dim = 1) <- "USA"
out[, , conv] <- GDPuc::convertGDP(out[, , conv],
unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")
getItems(out, dim = 1) <- "GLO"

# correct the prices from online sources for dry matter values
out[, , missingCommodities] <- out[, , missingCommodities] / dm[, , missingCommodities]

Expand All @@ -143,7 +120,7 @@ calcIniFoodPrice <- function(datasource = "FAO", year = "y2005", products = "kfo

return(list(x = out,
weight = NULL,
unit = "US$2017/tDM",
unit = "US$05/tDM",
description = description,
isocountries = FALSE))
}
12 changes: 6 additions & 6 deletions R/calcMAgPIEReport.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ calcMAgPIEReport <- function(subtype) {
x <- readSource("MAgPIE", subtype = "MAgPIEReport_extensive")

if (subtype == "CostTotal") {
# with transformation factor from 10E6 US$2017 to 10E12 US$2017
x <- x[, , "Costs Without Incentives (million US$17/yr)"] / 1000 / 1000
# with transformation factor from 10E6 US$2005 to 10E12 US$2005
x <- x[, , "Costs Without Incentives (million US$05/yr)"] / 1000 / 1000
d <- "Total Landuse Costs from MAgPIE excluding emission costs"
u <- "T$2017/yr"
u <- "T$2005/yr"
} else if (subtype == "CostMAC") {
# with transformation factor from 10E6 US$2017 to 10E12 US$2017
x <- x[, , "Costs Accounting|+|MACCS (million US$17/yr)"] / 1000 / 1000
# with transformation factor from 10E6 US$2005 to 10E12 US$2005
x <- x[, , "Costs Accounting|+|MACCS (million US$05/yr)"] / 1000 / 1000
d <- "MAC Costs for LU emissions from MAgPIE"
u <- "T$2017/yr"
u <- "T$2005/yr"
} else if (subtype == "ProductionBiomass") {
x <- x[, , "Demand|Bioenergy|2nd generation|++|Bioenergy crops (EJ/yr)"] / 31.536 # EJ to TWa
d <- "Production of ligno-cellulosic purpose grown biomass in MAgPIE"
Expand Down
10 changes: 5 additions & 5 deletions R/calcPriceAgriculture.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#' @importFrom reshape2 melt acast
#'

calcPriceAgriculture <- function(datasource = "IMPACT3.2.2World_Price", unit = "US$17/tDM") {
calcPriceAgriculture <- function(datasource = "IMPACT3.2.2World_Price", unit = "US$05/tDM") {

if (datasource == "IMPACT3.2.2World_Price") {

Expand Down Expand Up @@ -70,7 +70,7 @@ calcPriceAgriculture <- function(datasource = "IMPACT3.2.2World_Price", unit = "

} else if (datasource == "WBGEM") {

# Prices in US$17/tDM
# Prices in US$05/tDM
x <- calcOutput("WBGEM", aggregate = FALSE)

# sectoral mappings
Expand Down Expand Up @@ -138,7 +138,7 @@ calcPriceAgriculture <- function(datasource = "IMPACT3.2.2World_Price", unit = "

} else if (datasource == "FAO") {

# Annual producer prices in US$17/tDM
# Annual producer prices in US$05/tDM
out <- readSource("FAO_online", subtype = "PricesProducerAnnual", convert = TRUE)
aggregation <- toolGetMapping("FAOitems_online.csv",
type = "sectoral", where = "mappingfolder")
Expand Down Expand Up @@ -184,10 +184,10 @@ calcPriceAgriculture <- function(datasource = "IMPACT3.2.2World_Price", unit = "
isocountries <- TRUE
}

if (unit != "US$17/tDM") {
if (unit != "US$05/tDM") {
# Transform to selected currency unit
out <- GDPuc::convertGDP(out,
unit_in = "constant 2017 US$MER",
unit_in = "constant 2005 US$MER",
unit_out = unit,
replace_NAs = "no_conversion")
}
Expand Down
10 changes: 1 addition & 9 deletions R/calcWBGEM.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,9 @@ calcWBGEM <- function() {
out <- mbind(.rename(tmp1), .rename(tmp2), .rename(tmp3))
out <- out * adjustFactor2005
out[is.na(out)] <- 0

#inflate to 2017 using US inflation for global value
getItems(out, dim = 1) <- "USA"
out <- GDPuc::convertGDP(out,
unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")
getItems(out, dim = 1) <- "GLO"

return(list(x = out,
unit = "real2017 USD per ton",
unit = "real2005 USD per ton",
weight = NULL,
description = "WBGEM global price of commodity"))
}
5 changes: 2 additions & 3 deletions R/convertGTAPv8v9.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ convertGTAPv8v9 <- function(x, subtype) {

} else {
gdpMer <- calcOutput("GDPPast", GDPPast = "WDI-MI",
unit = "constant 2017 US$MER", aggregate = FALSE)
unit = "constant 2005 US$MER", aggregate = FALSE)
gdpMer <- gdpMer[, getYears(x), , drop = TRUE]
w1 <- GDPuc::convertGDP(gdpMer,
unit_in = "constant 2017 US$MER",
w1 <- GDPuc::convertGDP(gdpMer, unit_in = "constant 2005 US$MER",
unit_out = "current US$MER",
replace_NAs = "no_conversion")
getNames(w1) <- NULL
Expand Down
14 changes: 5 additions & 9 deletions R/convertICP2017.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#' @title convertICP2017
#' @description converts data of World Bank ICP round, downloaded from
#' here: https://databank.worldbank.org/source/icp-2017
#' mainly a currency conversion to MER2017. Assume that in the original dataset,
#' mainly a currency conversion to MER05. Assume that in the original dataset,
#' 2011 values are in 2011MER and 2017 in 2017MER, given the ICP rounds
#'
#' @param subtype data subtype needed. Either "priceLevel", or "per_cap_exp"
Expand All @@ -17,21 +17,17 @@ convertICP2017 <- function(x, subtype = "per_cap_expMER") {
# currency convert for expenditures
if (subtype == "per_cap_expMER") {

x2011 <- GDPuc::convertGDP(x[, 2011, ],
unit_in = "constant 2011 US$MER",
unit_out = "constant 2017 US$MER")
x2017 <- x[, 2017, ]
x2011 <- GDPuc::convertGDP(x[, 2011, ], unit_in = "constant 2011 US$MER", unit_out = "constant 2005 US$MER")
x2017 <- GDPuc::convertGDP(x[, 2017, ], unit_in = "constant 2017 US$MER", unit_out = "constant 2005 US$MER")
x <- mbind(x2011, x2017)
x[is.na(x)] <- 0
}

# currency convert for expenditures
if (subtype == "per_cap_expPPP") {

x2011 <- GDPuc::convertGDP(x[, 2011, ],
unit_in = "constant 2011 US$PPP",
unit_out = "constant 2017 US$MER")
x2017 <- x[, 2017, ]
x2011 <- GDPuc::convertGDP(x[, 2011, ], unit_in = "constant 2011 US$PPP", unit_out = "constant 2005 US$MER")
x2017 <- GDPuc::convertGDP(x[, 2017, ], unit_in = "constant 2017 US$PPP", unit_out = "constant 2005 US$MER")
x <- mbind(x2011, x2017)
x[is.na(x)] <- 0
}
Expand Down
110 changes: 51 additions & 59 deletions R/convertSSPResults.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ convertSSPResults <- function(x) {

# ---- Land ----

# nolint start
#nolint start
selection <- c("Land Cover (million ha)", "Land Cover|Built-up Area (million ha)",
"Land Cover|Cropland (million ha)", "Land Cover|Cropland|Energy Crops (million ha)",
"Land Cover|Forest (million ha)", "Land Cover|Forest|Forestry (million ha)",
"Land Cover|Forest|Forestry|Harvested Area (million ha)", "Land Cover|Forest|Natural Forest (million ha)",
"Land Cover|Other Arable Land (million ha)", "Land Cover|Other Land (million ha)",
"Land Cover|Other Natural Land (million ha)", "Land Cover|Pasture (million ha)")
# nolint end
#nolint end

# use land area as weight
weight <- setYears(dimSums(calcOutput("LanduseInitialisation", aggregate = FALSE), dim = 3)[, 2010, ], NULL)
Expand All @@ -69,13 +69,13 @@ convertSSPResults <- function(x) {
# ---- Bioenergy ----

selection <- c("Primary Energy|Biomass|1st Generation (EJ/yr)",
"Primary Energy|Biomass|Energy Crops (EJ/yr)",
"Agricultural Demand|Bioenergy|1st generation (million t DM/yr)",
"Agricultural Demand|Bioenergy|2nd generation (million t DM/yr)")
"Primary Energy|Biomass|Energy Crops (EJ/yr)",
"Agricultural Demand|Bioenergy|1st generation (million t DM/yr)",
"Agricultural Demand|Bioenergy|2nd generation (million t DM/yr)")

# use harvested area as weight
weightBio <- setYears(dimSums(calcOutput("Croparea", sectoral = "kcr", physical = TRUE, aggregate = FALSE),
dim = 3)[, 2010, ], NULL)
dim = 3)[, 2010, ], NULL)

for (sel in selection) {
print(sel)
Expand All @@ -93,10 +93,6 @@ convertSSPResults <- function(x) {

data <- x[, , selection]
data[is.na(data)] <- 0
data <- convertGDP(data, unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")
getNames(data, dim = 3) <- "Price|Carbon (US$2017/t CO2)"
aggregatedREG <- toolAggregate(data, rel = mappingFile, weight = NULL, dim = 1, partrel = TRUE,
from = "RegionCode", to = "CountryCode")
aggregatedREG <- toolCountryFill(aggregatedREG, 000)
Expand All @@ -107,68 +103,64 @@ convertSSPResults <- function(x) {
selection <- c("Price|Primary Energy|Biomass (US$2005/GJ)")

data <- x[, , selection]
data <- convertGDP(data, unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")
getNames(data, dim = 3) <- "Price|Primary Energy|Biomass (US$2017/GJ)"
aggregatedREG <- toolAggregate(data, rel = mappingFile, weight = NULL, dim = 1, partrel = TRUE,
from = "RegionCode", to = "CountryCode")
aggregatedREG <- toolCountryFill(aggregatedREG, 000)
out <- mbind(out, aggregatedREG)

### check for NA's
if (any(is.na(out))) {
vcat(verbosity = 1, "SSP3 results of MESSAGE-GLOBIOM contains NAs which where substituted by 0")
}
vcat(verbosity = 1, "SSP3 results of MESSAGE-GLOBIOM contains NAs which where substituted by 0")
}
out[, c("y2005", "y2010"), "MESSAGE-GLOBIOM.Land Cover|Cropland|Energy Crops (million ha)"] <- 0
if (any(is.na(out))) {
vcat(verbosity = 1, "NAs in dataset")
}
vcat(verbosity = 1, "NAs in dataset")
}

# ---- Select scenarios ----

subset <- c("SSP1-19-SPA1-V16.IMAGE",
"SSP1-26-SPA1-V15.IMAGE",
"SSP1-34-SPA1-V15.IMAGE",
"SSP1-45-SPA1-V15.IMAGE",
"SSP1-Ref-SPA0-V15.IMAGE",

"SSP1-19-SPA1-V16.REMIND-MAGPIE",
"SSP1-26-SPA1-V15.REMIND-MAGPIE",
"SSP1-34-SPA1-V15.REMIND-MAGPIE",
"SSP1-45-SPA1-V15.REMIND-MAGPIE",
"SSP1-Ref-SPA0-V15.REMIND-MAGPIE",

"SSP2-19-SPA2-V16.MESSAGE-GLOBIOM",
"SSP2-26-SPA2-V16.MESSAGE-GLOBIOM",
"SSP2-34-SPA2-V16.MESSAGE-GLOBIOM",
"SSP2-45-SPA2-V16.MESSAGE-GLOBIOM",
"SSP2-60-SPA2-V16.MESSAGE-GLOBIOM",
"SSP2-Ref-SPA0-V16.MESSAGE-GLOBIOM",

"SSP2-19-SPA2-V16.REMIND-MAGPIE",
"SSP2-26-SPA2-V15.REMIND-MAGPIE",
"SSP2-34-SPA2-V15.REMIND-MAGPIE",
"SSP2-45-SPA2-V15.REMIND-MAGPIE",
"SSP2-60-SPA2-V15.REMIND-MAGPIE",
"SSP2-Ref-SPA0-V15.REMIND-MAGPIE",

"SSP3-34-SPA3-V15.AIM/CGE",
"SSP3-45-SPA3-V15.AIM/CGE",
"SSP3-60-SPA3-V15.AIM/CGE",

"SSP4-26-SPA4-V16.GCAM4",
"SSP4-34-SPA4-V16.GCAM4",
"SSP4-45-SPA4-V16.GCAM4",
"SSP4-60-SPA4-V16.GCAM4",
"SSP4-Ref-SPA0-V16.GCAM4",

"SSP5-19-SPA5-V16.REMIND-MAGPIE",
"SSP5-26-SPA5-V15.REMIND-MAGPIE",
"SSP5-34-SPA5-V15.REMIND-MAGPIE",
"SSP5-45-SPA5-V15.REMIND-MAGPIE",
"SSP5-60-SPA5-V15.REMIND-MAGPIE",
"SSP5-Ref-SPA0-V15.REMIND-MAGPIE")
"SSP1-26-SPA1-V15.IMAGE",
"SSP1-34-SPA1-V15.IMAGE",
"SSP1-45-SPA1-V15.IMAGE",
"SSP1-Ref-SPA0-V15.IMAGE",

"SSP1-19-SPA1-V16.REMIND-MAGPIE",
"SSP1-26-SPA1-V15.REMIND-MAGPIE",
"SSP1-34-SPA1-V15.REMIND-MAGPIE",
"SSP1-45-SPA1-V15.REMIND-MAGPIE",
"SSP1-Ref-SPA0-V15.REMIND-MAGPIE",

"SSP2-19-SPA2-V16.MESSAGE-GLOBIOM",
"SSP2-26-SPA2-V16.MESSAGE-GLOBIOM",
"SSP2-34-SPA2-V16.MESSAGE-GLOBIOM",
"SSP2-45-SPA2-V16.MESSAGE-GLOBIOM",
"SSP2-60-SPA2-V16.MESSAGE-GLOBIOM",
"SSP2-Ref-SPA0-V16.MESSAGE-GLOBIOM",

"SSP2-19-SPA2-V16.REMIND-MAGPIE",
"SSP2-26-SPA2-V15.REMIND-MAGPIE",
"SSP2-34-SPA2-V15.REMIND-MAGPIE",
"SSP2-45-SPA2-V15.REMIND-MAGPIE",
"SSP2-60-SPA2-V15.REMIND-MAGPIE",
"SSP2-Ref-SPA0-V15.REMIND-MAGPIE",

"SSP3-34-SPA3-V15.AIM/CGE",
"SSP3-45-SPA3-V15.AIM/CGE",
"SSP3-60-SPA3-V15.AIM/CGE",

"SSP4-26-SPA4-V16.GCAM4",
"SSP4-34-SPA4-V16.GCAM4",
"SSP4-45-SPA4-V16.GCAM4",
"SSP4-60-SPA4-V16.GCAM4",
"SSP4-Ref-SPA0-V16.GCAM4",

"SSP5-19-SPA5-V16.REMIND-MAGPIE",
"SSP5-26-SPA5-V15.REMIND-MAGPIE",
"SSP5-34-SPA5-V15.REMIND-MAGPIE",
"SSP5-45-SPA5-V15.REMIND-MAGPIE",
"SSP5-60-SPA5-V15.REMIND-MAGPIE",
"SSP5-Ref-SPA0-V15.REMIND-MAGPIE")

out <- out[, , subset]

Expand Down
9 changes: 0 additions & 9 deletions R/readIMPACT3.2.2World_Price.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,5 @@ readIMPACT3.2.2World_Price <- function() { # nolint: object_name_linter.
data <- data[!is.na(data[[1]]), ]
data$scenario <- sub(".", "p", data$scenario, fixed = TRUE)
data <- as.magpie(data)

#inflate to 2017 using US inflation for global value
getItems(data, dim = 1) <- "USA"
data <- GDPuc::convertGDP(data,
unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")
getItems(data, dim = 1) <- "GLO"

return(data)
}

0 comments on commit b23d349

Please sign in to comment.