Skip to content

Commit

Permalink
include WB Income groups region mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
David Chen committed Jul 12, 2023
1 parent 1d756e2 commit 6340548
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '232464816'
ValidationKey: '232508150'
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: '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:
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: 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", , "[email protected]", role = c("aut", "cre")),
person("Florian", "Humpenoeder", , "[email protected]", role = "aut"),
Expand Down
40 changes: 17 additions & 23 deletions R/processing.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -39,7 +39,7 @@ In case of questions / problems please contact Benjamin Leon Bodirsky <bodirsky@

To cite package **magpie4** in publications use:

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.2, <URL: https://github.com/pik-piam/magpie4>.
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, <URL: https://github.com/pik-piam/magpie4>.

A BibTeX entry for LaTeX users is

Expand All @@ -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},
}
Expand Down
228 changes: 228 additions & 0 deletions inst/extdata/regionmappingWBIncomeGroups.csv
Original file line number Diff line number Diff line change
@@ -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,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: 30 additions & 0 deletions inst/extdata/variablemappingICP.csv
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 6340548

Please sign in to comment.