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

Implement explicit scenario choice across package. #29

Closed
wants to merge 2 commits into from
Closed
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: '3019950'
ValidationKey: '3222080'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
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: 'mrindustry: input data generation for the REMIND industry module'
version: 0.15.0
date-released: '2025-02-14'
version: 0.16.0
date-released: '2025-02-19'
abstract: The mrindustry packages contains data preprocessing for the REMIND model.
authors:
- family-names: Benke
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: mrindustry
Title: input data generation for the REMIND industry module
Version: 0.15.0
Date: 2025-02-14
Version: 0.16.0
Date: 2025-02-19
Authors@R: c(
person(given = "Falk", family = "Benke", email = "[email protected]",
role = c("aut", "cre")),
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
11 changes: 5 additions & 6 deletions R/calcCementShare.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#' 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
#' by GDP for aggregation and converge towards global values by 2100.
#' Non-OECD figures from IEA 2017
#' [Energy Technology Perspectives](https://www.zotero.org/groups/52011/rd3/items/X8XCUJ5U).
#' Shares are weighted by GDP for aggregation and converge towards global values by 2100.
#'
#' @md
#' @return A list with a [`magpie`][magclass::magclass] object `x`, `weight`,
Expand Down 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