Skip to content

Commit

Permalink
Merge pull request pik-piam#532 from fbenke-pik/expert
Browse files Browse the repository at this point in the history
add expert guess 'tradeConstraints'
  • Loading branch information
fbenke-pik authored Sep 2, 2024
2 parents 8728c5b + 4663222 commit d7a27a6
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '37153004'
ValidationKey: '37180416'
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: 'mrremind: MadRat REMIND Input Data Package'
version: 0.186.1
date-released: '2024-08-29'
version: 0.186.2
date-released: '2024-09-02'
abstract: The mrremind packages contains data preprocessing for the REMIND model.
authors:
- family-names: Baumstark
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: mrremind
Title: MadRat REMIND Input Data Package
Version: 0.186.1
Date: 2024-08-29
Version: 0.186.2
Date: 2024-09-02
Authors@R: c(
person("Lavinia", "Baumstark", , "[email protected]", role = c("aut", "cre")),
person("Renato", "Rodrigues", role = "aut"),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export(calcEDGAR7Fgases)
export(calcEEAGHGProjections)
export(calcEmber)
export(calcEmissionFactorsFeedstocks)
export(calcExpertGuess)
export(calcFloorspace)
export(calcGlobalEnergyMonitor)
export(calcHRE)
Expand Down
32 changes: 32 additions & 0 deletions R/calcExpertGuess.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#' Calculate expert guesses
#'
#' @author Falk Benke
#'
#' @param subtype must be 'tradeConstraints' (more to come)
#' @export
calcExpertGuess <- function(subtype) {
if (subtype != "tradeConstraints") {
stop("Invalid subtype. Supported subtypes: 'tradeConstraints'")
}

x <- readSource("ExpertGuess", subtype = subtype, convert = FALSE)

if (subtype == "tradeConstraints") {
unit <- "unitless"
description <- c(
"parameter by Nicolas Bauer (2024) for the region specific ",
"trade constraints, values different to 1 activate constraints ",
"and the value is used as effectiveness to varying degrees ",
"such as percentage numbers"
)
isocountries <- FALSE
}

return(list(
x = x,
weight = NULL,
unit = unit,
description = description,
isocountries = isocountries
))
}
2 changes: 2 additions & 0 deletions R/fullREMIND.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,6 @@ fullREMIND <- function() {
calcOutput("EffortSharingRefEmi", subtype = "EEA_GHG", round = 6, file = "p47_ESR_GHG_referenceEmissions.cs4r")
calcOutput("EffortSharingRefEmi", subtype = "REMIND_CO2", round = 6, file = "p47_ESR_CO2_referenceEmissions.cs4r")
calcOutput("ETSRefEmi", subtype = "EEA_GHG", round = 6, file = "p47_ETS_GHG_referenceEmissions.cs4r")
calcOutput("ExpertGuess", subtype = "tradeConstraints", aggregate = FALSE, file = "p24_trade_constraints.cs4r")

}
81 changes: 45 additions & 36 deletions R/readExpertGuess.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@
#' convergence from historic to target shares is to be applied.
#' - `cement_production_convergence_parameters`: convergence year and level
#' (relative to global average) to which per-capita cement demand converges
#' - Any of the others nobody cared to document.
#' - `ies`
#' - `prtp`
#' - `CCSbounds`
#' - `costsTradePeFinancial`
#' - `tradeContsraints`: parameter by Nicolas Bauer (2024) for the region
#' specific trade constraints, values different to 1 activate constraints
#' and the value is used as effectiveness to varying degrees such as percentage numbers
#' @return magpie object of the data
#' @author Lavinia Baumstark
#' @seealso \code{\link{readSource}}
#' @examples
#'
#' \dontrun{ a <- readSource(type="ExpertGuess",subtype="ies")
#' \dontrun{
#' a <- readSource(type = "ExpertGuess", subtype = "ies")
#' }
#'
#' @importFrom dplyr bind_rows filter pull select
Expand All @@ -26,9 +32,6 @@
#' @importFrom tidyr expand_grid

readExpertGuess <- function(subtype) {
path <- '~/PIK/swap/inputdata/sources/ExpertGuess/'
path <- './'

if (subtype == "ies") {
a <- read.csv("ies.csv", sep = ";")
} else if (subtype == "prtp") {
Expand All @@ -39,63 +42,69 @@ readExpertGuess <- function(subtype) {
a <- read.csv("co2prices-2023-06.csv", sep = ";")
} else if (subtype == "costsTradePeFinancial") {
a <- read.csv("pm_costsTradePeFinancial.csv",
sep = ";",
skip = 2)
sep = ";",
skip = 2
)
}

if (subtype == "ies" |
subtype == "prtp" |
subtype == "CCSbounds" | subtype == "co2prices") {
if (subtype == "ies" || subtype == "prtp" || subtype == "CCSbounds" || subtype == "co2prices") {
a$RegionCode <- NULL
a$Country <- NULL
a$Country <- NULL
out <- as.magpie(a)
} else if (subtype == "costsTradePeFinancial") {
out <- as.magpie(a,
spatial = 1,
temporal = 0,
datacol = 3)
spatial = 1,
temporal = 0,
datacol = 3
)
out <- collapseNames(out)
# getSets(out) <- c("region","year","type","pe")
}

if (subtype == "ies" | subtype == "prtp") {
if (subtype == "ies" || subtype == "prtp") {
getYears(out) <- "2005"
}

if ('Chinese_Steel_Production' == subtype) {
out <- read_csv(file = file.path(path, 'Chinese_Steel_Production.csv'),
comment = '#',
show_col_types = FALSE) %>%
if ("Chinese_Steel_Production" == subtype) {
out <- read_csv(
file = "Chinese_Steel_Production.csv",
comment = "#",
show_col_types = FALSE
) %>%
madrat_mule()
} else if ('industry_max_secondary_steel_share' == subtype) {
} else if ("industry_max_secondary_steel_share" == subtype) {
out <- read_csv(
file = file.path(path, 'industry_max_secondary_steel_share.csv'),
comment = '#',
file = "industry_max_secondary_steel_share.csv",
comment = "#",
show_col_types = FALSE
) %>%
madrat_mule()
} else if ('cement_production_convergence_parameters' == subtype) {
} else if ("cement_production_convergence_parameters" == subtype) {
out <- read_csv(
file = file.path(path, 'cement_production_convergence_parameters.csv'),
col_types = 'cdi',
comment = '#')
file = "cement_production_convergence_parameters.csv",
col_types = "cdi",
comment = "#"
)

out <- bind_rows(
out %>%
filter(!is.na(.data$region)),

out %>%
head(n = 1) %>%
filter(is.na(.data$region)) %>%
select(-'region') %>%
expand_grid(region = toolGetMapping(name = 'regionmapping_21_EU11.csv',
type = 'regional', where = "mappingfolder") %>%
pull('RegionCode') %>%
unique() %>%
sort() %>%
setdiff(out$region))
select(-"region") %>%
expand_grid(region = toolGetMapping(
name = "regionmapping_21_EU11.csv",
type = "regional", where = "mappingfolder"
) %>%
pull("RegionCode") %>%
unique() %>%
sort() %>%
setdiff(out$region))
) %>%
madrat_mule()
} else if (subtype == "tradeConstraints") {
a <- read.csv("tradeConstraints.csv", sep = ";")
out <- as.magpie(a)
}

return(out)
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 REMIND Input Data Package

R package **mrremind**, version **0.186.1**
R package **mrremind**, version **0.186.2**

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

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Lavinia Baumstark <lavinia@pik-po

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

Baumstark L, Rodrigues R, Levesque A, Oeser J, Bertram C, Mouratiadou I, Malik A, Schreyer F, Soergel B, Rottoli M, Mishra A, Dirnaichner A, Pehl M, Giannousakis A, Klein D, Strefler J, Feldhaus L, Brecha R, Rauner S, Dietrich J, Bi S, Benke F, Weigmann P, Richters O, Hasse R, Fuchs S, Mandaroux R, Koch J (2024). _mrremind: MadRat REMIND Input Data Package_. R package version 0.186.1, <https://github.com/pik-piam/mrremind>.
Baumstark L, Rodrigues R, Levesque A, Oeser J, Bertram C, Mouratiadou I, Malik A, Schreyer F, Soergel B, Rottoli M, Mishra A, Dirnaichner A, Pehl M, Giannousakis A, Klein D, Strefler J, Feldhaus L, Brecha R, Rauner S, Dietrich J, Bi S, Benke F, Weigmann P, Richters O, Hasse R, Fuchs S, Mandaroux R, Koch J (2024). _mrremind: MadRat REMIND Input Data Package_. R package version 0.186.2, <https://github.com/pik-piam/mrremind>.

A BibTeX entry for LaTeX users is

Expand All @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is
title = {mrremind: MadRat REMIND Input Data Package},
author = {Lavinia Baumstark and Renato Rodrigues and Antoine Levesque and Julian Oeser and Christoph Bertram and Ioanna Mouratiadou and Aman Malik and Felix Schreyer and Bjoern Soergel and Marianna Rottoli and Abhijeet Mishra and Alois Dirnaichner and Michaja Pehl and Anastasis Giannousakis and David Klein and Jessica Strefler and Lukas Feldhaus and Regina Brecha and Sebastian Rauner and Jan Philipp Dietrich and Stephen Bi and Falk Benke and Pascal Weigmann and Oliver Richters and Robin Hasse and Sophie Fuchs and Rahel Mandaroux and Johannes Koch},
year = {2024},
note = {R package version 0.186.1},
note = {R package version 0.186.2},
url = {https://github.com/pik-piam/mrremind},
}
```
12 changes: 9 additions & 3 deletions man/readExpertGuess.Rd

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

0 comments on commit d7a27a6

Please sign in to comment.