Skip to content

Commit

Permalink
Merge pull request #133 from fbenke-pik/gdp
Browse files Browse the repository at this point in the history
replace unit conversion functions with madrat tool wrappers
  • Loading branch information
fbenke-pik authored Oct 11, 2024
2 parents 3ec2e7b + 32fde78 commit b8e5d6e
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
ValidationKey: '288340884'
ValidationKey: '288360891'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
AcceptedNotes:
- unable to verify current time
- Imports includes .* non-default packages.
- installed size is .*
- .* includes the non-default packages.*
AutocreateReadme: yes
allowLinterWarnings: no
enforceVersionUpdate: no
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cff-version: 1.2.0
message: If you use this software, please cite it using the metadata from this file.
type: software
title: 'mrcommons: MadRat commons Input Data Library'
version: 1.44.12
version: 1.44.13
date-released: '2024-10-11'
abstract: Provides useful functions and a common structure to all the input data required
to run models like MAgPIE and REMIND of model input data.
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mrcommons
Type: Package
Title: MadRat commons Input Data Library
Version: 1.44.12
Version: 1.44.13
Date: 2024-10-11
Authors@R: c(person("Benjamin Leon", "Bodirsky", email = "bodirsky@pik-potsdam.de", role = "aut"),
person("Kristine", "Karstens", role = "aut"),
Expand Down Expand Up @@ -40,6 +40,7 @@ Description: Provides useful functions and a common structure to all the input d
and REMIND of model input data.
Depends:
R (>= 2.10.0),
GDPuc (>= 1.3.0),
magclass (>= 3.17),
madrat (>= 3.10.0),
mrdrivers (>= 1.0.0),
Expand All @@ -50,7 +51,6 @@ Imports:
data.table,
dplyr,
hdf5r,
GDPuc (>= 1.0.5),
luscale,
magpiesets (>= 0.44.2),
ncdf4,
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ export(readHoulton2018)
export(readJRC_IDEES)
export(toolCalcIEAfromStructureMappingPEFE)
export(toolPregnant)
import(GDPuc)
import(madrat)
import(magclass)
import(mrdrivers)
import(mrfaocore)
import(mrlandcore)
import(mstools)
importFrom(GDPuc,convertGDP)
importFrom(GDPuc,toolConvertGDP)
importFrom(countrycode,countrycode)
importFrom(data.table,":=")
importFrom(data.table,as.data.table)
Expand Down
6 changes: 3 additions & 3 deletions R/calcGTAPTotalTransportCosts.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ calcGTAPTotalTransportCosts <- function(costType = "transport", version = "9") {
# half of transport of inputs to market and half of transport from market to consumer
totalTcosts <- (tcostInputs + tcostToSecondary) / 2

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

return(list(x = totalTcosts,
weight = NULL,
Expand Down
12 changes: 6 additions & 6 deletions R/calcIniFoodPrice.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ calcIniFoodPrice <- function(datasource = "FAO", year = "y2005", products = "kfo
"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")
out[, , conv] <- GDPuc::toolConvertGDP(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
Expand Down Expand Up @@ -122,9 +122,9 @@ calcIniFoodPrice <- function(datasource = "FAO", year = "y2005", products = "kfo
"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")
out[, , conv] <- GDPuc::toolConvertGDP(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
Expand Down
4 changes: 2 additions & 2 deletions R/calcMAgPIEReport.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ calcMAgPIEReport <- function(subtype) {
# with transformation factor from 10E6 US$2005 to 10E12 US$2005
x <- x[, , "Costs Without Incentives (million US$05/yr)"] / 1000 / 1000
# convert from US$2005 -> US$2017
x <- GDPuc::convertGDP(
x <- GDPuc::toolConvertGDP(
gdp = x,
unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 Int$PPP",
Expand All @@ -20,7 +20,7 @@ calcMAgPIEReport <- function(subtype) {
# with transformation factor from 10E6 US$2005 to 10E12 US$2005
x <- x[, , "Costs Accounting|+|MACCS (million US$05/yr)"] / 1000 / 1000
# convert from US$2005 -> US$2017
x <- GDPuc::convertGDP(
x <- GDPuc::toolConvertGDP(
gdp = x,
unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 Int$PPP",
Expand Down
8 changes: 4 additions & 4 deletions R/calcPriceAgriculture.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ calcPriceAgriculture <- function(datasource = "IMPACT3.2.2World_Price", unit = "

if (unit != "US$17/tDM") {
# Transform to selected currency unit
out <- GDPuc::convertGDP(out,
unit_in = "constant 2017 US$MER",
unit_out = unit,
replace_NAs = "no_conversion")
out <- GDPuc::toolConvertGDP(out,
unit_in = "constant 2017 US$MER",
unit_out = unit,
replace_NAs = "no_conversion")
}

if (!is.null(weight)) {
Expand Down
6 changes: 3 additions & 3 deletions R/calcWBGEM.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ calcWBGEM <- function() {

# 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")
out <- GDPuc::toolConvertGDP(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,
Expand Down
10 changes: 5 additions & 5 deletions R/convertGTAPv8v9.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' \dontrun{
#' a <- readSource("convertGTAPv8v9", "81:SF01", convert = TRUE)
#' }
#' @importFrom GDPuc convertGDP
#' @importFrom GDPuc toolConvertGDP
convertGTAPv8v9 <- function(x, subtype) {

split <- toolSplitSubtype(subtype, list(version = NULL, header = NULL))
Expand Down Expand Up @@ -68,10 +68,10 @@ convertGTAPv8v9 <- function(x, subtype) {
gdpMer <- calcOutput("GDPPast", GDPPast = "WDI-MI",
unit = "constant 2017 US$MER", aggregate = FALSE)
gdpMer <- gdpMer[, getYears(x), , drop = TRUE]
w1 <- GDPuc::convertGDP(gdpMer,
unit_in = "constant 2017 US$MER",
unit_out = "current US$MER",
replace_NAs = "no_conversion")
w1 <- GDPuc::toolConvertGDP(gdpMer,
unit_in = "constant 2017 US$MER",
unit_out = "current US$MER",
replace_NAs = "no_conversion")
getNames(w1) <- NULL
w2 <- w1

Expand Down
12 changes: 6 additions & 6 deletions R/convertICP2017.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ 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")
x2011 <- GDPuc::toolConvertGDP(x[, 2011, ],
unit_in = "constant 2011 US$MER",
unit_out = "constant 2017 US$MER")
x2017 <- x[, 2017, ]
x <- mbind(x2011, x2017)
x[is.na(x)] <- 0
Expand All @@ -28,9 +28,9 @@ 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")
x2011 <- GDPuc::toolConvertGDP(x[, 2011, ],
unit_in = "constant 2011 US$PPP",
unit_out = "constant 2017 US$MER")
x2017 <- x[, 2017, ]
x <- mbind(x2011, x2017)
x[is.na(x)] <- 0
Expand Down
10 changes: 5 additions & 5 deletions R/convertSSPResults.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ convertSSPResults <- function(x) {
data <- x[, , selection]
data[is.na(data)] <- 0
#convert from USD05MER to USD17MER based on USA values for all countries as the CO2 price is global.
data <- data * round(GDPuc::convertSingle(1, "USA", unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER"), 2)
data <- data * round(GDPuc::toolConvertSingle(1, "USA", unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER"), 2)
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")
Expand All @@ -107,9 +107,9 @@ 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")
data <- toolConvertGDP(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")
Expand Down
2 changes: 1 addition & 1 deletion R/imports.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by lucode2: do not edit by hand

#' @import magclass madrat mrdrivers mrfaocore mrlandcore mstools
#' @import GDPuc magclass madrat mrdrivers mrfaocore mrlandcore mstools
NULL
8 changes: 4 additions & 4 deletions R/readIMPACT3.2.2World_Price.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ readIMPACT3.2.2World_Price <- function() { # nolint: object_name_linter.

#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")
data <- GDPuc::toolConvertGDP(data,
unit_in = "constant 2005 US$MER",
unit_out = "constant 2017 US$MER",
replace_NAs = "no_conversion")
getItems(data, dim = 1) <- "GLO"

return(data)
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 commons Input Data Library

R package **mrcommons**, version **1.44.12**
R package **mrcommons**, version **1.44.13**

[![CRAN status](https://www.r-pkg.org/badges/version/mrcommons)](https://cran.r-project.org/package=mrcommons) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3822009.svg)](https://doi.org/10.5281/zenodo.3822009) [![R build status](https://github.com/pik-piam/mrcommons/workflows/check/badge.svg)](https://github.com/pik-piam/mrcommons/actions) [![codecov](https://codecov.io/gh/pik-piam/mrcommons/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/mrcommons) [![r-universe](https://pik-piam.r-universe.dev/badges/mrcommons)](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 **mrcommons** in publications use:

Bodirsky B, Karstens K, Baumstark L, Weindl I, Wang X, Mishra A, Wirth S, Stevanovic M, Steinmetz N, Kreidenweis U, Rodrigues R, Popov R, Humpenoeder F, Giannousakis A, Levesque A, Klein D, Araujo E, Beier F, Oeser J, Pehl M, Leip D, Crawford M, Molina Bacca E, von Jeetze P, Martinelli E, Schreyer F, Soergel B, Sauer P, Hötten D, Hasse R, Abrahão G, Weigmann P, Dietrich J (2024). _mrcommons: MadRat commons Input Data Library_. doi:10.5281/zenodo.3822009 <https://doi.org/10.5281/zenodo.3822009>, R package version 1.44.12, <https://github.com/pik-piam/mrcommons>.
Bodirsky B, Karstens K, Baumstark L, Weindl I, Wang X, Mishra A, Wirth S, Stevanovic M, Steinmetz N, Kreidenweis U, Rodrigues R, Popov R, Humpenoeder F, Giannousakis A, Levesque A, Klein D, Araujo E, Beier F, Oeser J, Pehl M, Leip D, Crawford M, Molina Bacca E, von Jeetze P, Martinelli E, Schreyer F, Soergel B, Sauer P, Hötten D, Hasse R, Abrahão G, Weigmann P, Dietrich J (2024). _mrcommons: MadRat commons Input Data Library_. doi:10.5281/zenodo.3822009 <https://doi.org/10.5281/zenodo.3822009>, R package version 1.44.13, <https://github.com/pik-piam/mrcommons>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,8 +48,8 @@ A BibTeX entry for LaTeX users is
title = {mrcommons: MadRat commons Input Data Library},
author = {Benjamin Leon Bodirsky and Kristine Karstens and Lavinia Baumstark and Isabelle Weindl and Xiaoxi Wang and Abhijeet Mishra and Stephen Wirth and Mishko Stevanovic and Nele Steinmetz and Ulrich Kreidenweis and Renato Rodrigues and Roman Popov and Florian Humpenoeder and Anastasis Giannousakis and Antoine Levesque and David Klein and Ewerton Araujo and Felicitas Beier and Julian Oeser and Michaja Pehl and Debbora Leip and Michael Crawford and Edna {Molina Bacca} and Patrick {von Jeetze} and Eleonora Martinelli and Felix Schreyer and Bjoern Soergel and Pascal Sauer and David Hötten and Robin Hasse and Gabriel Abrahão and Pascal Weigmann and Jan Philipp Dietrich},
year = {2024},
note = {R package version 1.44.12},
doi = {10.5281/zenodo.3822009},
note = {R package version 1.44.13},
url = {https://github.com/pik-piam/mrcommons},
doi = {10.5281/zenodo.3822009},
}
```

0 comments on commit b8e5d6e

Please sign in to comment.