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

Add REMIND input data #40

Merged
merged 3 commits into from
Dec 20, 2023
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: '10268910'
ValidationKey: '10288620'
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
- 'Warning: namespace ''.*'' is not available and has been replaced'
Expand Down
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: 'mrland: MadRaT land data package'
version: 0.52.1
version: 0.52.2
date-released: '2023-12-19'
abstract: The package provides land related data via the madrat framework.
authors:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: mrland
Title: MadRaT land data package
Version: 0.52.1
Version: 0.52.2
Date: 2023-12-19
Authors@R: c(
person("Jan Philipp", "Dietrich", , "[email protected]", role = c("aut", "cre")),
Expand Down
119 changes: 73 additions & 46 deletions R/readREMIND.R
Original file line number Diff line number Diff line change
@@ -1,67 +1,94 @@
#' @title readREMIND
#' @description Reads in a reporting mif file from REMIND
#'
#'
#' @param subtype Either "intensive" or "extensive"
#' @return MAgPIE object with regional aggregation of REMIND H12
#' @author David Klein
#' @seealso
#' \code{\link{readSource}}
#' @examples
#'
#' \dontrun{
#'
#' \dontrun{
#' readSource("REMIND",aggregate=FALSE)
#' }
#' @importFrom magclass read.report

readREMIND <- function(subtype) {

# /p/projects/remind/runs/r8473-trunk-C/output/r8473-trunk-C_*/report.mif

file_list <- c("REMIND_generic_r8473-trunk-C_Budg600-rem-5.mif",
"REMIND_generic_r8473-trunk-C_Budg950-rem-5.mif",
"REMIND_generic_r8473-trunk-C_Budg1300-rem-5.mif",
"REMIND_generic_r8473-trunk-C_NDC-rem-5.mif",
"REMIND_generic_r8473-trunk-C_NPi-rem-5.mif")

if(grepl("_",subtype)){

subtype <- strsplit(subtype, split="_")
revision <- as.numeric(unlist(subtype)[2])

if (revision > 4.58) {
file_list <- c(file_list,
"REMIND_generic_C_SDP-NPi-rem-5.mif",
"REMIND_generic_C_SDP-PkBudg900-rem-5.mif",
"REMIND_generic_C_SDP-PkBudg1000-rem-5.mif",
"REMIND_generic_C_SDP-PkBudg1100-rem-5.mif",
"REMIND_generic_C_SSP1-NPi-rem-5.mif",
"REMIND_generic_C_SSP1-PkBudg900-rem-5.mif",
"REMIND_generic_C_SSP1-PkBudg1100-rem-5.mif",
"REMIND_generic_C_SSP1-PkBudg1300-rem-5.mif",
"REMIND_generic_C_SSP2-NPi-rem-5.mif",
"REMIND_generic_C_SSP2-PkBudg900-rem-5.mif",
"REMIND_generic_C_SSP2-PkBudg1100-rem-5.mif",
"REMIND_generic_C_SSP2-PkBudg1300-rem-5.mif",
"REMIND_generic_C_SSP5-NPi-rem-5.mif",
"REMIND_generic_C_SSP5-PkBudg900-rem-5.mif",
"REMIND_generic_C_SSP5-PkBudg1100-rem-5.mif",
"REMIND_generic_C_SSP5-PkBudg1300-rem-5.mif")
.readAndRename <- function(fileList, pattern, replacement) {
x <- NULL
for (f in fileList) {

Check warning on line 20 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L18-L20

Added lines #L18 - L20 were not covered by tests
# select REMIND only since newer coupled REMIND reportings also contain MAgPIE
x <- mbind(x, read.report(f, as.list = FALSE)[, , "REMIND"])

Check warning on line 22 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L22

Added line #L22 was not covered by tests
}
# remove model and variable name
x <- collapseNames(x)

Check warning on line 25 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L25

Added line #L25 was not covered by tests
# shorten names of the REMIND scenarios
getNames(x) <- gsub(pattern, replacement, getNames(x))
return(x)

Check warning on line 28 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L27-L28

Added lines #L27 - L28 were not covered by tests
}

x <- NULL
for(f in file_list) {
x <- mbind(x,read.report(f,as.list = FALSE))

# Please refer to the 2019-R2M41/readme.txt for the source of the data
fileList <- c("2019-R2M41/REMIND_generic_r8473-trunk-C_Budg600-rem-5.mif",
"2019-R2M41/REMIND_generic_r8473-trunk-C_Budg950-rem-5.mif",
"2019-R2M41/REMIND_generic_r8473-trunk-C_Budg1300-rem-5.mif",
"2019-R2M41/REMIND_generic_r8473-trunk-C_NDC-rem-5.mif",
"2019-R2M41/REMIND_generic_r8473-trunk-C_NPi-rem-5.mif")

Check warning on line 36 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L32-L36

Added lines #L32 - L36 were not covered by tests

out <- .readAndRename(fileList = fileList, pattern = "r8473-trunk-C_", replacement = "R2M41-SSP2-")

Check warning on line 38 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L38

Added line #L38 was not covered by tests

if (grepl("_", subtype)) {

Check warning on line 40 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L40

Added line #L40 was not covered by tests

subtype <- strsplit(subtype, split = "_")
revision <- as.numeric(unlist(subtype)[2])

Check warning on line 43 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L42-L43

Added lines #L42 - L43 were not covered by tests

if (revision > 4.58) {

Check warning on line 45 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L45

Added line #L45 was not covered by tests
# Please refer to the 2021-R21M42/readme.txt for the source of the data
fileList <- c("2021-R21M42/REMIND_generic_C_SDP-NPi-rem-5.mif",
"2021-R21M42/REMIND_generic_C_SDP-PkBudg900-rem-5.mif",
"2021-R21M42/REMIND_generic_C_SDP-PkBudg1000-rem-5.mif",
"2021-R21M42/REMIND_generic_C_SDP-PkBudg1100-rem-5.mif",
"2021-R21M42/REMIND_generic_C_SSP1-NPi-rem-5.mif",
"2021-R21M42/REMIND_generic_C_SSP1-PkBudg900-rem-5.mif",
"2021-R21M42/REMIND_generic_C_SSP1-PkBudg1100-rem-5.mif",
"2021-R21M42/REMIND_generic_C_SSP1-PkBudg1300-rem-5.mif",
"2021-R21M42/REMIND_generic_C_SSP2-NPi-rem-5.mif",
"2021-R21M42/REMIND_generic_C_SSP2-PkBudg900-rem-5.mif",
"2021-R21M42/REMIND_generic_C_SSP2-PkBudg1100-rem-5.mif",
"2021-R21M42/REMIND_generic_C_SSP2-PkBudg1300-rem-5.mif",
"2021-R21M42/REMIND_generic_C_SSP5-NPi-rem-5.mif",
"2021-R21M42/REMIND_generic_C_SSP5-PkBudg900-rem-5.mif",
"2021-R21M42/REMIND_generic_C_SSP5-PkBudg1100-rem-5.mif",
"2021-R21M42/REMIND_generic_C_SSP5-PkBudg1300-rem-5.mif")

Check warning on line 62 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L47-L62

Added lines #L47 - L62 were not covered by tests

out <- mbind(out, .readAndRename(fileList = fileList, pattern = "C_(SDP|SSP)", replacement = "R21M42-\\1"))

Check warning on line 64 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L64

Added line #L64 was not covered by tests
}

if (revision >= 4.96) {

Check warning on line 67 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L67

Added line #L67 was not covered by tests
# Please refer to the 2023-R32M46/readme.txt for the source of the data
fileList <- c("2023-R32M46/REMIND_generic_C_SDP_MC-NDC-rem-5.mif",
"2023-R32M46/REMIND_generic_C_SDP_MC-NPi-rem-5.mif",
"2023-R32M46/REMIND_generic_C_SDP_MC-PkBudg650-rem-5.mif",
"2023-R32M46/REMIND_generic_C_SSP1-NDC-rem-5.mif",
"2023-R32M46/REMIND_generic_C_SSP1-NPi-rem-5.mif",
"2023-R32M46/REMIND_generic_C_SSP1-PkBudg1050-rem-5.mif",
"2023-R32M46/REMIND_generic_C_SSP1-PkBudg650-rem-5.mif",
"2023-R32M46/REMIND_generic_C_SSP2EU-NDC-rem-5.mif",
"2023-R32M46/REMIND_generic_C_SSP2EU-NPi-rem-5.mif",
"2023-R32M46/REMIND_generic_C_SSP2EU-PkBudg1050-rem-5.mif",
"2023-R32M46/REMIND_generic_C_SSP2EU-PkBudg650-rem-5.mif",
"2023-R32M46/REMIND_generic_C_SSP5-NDC-rem-5.mif",
"2023-R32M46/REMIND_generic_C_SSP5-NPi-rem-5.mif",
"2023-R32M46/REMIND_generic_C_SSP5-PkBudg1050-rem-5.mif",
"2023-R32M46/REMIND_generic_C_SSP5-PkBudg650-rem-5.mif")

Check warning on line 83 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L69-L83

Added lines #L69 - L83 were not covered by tests

out <- mbind(out, .readAndRename(fileList = fileList, pattern = "C_(SDP_MC|SSP)", replacement = "R32M46-\\1"))

Check warning on line 85 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L85

Added line #L85 was not covered by tests
}
}

# remove model and variable name
x <- collapseNames(x)


# shorten names of the REMIND scenarios
getNames(x) <- gsub("r8473-trunk-C_", "R2M41-SSP2-",getNames(x))
getNames(x) <- gsub("C_(SDP|SSP)", "R21M42-\\1",getNames(x))
getNames(x) <- gsub("-rem-5","",getNames(x))
getNames(out) <- gsub("-rem-5", "", getNames(out))

Check warning on line 90 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L90

Added line #L90 was not covered by tests

return(x)
return(out)

Check warning on line 92 in R/readREMIND.R

View check run for this annotation

Codecov / codecov/patch

R/readREMIND.R#L92

Added line #L92 was not covered by tests

}
6 changes: 3 additions & 3 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.52.1**
R package **mrland**, version **0.52.2**

[![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 (2023). _mrland: MadRaT land data package_. doi:10.5281/zenodo.3822083 <https://doi.org/10.5281/zenodo.3822083>, R package version 0.52.1, <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 (2023). _mrland: MadRaT land data package_. doi: 10.5281/zenodo.3822083 (URL: https://doi.org/10.5281/zenodo.3822083), R package version 0.52.2, <URL: https://github.com/pik-piam/mrland>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,7 +48,7 @@ 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},
year = {2023},
note = {R package version 0.52.1},
note = {R package version 0.52.2},
doi = {10.5281/zenodo.3822083},
url = {https://github.com/pik-piam/mrland},
}
Expand Down
2 changes: 1 addition & 1 deletion man/readREMIND.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading