diff --git a/.buildlibrary b/.buildlibrary index 827624b..a633979 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -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' diff --git a/CITATION.cff b/CITATION.cff index 7a17d51..e75481a 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -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 diff --git a/DESCRIPTION b/DESCRIPTION index 4deb7f3..74af207 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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"), diff --git a/R/calcAfforestCosts.R b/R/calcAfforestCosts.R index 13e6aef..6e69c5c 100644 --- a/R/calcAfforestCosts.R +++ b/R/calcAfforestCosts.R @@ -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")) } diff --git a/R/calcGDPdeflator.R b/R/calcGDPdeflator.R new file mode 100644 index 0000000..283d61f --- /dev/null +++ b/R/calcGDPdeflator.R @@ -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")) + +} diff --git a/R/calcGHGPrices.R b/R/calcGHGPrices.R index f5c56c2..828ccf8 100644 --- a/R/calcGHGPrices.R +++ b/R/calcGHGPrices.R @@ -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)) @@ -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)") @@ -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") @@ -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") { @@ -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, diff --git a/R/calcIrrigationInvCosts.R b/R/calcIrrigationInvCosts.R index 8e764ad..6185ee5 100644 --- a/R/calcIrrigationInvCosts.R +++ b/R/calcIrrigationInvCosts.R @@ -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")) } diff --git a/R/calcTradeMargin.R b/R/calcTradeMargin.R index 694aa7d..b67a87e 100644 --- a/R/calcTradeMargin.R +++ b/R/calcTradeMargin.R @@ -143,11 +143,10 @@ 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 { @@ -155,7 +154,7 @@ calcTradeMargin <- function(gtap_version = "GTAP9", bilateral = FALSE, producer_ 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 diff --git a/R/calcTradeTariff.R b/R/calcTradeTariff.R index c075b8a..8d60414 100644 --- a/R/calcTradeTariff.R +++ b/R/calcTradeTariff.R @@ -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) } @@ -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, diff --git a/R/calcValueProduction.R b/R/calcValueProduction.R index 67314f0..df99727 100644 --- a/R/calcValueProduction.R +++ b/R/calcValueProduction.R @@ -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, diff --git a/R/convertSathayeForest.R b/R/convertSathayeForest.R index bc4b22e..9ec2940 100644 --- a/R/convertSathayeForest.R +++ b/R/convertSathayeForest.R @@ -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) } diff --git a/R/fullMAGPIE.R b/R/fullMAGPIE.R index 45277ac..218691e 100644 --- a/R/fullMAGPIE.R +++ b/R/fullMAGPIE.R @@ -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, @@ -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) diff --git a/README.md b/README.md index b0d6172..f155433 100644 --- a/README.md +++ b/README.md @@ -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) @@ -39,7 +39,7 @@ In case of questions / problems please contact Jan Philipp Dietrich , R package version 0.61.2, . +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, . A BibTeX entry for LaTeX users is @@ -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}, } ``` diff --git a/man/calcGDPdeflator.Rd b/man/calcGDPdeflator.Rd new file mode 100644 index 0000000..c4f717f --- /dev/null +++ b/man/calcGDPdeflator.Rd @@ -0,0 +1,25 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calcGDPdeflator.R +\name{calcGDPdeflator} +\alias{calcGDPdeflator} +\title{calcGDPdeflator} +\usage{ +calcGDPdeflator(yearFrom = 2017, yearTo = 2005, currency = "PPP") +} +\arguments{ +\item{yearFrom}{year in "y2005" format} + +\item{yearTo}{year in "y2005" format} + +\item{currency}{"PPP" or "MER"} +} +\value{ +List of magpie objects with results on country level, weight on country level, unit and description. +} +\description{ +calculates a iso-level deflator, +this is needed to run food demand and livestock regressions consistently +} +\author{ +David Chen +} diff --git a/man/calcIrrigationInvCosts.Rd b/man/calcIrrigationInvCosts.Rd index c4dc722..a6b6f77 100644 --- a/man/calcIrrigationInvCosts.Rd +++ b/man/calcIrrigationInvCosts.Rd @@ -10,11 +10,12 @@ calcIrrigationInvCosts() MAgPIE object } \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. +This function calculates irrigation investment costs for each country until + the year 2050. Values linearly converge towards the value of Germany (1995) + by 2050. } \examples{ -\dontrun{ +\dontrun{ calcOutput("IrrigationInvCosts") }