Package 'magpiesets'

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

Help Index


Magpie Sets Processing Tools

Description

Package contains helper functions for reporting and validation (special focus on commodities)

Arguments

version

Switch between different version of the magpiesets library

default_sep18 default MAgPIE 4.0 set with 49 products in 'kall'
biogas_dec18 biogas extension including biogas, biochar and manure in 'kall'
biochar_jan19 biochar extension including biochar and pyrolyzing

Author(s)

Benjamin Leon Bodirsky (Maintainer: [email protected]), Florian Humpenoeder, Abhijeet Mishra, Kristine Karstens

See Also

Useful links:


addLocation

Description

Function translates (if possible) cell numbers into coordinates or coordinates into cell numbers and adds them to the spatial dimension of the object.

Usage

addLocation(x, fillMissing = NULL, naCellNumber = 0, format = "both")

Arguments

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.

Value

magpie object with added spatial subdimensions

Author(s)

Jan Philipp Dietrich, Felicitas Beier, Michael Crawford

Examples

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)

Cell2Country

Description

function returning the mapping between grid and country

Usage

Cell2Country()

Value

data frame returning the mapping between cells and countries

Author(s)

Edna J. Molina Bacca

Examples

## Not run: 
   Cell2Country()
  
## End(Not run)

findset

Description

function returning set item of MAgPIE sets

Usage

findset(set, alias = FALSE, noset = "warning", version = NULL)

Arguments

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)

Value

MAgPIE set items

Author(s)

Benjamin Leon Bodirsky, Florian Humpenoeder, Kristine Karstens

Examples

## Not run: 
    findset("kcr")
  
## End(Not run)

FRA names

Description

function returning the reporting names from FRA 2020 category

Usage

FRAnames(x, from = "franames", to = "magpienames", mapping = "fra_names.csv")

Arguments

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.

Value

vector with reporting names or volors

Author(s)

Abhijeet Nishra

Examples

## Not run: 
    FRAnames("nat_reg")
    FRAnames("tece",to="reportingcolors")
  
## End(Not run)

reporthelper

Description

Aggregates MAgPIE products to standard reporting categories and changes to reporting names. Automatically recognizes if only a reduced form of "kall" is provided.

Usage

reporthelper(
  x,
  dim = 3.1,
  level_zero_name = "All products",
  detail = TRUE,
  sort = FALSE,
  partly = FALSE,
  version = NULL
)

Arguments

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

Value

MAgPIE object with aggregated and renamed items in 3rd dimension

Author(s)

Benjamin Leon Bodirsky, Florian Humpenoeder, Kristine Karstens

Examples

## Not run: 
x <- calories(level = "regglo", products = "kcr", attributes = "protein")
x <- reporthelper(x)

## End(Not run)

reportingnames

Description

function returning the reporting names of a vector

Usage

reportingnames(
  x,
  from = "magpienames",
  to = "reportingnames",
  mapping = "reportingnames.csv"
)

Arguments

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.

Value

vector with reporting names or volors

Author(s)

Benjamin Leon Bodirsky, Florian Humpenoeder, Patrick v. Jeetze

Examples

## Not run: 
    reportingnames("tece")
    reportingnames("tece",to="reportingcolors")
  
## End(Not run)

reportingReverse

Description

reverses the reporting format with tree structure (e.g. "Demand", "Demand|Agriculture|Food (Mt DM)") into a conventional magpie format

Usage

reportingReverse(x)

Arguments

x

a MAgPIE which has the format of a report file (e.g. "Demand|Agriculture|Food (Mt DM)")

Value

a MAgPIE object with higher dimensionailty

Author(s)

Benjamin Leon Bodirsky

Examples

## Not run: 
budget <- calcOutput("ValidDemand")
    reportingReverse(budget)

## End(Not run)

summationhelper

Description

Modifies name of variables in a magpie object to add summation symbols.

Usage

summationhelper(x, sep = "+", dim = 3.1, check = TRUE, excludeLevels = 0)

Arguments

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.

Details

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 ?

Value

MAgPIE object

Author(s)

Abhijeet Mishra, Kristine Karstens

Examples

## Not run: 
    x <- calcOutput("LanduseInitialisation",aggregate = FALSE)
    getNames(x) <- paste0("Land Cover|", reportingnames(getNames(x))," (million ha)")   
    x <- summationhelper(x)
  
## End(Not run)