diff --git a/.buildlibrary b/.buildlibrary index 7dbed210..c4d7626c 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '232464816' +ValidationKey: '232508150' AutocreateReadme: yes AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' diff --git a/CITATION.cff b/CITATION.cff index 1842cf4b..3c23657a 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: 'magpie4: MAgPIE outputs R package for MAgPIE version 4.x' -version: 1.189.2 -date-released: '2023-07-10' +version: 1.189.3 +date-released: '2023-07-12' abstract: Common output routines for extracting results from the MAgPIE framework (versions 4.x). authors: diff --git a/DESCRIPTION b/DESCRIPTION index 4efb1af3..f5b1d673 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: magpie4 Title: MAgPIE outputs R package for MAgPIE version 4.x -Version: 1.189.2 -Date: 2023-07-10 +Version: 1.189.3 +Date: 2023-07-12 Authors@R: c( person("Benjamin Leon", "Bodirsky", , "bodirsky@pik-potsdam.de", role = c("aut", "cre")), person("Florian", "Humpenoeder", , "humpenoeder@pik-potsdam.de", role = "aut"), diff --git a/R/processing.R b/R/processing.R index 2885a802..a74e0df4 100644 --- a/R/processing.R +++ b/R/processing.R @@ -1,53 +1,47 @@ #' @title processing -#' @description Calculates MAgPIE disaggregated processing out of a gdx file -#' +#' @description Calculates MAgPIE disaggregated processing out of a gdx file +#' #' @export -#' +#' #' @param gdx GDX file -#' @param file a file name the output should be written to using write.magpie #' @param level Level of regional aggregation ("reg", "glo", "regglo") -#' @param products Selection of products (either by naming products, e.g. "tece", or naming a set,e.g."kcr") #' @param product_aggr aggregate over products or not (boolean) #' @param attributes dry matter: Mt ("dm"), gross energy: PJ ("ge"), reactive nitrogen: Mt ("nr"), phosphor: Mt ("p"), potash: Mt ("k"), wet matter: Mt ("wm"). Can also be a vector. -#' @param type Demand type(s): "Food", "Feed", "Processing", "Material", "Bioenergy", "Seed", "Supply chain loss", "Domestic Balanceflow"; NULL returns all types +#' @param type Demand type(s): "Food", "Feed", "Processing", "Material", "Bioenergy", "Seed", "Supply chain loss", "Domestic Balanceflow"; NULL returns all types #' @param indicator process or secondary product output #' @details Demand definitions are equivalent to FAO CBS categories #' @return processing as MAgPIE object (Unit depends on attributes) #' @author David Chen, Benjamin Leon Bodirsky #' @importFrom magclass add_dimension dimOrder #' @examples -#' +#' #' \dontrun{ #' x <- processing(gdx = gdx, level="regglo", products="kcr", indicator="primary_to_process") #' } #' -processing<-function(gdx,file=NULL,level="reg",products=readGDX(gdx,"kall"),product_aggr=FALSE,attributes="dm",type=NULL, indicator = "secondary_from_primary"){ - - - if (!all(products%in%readGDX(gdx,"kall"))){ - products<-readGDX(gdx,"kall") -} +processing<-function(gdx, level="reg", product_aggr = FALSE, attributes="dm", + type=NULL, indicator = "secondary_from_primary"){ + +if(indicator=="primary_to_process"){ -if(indicator=="primary_to_process"){ - #primary into process -processdemand<-readGDX(gdx= gdx, "ov20_dem_processing", select = list(type="level")) +processdemand <- readGDX(gdx = gdx, "ov20_dem_processing", select = list(type="level")) -out<- dimOrder(processdemand, c(1,2)) -glo <- setItems(dimSums(out, dim=1),dim=1,"GLO") +out<- dimOrder(processdemand, c(1, 2)) +glo <- setItems(dimSums(out, dim=1), dim=1, "GLO") out <- mbind(out, glo) } #primary to secondary else if(indicator == "secondary_from_primary"){ processdemand<-readGDX(gdx= gdx, "ov20_dem_processing", select = list(type="level")) - -conv_factors <- readGDX(gdx = gdx, "f20_processing_conversion_factors") -years = getYears(processdemand) -conv_factors1<- conv_factors[,years,] +convFactors <- readGDX(gdx = gdx, "f20_processing_conversion_factors") + +years = getYears(processdemand) +convFactors <- convFactors[,years,] -out<- processdemand * dimSums(conv_factors1, dim=3.1) +out<- processdemand * dimSums(convFactors, dim = 3.1) out<- dimSums(out, dim = 3.1) glo <- setItems(dimSums(out, dim=1),dim=1,"GLO") out <- mbind(out, glo) diff --git a/README.md b/README.md index d41b2ca2..312b7e8b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MAgPIE outputs R package for MAgPIE version 4.x -R package **magpie4**, version **1.189.2** +R package **magpie4**, version **1.189.3** [![CRAN status](https://www.r-pkg.org/badges/version/magpie4)](https://cran.r-project.org/package=magpie4) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.1158582.svg)](https://doi.org/10.5281/zenodo.1158582) [![R build status](https://github.com/pik-piam/magpie4/workflows/check/badge.svg)](https://github.com/pik-piam/magpie4/actions) [![codecov](https://codecov.io/gh/pik-piam/magpie4/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/magpie4) [![r-universe](https://pik-piam.r-universe.dev/badges/magpie4)](https://pik-piam.r-universe.dev/builds) @@ -39,7 +39,7 @@ In case of questions / problems please contact Benjamin Leon Bodirsky . +Bodirsky B, Humpenoeder F, Dietrich J, Stevanovic M, Weindl I, Karstens K, Wang X, Mishra A, Beier F, Breier J, Yalew A, Chen D, Biewald A, Wirth S, von Jeetze P, Leip D, Crawford M, Alves M (2023). _magpie4: MAgPIE outputs R package for MAgPIE version 4.x_. doi: 10.5281/zenodo.1158582 (URL: https://doi.org/10.5281/zenodo.1158582), R package version 1.189.3, . A BibTeX entry for LaTeX users is @@ -48,7 +48,7 @@ A BibTeX entry for LaTeX users is title = {magpie4: MAgPIE outputs R package for MAgPIE version 4.x}, author = {Benjamin Leon Bodirsky and Florian Humpenoeder and Jan Philipp Dietrich and Miodrag Stevanovic and Isabelle Weindl and Kristine Karstens and Xiaoxi Wang and Abhijeet Mishra and Felicitas Beier and Jannes Breier and Amsalu Woldie Yalew and David Chen and Anne Biewald and Stephen Wirth and Patrick {von Jeetze} and Debbora Leip and Michael Crawford and Marcos Alves}, year = {2023}, - note = {R package version 1.189.2}, + note = {R package version 1.189.3}, doi = {10.5281/zenodo.1158582}, url = {https://github.com/pik-piam/magpie4}, } diff --git a/inst/extdata/regionmappingWBIncomeGroups.csv b/inst/extdata/regionmappingWBIncomeGroups.csv new file mode 100644 index 00000000..994af76e --- /dev/null +++ b/inst/extdata/regionmappingWBIncomeGroups.csv @@ -0,0 +1,228 @@ +iso3c,2000,2005,2010,2015,2020 +AFG,L,L,L,L,L +ALB,LM,LM,UM,UM,UM +DZA,LM,LM,UM,UM,LM +ASM,UM,UM,UM,UM,UM +AND,H,H,H,H,H +AGO,L,LM,LM,UM,LM +ATG,UM,H,UM,H,H +ARG,UM,UM,UM,UM,UM +ARM,L,LM,LM,LM,UM +ABW,H,H,H,H,H +AUS,H,H,H,H,H +AUT,H,H,H,H,H +AZE,L,LM,UM,UM,UM +BHS,H,H,H,H,H +BHR,UM,H,H,H,H +BGD,L,L,L,LM,LM +BRB,H,UM,H,H,H +BLR,LM,LM,UM,UM,UM +BEL,H,H,H,H,H +BLZ,LM,UM,LM,UM,LM +BEN,L,L,L,L,LM +BMU,H,H,H,H,H +BTN,L,L,LM,LM,LM +BOL,LM,LM,LM,LM,LM +BIH,LM,LM,UM,UM,UM +BWA,UM,UM,UM,UM,UM +BRA,UM,LM,UM,UM,UM +VGB,..,..,..,H,H +BRN,H,H,H,H,H +BGR,LM,LM,UM,UM,UM +BFA,L,L,L,L,L +BDI,L,L,L,L,L +CPV,LM,LM,LM,LM,LM +KHM,L,L,L,LM,LM +CMR,L,LM,LM,LM,LM +CAN,H,H,H,H,H +CYM,H,H,H,H,H +CAF,L,L,L,L,L +TCD,L,L,L,L,L +CHI,H,H,H,H,H +CHL,UM,UM,UM,H,H +CHN,LM,LM,UM,UM,UM +COL,LM,LM,UM,UM,UM +COM,L,L,L,L,LM +COD,L,L,L,L,L +COG,L,LM,LM,LM,LM +CRI,UM,UM,UM,UM,UM +CIV,L,L,LM,LM,LM +HRV,UM,UM,H,H,H +CUB,LM,LM,UM,UM,UM +CUW,..,..,H,H,H +CYP,H,H,H,H,H +CZE,UM,UM,H,H,H +DNK,H,H,H,H,H +DJI,LM,LM,L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,LM,LM,LM,LM,LM +KNA,UM,UM,UM,H,H +LCA,UM,UM,UM,UM,UM +MAF,..,..,H,H,H +VCT,LM,UM,UM,UM,UM +SDN,L,L,LM,LM,L +SUR,LM,LM,UM,UM,UM +SWE,H,H,H,H,H +CHE,H,H,H,H,H +SYR,LM,LM,LM,LM,L +TWN,H,H,H,H,H +TJK,L,L,L,LM,LM +TZA,L,L,L,L,LM +THA,LM,LM,UM,UM,UM +TLS,..,L,LM,LM,LM +TGO,L,L,L,L,L +TON,LM,LM,LM,LM,UM +TTO,UM,UM,H,H,H +TUN,LM,LM,UM,LM,LM +TUR,UM,UM,UM,UM,UM +TKM,LM,LM,LM,UM,UM +TCA,..,..,H,H,H +TUV,..,..,LM,UM,UM +UGA,L,L,L,L,L +UKR,L,LM,LM,LM,LM +ARE,H,H,H,H,H +GBR,H,H,H,H,H +USA,H,H,H,H,H +URY,UM,UM,UM,H,H +UZB,L,L,LM,LM,LM +VUT,LM,LM,LM,LM,LM +VEN,UM,UM,UM,UM, +VNM,L,L,LM,LM,LM +VIR,H,H,H,H,H +PSE,LM,LM,LM,LM,LM +YEM,L,L,LM,LM,L +ZMB,L,L,LM,LM,LM +ZWE,L,L,L,L,LM +,,,,, +,,,,, +,,,,, +CSK,,,,, +MYT,UM,UM,UM,, +ANT,H,H,,, +YUG,LM,LM,,, +SUN,,,,, +YUGf,,,,, diff --git a/inst/extdata/variablemappingICP.csv b/inst/extdata/variablemappingICP.csv new file mode 100644 index 00000000..dff9b0f5 --- /dev/null +++ b/inst/extdata/variablemappingICP.csv @@ -0,0 +1,30 @@ +BHName,k +Milk products,livst_milk +Eggs,livst_egg +Fruit,others +Bread and cereals,tece +Bread and cereals,maiz +Bread and cereals,trce +Bread and cereals,rice_pro +Bread and cereals,brans +Meat,livst_rum +Meat,livst_pig +Meat,livst_chick +Meat,fish +Processed,oils +Processed,oilpalm +Processed,sugar +Processed,molasses +Processed,oilcakes +Processed,alcohol +Processed,scp +Vegetables,soybean +Vegetables,rapeseed +Vegetables,groundnut +Vegetables,sunflower +Vegetables,potato +Vegetables,puls_pro +Vegetables,cassav_sp +Vegetables,sugr_cane +Vegetables,sugr_beet +Vegetables,Vegetables diff --git a/man/processing.Rd b/man/processing.Rd index f01d2af6..b2137bdd 100644 --- a/man/processing.Rd +++ b/man/processing.Rd @@ -6,9 +6,7 @@ \usage{ processing( gdx, - file = NULL, level = "reg", - products = readGDX(gdx, "kall"), product_aggr = FALSE, attributes = "dm", type = NULL, @@ -18,12 +16,8 @@ processing( \arguments{ \item{gdx}{GDX file} -\item{file}{a file name the output should be written to using write.magpie} - \item{level}{Level of regional aggregation ("reg", "glo", "regglo")} -\item{products}{Selection of products (either by naming products, e.g. "tece", or naming a set,e.g."kcr")} - \item{product_aggr}{aggregate over products or not (boolean)} \item{attributes}{dry matter: Mt ("dm"), gross energy: PJ ("ge"), reactive nitrogen: Mt ("nr"), phosphor: Mt ("p"), potash: Mt ("k"), wet matter: Mt ("wm"). Can also be a vector.}