Title: | MAgPIE sets for R |
---|---|
Description: | A library containing MAgPIE sets and other support functions. |
Authors: | Benjamin Leon Bodirsky [aut, cre], Florian Humpenoeder [aut], Abhijeet Mishra [aut], Kristine Karstens [aut], Isabelle Weindl [aut], Edna Molina Bacca [aut], Patrick von Jeetze [aut], Jan Philipp Dietrich [aut] |
Maintainer: | Benjamin Leon Bodirsky <[email protected]> |
License: | LGPL-3 | file LICENSE |
Version: | 0.46.1 |
Built: | 2024-10-19 07:16:01 UTC |
Source: | https://github.com/pik-piam/magpiesets |
Package contains helper functions for reporting and validation (special focus on commodities)
version |
Switch between different version of the magpiesets library
|
Benjamin Leon Bodirsky (Maintainer: [email protected]), Florian Humpenoeder, Abhijeet Mishra, Kristine Karstens
Useful links:
Report bugs at https://github.com/pik-piam/magpiesets/issues
Function translates (if possible) cell numbers into coordinates or coordinates into cell numbers and adds them to the spatial dimension of the object.
addLocation(x, fillMissing = NULL, naCellNumber = 0, format = "both")
addLocation(x, fillMissing = NULL, naCellNumber = 0, format = "both")
x |
magpie object to be enriched with spatial information. Currently only works for 0.5 degree data sets with 59199 or 67420 cells or a subset of it. |
fillMissing |
if NULL cells missing from the total 59199 are just being ignore. If set to a value missing cells will be added with this value (e.g. all set to 0 if fillMissing is 0) |
naCellNumber |
number or string given as cell number for cells which do not have an assigned cell number in the 59199 mapping |
format |
either "both" or "iso.grid". When set to "iso.grid", the function will remove the pre-existing spatial dimensions after adding the coordinates' sorted iso.grid location. This argument is ignored for input objects initially containing iso.grid and LPJ datasets. |
magpie object with added spatial subdimensions
Jan Philipp Dietrich, Felicitas Beier, Michael Crawford
map <- Cell2Country() x <- y <- z <- population_magpie getCoords(x) <- map[100:109, c("lon", "lat")] getItems(x, "i") <- NULL addLocation(x) getCoords(y) <- map[100:109, c("lon", "lat")] getItems(y, "i") <- NULL addLocation(y, format = "iso.grid") getCells(z) <- map$celliso[100:109] addLocation(z)
map <- Cell2Country() x <- y <- z <- population_magpie getCoords(x) <- map[100:109, c("lon", "lat")] getItems(x, "i") <- NULL addLocation(x) getCoords(y) <- map[100:109, c("lon", "lat")] getItems(y, "i") <- NULL addLocation(y, format = "iso.grid") getCells(z) <- map$celliso[100:109] addLocation(z)
function returning the mapping between grid and country
Cell2Country()
Cell2Country()
data frame returning the mapping between cells and countries
Edna J. Molina Bacca
## Not run: Cell2Country() ## End(Not run)
## Not run: Cell2Country() ## End(Not run)
function returning set item of MAgPIE sets
findset(set, alias = FALSE, noset = "warning", version = NULL)
findset(set, alias = FALSE, noset = "warning", version = NULL)
set |
a MAgPIE set (e.g. "kcr"), or a vector of sets. |
alias |
if TRUE, set elements are extended by '_alias'. Can be used to avoid doubling of dimnames. |
noset |
if "original", a set that has no mapping is returned without changes; otherwhise a vector of length 0 is returned, plus a warning that the set does not exist. |
version |
Switch between different version of the magpiesets library (use 'versionset' to load version types itself) |
MAgPIE set items
Benjamin Leon Bodirsky, Florian Humpenoeder, Kristine Karstens
## Not run: findset("kcr") ## End(Not run)
## Not run: findset("kcr") ## End(Not run)
function returning the reporting names from FRA 2020 category
FRAnames(x, from = "franames", to = "magpienames", mapping = "fra_names.csv")
FRAnames(x, from = "franames", to = "magpienames", mapping = "fra_names.csv")
x |
a vector of common FRA 2020 names (e.g. c("nat_reg","agb")) |
from |
fra names for common magpie abbreviations, FRAnames for reverse translation |
to |
Common names for official reporting names, reportincolors for typical colorcode of an item |
mapping |
csv file in inst/extdata folder. |
vector with reporting names or volors
Abhijeet Nishra
## Not run: FRAnames("nat_reg") FRAnames("tece",to="reportingcolors") ## End(Not run)
## Not run: FRAnames("nat_reg") FRAnames("tece",to="reportingcolors") ## End(Not run)
Aggregates MAgPIE products to standard reporting categories and changes to reporting names. Automatically recognizes if only a reduced form of "kall" is provided.
reporthelper( x, dim = 3.1, level_zero_name = "All products", detail = TRUE, sort = FALSE, partly = FALSE, version = NULL )
reporthelper( x, dim = 3.1, level_zero_name = "All products", detail = TRUE, sort = FALSE, partly = FALSE, version = NULL )
x |
Magpie object with data that shall be reported |
dim |
Dimension in which magpie products ("tece" etc) can be found |
level_zero_name |
the general reporting name of the Magpie object (e.g. "Agricultural Production") |
detail |
if detail=F, the subcategories of groups are not reported (e.g. "soybean" within "oilcrops") |
sort |
sort items in 3rd dimension alphabetically (TRUE or FALSE) |
partly |
boolean or set name, that should be reported in detail, even if it is just partly provided within the gdx |
version |
Switch between different version of the magpiesets library |
MAgPIE object with aggregated and renamed items in 3rd dimension
Benjamin Leon Bodirsky, Florian Humpenoeder, Kristine Karstens
## Not run: x <- calories(level = "regglo", products = "kcr", attributes = "protein") x <- reporthelper(x) ## End(Not run)
## Not run: x <- calories(level = "regglo", products = "kcr", attributes = "protein") x <- reporthelper(x) ## End(Not run)
function returning the reporting names of a vector
reportingnames( x, from = "magpienames", to = "reportingnames", mapping = "reportingnames.csv" )
reportingnames( x, from = "magpienames", to = "reportingnames", mapping = "reportingnames.csv" )
x |
a vector of common magpie names (e.g. c("tece","trce")) |
from |
magpienames for common magpie abbreviations, reportingnames for reverse translation |
to |
reportingnames for official reporting names, reportincolors for typical colorcode of an item |
mapping |
csv file in inst/extdata folder. |
vector with reporting names or volors
Benjamin Leon Bodirsky, Florian Humpenoeder, Patrick v. Jeetze
## Not run: reportingnames("tece") reportingnames("tece",to="reportingcolors") ## End(Not run)
## Not run: reportingnames("tece") reportingnames("tece",to="reportingcolors") ## End(Not run)
reverses the reporting format with tree structure (e.g. "Demand", "Demand|Agriculture|Food (Mt DM)") into a conventional magpie format
reportingReverse(x)
reportingReverse(x)
x |
a MAgPIE which has the format of a report file (e.g. "Demand|Agriculture|Food (Mt DM)") |
a MAgPIE object with higher dimensionailty
Benjamin Leon Bodirsky
## Not run: budget <- calcOutput("ValidDemand") reportingReverse(budget) ## End(Not run)
## Not run: budget <- calcOutput("ValidDemand") reportingReverse(budget) ## End(Not run)
Modifies name of variables in a magpie object to add summation symbols.
summationhelper(x, sep = "+", dim = 3.1, check = TRUE, excludeLevels = 0)
summationhelper(x, sep = "+", dim = 3.1, check = TRUE, excludeLevels = 0)
x |
MAgPIE object from validation calculations in "almost" ready format. for e.g. from x <- calcOutput("ValidDemand","FAO") |
sep |
summation symbol (+,++,-) |
dim |
Dimension in which the modification, should take place |
check |
Switch to turn off checking routine, if FALSE. Default is TRUE. |
excludeLevels |
levels to be excluded from summation, e.g. 1 for Trade in Trade|Net-Exports. |
summationhelper should help to organize the subcategories into groups for e.g. stackplots. Notice the following hints:
Every name should just contain one summation symbol (mostly '+').
The position of the symbol (counted in '|' from left side) will determine the level.
Every subitem containing the same summation symbol in the same level with the same supercategory name will be summed.
Items without any summation symbol will ge ignored.
Items with different summation symbols will be summed up separately.
In most of the cases a summation symbol will be just placed before the last level (counted in '|' from left side).
It is helpful to think about which group of items should be stacked in a stackplot.
An example how a summation symbol placement could look like:
Toplevel Toplevel|+|Item 1 Toplevel|+|Item 2 Toplevel|Item 2|+|Subitem 1 Toplevel|Item 2|+|Subitem 1 Toplevel|++|Item A Toplevel|++|Item B Toplevel|Item ?
MAgPIE object
Abhijeet Mishra, Kristine Karstens
## Not run: x <- calcOutput("LanduseInitialisation",aggregate = FALSE) getNames(x) <- paste0("Land Cover|", reportingnames(getNames(x))," (million ha)") x <- summationhelper(x) ## End(Not run)
## Not run: x <- calcOutput("LanduseInitialisation",aggregate = FALSE) getNames(x) <- paste0("Land Cover|", reportingnames(getNames(x))," (million ha)") x <- summationhelper(x) ## End(Not run)