Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shift to US$2017 for currency units #523

Merged
merged 54 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
2915d90
update unit conversion to USD 2017
fbenke-pik Jul 15, 2024
7cd959b
drop price conversion in BP reference data
fbenke-pik Jul 15, 2024
a5e9054
convert unit in calcCO2Prices
fbenke-pik Jul 16, 2024
8b84568
convert unit in calcCostsWeathering
fbenke-pik Jul 16, 2024
d6811da
convert unit in calcDiffInvestCosts
fbenke-pik Jul 17, 2024
9d7e6ea
convert unit calcEconometricEmiParameter
fbenke-pik Jul 17, 2024
b0c2d48
convert prices in calcEU_ReferenceScenario
fbenke-pik Jul 17, 2024
83e447e
update unit conversion in calcPETaxes
fbenke-pik Jul 18, 2024
600bd49
update monetary unit conversion in convertIIASA_subs_taxes
fbenke-pik Jul 18, 2024
e9bce4a
Merge branch 'master' into update_2024
fbenke-pik Jul 19, 2024
c488077
Merge branch 'master' of https://github.com/pik-piam/mrremind into up…
fbenke-pik Jul 19, 2024
7eb4a0f
convert unit in calcFossilExtraction
fbenke-pik Jul 19, 2024
b90023d
switch NA replacement strategy in convertGDP
fbenke-pik Jul 19, 2024
756d5b2
convert currency units in calcINNOPATHS
fbenke-pik Jul 19, 2024
18d03e5
move jrc idees mappings to library
fbenke-pik Jul 19, 2024
4166c09
connvert currency units in calcJRC_IDEES
fbenke-pik Jul 19, 2024
e2769c1
convert currency in calcTaxConvergence
fbenke-pik Jul 19, 2024
00686e7
convert currency in calcTaxLimits
fbenke-pik Jul 19, 2024
8db99f2
convert currency in calcTaxXport
fbenke-pik Jul 19, 2024
5065918
remove := operator from mutate
fbenke-pik Jul 22, 2024
c73a8f9
convert currency units in convertUNIDO
fbenke-pik Jul 22, 2024
4d6392c
Merge branch 'master' into update_2024
fbenke-pik Jul 23, 2024
b55e9b4
apply autoformat
fbenke-pik Jul 23, 2024
58fd7c5
convert unit in calcCostsTrandePeFinancial
fbenke-pik Jul 24, 2024
53e9506
convert costs in convertGEA2021
fbenke-pik Jul 24, 2024
6d0a8ab
specify parameters to calcMACCsCH4 and calcMACCsN2O explicitly
fbenke-pik Jul 25, 2024
7d30475
convert GDP in calcBiomassPrices
fbenke-pik Jul 25, 2024
1a9e69b
Merge branch 'master' of https://github.com/pik-piam/mrremind into up…
fbenke-pik Jul 25, 2024
856ed5c
convert prices in calcBP
fbenke-pik Jul 26, 2024
f4c93db
increment version (dev)
fbenke-pik Jul 29, 2024
7fb6a9a
change default unit assumption for units from Int to US
fbenke-pik Aug 2, 2024
629f600
unify unit naming in calc functions
fbenke-pik Aug 12, 2024
959500b
Merge branch 'master' of https://github.com/pik-piam/mrremind into up…
fbenke-pik Aug 29, 2024
49fd3a3
bugfix in convertIIASA_subs_taxes
fbenke-pik Aug 29, 2024
79fea0c
Merge branch 'master' into update_2024
fbenke-pik Aug 30, 2024
d438438
add GDPuc as dependency
fbenke-pik Aug 30, 2024
18ae072
adjust unit in calcEDGETransport
fbenke-pik Aug 30, 2024
ea7df33
Merge branch 'master' into update_2024
fbenke-pik Sep 2, 2024
a465f9a
Merge branch 'master' into update_2024
fbenke-pik Sep 3, 2024
775cee4
adjust replace_NAs parameter in unit conversion
fbenke-pik Sep 3, 2024
5f54a26
Merge branch 'master' of https://github.com/pik-piam/mrremind into up…
fbenke-pik Sep 3, 2024
e169276
Merge branch 'master' of https://github.com/pik-piam/mrremind into up…
fbenke-pik Sep 5, 2024
1ff1f6f
increment to dev version
fbenke-pik Sep 6, 2024
22a6df5
convert currencty in convertTransportSubsidies
fbenke-pik Sep 6, 2024
6a6db58
fix minor bug in calcMacroInvestments
fbenke-pik Sep 9, 2024
4389a0c
fix bug in calcCostsWeathering
fbenke-pik Sep 9, 2024
c5f8d78
fix bug in calcBiomassPrices
fbenke-pik Sep 9, 2024
6ba9f01
fix bug in convertGEA2012
fbenke-pik Sep 9, 2024
dbd2d75
remove no longer needed workaround
fbenke-pik Sep 9, 2024
0aa98f5
fix bug in calcCO2Prices
fbenke-pik Sep 10, 2024
15ef815
Merge branch 'master' of https://github.com/pik-piam/mrremind into up…
fbenke-pik Sep 19, 2024
da8377a
increment dev version
fbenke-pik Sep 19, 2024
4c627b3
Merge branch 'master' of https://github.com/pik-piam/mrremind into up…
fbenke-pik Sep 20, 2024
28de8d4
increment version
fbenke-pik Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '38191335'
ValidationKey: '38213232'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cff-version: 1.2.0
message: If you use this software, please cite it using the metadata from this file.
type: software
title: 'mrremind: MadRat REMIND Input Data Package'
version: 0.191.1
date-released: '2024-09-19'
version: 0.191.2
date-released: '2024-09-20'
abstract: The mrremind packages contains data preprocessing for the REMIND model.
authors:
- family-names: Baumstark
Expand Down
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: mrremind
Title: MadRat REMIND Input Data Package
Version: 0.191.1
Date: 2024-09-19
Version: 0.191.2
Date: 2024-09-20
Authors@R: c(
person("Lavinia", "Baumstark", , "[email protected]", role = c("aut", "cre")),
person("Renato", "Rodrigues", role = "aut"),
Expand Down Expand Up @@ -52,6 +52,7 @@ Imports:
data.table,
dplyr,
ggplot2,
GDPuc (>= 1.0.5),
Hmisc,
luscale,
magrittr,
Expand Down
2 changes: 1 addition & 1 deletion R/EDGE-Industry.R
Original file line number Diff line number Diff line change
Expand Up @@ -2808,7 +2808,7 @@ calcIndustry_Value_Added <- function(subtype = 'physical',
return(list(x = x %>%
as.magpie(spatial = 2, temporal = 4, data = 5),
weight = NULL,
unit = '$tn/year',
unit = 'trillion US$2017/year',
description = 'chemicals and other industry value added'))

}
15 changes: 10 additions & 5 deletions R/UNIDO.R
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,16 @@ convertUNIDO <- function(x, subtype = 'INDSTAT2')
# the maximum
summarise(value = max(.data$value), .groups = 'drop')

# return ----
# convert from $2005 to $2017 and return ----
x %>%
as.magpie(spatial = 1, temporal = 3, data = ncol(.)) %>%
toolCountryFill(verbosity = 2) %>%
return()
as.magpie(spatial = 1, temporal = 3, data = ncol(.)) %>%
toolCountryFill(verbosity = 2) %>%
0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q marked this conversation as resolved.
Show resolved Hide resolved
GDPuc::convertGDP(
unit_in = "constant 2005 US$MER",
unit_out = mrdrivers::toolGetUnitDollar(),
replace_NAs = "with_USA"
) %>%
return()
}
)

