From bf853ba7b963423df455cd0ee749ce82c2e9732b Mon Sep 17 00:00:00 2001 From: David Meng-Chuen Chen <37618991+caviddhen@users.noreply.github.com> Date: Tue, 3 Sep 2024 12:59:50 +0200 Subject: [PATCH] Revert "Gdp update" --- R/calcGTAPTotalTransportCosts.R | 4 +- R/calcIniFoodPrice.R | 29 +-------- R/calcMAgPIEReport.R | 12 ++-- R/calcPriceAgriculture.R | 10 +-- R/calcWBGEM.R | 10 +-- R/convertGTAPv8v9.R | 5 +- R/convertICP2017.R | 14 ++-- R/convertSSPResults.R | 110 +++++++++++++++----------------- R/readIMPACT3.2.2World_Price.R | 9 --- 9 files changed, 75 insertions(+), 128 deletions(-) diff --git a/R/calcGTAPTotalTransportCosts.R b/R/calcGTAPTotalTransportCosts.R index 0d3b4d6d..6e7c8366 100644 --- a/R/calcGTAPTotalTransportCosts.R +++ b/R/calcGTAPTotalTransportCosts.R @@ -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")) } diff --git a/R/calcIniFoodPrice.R b/R/calcIniFoodPrice.R index 07bcfc20..d22b4dd7 100644 --- a/R/calcIniFoodPrice.R +++ b/R/calcIniFoodPrice.R @@ -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()] @@ -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) @@ -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[, , ] @@ -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] @@ -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)) } diff --git a/R/calcMAgPIEReport.R b/R/calcMAgPIEReport.R index 4d5fcba4..b0d17d6d 100644 --- a/R/calcMAgPIEReport.R +++ b/R/calcMAgPIEReport.R @@ -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" diff --git a/R/calcPriceAgriculture.R b/R/calcPriceAgriculture.R index 1a404342..73919ce7 100644 --- a/R/calcPriceAgriculture.R +++ b/R/calcPriceAgriculture.R @@ -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") { @@ -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 @@ -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") @@ -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") } diff --git a/R/calcWBGEM.R b/R/calcWBGEM.R index 10ba9fe6..06cd6b92 100644 --- a/R/calcWBGEM.R +++ b/R/calcWBGEM.R @@ -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")) } diff --git a/R/convertGTAPv8v9.R b/R/convertGTAPv8v9.R index 05e90126..4d8f0795 100644 --- a/R/convertGTAPv8v9.R +++ b/R/convertGTAPv8v9.R @@ -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 diff --git a/R/convertICP2017.R b/R/convertICP2017.R index 74748d6e..36d9da01 100644 --- a/R/convertICP2017.R +++ b/R/convertICP2017.R @@ -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" @@ -17,10 +17,8 @@ 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 } @@ -28,10 +26,8 @@ convertICP2017 <- function(x, subtype = "per_cap_expMER") { # 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 } diff --git a/R/convertSSPResults.R b/R/convertSSPResults.R index 9e45b89b..c6a39bde 100644 --- a/R/convertSSPResults.R +++ b/R/convertSSPResults.R @@ -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) @@ -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) @@ -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) @@ -107,10 +103,6 @@ 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) @@ -118,57 +110,57 @@ convertSSPResults <- function(x) { ### 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] diff --git a/R/readIMPACT3.2.2World_Price.R b/R/readIMPACT3.2.2World_Price.R index 131c7858..0d5ecc14 100644 --- a/R/readIMPACT3.2.2World_Price.R +++ b/R/readIMPACT3.2.2World_Price.R @@ -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) }