From e815803b134996667a2db766e0e65f0732e056db Mon Sep 17 00:00:00 2001 From: Falk Benke Date: Fri, 8 Mar 2024 15:33:01 +0100 Subject: [PATCH] increment version --- .buildlibrary | 2 +- CITATION.cff | 4 +- DESCRIPTION | 4 +- R/reportEmi.R | 3 +- R/validateEfficiency.R | 135 +++++++++++++++++++++++++++++++++++++++++ README.md | 6 +- man/remind2-package.Rd | 1 - 7 files changed, 145 insertions(+), 10 deletions(-) create mode 100644 R/validateEfficiency.R diff --git a/.buildlibrary b/.buildlibrary index f422610e..23cf851a 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '224749174' +ValidationKey: '2248124229790' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/CITATION.cff b/CITATION.cff index e1628d77..93e71a73 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -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: 'remind2: The REMIND R package (2nd generation)' -version: 1.135.9 -date-released: '2024-03-04' +version: 1.135.9.9001 +date-released: '2024-03-08' abstract: Contains the REMIND-specific routines for data and model output manipulation. authors: - family-names: Rodrigues diff --git a/DESCRIPTION b/DESCRIPTION index ac4dea6a..9407b8fa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: remind2 Title: The REMIND R package (2nd generation) -Version: 1.135.9 -Date: 2024-03-04 +Version: 1.135.9.9001 +Date: 2024-03-08 Authors@R: c( person("Renato", "Rodrigues", , "renato.rodrigues@pik-potsdam.de", role = c("aut", "cre")), person("Lavinia", "Baumstark", role = "aut"), diff --git a/R/reportEmi.R b/R/reportEmi.R index 1ca92fbb..f7bf760c 100644 --- a/R/reportEmi.R +++ b/R/reportEmi.R @@ -320,7 +320,8 @@ reportEmi <- function(gdx, output = NULL, regionSubsetList = NULL, t = c(seq(200 } # Read-in plastic-related variables - v37_plasticsCarbon <- readGDX(gdx, "v37_plasticsCarbon", field = "l", restore_zeros = FALSE, react = "silent")[,t,] + v37_plasticsCarbon <- readGDX(gdx, "v37_plasticsCarbon", field = "l", temporal = 1, spatial = 2, + restore_zeros = FALSE, react = "silent")[,t,] if (length(v37_plasticsCarbon) == 0) { v37_plasticsCarbon <- NULL } diff --git a/R/validateEfficiency.R b/R/validateEfficiency.R new file mode 100644 index 00000000..3d19ae4b --- /dev/null +++ b/R/validateEfficiency.R @@ -0,0 +1,135 @@ +# | (C) 2006-2023 Potsdam Institute for Climate Impact Research (PIK) +# | authors, and contributors see CITATION.cff file. This file is part +# | of REMIND and licensed under AGPL-3.0-or-later. Under Section 7 of +# | AGPL-3.0, you are granted additional permissions described in the +# | REMIND License Exception, version 1.0 (see LICENSE file). +# | Contact: remind@pik-potsdam.de + +library(magclass) +library(remind2) +library(lucode2) +library(gms) +library(methods) +library(edgeTransport) +library(quitte) +############################# BASIC CONFIGURATION ############################# +gdx_name <- "fulldata.gdx" # name of the gdx +gdx_ref_name <- "input_ref.gdx" # name of the ref for < cm_startyear +gdx_refpolicycost_name <- "input_refpolicycost.gdx" # name of the reference gdx (for policy cost calculation) + + +if(!exists("source_include")) { + # Define arguments that can be read from command line + outputdir <- "." + readArgs("outputdir", "gdx_name", "gdx_ref_name", "gdx_refpolicycost_name") +} + +gdx <- file.path(outputdir, gdx_name) +gdx_ref <- file.path(outputdir, gdx_ref_name) +gdx_refpolicycost <- file.path(outputdir, gdx_refpolicycost_name) +if (! file.exists(gdx_ref)) gdx_ref <- NULL +if (! file.exists(gdx_refpolicycost)) gdx_refpolicycost <- NULL +scenario <- getScenNames(outputdir) +############################################################################### +# paths of the reporting files +remind_reporting_file <- file.path(outputdir,paste0("REMIND_generic_", scenario,".mif")) +magicc_reporting_file <- file.path(outputdir,paste0("REMIND_climate_", scenario, ".mif")) +LCOE_reporting_file <- file.path(outputdir,paste0("REMIND_LCOE_", scenario, ".csv")) + +remind_policy_reporting_file <- file.path(outputdir,paste0("REMIND_generic_",scenario,"_adjustedPolicyCosts.mif")) +remind_policy_reporting_file <- remind_policy_reporting_file[file.exists(remind_policy_reporting_file)] +if (length(remind_policy_reporting_file) > 0) { + unlink(remind_policy_reporting_file) + message("\n", paste(basename(remind_policy_reporting_file), collapse = ", "), " deleted.") + message(paste(basename(remind_reporting_file), collapse = ", "), " will contain policy costs based on input_refpolicycost.gdx.") +} + +configfile <- file.path(outputdir, "config.Rdata") +envir <- new.env() +load(configfile, envir = envir) + +# produce REMIND reporting *.mif based on gdx information +message("\n### start generation of mif files at ", Sys.time()) +convGDX2MIF(gdx, gdx_refpolicycost = gdx_refpolicycost, file = remind_reporting_file, + scenario = scenario, gdx_ref = gdx_ref) + +# MAGICC code not working with REMIND-EU +# generate MAGICC reporting and append to REMIND reporting +if (0 == nchar(Sys.getenv('MAGICC_BINARY'))) { + warning('Can\'t find magicc executable under environment variable MAGICC_BINARY') +} else { + message("Generate ", basename(magicc_reporting_file)) + system(paste("cd ",outputdir ,"/magicc; ", + "pwd;", + "sed -f modify_MAGCFG_USER_CFG.sed -i MAGCFG_USER.CFG; ", + Sys.getenv('MAGICC_BINARY'), '; ', + "awk -f MAGICC_reporting.awk -v c_expname=\"", scenario, "\"", + " < climate_reporting_template.txt ", + " > ","../../../", magicc_reporting_file,"; ", + "sed -i 's/;glob;/;World;/g' ","../../../", magicc_reporting_file, "; ", + "cat ", "../../../",magicc_reporting_file, " >> ", "../../../",remind_reporting_file, "; ", + sep = "")) +} + + +## generate EDGE-T reporting if it is needed +## the reporting is appended to REMIND_generic_.MIF +## REMIND_generic__withoutPlus.MIF is replaced. + +edgetOutputDir <- file.path(outputdir, "EDGE-T") +if(file.exists(edgetOutputDir)) { + if (! file.exists(file.path(edgetOutputDir, "demandF_plot_pkm.RDS"))) { + message("EDGE-T reporting files are missing, probably because the run was killed.") + message("Rerunning toolIterativeEDGETransport(reporting = TRUE).") + savewd <- getwd() + setwd(outputdir) + edgeTransport::toolIterativeEDGETransport(reporting = TRUE) + setwd(savewd) + } + message("start generation of EDGE-T reporting") + EDGET_output <- toolReportEDGET(edgetOutputDir, + extendedReporting = FALSE, + scenario_title = scenario, model_name = "REMIND", + gdx = file.path(outputdir, "fulldata.gdx")) + + write.mif(EDGET_output, remind_reporting_file, append = TRUE) + deletePlus(remind_reporting_file, writemif = TRUE) + + message("end generation of EDGE-T reporting") +} + +magpie_reporting_file <- envir$cfg$pathToMagpieReport +if (! is.null(magpie_reporting_file) && file.exists(magpie_reporting_file)) { + message("add MAgPIE reporting from ", magpie_reporting_file) + tmp_rem <- quitte::as.quitte(remind_reporting_file) + tmp_mag <- dplyr::filter(quitte::as.quitte(magpie_reporting_file), .data$period %in% unique(tmp_rem$period)) + # remove population from magpie reporting to avoid duplication (units "million" vs. "million people") + sharedvariables <- intersect(tmp_mag$variable, tmp_rem$variable) + if (length(sharedvariables) > 0) { + message("The following variables will be dropped from MAgPIE reporting because they are in REMIND reporting: ", paste(sharedvariables, collapse = ", ")) + tmp_mag <- dplyr::filter(tmp_mag, ! .data$variable %in% sharedvariables) + } + # harmonize scenario name from -mag-xx to -rem-xx + tmp_mag$scenario <- paste0(scenario) + tmp_rem_mag <- rbind(tmp_rem, tmp_mag) + quitte::write.mif(tmp_rem_mag, path = remind_reporting_file) + deletePlus(remind_reporting_file, writemif = TRUE) +} + +message("### end generation of mif files at ", Sys.time()) + +## produce REMIND LCOE reporting *.csv based on gdx information +message("### start generation of LCOE reporting at ", Sys.time()) +tmp <- try(convGDX2CSV_LCOE(gdx,file=LCOE_reporting_file,scen=scenario)) # execute convGDX2MIF_LCOE +message("### end generation of LCOE reporting at ", Sys.time()) + +## generate DIETER reporting if it is needed +## the reporting is appended to REMIND_generic_.MIF in "DIETER" Sub Directory +DIETERGDX <- "report_DIETER.gdx" +if(file.exists(file.path(outputdir, DIETERGDX))){ + message("start generation of DIETER reporting at ", Sys.time()) + remind2::reportDIETER(DIETERGDX,outputdir) + message("end generation of DIETER reporting at ", Sys.time()) +} + +message("### reporting finished.") diff --git a/README.md b/README.md index 0d1356a4..274d1333 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # The REMIND R package (2nd generation) -R package **remind2**, version **1.135.9** +R package **remind2**, version **1.135.9.9001** [![CRAN status](https://www.r-pkg.org/badges/version/remind2)](https://cran.r-project.org/package=remind2) [![R build status](https://github.com/pik-piam/remind2/workflows/check/badge.svg)](https://github.com/pik-piam/remind2/actions) [![codecov](https://codecov.io/gh/pik-piam/remind2/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/remind2) [![r-universe](https://pik-piam.r-universe.dev/badges/remind2)](https://pik-piam.r-universe.dev/builds) @@ -49,7 +49,7 @@ In case of questions / problems please contact Renato Rodrigues . +Rodrigues R, Baumstark L, Benke F, Dietrich J, Dirnaichner A, Duerrwaechter J, Führlich P, Giannousakis A, Hasse R, Hilaire J, Klein D, Koch J, Kowalczyk K, Levesque A, Malik A, Merfort A, Merfort L, Morena-Leiva S, Pehl M, Pietzcker R, Rauner S, Richters O, Rottoli M, Schötz C, Schreyer F, Siala K, Sörgel B, Spahr M, Strefler J, Verpoort P, Weigmann P (2024). _remind2: The REMIND R package (2nd generation)_. R package version 1.135.9.9001, . A BibTeX entry for LaTeX users is @@ -58,7 +58,7 @@ A BibTeX entry for LaTeX users is title = {remind2: The REMIND R package (2nd generation)}, author = {Renato Rodrigues and Lavinia Baumstark and Falk Benke and Jan Philipp Dietrich and Alois Dirnaichner and Jakob Duerrwaechter and Pascal Führlich and Anastasis Giannousakis and Robin Hasse and Jérome Hilaire and David Klein and Johannes Koch and Katarzyna Kowalczyk and Antoine Levesque and Aman Malik and Anne Merfort and Leon Merfort and Simón Morena-Leiva and Michaja Pehl and Robert Pietzcker and Sebastian Rauner and Oliver Richters and Marianna Rottoli and Christof Schötz and Felix Schreyer and Kais Siala and Björn Sörgel and Mike Spahr and Jessica Strefler and Philipp Verpoort and Pascal Weigmann}, year = {2024}, - note = {R package version 1.135.9}, + note = {R package version 1.135.9.9001}, url = {https://github.com/pik-piam/remind2}, } ``` diff --git a/man/remind2-package.Rd b/man/remind2-package.Rd index 7b64919d..5169a479 100644 --- a/man/remind2-package.Rd +++ b/man/remind2-package.Rd @@ -3,7 +3,6 @@ \docType{package} \name{remind2-package} \alias{remind2-package} -\alias{_PACKAGE} \alias{remind2} \title{The REMIND R package (2nd generation)} \description{