From c63f649987d190e9c588d9d1150a60802fe69ae2 Mon Sep 17 00:00:00 2001 From: Chen Gong <> Date: Mon, 11 Dec 2023 14:32:33 +0100 Subject: [PATCH] calcKayaDecomp.R --- .buildlibrary | 2 +- CITATION.cff | 4 +-- DESCRIPTION | 4 +-- NAMESPACE | 3 -- R/calcKayaDecomp.R | 66 ------------------------------------------- README.md | 6 ++-- man/calcKayaDecomp.Rd | 32 --------------------- 7 files changed, 8 insertions(+), 109 deletions(-) delete mode 100644 R/calcKayaDecomp.R delete mode 100644 man/calcKayaDecomp.Rd diff --git a/.buildlibrary b/.buildlibrary index 3c2b1f1c..2cbfed91 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '221622198' +ValidationKey: '221686904' 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 1cb22e02..bddca7b9 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.125.1 -date-released: '2023-12-07' +version: 1.125.2 +date-released: '2023-12-11' abstract: Contains the REMIND-specific routines for data and model output manipulation. authors: - family-names: Rodrigues diff --git a/DESCRIPTION b/DESCRIPTION index e6484e41..7f0db975 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: remind2 Title: The REMIND R package (2nd generation) -Version: 1.125.1 -Date: 2023-12-07 +Version: 1.125.2 +Date: 2023-12-11 Authors@R: c( person("Renato", "Rodrigues", , "renato.rodrigues@pik-potsdam.de", role = c("aut", "cre")), person("Lavinia", "Baumstark", role = "aut"), diff --git a/NAMESPACE b/NAMESPACE index 23e0a152..9b982164 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,5 @@ # Generated by roxygen2: do not edit by hand -export(calcKayaDecomp) export(calcNetTrade) export(calcNetTradeValue) export(calcPrice) @@ -226,7 +225,6 @@ importFrom(magclass,getNames) importFrom(magclass,getRegions) importFrom(magclass,getSets) importFrom(magclass,getYears) -importFrom(magclass,is.magpie) importFrom(magclass,lowpass) importFrom(magclass,magpie_expand) importFrom(magclass,mbind) @@ -235,7 +233,6 @@ importFrom(magclass,mselect) importFrom(magclass,ndata) importFrom(magclass,new.magpie) importFrom(magclass,read.report) -importFrom(magclass,setCells) importFrom(magclass,setItems) importFrom(magclass,setNames) importFrom(magclass,setYears) diff --git a/R/calcKayaDecomp.R b/R/calcKayaDecomp.R deleted file mode 100644 index c10908c1..00000000 --- a/R/calcKayaDecomp.R +++ /dev/null @@ -1,66 +0,0 @@ -#' Calculates Kaya decomposition -#' -#' Calculates Kaya decomposition normaized to a ref_year: CO2 FF&I/FE, FE/GDP, -#' GDP/Population, Population -#' -#' -#' @param gdx path to the gdx -#' @param mif path to a mif or data in the mif-format (if provided, the mif will be used instead of the gdx) -#' @param ref_year reference year for the normalization, NULL for no normalization -#' @return magpie object with the kaya decomposition -#' @author Lavinia Baumstark -#' @examples -#' -#' \dontrun{ -#' kaya <- calcKayaDecomp(gdx,mif=NULL,ref_year=2005) -#' } -#' -#' @export -#' @importFrom magclass is.magpie read.report getRegions setCells getYears getNames<- collapseNames mbind getSets getSets<- setYears -calcKayaDecomp <- function(gdx,mif=NULL,ref_year=2005){ - - if(is.null(mif)){ - # read data from gdx - emiCO2 <- readEmissions(gdx,emiengregi="co2",eminegregi="co2cement") - fe <- readFE(gdx) - gdp <- readGDPMER(gdx) - pop <- readPopulation(gdx) - } else{ - if(!is.magpie(mif)){ - # read data from mif - mif <- read.report(mif,as.list=FALSE) - } - emiCO2 <- mif[,,"Emi|CO2|Energy (Mt CO2/yr)"] - fe <- mif[,,"FE (EJ/yr)"] - gdp <- mif[,,"GDP|MER (billion US$2005/yr)"] - pop <- mif[,,"Population (million)"] - } - - # quick fix for the right regions - reg <- intersect(getRegions(gdp),getRegions(fe)) - - # calculate kaya decomposition - Emi_FE <- setCells(emiCO2[reg,intersect(getYears(fe),getYears(gdp)),],getRegions(gdp[reg,,]))/setCells(fe[reg,intersect(getYears(fe),getYears(gdp)),],getRegions(gdp[reg,,])) - getNames(Emi_FE) <- "CO2 FF&I/FE" - if(is.null(ref_year)) { getNames(Emi_FE) <- "CO2 FF&I [Mt CO2/yr]/FE [EJ/yr]" } - FE_GDP <- setCells(fe[reg,intersect(getYears(fe),getYears(gdp)),],getRegions(gdp[reg,,]))/setCells(gdp[reg,intersect(getYears(fe),getYears(gdp)),],getRegions(gdp[reg,,])) - getNames(FE_GDP) <- "FE/GDP" - if(is.null(ref_year)) { getNames(FE_GDP) <- "FE [EJ/yr]/GDP [billion US$2005/yr]" } - GDP_POP <- (gdp[reg,intersect(getYears(fe),getYears(gdp)),])/pop[reg,intersect(getYears(fe),getYears(gdp)),] - getNames(GDP_POP) <- "GDP/Population" - if(is.null(ref_year)) { getNames(GDP_POP) <- "GDP [billion US$2005/yr]/Population [million]" } - POP <- pop[reg,intersect(getYears(fe),getYears(gdp)),] - getNames(POP) <- "Population" - if(is.null(ref_year)) { getNames(POP) <- "Population [million]" } - - # combine to kaya - kaya <- collapseNames(mbind(Emi_FE,FE_GDP,GDP_POP,POP)) - getSets(kaya)[length(getSets(kaya))] <- "data1" - - if(!is.null(ref_year)) { - # nomalize to reference year - kaya <- kaya / setYears(kaya[,ref_year,],NULL) - } - - return(kaya) -} diff --git a/README.md b/README.md index f9bfc259..63bdb4b1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # The REMIND R package (2nd generation) -R package **remind2**, version **1.125.1** +R package **remind2**, version **1.125.2** [![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, 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 (2023). _remind2: The REMIND R package (2nd generation)_. R package version 1.125.2, . 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 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 = {2023}, - note = {R package version 1.125.1}, + note = {R package version 1.125.2}, url = {https://github.com/pik-piam/remind2}, } ``` diff --git a/man/calcKayaDecomp.Rd b/man/calcKayaDecomp.Rd deleted file mode 100644 index 223a0ead..00000000 --- a/man/calcKayaDecomp.Rd +++ /dev/null @@ -1,32 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/calcKayaDecomp.R -\name{calcKayaDecomp} -\alias{calcKayaDecomp} -\title{Calculates Kaya decomposition} -\usage{ -calcKayaDecomp(gdx, mif = NULL, ref_year = 2005) -} -\arguments{ -\item{gdx}{path to the gdx} - -\item{mif}{path to a mif or data in the mif-format (if provided, the mif will be used instead of the gdx)} - -\item{ref_year}{reference year for the normalization, NULL for no normalization} -} -\value{ -magpie object with the kaya decomposition -} -\description{ -Calculates Kaya decomposition normaized to a ref_year: CO2 FF&I/FE, FE/GDP, -GDP/Population, Population -} -\examples{ - - \dontrun{ - kaya <- calcKayaDecomp(gdx,mif=NULL,ref_year=2005) - } - -} -\author{ -Lavinia Baumstark -}