Skip to content

Commit

Permalink
Merge pull request pik-piam#287 from 0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q…
Browse files Browse the repository at this point in the history
…/fix/crappy_magclass_heuristic

avoid as.magpie() heuristic
  • Loading branch information
0UmfHxcvx5J7JoaOhFSs5mncnisTJJ6q authored Jun 20, 2022
2 parents 14cb17f + 4a04781 commit 7aed6a0
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 44 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '25908376'
ValidationKey: '25927539'
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 .zenodo.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"title": "mrremind: MadRat REMIND Input Data Package",
"version": "0.135.2",
"version": "0.135.3",
"description": "<p>The mrremind packages contains data preprocessing for the REMIND model.<\/p>",
"creators": [
{
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: mrremind
Type: Package
Title: MadRat REMIND Input Data Package
Version: 0.135.2
Version: 0.135.3
Date: 2022-06-20
Authors@R: c(person("Lavinia", "Baumstark", email = "[email protected]", role = c("aut","cre")),
person("Renato", "Rodrigues", role = "aut"),
Expand Down
57 changes: 29 additions & 28 deletions R/calcCementShare.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' Calculate Cement Share in NONMET FE Use
#'
#'
#' Estimated shares of cement in `NONMET` final energy use based on OECD and
#' Non-OECD figures from IEA 2017 [Energy Technology Perspectives](
#' https://www.zotero.org/groups/52011/rd3/items/X8XCUJ5U). Shares are weighted
Expand All @@ -8,11 +8,11 @@
#' @md
#' @return A list with a [`magpie`][magclass::magclass] object `x`, `weight`,
#' `unit`, `description`, `min`, and `max`.
#'
#'
#' @author Michaja Pehl
#'
#'
#' @seealso [`calcOutput()`]
#'
#'
#' @importFrom dplyr bind_rows left_join select filter mutate pull
#' @importFrom madrat toolGetMapping calcOutput
#' @importFrom magclass as.magpie dimSums
Expand All @@ -30,42 +30,43 @@ calcCementShare <- function() {
'feli_cement', 0.73, 0.62, 0.66,
'fega_cement', 0.03, 0.75, 0.40,
'feh2_cement', 0.03, 0.75, 0.40,
'feel_cement', 0.34, 0.68, 0.59) %>%
'feel_cement', 0.34, 0.68, 0.59) %>%
pivot_longer(-'fety', names_to = 'region')

list(x = bind_rows(
left_join(
toolGetMapping('regionmappingOECD.csv', 'regional') %>%
as_tibble() %>%
toolGetMapping('regionmappingOECD.csv', 'regional') %>%
as_tibble() %>%
select(iso3c = 'CountryCode', region = 'RegionCode'),
cement_NONMET_share %>%

cement_NONMET_share %>%
filter('World' != !!sym('region')),

'region'
) %>%
select(-'region') %>%
) %>%
select(-'region') %>%
mutate(year = 2015),
cement_NONMET_share %>%
filter('World' == !!sym('region')) %>%
select(-'region') %>%
mutate(iso3c = NA_character_) %>%

cement_NONMET_share %>%
filter('World' == !!sym('region')) %>%
select(-'region') %>%
mutate(iso3c = NA_character_) %>%
complete(nesting(!!sym('fety'), !!sym('value')),
iso3c = toolGetMapping('regionmappingOECD.csv', 'regional') %>%
pull('CountryCode')) %>%
filter(!is.na(!!sym('iso3c'))) %>%
iso3c = toolGetMapping('regionmappingOECD.csv', 'regional') %>%
pull('CountryCode')) %>%
filter(!is.na(!!sym('iso3c'))) %>%
mutate(year = 2100)
) %>%
) %>%
interpolate_missing_periods(
year = unique(quitte::remind_timesteps$period),
expand.values = TRUE) %>%
as.magpie(),

weight = calcOutput('GDP', aggregate = FALSE) %>%
`[`(,unique(quitte::remind_timesteps$period),'gdp_SSP2') %>%
expand.values = TRUE) %>%
select('iso3c', 'year', 'fety', 'value') %>%
as.magpie(spatial = 1, temporal = 2, data = 4),

weight = calcOutput('GDP', aggregate = FALSE) %>%
`[`(,unique(quitte::remind_timesteps$period),'gdp_SSP2') %>%
dimSums(dim = 3),

unit = 'share',
description = 'Share of Cement in NONMET FE use',
min = 0, max = 1)
Expand Down
21 changes: 11 additions & 10 deletions R/calcEnergyEffPaths.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
#' Efficiency paths for CES variables beyond calibration CES nest
#'
#'
#' Returns the Efficiency paths for Macro variables
#'
#'
#' @author Antoine Levesque
#' @importFrom quitte removeColNa interpolate_missing_periods_ inline.data.frame getVars

calcEnergyEffPaths <- function() {
#----- Functions ------------------

#----- READ-IN DATA ------------------
fe = calcOutput("FEdemand",subtype = "FE_for_Eff",aggregate = F)
ue = calcOutput("FEdemand",subtype = "UE_for_Eff",aggregate = F)
#----- PARAMETERS ------------------
t0 = 2005

#----- PROCESS DATA ------------------

ue_names = getNames(ue)
fe = fe[,,ue_names]

output = ue/fe

# Fill NAs and Os, and replace with 50% efficiency for fully empty entries
output = output %>% as.quitte() %>%
mutate_(value = ~ifelse((is.na(value) | value == 0),NA,value)) %>%
Expand All @@ -29,12 +29,13 @@ calcEnergyEffPaths <- function() {
select_(~-tmp) %>% ungroup() %>%
interpolate_missing_periods_(list(period = getYears(output,T)),expand.values = T) %>%
removeColNa() %>%
as.magpie()

select('scenario', 'region', 'period', 'item', 'value') %>%
as.magpie(spatial = 2, temporal = 3, data = 5)


weight_fe = fe
weight_fe[weight_fe == 0 ] <- 1e-6

return(list(x=output,weight=weight_fe,
unit = "energy efficiency paths",
description = "Efficiency pathways for CES variables outside the calibration CES nest"))
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.135.2**
R package **mrremind**, version **0.135.3**

[![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/ui#builds)

Expand Down Expand Up @@ -38,7 +38,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 (2022). _mrremind: MadRat REMIND Input Data Package_. R package version 0.135.2, <URL: 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 (2022). _mrremind: MadRat REMIND Input Data Package_. R package version 0.135.3, <URL: https://github.com/pik-piam/mrremind>.

A BibTeX entry for LaTeX users is

Expand All @@ -47,7 +47,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},
year = {2022},
note = {R package version 0.135.2},
note = {R package version 0.135.3},
url = {https://github.com/pik-piam/mrremind},
}
```

0 comments on commit 7aed6a0

Please sign in to comment.