Skip to content

Commit

Permalink
Merge pull request #139 from fbenke-pik/refactor
Browse files Browse the repository at this point in the history
correct transport issue in IEA data
  • Loading branch information
fbenke-pik authored Nov 20, 2024
2 parents 5dd0be8 + 9fe6422 commit a14955f
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '29377174'
ValidationKey: '29408949'
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: 'mrcommons: MadRat commons Input Data Library'
version: 1.46.6
date-released: '2024-11-12'
version: 1.46.7
date-released: '2024-11-20'
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.
authors:
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: mrcommons
Type: Package
Title: MadRat commons Input Data Library
Version: 1.46.6
Date: 2024-11-12
Version: 1.46.7
Date: 2024-11-20
Authors@R: c(person("Benjamin Leon", "Bodirsky", email = "[email protected]", role = "aut"),
person("Kristine", "Karstens", role = "aut"),
person("Lavinia", "Baumstark", role = "aut"),
Expand Down
25 changes: 20 additions & 5 deletions R/convertIEA.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#'
convertIEA <- function(x, subtype) {
if (grepl("EnergyBalances", subtype)) {

# aggregate Kosovo to Serbia
x1 <- x["KOS", , ]
getItems(x1, dim = 1) <- c("SRB")
Expand All @@ -37,8 +36,10 @@ convertIEA <- function(x, subtype) {
# disaggregating Other Africa (IAF),
# Other non-OECD Americas (ILA) and
# Other non-OECD Asia (IAS) regions to countries
mappingfile <- toolGetMapping(type = "regional", name = "regionmappingIEA_Other2016.csv",
returnPathOnly = TRUE, where = "mappingfolder")
mappingfile <- toolGetMapping(
type = "regional", name = "regionmappingIeaOther2016.csv",
returnPathOnly = TRUE, where = "mrcommons"
)
mapping <- read.csv2(mappingfile, stringsAsFactors = TRUE) %>%
filter(!(!!sym("CountryCode") %in% getItems(x, dim = 1)))
xadd <- toolAggregate(x[levels(mapping[[2]]), , ], mapping, weight = w[as.vector(mapping[[1]]), , ])
Expand Down Expand Up @@ -71,8 +72,9 @@ convertIEA <- function(x, subtype) {
missingFlows <- setdiff(
expand.grid(
iea_product = getItems(x[, , "ELMAINE"], dim = 3.1) %>% # nolint
union(getItems(x[, , "ELMAINC"], dim = 3.1)) %>%
union(getItems(x[, , "HEMAINC"], dim = 3.1)), iea_flows = c("ELMAINE", "ELMAINC", "HEMAINC")) %>%
union(getItems(x[, , "ELMAINC"], dim = 3.1)) %>%
union(getItems(x[, , "HEMAINC"], dim = 3.1)), iea_flows = c("ELMAINE", "ELMAINC", "HEMAINC")
) %>%
unite("product.flow", c("iea_product", "iea_flows"), sep = ".") %>%
pull("product.flow"), getItems(x, dim = 3)
)
Expand Down Expand Up @@ -105,6 +107,19 @@ convertIEA <- function(x, subtype) {
x[, , "ELAUTOE"] <- tmp
tmp <- mcalc(d, ELAUTOC ~ ifelse(HEAUTOC > 0, ELAUTOC, 0), append = FALSE)
x[, , "ELAUTOC"] <- tmp


# Correct transport reporting issue in IEA data for NONBIODIES.MARBUNK in RUS
# FE is reported in 1990 and 2010 but not in the years in between.
# This cause problems in the harmonization of EDGE-Transport and the IEA data
# in 2005 as there is no MARBUNK demand at all for REF regions.

x["RUS", seq(1990, 2010, 1), "NONBIODIES.MARBUNK"] <-
x["RUS", c(1990, 2010), "NONBIODIES.MARBUNK"] |> time_interpolate(seq(1990, 2010, 1))

# Adjust totals
x["RUS", seq(1991, 2009, 1), "TOTAL.MARBUNK"] <-
x["RUS", seq(1991, 2009, 1), "TOTAL.MARBUNK"] + x["RUS", seq(1991, 2009, 1), "NONBIODIES.MARBUNK"]
}

return(x)
Expand Down
6 changes: 3 additions & 3 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.46.6**
R package **mrcommons**, version **1.46.7**

[![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.46.6, <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.46.7, <https://github.com/pik-piam/mrcommons>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,7 +48,7 @@ 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.46.6},
note = {R package version 1.46.7},
url = {https://github.com/pik-piam/mrcommons},
doi = {10.5281/zenodo.3822009},
}
Expand Down
67 changes: 67 additions & 0 deletions inst/extdata/regional/regionmappingIeaOther2016.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
CountryCode;RegionCode
BFA;IAF
BDI;IAF
CPV;IAF
CAF;IAF
TCD;IAF
COM;IAF
DJI;IAF
GNQ;IAF
GMB;IAF
GIN;IAF
GNB;IAF
LSO;IAF
LBR;IAF
MDG;IAF
MWI;IAF
MLI;IAF
MRT;IAF
REU;IAF
RWA;IAF
STP;IAF
SYC;IAF
SLE;IAF
SOM;IAF
SWZ;IAF
UGA;IAF
ATG;ILA
ABW;ILA
BHS;ILA
BRB;ILA
BLZ;ILA
BMU;ILA
VGB;ILA
CYM;ILA
DMA;ILA
FLK;ILA
GUF;ILA
GRD;ILA
GLP;ILA
GUY;ILA
MTQ;ILA
MSR;ILA
PRI;ILA
BES;ILA
KNA;ILA
LCA;ILA
SPM;ILA
VCT;ILA
SXM;ILA
TCA;ILA
AFG;IAS
BTN;IAS
COK;IAS
TLS;IAS
FJI;IAS
PYF;IAS
KIR;IAS
LAO;IAS
MAC;IAS
MDV;IAS
NCL;IAS
PLW;IAS
PNG;IAS
WSM;IAS
SLB;IAS
TON;IAS
VUT;IAS

0 comments on commit a14955f

Please sign in to comment.