Skip to content

Commit

Permalink
Implement explicit scenario choice across package.
Browse files Browse the repository at this point in the history
Introduce a scenario argument to calcFeDemandIndustry, calcIndustry_EEK and calcIndustry_Value_Added. The larger picture is the attempt to step away from a default set of scenarios. The choice of scenarios should be explicit. In the case of the input data pipeline, it is made in fullREMIND and then passed on to the different calcOutput functions. Hopefully this will help us control/drop/introduce new scenarios more easily in the future.
Add placeholder assumptions in inst data for the SSP2IndiaDEA scenarios.
Move SSP2_NAV_all duplication over from mrremind.
Remove naming argument in mrdrivers functions.
Delete convertUSGS, fixes #14.
General refactoring.
  • Loading branch information
johanneskoch94 committed Feb 19, 2025
1 parent 804e3d3 commit 103a849
Show file tree
Hide file tree
Showing 28 changed files with 631 additions and 825 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '3019950'
ValidationKey: '30380717133'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
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: 'mrindustry: input data generation for the REMIND industry module'
version: 0.15.0
version: 0.15.0.9001
date-released: '2025-02-14'
abstract: The mrindustry packages contains data preprocessing for the REMIND model.
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: mrindustry
Title: input data generation for the REMIND industry module
Version: 0.15.0
Version: 0.15.0.9001
Date: 2025-02-14
Authors@R: c(
person(given = "Falk", family = "Benke", email = "[email protected]",
Expand Down
6 changes: 0 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export(calcindustry_subsectors_specific)
export(convertADVANCE_WP2)
export(convertMueller)
export(convertUNIDO)
export(convertUSGS)
export(readADVANCE_WP2)
export(readIEA_WEIO_2014)
export(readMueller)
Expand All @@ -39,9 +38,6 @@ importFrom(GDPuc,convertGDP)
importFrom(assertr,assert)
importFrom(assertr,in_set)
importFrom(assertr,not_na)
importFrom(assertr,verify)
importFrom(assertr,within_bounds)
importFrom(dplyr,across)
importFrom(dplyr,anti_join)
importFrom(dplyr,arrange)
importFrom(dplyr,as_tibble)
Expand Down Expand Up @@ -93,7 +89,6 @@ importFrom(ggplot2,scale_shape_manual)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_minimal)
importFrom(madrat,toolCountryFill)
importFrom(madrat,toolGetMapping)
importFrom(magclass,"getNames<-")
importFrom(magclass,"getYears<-")
importFrom(magclass,add_dimension)
Expand Down Expand Up @@ -133,7 +128,6 @@ importFrom(readr,cols)
importFrom(readr,read_csv)
importFrom(readr,read_delim)
importFrom(readr,read_rds)
importFrom(readr,write_rds)
importFrom(readxl,excel_sheets)
importFrom(readxl,read_excel)
importFrom(rlang,"!!!")
Expand Down
15 changes: 8 additions & 7 deletions R/UNIDO.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
#' Read and convert data from United Nations Industrial Organisation.
#'
#' @md
#' @param subtype one of
#' - `INDSTAT2`: read INDSTAT 2 data
#' - `INDSTAT3`: read INDSTAT 3 data from [https://stat.unido.org/data/download?dataset=indstat&revision=3]
#' - `INDSTAT4`: read INDSTAT 4 data from [https://stat.unido.org/data/download?dataset=indstat&revision=4]
#' @param subtype A string. One of:
#' \itemize{
#' \item "INDSTAT2": read INDSTAT 2 data
#' \item "INDSTAT3": read INDSTAT 3 data from [here](https://stat.unido.org/data/download?dataset=indstat&revision=3)
#' \item "INDSTAT4": read INDSTAT 4 data from [here](https://stat.unido.org/data/download?dataset=indstat&revision=4)
#' INDSTAT 4 data quality has not been vetted and should not be used for
#' production.
#' }
#' @param exclude Exclude faulty data (`TRUE`, default) or not. Return a tibble
#' of country/subsector/year combinations for `exclude = 'return'`.
#' (Work-in-progress)
Expand Down Expand Up @@ -72,7 +74,6 @@
#'
#' @seealso [`readSource()`], [`calcOutput()`]
#'
#' @importFrom assertr assert not_na verify
#' @importFrom dplyr anti_join between bind_rows filter group_by inner_join
#' left_join mutate n select summarise ungroup
#' @importFrom GDPuc convertGDP
Expand All @@ -84,7 +85,7 @@
#' @importFrom rlang !!! .data is_empty syms
#' @importFrom tibble tibble tribble
#' @importFrom tidyr drop_na expand_grid unite

#'
#' @rdname UNIDO
#' @export
readUNIDO <- function(subtype = 'INDSTAT3')
Expand Down Expand Up @@ -260,7 +261,7 @@ convertUNIDO <- function(x, subtype = 'INDSTAT3', exclude = TRUE)
c('country' = 'un')
) %>%
select(-'country') %>%
assert(not_na, everything())
assertr::assert(assertr::not_na, everything())

}

Expand Down
5 changes: 2 additions & 3 deletions R/calcCementShare.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ calcCementShare <- function() {
select('iso3c', 'year', 'fety', 'value') %>%
as.magpie(spatial = 1, temporal = 2, data = 4),

weight = calcOutput('GDP', scenario = "SSP2", naming = "scenario", aggregate = FALSE) %>%
`[`(, unique(quitte::remind_timesteps$period), ) %>%
dimSums(dim = 3),
weight = calcOutput("GDP", scenario = "SSP2", aggregate = FALSE, years = unique(quitte::remind_timesteps$period)) %>%
collapseDim(dim = 3),

unit = 'share',
description = 'Share of Cement in NONMET FE use',
Expand Down
13 changes: 5 additions & 8 deletions R/calcChemicalFeedstocksShare.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
#'
#' @seealso [`calcOutput()`]
#'
#' @importFrom assertr assert not_na
#' @importFrom dplyr filter group_by inner_join mutate pull select summarise
#' @importFrom quitte character.data.frame interpolate_missing_periods_
#' @importFrom rlang .data sym
#' @importFrom tibble as_tibble
#' @importFrom tidyr complete everything nesting
#' @importFrom magclass collapseDim

#' @export
#'
calcChemicalFeedstocksShare <- function()
{
region_mapping <- toolGetMapping(
Expand Down Expand Up @@ -82,20 +81,18 @@ calcChemicalFeedstocksShare <- function()
value = 'share', expand.values = TRUE) %>%
full_join(region_mapping, 'region') %>%
select('iso3c', 'year', 'share') %>%
assert(not_na, everything())
assertr::assert(assertr::not_na, everything())

weight <- calcOutput('GDP', scenario = "SSP2", naming = "scenario", aggregate = FALSE) %>%
dimSums(dim = 3)
weight <- calcOutput("GDP", scenario = "SSP2", aggregate = FALSE) %>%
collapseDim(dim = 3)

return(
list(
x = x %>%
filter(.data$year %in% unique(quitte::remind_timesteps$period)) %>%
as.magpie(spatial = 1, temporal = 2, tidy = TRUE) %>%
collapseDim(dim = 3),

weight = weight[,unique(quitte::remind_timesteps$period),],

weight = weight[, unique(quitte::remind_timesteps$period), ],
unit = 'share',
description = 'Share of feedstocks in chemicals FE input',
min = 0, max = 1)
Expand Down
Loading

0 comments on commit 103a849

Please sign in to comment.