Title: | Tool functions that can be used by several madrat-dependent or magpie4 output functions |
---|---|
Description: | Tool functions that can be used by several madrat-dependent or magpie4 output functions. |
Authors: | Benjamin Leon Bodirsky [aut, cre], Kristine Karstens [aut], Felicitas Beier [aut], Jan Philipp Dietrich [aut] |
Maintainer: | Benjamin Leon Bodirsky <[email protected]> |
License: | LGPL-3 | file LICENSE |
Version: | 0.11.1 |
Built: | 2024-12-04 13:32:54 UTC |
Source: | https://github.com/pik-piam/mstools |
Tool functions that can be used by several madrat-dependent or magpie4 output functions.
Maintainer: Benjamin Leon Bodirsky [email protected]
Authors:
Kristine Karstens
Felicitas Beier
Jan Philipp Dietrich [email protected]
Useful links:
Report bugs at https://github.com/pik-piam/magpie4/issues
Aggregate cellular data (with coordinate information) to countries and perform consistency checks
toolAggregateCell2Country(x, weight = NULL, ...)
toolAggregateCell2Country(x, weight = NULL, ...)
x |
cellular magpie object with coordinates |
weight |
aggregation weight |
... |
additional options forwarded to 'toolCountryFill' |
return country ISO level data
Jan Philipp Dietrich
Sets cell names to "iso country code"."cell number"
toolCell2isoCell(x, cells = "magpiecell")
toolCell2isoCell(x, cells = "magpiecell")
x |
magpie object on cellular level |
cells |
switch between magpie cells (59199) and lpj cells (67420) |
return changed input data
Kristine Karstens
Aggregates cellular data to ISO country level after conversion of cellular data to a specific cell setup (this type is relevant as some settings, such as "magpiecell" remove some cells and therby affect country sums)
toolConv2CountryByCelltype(x, cells)
toolConv2CountryByCelltype(x, cells)
x |
magpie object on cellular level |
cells |
switch between 59199 ("magpiecell") and 67420 ("lpjcell") cells |
return selected input data on ISO country level
Jan Philipp Dietrich
Transforms an object with coordinate spatial data (on half-degree) to isocell (59199) standard
toolCoord2Isocell( x, cells = "magpiecell", fillMissing = NULL, warnMissing = TRUE )
toolCoord2Isocell( x, cells = "magpiecell", fillMissing = NULL, warnMissing = TRUE )
x |
Object to be transformed from coordinates to (old) magpie isocell standard |
cells |
Switch between "magpiecell" (59199) and "lpjcell" (67420) |
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) |
warnMissing |
Switch which controls whether missing cells should trigger a warning or not |
magpie object with 59199 cells in isocell naming
Kristine Karstens, Felicitas Beier, Jan Philipp Dietrich
Transforms an object with coordinate spatial data (on half-degree) to object with 67420 cells and coordinate and iso country information
toolCoord2Isocoord(x)
toolCoord2Isocoord(x)
x |
magclass object to be transformed from coordinates to iso-coordinate |
magpie object with 67420 cells in x.y.iso naming
Felicitas Beier, Michael Crawford
Fills bilateral iso-level magpie objects to 249 x 249 countries
toolCountryFillBilateral(x, fill = NA)
toolCountryFillBilateral(x, fill = NA)
x |
input variable, a bilateral magclass object |
fill |
fill value, default NA |
tool function for status reporting. It performs a difference check between
two objects and returns either a message via toolStatusMessage
, that
the test was successful or that it failed.
toolExpectLessDiff(x, y, maxdiff, description, level = 0, maxdiff2 = NULL)
toolExpectLessDiff(x, y, maxdiff, description, level = 0, maxdiff2 = NULL)
x |
object 1 |
y |
object 2 which has the same format as object 1 |
maxdiff |
allowed maximum difference per element between x and y. |
description |
a description of the check |
level |
as the test result will be linked to a function call, the function
needs to know to which call it should be linked. by default ( |
maxdiff2 |
optional additional threshold. If set it will serve as a second, critial threshold
which will throw a warning (instead of a simple note in case of |
Jan Philipp Dietrich
getMadratMessage
, toolExpectTrue
, toolStatusMessage
toolExpectLessDiff(1:3, 2:4, 10, "data is sufficiently close", level = -1) getMadratMessage("status")
toolExpectLessDiff(1:3, 2:4, 10, "data is sufficiently close", level = -1) getMadratMessage("status")
tool function for status reporting. It performs a logical check
and returns either a message via toolStatusMessage
, that
the test was successful or that it failed.
toolExpectTrue(check, description, level = 0, falseStatus = "note")
toolExpectTrue(check, description, level = 0, falseStatus = "note")
check |
logical check to be run (has to be either TRUE or FALSE) |
description |
a description of the check |
level |
as the test result will be linked to a function call, the function
needs to know to which call it should be linked. by default ( |
falseStatus |
the type of status that is used when the check fails (typically "note" for a simple message or "warn" for a warning). |
Jan Philipp Dietrich
getMadratMessage
, toolExpectLessDiff
,
toolStatusMessage
, toolWriteMadratLog
toolExpectTrue(is.numeric(1), "data is numeric", level = -1) getMadratMessage("status")
toolExpectTrue(is.numeric(1), "data is numeric", level = -1) getMadratMessage("status")
Disaggregates fertilizer usage, trying to best match a certain soil nitrogen uptake efficiency (SNUpE). Also used in magpie4 library
toolFertilizerDistribution( iteration_max = 50, max_snupe = 0.85, mapping, from, to, fertilizer, SNUpE, withdrawals, organicinputs, threshold = 0.5 )
toolFertilizerDistribution( iteration_max = 50, max_snupe = 0.85, mapping, from, to, fertilizer, SNUpE, withdrawals, organicinputs, threshold = 0.5 )
iteration_max |
maximum iteration for downscaling |
max_snupe |
the maximum level of nue or snupe |
mapping |
mapping used for disaggregation |
from |
name of from column in mapping |
to |
name of to column in mapping |
fertilizer |
total inorganic fertilizer to be distributed on regional leve |
SNUpE |
Nitrogen use efficiency or SNUPE on regional level which should be matched best possible |
withdrawals |
nitrogen withdrawals on cell level |
organicinputs |
non-inroganic fertilizer inputs on cell level |
threshold |
threshold in Tg Nr until when the distribution counts as converged |
magpie object with fertilizer usage on cell level
Benjamin Leon Bodirsky
This function freeze values given a specific year and optionally additionally at the first non-zero value
toolFreezeEffect(x, year, constrain = FALSE)
toolFreezeEffect(x, year, constrain = FALSE)
x |
data set to freeze |
year |
year to hold constant (onwards) |
constrain |
if FALSE, no constrain. Other options: 'first_use' (freeze from 'first use' ( <=> !=0 )) |
magpie object with global parameters
Kristine Karstens
loads mapping of cellular coordinate data (67420 halfdegree cells) to country iso codes
toolGetMappingCoord2Country(pretty = FALSE, extended = FALSE)
toolGetMappingCoord2Country(pretty = FALSE, extended = FALSE)
pretty |
If TRUE, coordinate data is returned as numeric 'lon' and 'lat' columns |
extended |
If TRUE, additional cells missing in the original 67420 data set will be returned as well. |
data frame of mapping
Felicitas Beier, Kristine Karstens
toolHarmonize2Baseline
toolHarmonize2Baseline( x, base, ref_year = "y2015", method = "limited", hard_cut = FALSE )
toolHarmonize2Baseline( x, base, ref_year = "y2015", method = "limited", hard_cut = FALSE )
x |
magclass object that should be set on baseline |
base |
magclass object for baseline |
ref_year |
Reference year |
method |
additive: x is harmonized to base by additive factor multiplicative: x is harmonized to base by multiplicative factor limited: multiplicative harmonization, but for an underestimated baseline the signal is limited to the additive term rather than the multiplicative factor |
hard_cut |
Switch to TRUE for data that can not be harmonized, but have to be glued together |
the averaged data in magclass format
Kristine Karstens, Felicitas Beier
Holds a historical dataset constant for the entire period years
.
toolHoldConstant(x, years)
toolHoldConstant(x, years)
x |
MAgPIE object to be continued. |
years |
years for which the data should exist (hold constant, if missing) |
MAgPIE object with completed time dimensionality.
Benjamin Leon Bodirsky, Jan Philipp Dietrich
Holds a historical dataset constant for the entire simulation period "time".
toolHoldConstantBeyondEnd(x)
toolHoldConstantBeyondEnd(x)
x |
MAgPIE object to be continued. |
MAgPIE object with completed time dimensionality.
Benjamin Leon Bodirsky
Select country names of countries which are present on cellular level
toolIso2CellCountries(x, cells = "magpiecell", absolute = NULL)
toolIso2CellCountries(x, cells = "magpiecell", absolute = NULL)
x |
magpie object on iso country level |
cells |
switch between 59199 ("magpiecell") and 67420 ("lpjcell") cells |
absolute |
switch declaring the values as absolute (TRUE) or relative (FALSE) for additional (type-specific) diagnostic information. If not defined (NULL) additional diagnostics will not be shown. |
return selected input data
Kristine Karstens, Felicitas Beier, Jan Philipp Dietrich
Translate iso country code to country names
toolIsocode2Country(x)
toolIsocode2Country(x)
x |
Array of iso country codes |
return array of country names
Kristine Karstens
Smooth a time series using a given method and its default settings
toolSmooth(x, method = "spline")
toolSmooth(x, method = "spline")
x |
magclass object that should be smoothed |
method |
spline, average or more (See default argument for current default setting) |
smoothed data in magclass format
Kristine Karstens
tool to trigger status messages describing the data quality at different stages of processing. Messages are directly written to the log at execution but also collected to be finally returned as data report.
toolStatusMessage(status, message, level = 0)
toolStatusMessage(status, message, level = 0)
status |
status indicator of the messages. Currently either "ok" (check succesful / quality ok), "note" (check unsuccessful but still acceptable) or "warn" (check unsuccessful / undesired result). |
message |
message to be triggered. |
level |
as the test result will be linked to a function call, the function
needs to know to which call it should be linked. by default ( |
Jan Philipp Dietrich
getMadratMessage
, toolExpectLessDiff
, toolStatusMessage
toolStatusMessage("ok", "everything is ok", level = -1) toolStatusMessage("note", "this is not optimal but probably acceptable", level = -1) toolStatusMessage("warn", "this is not ok", level = -1) getMadratMessage("status")
toolStatusMessage("ok", "everything is ok", level = -1) toolStatusMessage("note", "this is not optimal but probably acceptable", level = -1) toolStatusMessage("warn", "this is not ok", level = -1) getMadratMessage("status")
Efficient method to sum cellular data with country dimension as first sub-dimension to country level
toolSum2Country(x)
toolSum2Country(x)
x |
magpie object on cellular level with countries in dim 1.1 |
return selected input data on ISO country level
Jan Philipp Dietrich
Tool function for writing madrat messages to a log file. Useful
after running madrat calculations which are performing checks via
toolExpectTrue
or other toolExpect functions.
toolWriteMadratLog( checkResults = getMadratMessage("status"), logPath = "status.log" )
toolWriteMadratLog( checkResults = getMadratMessage("status"), logPath = "status.log" )
checkResults |
list of check results as returned by |
logPath |
path to the log file to be written |
Pascal Sauer