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

Update to 2017 GDP Base Year #46

Merged
merged 13 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: '12226536'
ValidationKey: '12393180'
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: 'mrland: MadRaT land data package'
version: 0.61.2
date-released: '2024-09-12'
version: 0.62.0
date-released: '2024-09-23'
abstract: The package provides land related data via the madrat framework.
authors:
- family-names: Dietrich
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: mrland
Title: MadRaT land data package
Version: 0.61.2
Date: 2024-09-12
Version: 0.62.0
Date: 2024-09-23
Authors@R: c(
person("Jan Philipp", "Dietrich", , "dietrich@pik-potsdam.de", role = c("aut", "cre")),
person("Abhijeet", "Mishra", role = "aut"),
Expand Down
2 changes: 1 addition & 1 deletion R/calcAfforestCosts.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ calcAfforestCosts <- function() {
l <- setYears(readSource("FAO_online","Land")[,2001,"6601|Land area.Area_(1000_ha)",drop=TRUE],NULL)
l[is.na(l)|is.nan(l)] <- 0

return(list(x=x,weight=l,unit="US$2004/ha",description="Afforestation factor requirement costs"))
return(list(x=x,weight=l,unit="US$2017/ha",description="Afforestation factor requirement costs"))
}
39 changes: 39 additions & 0 deletions R/calcGDPdeflator.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#' @title calcGDPdeflator
#' @description calculates a iso-level deflator,
#' this is needed to run food demand and livestock regressions consistently
#' @param yearFrom year in "y2005" format
#' @param yearTo year in "y2005" format
#' @param currency "PPP" or "MER"
#' @return List of magpie objects with results on country level, weight on country level, unit and description.
#' @author David Chen
#' @importFrom GDPuc convertGDP

calcGDPdeflator <- function(yearFrom = 2017, yearTo = 2005, currency = "PPP") {

reg <- getItems(calcOutput("GDP", unit = "constant 2005 Int$PPP",
naming = "scenario",
aggregate = FALSE), dim = 1)

defl2017 <- new.magpie(cells_and_regions = reg,
years = NULL,
names = NULL,
fill = 1)

if (currency == "PPP") {
unit <- "Int$PPP"
} else if (currency == "MER") {
unit <- "US$MER"
}

defl2017 <- convertGDP(defl2017,
unit_in = paste("constant", yearFrom, unit, sep = " "),
unit_out = paste("constant", yearTo, unit, sep = " "),
replace_NAs = c("linear", "no_conversion"))
getNames(defl2017) <- NULL

return(list(x = defl2017,
weight = NULL,
unit = "$/$",
description = "GDP base year deflator"))

}
27 changes: 23 additions & 4 deletions R/calcGHGPrices.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ calcGHGPrices <- function(emissions = "pollutants", datasource = "REMMAG", rev =
x[, , setToZero] <- 0

description <- "GHG certificate prices for different scenarios based on data from REMIND-MAgPIE coupling"


#convert these to 2017$ here
x <- convertGDP(x, unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")

} else if (datasource == "Strefler2021") {
x <- readSource("Strefler2021", subtype = paste0("intensive_", rev))
Expand Down Expand Up @@ -99,6 +103,12 @@ calcGHGPrices <- function(emissions = "pollutants", datasource = "REMMAG", rev =
# swap dimensions (scenario and gas) such that in the output file gas is in lines and scenarios in columns
getNames(x) <- gsub("^([^\\.]*)\\.(.*$)", "\\2.\\1", getNames(x))

# convert these to 2017$ here
x <- convertGDP(x, unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")


description <- paste("GHG certificate prices for different scenarios taken",
"from Strefler et al 2021 (DOI 10.1038/s41467-021-22211-2)")

Expand All @@ -115,14 +125,18 @@ calcGHGPrices <- function(emissions = "pollutants", datasource = "REMMAG", rev =
} else if (emissions != "ghg") {
stop("unknown emission type")
}

#convert these to 2017$ here
x <- convertGDP(x, unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")

description <- "ghg certificate prices for different scenarios based on data from REMIND-MAgPIE-coupling"


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

x <- readSource("SSPResults")
x <- collapseNames(x[, , "Price|Carbon (US$2005/t CO2)"])
x <- collapseNames(x[, , "Price|Carbon (US$2017/t CO2)"])
x <- x * 44 / 12

pollutants <- findset("pollutants")
Expand Down Expand Up @@ -191,6 +205,11 @@ calcGHGPrices <- function(emissions = "pollutants", datasource = "REMMAG", rev =
# fill missing years in the future
x <- time_interpolate(x, seq(1995, 2150, 5), extrapolation_type = "constant")

#convert these to 2017$ here
x <- convertGDP(x, unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")

description <- "ghg certificate prices for different scenarios based on CO2 prices provided by IMAGE"

} else if (datasource == "SSP_and_REM") {
Expand Down Expand Up @@ -218,7 +237,7 @@ calcGHGPrices <- function(emissions = "pollutants", datasource = "REMMAG", rev =
pop <- calcOutput("Population", aggregate = FALSE)

return(list(x = x, weight = pop[, 2010, 1],
unit = "US$ 2005 per t N2O-N CH4 and CO2-C",
unit = "US$ 2017 per t N2O-N CH4 and CO2-C",
description = description,
note = "As weight for aggregation currently population data from 2010 is used.",
min = 0,
Expand Down
90 changes: 53 additions & 37 deletions R/calcIrrigationInvCosts.R
Original file line number Diff line number Diff line change
@@ -1,54 +1,70 @@
#' @title calcIrrigationInvCosts
#'
#' @description This function calculates irrigation investment costs for each country until the year 2050.
#' Values linearly converge towards the value of Germany (1995) by 2050.
#'
#'
#' @description This function calculates irrigation investment costs for each country until
#' the year 2050. Values linearly converge towards the value of Germany (1995)
#' by 2050.
#'
#' @return MAgPIE object
#'
#'
#' @author Nele Steinmetz, Felicitas Beier
#'
#'
#' @seealso \code{\link{calcOutput}}, \code{\link{readWBirrigation}},
#' \code{\link{convertWBirrigation}}
#'
#'
#' @examples
#' \dontrun{
#' \dontrun{
#' calcOutput("IrrigationInvCosts")
#' }
#'
#' @import magclass
#'
#'
#' @import magclass
#'
calcIrrigationInvCosts <- function() {

# Investment costs for expanding irrigation infrastructure in US$ per hectare

# Investment costs for expanding irrigation infrastructure in 1000 US$ per hectare
# Note: in World Bank report (William I. Jones, 1991), p. 98, given in US$ per hectare
# But: csv table has transformed values (in 1000 US$ per hectare)
WBirrigation <- readSource("WBirrigation")
getYears(WBirrigation) <- NULL

# irrigation cost constant until 2015
data <- new.magpie(getRegions(WBirrigation), 1995:2050, "ad_unit_cost")
data[,1995:2050,] <- WBirrigation
data <- new.magpie(cells_and_regions = getRegions(WBirrigation),
years = 1995:2050,
names = "ad_unit_cost",
fill = NA)
data[, 1995:2050, ] <- WBirrigation

# Transform fromm 1000 USD$ per hectare to US$ per hectare
data <- data * 1000

# conversion: $1995 to $2004
data <- data * 1000 * 1.19

data <- convertGDP(data,
unit_in = "constant 1995 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")

# from 2015 onwards, data converges to value of Germany until 2050
data_DEU <- new.magpie(getRegions(WBirrigation), 1995:2050, "ad_unit_cost", fill=as.numeric(data["DEU","y1995",]))

years <- new.magpie("GLO", getYears(data), NULL, getYears(data,as.integer=TRUE))
pos <- (years - 2015) / (2050 - 2015)
pos[pos<0] <- 0
pos[pos>1] <- 1

data <- data_DEU*pos + data*(1-pos)
dataDEU <- new.magpie(cells_and_regions = getRegions(WBirrigation),
years = 1995:2050,
names = "ad_unit_cost",
fill = as.numeric(data["DEU", "y1995", ]))

data <- convergence(origin = data, aim = dataDEU,
start_year = "y2015", end_year = "y2050",
type = "linear")

# expand this value until 2150
time_extend <- paste0("y", seq(2055,2150,5))
data <- time_interpolate(data, time_extend, extrapolation_type="constant", integrate_interpolated_years=TRUE)
timeExtend <- paste0("y", seq(2055, 2150, 5))
data <- time_interpolate(data, timeExtend,
extrapolation_type = "constant",
integrate_interpolated_years = TRUE)
getNames(data) <- NULL

# aggregation weight and transform from 1000ha to ha
w <- readSource("FAO_online", subtype="Land", convert=T)[,1995,"6610|Agricultural land.Area_(1000_ha)"] * 1000

return(list(x=data,
weight=w,
unit="US$2004",
description="unit cost for irrigation expansion"))

# aggregation weight and transform from 1000ha to Mha
w <- readSource("FAO_online", subtype = "Land",
convert = TRUE)[, 1995, "6610|Agricultural land.Area_(1000_ha)"] * 1000

return(list(x = data,
weight = w,
unit = "US$MER2017",
description = "unit cost for irrigation expansion"))
}
7 changes: 3 additions & 4 deletions R/calcTradeMargin.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,18 @@ calcTradeMargin <- function(gtap_version = "GTAP9", bilateral = FALSE, producer_
weight[, , "distillers_grain"] <- weight[, , "tece"]

if (gtap_version == "GTAP9") {
if (!bilateral) {
out <- GDPuc::convertGDP(out, unit_in = "current US$MER",
unit_out = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")
}

out <- setYears(out[, 2011, ], NULL)
weight <- setYears(weight[, 2011, ], NULL)
} else {
out <- setYears(out, NULL)
weight <- setYears(weight, NULL)
}

unit <- "US$05"
unit <- "US$2017"
description <- "Trade margins"

# add tiny value to weight to avoid 0 weights creating 0 values
Expand Down
7 changes: 3 additions & 4 deletions R/calcTradeTariff.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,10 @@ calcTradeTariff<- function(gtap_version = "GTAP9", type_tariff = "total", bilate
p <- add_dimension(p, dim = 1.2, nm = getItems(p, dim = 1))
}
if (gtap_version == "GTAP9") {
if (!bilateral) {
y <- GDPuc::convertGDP(y, unit_in = "current US$MER",
unit_out = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")
}

y <- setYears(y[, 2011, ], NULL)
}

Expand Down Expand Up @@ -164,7 +163,7 @@ calcTradeTariff<- function(gtap_version = "GTAP9", type_tariff = "total", bilate


description <- paste0(type_tariff, "trade tariff")
unit <- "USD05MER/tDM"
unit <- "US$2017/tDM"
return(list(x = out,
weight = weight,
unit = unit,
Expand Down
2 changes: 1 addition & 1 deletion R/calcValueProduction.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ x <- prod[regions, , common] * prices[regions, , common]
}
return(list(x = x,
weight = NULL,
unit = "US$05/tDM",
unit = "US$2017/tDM",
description = "Crop Production Value",
min = 0,
max = Inf,
Expand Down
11 changes: 7 additions & 4 deletions R/convertSathayeForest.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
#' }
#'
convertSathayeForest <- function(x) {

# convert data from $US-2000 into $US-2004
x <- x * 1.091

# convert data from $US-2000 into $US-2017
y <- toolAggregate(x, "regionmappingSathayeForest.csv", weight=NULL )

y <- convertGDP(y, unit_in = "constant 2000 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")


return(y)
}
5 changes: 4 additions & 1 deletion R/fullMAGPIE.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@ fullMAGPIE <- function(rev = numeric_version("0.1"), dev = "") {

# 09 drivers
calcOutput("GDP",
unit = "constant 2017 Int$PPP",
naming = "scenario",
aggregate = FALSE,
years = magYears,
round = 3, # please dont increase rounding, this can create errors
file = "f09_gdp_ppp_iso.csv")
calcOutput("GDP",
unit = "constant 2005 US$MER",
unit = "constant 2017 US$MER",
naming = "scenario",
aggregate = FALSE,
years = magYears,
Expand All @@ -76,6 +77,8 @@ fullMAGPIE <- function(rev = numeric_version("0.1"), dev = "") {
round = 6) # please dont increase rounding, this can create errors
calcOutput("PhysicalInactivity", aggregate = FALSE, years = magYears, round = 3,
file = "f09_physical_inactivity.cs3")
calcOutput("GDPdeflator", aggregate = FALSE, round = 3, file = "fm_gdp_defl_ppp.cs4",
currency = "PPP")

# 13 tc
calcOutput("ExoTcDummy", round = 4, file = "f13_tau_scenario.csv", aggregate = superregion)
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MadRaT land data package

R package **mrland**, version **0.61.2**
R package **mrland**, version **0.62.0**

[![CRAN status](https://www.r-pkg.org/badges/version/mrland)](https://cran.r-project.org/package=mrland) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3822083.svg)](https://doi.org/10.5281/zenodo.3822083) [![R build status](https://github.com/pik-piam/mrland/workflows/check/badge.svg)](https://github.com/pik-piam/mrland/actions) [![codecov](https://codecov.io/gh/pik-piam/mrland/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrland) [![r-universe](https://pik-piam.r-universe.dev/badges/mrland)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Jan Philipp Dietrich <dietrich@pi

To cite package **mrland** in publications use:

Dietrich J, Mishra A, Weindl I, Bodirsky B, Wang X, Baumstark L, Kreidenweis U, Klein D, Steinmetz N, Chen D, Humpenoeder F, von Jeetze P, Wirth S, Beier F, Hoetten D, Sauer P (2024). _mrland: MadRaT land data package_. doi:10.5281/zenodo.3822083 <https://doi.org/10.5281/zenodo.3822083>, R package version 0.61.2, <https://github.com/pik-piam/mrland>.
Dietrich J, Mishra A, Weindl I, Bodirsky B, Wang X, Baumstark L, Kreidenweis U, Klein D, Steinmetz N, Chen D, Humpenoeder F, von Jeetze P, Wirth S, Beier F, Hoetten D, Sauer P (2024). _mrland: MadRaT land data package_. doi: 10.5281/zenodo.3822083 (URL: https://doi.org/10.5281/zenodo.3822083), R package version 0.62.0, <URL: https://github.com/pik-piam/mrland>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,8 +48,8 @@ A BibTeX entry for LaTeX users is
title = {mrland: MadRaT land data package},
author = {Jan Philipp Dietrich and Abhijeet Mishra and Isabelle Weindl and Benjamin Leon Bodirsky and Xiaoxi Wang and Lavinia Baumstark and Ulrich Kreidenweis and David Klein and Nele Steinmetz and David Chen and Florian Humpenoeder and Patrick {von Jeetze} and Stephen Wirth and Felicitas Beier and David Hoetten and Pascal Sauer},
year = {2024},
note = {R package version 0.61.2},
url = {https://github.com/pik-piam/mrland},
note = {R package version 0.62.0},
doi = {10.5281/zenodo.3822083},
url = {https://github.com/pik-piam/mrland},
}
```
Loading