Expand Down Expand Up @@ -307,7 +312,7 @@ calcUNIDO <- function(subtype = 'INDSTAT2')

return(list(x = x,
weight = NULL,
unit = 'billion US$2005/yr',
unit = 'billion US$2017/yr',
description = 'industry subsector value added'))
}
)
Expand Down
41 changes: 36 additions & 5 deletions R/calcBP.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ calcBP <- function() {
map <- toolGetMapping("Mapping_BP.csv", type = "reportingVariables", where = "mrremind") %>%
filter(!is.na(.data$REMIND), .data$REMIND != "") %>%
mutate(
"from" := paste0(trimws(.data$variable), " (", .data$unit, ")"),
"to" := paste0(trimws(.data$REMIND), " (", .data$Unit_REMIND, ")"),
"conversion" := as.numeric(.data$Factor)
"from" = paste0(trimws(.data$variable), " (", .data$unit, ")"),
"to" = paste0(trimws(.data$REMIND), " (", .data$Unit_REMIND, ")"),
"conversion" = as.numeric(.data$Factor)
) %>%
select("from", "to", "conversion")

Expand All @@ -139,15 +139,46 @@ calcBP <- function() {
to = "to", verbosity = 2
)

# convert price units ----

# should be from US$2023, but 'convertGDP' currently returns NA
poil <- GDPuc::convertGDP(
gdp = x[, , "Price|Primary Energy|Oil (US$2023/GJ)"],
unit_in = "constant 2022 US$MER",
unit_out = mrdrivers::toolGetUnitDollar(),
replace_NAs = "with_USA"
)

getNames(poil) <- gsub("\\$2023", "\\$2017", getNames(poil))

# assume these units are in current MER
pcoalgas <- GDPuc::convertGDP(
gdp = x[, , c("Price|Primary Energy|Gas (US$/GJ)", "Price|Primary Energy|Coal (US$/GJ)")],
unit_in = "current US$MER",
unit_out = mrdrivers::toolGetUnitDollar(),
replace_NAs = "with_USA"
)

getNames(pcoalgas) <- gsub("\\$", "\\$2017", getNames(pcoalgas))


x <- x[, , c("Price|Primary Energy|Oil (US$2023/GJ)",
"Price|Primary Energy|Gas (US$/GJ)",
"Price|Primary Energy|Coal (US$/GJ)"), invert = TRUE]

x <- mbind(x, poil, pcoalgas)

# set weights ----

weights <- x
weights[, , ] <- NA
weights[, , "US$2005/GJ", pmatch = TRUE] <- 1
weights[, , "US$2017/GJ", pmatch = TRUE] <- 1

return(list(
x = x,
weight = weights,
mixed_aggregation = TRUE,
unit = c("Mt CO2/yr", "GW", "EJ/yr", "US$2005/GJ"),
unit = c("Mt CO2/yr", "GW", "EJ/yr", "US$2017/GJ"),
description = "Historical World Energy Statistics values as REMIND variables"
))
}
41 changes: 26 additions & 15 deletions R/calcBiomassPrices.R
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
#' read biomass supply curves from Magpie emulator
#' @return Magpie object with two parameters determining linear biomass supply curve
#' @import mrcommons

calcBiomassPrices <- function(){
calcBiomassPrices <- function() {

x <- readSource("MAgPIE", subtype = "supplyCurve_magpie_40")

# rename the rcp-scenarios to cm_rcp_scen switches used in REMIND
getNames(x) <- gsub("NDC-nocc_hist-PkBudg650", "rcp20", getNames(x))
getNames(x) <- gsub("NDC-nocc_hist-PkBudg650", "rcp20", getNames(x))
getNames(x) <- gsub("NDC-nocc_hist-PkBudg1050", "rcp26", getNames(x))
getNames(x) <- gsub("NDC-nocc_hist-NDC", "rcp45", getNames(x))
getNames(x) <- gsub("NPI-nocc_hist-Base", "none" , getNames(x))
getNames(x) <- gsub("NPI-nocc_hist-Base", "none", getNames(x))

# rename SSP-scenarios to cm_LU_emi_scen switches used in REMIND
getNames(x) <- gsub("SSP2EU", "SSP2", getNames(x))
getNames(x) <- gsub("SDP-MC", "SDP", getNames(x))

# Introduce new SSP/SDP dimension by replacing "-" with "."
getNames(x) <- gsub("(SSP[0-9]|SDP)-","\\1.",getNames(x))

getNames(x) <- gsub("(SSP[0-9]|SDP)-", "\\1.", getNames(x))
getSets(x)["d3.1"] <- "scen1"
getSets(x)["d3.2"] <- "scen2"
getSets(x)["d3.3"] <- "char"

# add supply curves for SSP3 using the curves from SSP2
tmp <- x[,,"SSP2"]
tmp <- x[, , "SSP2"]
getNames(tmp) <- gsub("SSP2", "SSP3", getNames(tmp))
x <- mbind(x, tmp)

# if fit coefficients of a country are NA for all years (there is no supplycurve at all for this country)
# generate artificial supplycurve with VERY high prices
x[,,"a"][is.na(x[,,"a"])] <- 1
x[,,"b"][is.na(x[,,"b"])] <- 0.1
x[, , "a"][is.na(x[, , "a"])] <- 1
x[, , "b"][is.na(x[, , "b"])] <- 0.1

# apply conversion from US$2005 to US$2017 to "a" and "b", so that the price
# calculated with these coefficients will be in US$2017
x <- GDPuc::convertGDP(
gdp = x,
unit_in = "constant 2005 US$MER",
unit_out = mrdrivers::toolGetUnitDollar(),
replace_NAs = "with_USA"
)

return(list(x = x,
weight = calcOutput("FAOLand", aggregate = F)[,,"6610",pmatch=TRUE][,"y2010",],
weight = calcOutput("FAOLand", aggregate = FALSE)[, , "6610", pmatch = TRUE][, "y2010", ],
unit = "none",
description = "coefficients for the bioenergy supplycurve",
aggregationFunction=toolBiomassSupplyAggregate))
aggregationFunction = toolBiomassSupplyAggregate))
}
13 changes: 12 additions & 1 deletion R/calcCO2Prices.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
calcCO2Prices <- function() {

# read data
x <- readSource("ExpertGuess", subtype = "co2prices")

# convert from $2005 to $2017

x <- GDPuc::convertGDP(
gdp = x,
unit_in = "constant 2005 US$MER",
unit_out = mrdrivers::toolGetUnitDollar(),
replace_NAs = "with_USA"
)

getNames(x) <- NULL

# read data used for weight
Expand All @@ -12,7 +23,7 @@ calcCO2Prices <- function() {
return(list(
x = x,
weight = ceds,
unit = "US$2005/t CO2",
unit = "US$2017/t CO2",
description = "CO2 prices in 2010, 2015 and 2020"
))
}
2 changes: 1 addition & 1 deletion R/calcCapital.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ calcCapital <- function() {
# tie outputs together ----
list(x = mbind(cap_future, EEK),
weight = NULL,
unit = "trillion 2005US$",
unit = "trillion US$2017",
description = "Capital stock, computed using the capital to GDP ratio from PWT, and GDP scenarios from mrdrivers.")
}
37 changes: 22 additions & 15 deletions R/calcCostsTradePeFinancial.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
#' Calculate Trade Cost
#'
#' Provides REMIND data for PE trade cost (energy losses on import, export and
#' use).
#'
#'
#'
#' Provides REMIND data for PE trade cost (energy losses on import, export and use).
#'
#' @author Regina Brecha, Lavinia Baumstark
#' @seealso \code{\link{calcOutput}}, \code{\link{readSource}}
#' @examples
#'
#' \dontrun{
#' \dontrun{
#' calcOutput("CostsTradePeFinancial")
#' }
#'
#'
calcCostsTradePeFinancial <- function() {

data <- readSource("ExpertGuess", subtype="costsTradePeFinancial")
w <- calcOutput("GDP",aggregate=FALSE)[,2005,"gdp_SSP2"]

return(list(x=data,weight=w,
unit="TW and ratio",
description="PE tradecosts (financial costs on import, export and use)"))
data <- readSource("ExpertGuess", subtype = "costsTradePeFinancial")

data <- GDPuc::convertGDP(
gdp = data,
unit_in = "constant 2005 US$MER",
unit_out = mrdrivers::toolGetUnitDollar(),
replace_NAs = "with_USA"
)

w <- calcOutput("GDP", aggregate = FALSE)[, 2005, "gdp_SSP2"]

return(list(
x = data,
weight = w,
unit = "trillion US$2017/TWa",
description = "PE tradecosts (financial costs on import, export and use)"
))
}
25 changes: 18 additions & 7 deletions R/calcCostsWeathering.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,32 @@
#' @return transport costs of spreading rock on the fields
#' @seealso \code{\link{calcOutput}}
#' @examples
#'
#' \dontrun{
#' calcOutput("CostsWeathering")
#' }
#'

calcCostsWeathering <- function() {

costs <- readSource("Strefler", subtype = "weathering_costs")
weight <- costs # get the same dimensions of the data

# convert from $2005 to $2017

x <- GDPuc::convertGDP(
gdp = costs,
unit_in = "constant 2005 US$MER",
unit_out = mrdrivers::toolGetUnitDollar(),
replace_NAs = "with_USA"
)

weight <- x # get the same dimensions of the data
weight[, , ] <- 1 # this will take the average of the countries to get the regional resolution

return(list(x = costs,
weight = weight,
unit = "T$/Gt stone",
description = "Transport costs for spreading rocks on the fields. The first rlf corresponds to climate regions (1 - warm, 2 - temperate). The second rlf are the distances of fields from the sources of the material."
return(list(
x = x,
weight = weight,
unit = "trillion US$2017/Gt stone",
description = "Transport costs for spreading rocks on the fields.
The first rlf corresponds to climate regions (1 - warm, 2 - temperate).
The second rlf are the distances of fields from the sources of the material."
))
}
Loading
Loading