| Title: | Reporting package for BRICK |
|---|---|
| Description: | This package contains BRICK-specific routines to report model results. The main functionality is to generate a mif-file from a given BRICK model run folder. |
| Authors: | Robin Hasse [aut, cre] (ORCID: <https://orcid.org/0000-0003-1818-3186>), Ricarda Rosemann [aut] (ORCID: <https://orcid.org/0009-0006-5939-3197>) |
| Maintainer: | Robin Hasse <[email protected]> |
| License: | LGPL-3 |
| Version: | 0.17.0 |
| Built: | 2026-06-03 13:24:29 UTC |
| Source: | https://github.com/pik-piam/reportbrick |
Add carrier dimension based on heating system technology
.addCarrierDimension(v_stock, hsCarrier).addCarrierDimension(v_stock, hsCarrier)
v_stock |
MagPIE object, BRICK variable |
hsCarrier |
data.frame, mapping between heating technology and energy carrier |
MagPIE object with additional carrier dimension
Robin Hasse
Aggregate
.agg(x, agg, silent = TRUE).agg(x, agg, silent = TRUE)
x |
MagPIE object, BRICK object |
agg |
named vector of dimensions to aggregate. |
silent |
logical, suppress warnings and printing of dimension mapping |
aggregated MagPIE objects without sub dimensions in dim 3
Check if the tolerance is violated anywhere
.checkForDeviation(stockBal, name, tol = 0.01).checkForDeviation(stockBal, name, tol = 0.01)
stockBal |
data frame with evaluation of a stock balance equation |
name |
character, name/identifier of the stock balance equation |
tol |
numeric, tolerance to check the equation against |
All Combinations of dimension elements
.combinations(lst).combinations(lst)
lst |
names list of dimension entries |
character vector with all combinations of the dimension elements
each separated by .
Robin Hasse
Compute the mean value in a data frame
.computeAvg(df, rprt = "", valueName = "value", exclude = list()).computeAvg(df, rprt = "", valueName = "value", exclude = list())
df |
data frame, containing the data to be evaluated |
rprt |
character, column names for which the mean should be reported separately |
valueName |
character, name of the column containing the values to be manipulated |
exclude |
named list with entries to be excluded from the data. The name gives the column name from which the entries given by the value should be removed. |
data frame averages as value column
Compute the deviation to target data
.computeDeviation(df, dfTarget).computeDeviation(df, dfTarget)
df |
data frame, containing data from calibration run |
dfTarget |
data frame, containing historical data as calibration target |
data frame where the value column contains the deviation from target data
Compute the sum of construction and renovation flow values
.computeFlowSum(flows, squareAndRoot = FALSE).computeFlowSum(flows, squareAndRoot = FALSE)
flows |
named list of data frames, each containing flow quantities.
Entries need to include |
squareAndRoot |
logical, whether the square should be taken before summing and the root afterwards. This option should be active if we're summing up roots of summed squares. |
data frame with the sum in the value column
Compute the ratio of the squares for two data sets
.computeRatioSq(dfx, dfy, addSign = TRUE).computeRatioSq(dfx, dfy, addSign = TRUE)
dfx |
data frame containing the data of the nominator |
dfy |
data frame containing the data of the denominator |
addSign |
logical indicating whether a heuristic sign of the squares should be computed |
data frame with squared ratio
Compute the relative deviation to calibration target data as the relative euclidean distance
.computeRelDev(dfDev, dfTarget, tCalib, notInTargetGrp = NULL).computeRelDev(dfDev, dfTarget, tCalib, notInTargetGrp = NULL)
dfDev |
data frame, containing deviation between calibration result and target data |
dfTarget |
data frame or a list of one or two data frames, containing target data. The option to pass two data frames is used to combine construction and renovation flows. If two data frames are passed, the first one is assumed to be construction, the second renovation |
tCalib |
numerical/factor, calibration time periods to filter calibration target data |
notInTargetGrp |
character vector, pass columns that target data should not be grouped by when computing the sum of the squares, although they exist in the data |
data frame with relative deviation in value column
Compute the sum
.computeSum(df, rprt = "", exclude = list()).computeSum(df, rprt = "", exclude = list())
df |
data frame containing the data to be evaluated |
rprt |
character, column names for which the sum should be reported separately |
exclude |
named list with entries to be excluded from the data. The name gives the column name from which the entries given by the value should be removed. |
data frame with summed values
Compute the square root of the sum of the squares in a data frame
.computeSumSq(df, tCalib, rprt = "", addSign = TRUE).computeSumSq(df, tCalib, rprt = "", addSign = TRUE)
df |
data frame, containing the data to be evaluated |
tCalib |
numeric, time periods the model was calibrated on |
rprt |
character, column names for which the sum of the squares should be reported separately |
addSign |
logical indicating whether the heuristic sign of the square should be computed |
data frame with the square root of the sum of squares as value column
Construct dimension mapping (either aggregation or reporting) with explicit set elements for each dimension
.constructDimMapping(agg, rprt, brickSets, silent).constructDimMapping(agg, rprt, brickSets, silent)
agg |
named vector of dimensions to aggregate |
rprt |
named vector of dimensions to report individually |
brickSets |
named list with definition of common set elements |
silent |
logical, suppress warnings and printing of dimension mapping |
nested named list with dimension mapping
Escape tag in curly brackets
.embrace(tag).embrace(tag)
tag |
character tag |
character, tag in curly brackets
Robin Hasse
Exclude data matching giving filter criteria from a data set
.excludeRows(data, exclude).excludeRows(data, exclude)
data |
data frame with the data set |
exclude |
named list with entries to be excluded from the data. The name gives the column name from which the entries given by the value should be removed. |
the given data set without the rows identified by the filter criteria
Extend dimensions of a data frame by adding NA entries, add variable name
.expandDims(df, varName, allSets).expandDims(df, varName, allSets)
df |
data frame to be extended |
varName |
character, variable name to be added |
allSets |
character, sets that need to be included as column names |
data frame
Find inconsistencies in set elements between reporting template and gdx
.findInconsistenSetElements(brickSets, gdx).findInconsistenSetElements(brickSets, gdx)
brickSets |
character, BRICK reporting template |
gdx |
file path to a BRICK gdx |
named list of missing and surplus sets elements
Find all tags in name escaped in curly brackets
.findTags(name).findTags(name)
name |
character, variable name |
vector of tags in name, NULL if there are none
Gives the column names of a list of data frames except the first and the last
one, i.e. qty and value.
.getDims(calibObj, removeDims = NULL).getDims(calibObj, removeDims = NULL)
calibObj |
list, calibration targets |
removeDims |
character, additional dimensions to be removed from the output |
character with dimension names
List any missing elements in any given dimension
.missingElements(x, dimLst).missingElements(x, dimLst)
x |
MagPIE object, BRICK object |
dimLst |
named vector, dimension ans names and elements as values |
vector of missing dimension elements in x
Read a symbol from several gdx files and combine in one data frame
.readGdxIter( gdx, symbol, maxIter, minIter = 0, asMagpie = TRUE, ttotFilter = NULL, replaceVar = FALSE, dims = NULL ).readGdxIter( gdx, symbol, maxIter, minIter = 0, asMagpie = TRUE, ttotFilter = NULL, replaceVar = FALSE, dims = NULL )
gdx |
Path to gdx files; all gdx file names are assumed to be numbered and
adhere to the structure: If |
symbol |
Symbol to be read from the gdxes |
maxIter |
Last iteration to be read |
minIter |
First iteration to be read |
asMagpie |
logical, convert to magpie object? |
ttotFilter |
numeric/factor, time periods to filter for |
replaceVar |
logical, replace column names |
dims |
character, containing the colum names expected for the object that is read in. Only required if the object does not exist to create replacement with NAs |
data frame of all results read in
bs and hs by bsr and hsr
Replace column names bs and hs by bsr and hsr
.replaceVarName(df).replaceVarName(df)
df |
data frame |
data frame where column names have been replaced
This is a wrapper around magclass::mselect that also allows the
selection of combinations of multiple dimensions.
.select(x, ...).select(x, ...)
x |
MAgPIE object |
... |
entry selection. Combined dimensions have to be seperated with
|
MAgPIE object containing only selected entries
Wrapper around setNames
.setNames(object, nm).setNames(object, nm)
object |
MAgPIE object |
nm |
a vector of names current names should be replaced with. If only one data element exists you can also set the name to NULL. |
NULL if object is NULL else object with manipulated names
Split each entry of a character vector and return one unnested character vector.
.split(x, split = "\\.").split(x, split = "\\.")
x |
character vector |
split |
character used to split |
character vector with each dimension as an own entry
Robin Hasse
Check the matching results for inconsistencies
checkMatching(path, tol = 0.01)checkMatching(path, tol = 0.01)
path |
character, path to the matching result files |
tol |
numeric, absolute tolerance in million m2 against which to check the stock balance equations |
Ricarda Rosemann
Read in all information from GDX file that was generated with BRICK and create the *.mif reporting
convGDX2MIF( gdx, tmpl = NULL, file = NULL, scenario = "default", t = NULL, silent = TRUE )convGDX2MIF( gdx, tmpl = NULL, file = NULL, scenario = "default", t = NULL, silent = TRUE )
gdx |
file path to a BRICK gdx |
tmpl |
character, BRICK reporting template. There has to be a brickSets
mapping named with the same suffix: |
file |
name of the mif file which will be written, if no name is provided a magpie object containing all the reporting information is returned |
scenario |
scenario name that is used in the *.mif reporting |
t |
numeric vector of reporting periods (years) |
silent |
boolean, suppress warnings and printing of dimension mapping |
Robin Hasse
Crop MagPIE object to given periods and fill missing periods
extendPeriods(x, periods, fill = NA)extendPeriods(x, periods, fill = NA)
x |
MagPIE object |
periods |
numeric vector with target periods |
fill |
value to fill missing period values |
MagPIE object with given periods in temporal dimension
Robin Hasse
Renders the file plotCalibration.Rmd to create the plots for the BRICK calibration
plotBRICKCalib( path = ".", cal = "BRICK_calibration_report.csv", outName = "", scenNames = NULL )plotBRICKCalib( path = ".", cal = "BRICK_calibration_report.csv", outName = "", scenNames = NULL )
path |
(named) character vector, path(s) to output directories. If several paths are given, the names can be used to pass short scenario names. |
cal |
character vector, name(s) of file(s) with calibration reporting results |
outName |
character, string added to the pdf file name and names of additionally saved plots |
scenNames |
character vector, scenario names for different paths.
Needs to be specified if |
Ricarda Rosemann
Plot the following matching reporting
comparison of the matching values and reference targets
share of initial heating systems thar have been removed over time
plotMatching(path, outputFolder = NULL) plotMatchingComparison(path, outputFolder = NULL)plotMatching(path, outputFolder = NULL) plotMatchingComparison(path, outputFolder = NULL)
path |
character, path to the run |
outputFolder |
character, directory where output file is stored. If NULL, the plots folder inside the given path is used. |
file path to created output file
Robin Hasse
This function creates an explicit named list with the elements of all BRICK dimensions and corresponding reporting names.
readBrickSets(tmpl = NULL)readBrickSets(tmpl = NULL)
tmpl |
character, BRICK reporting template |
named list with definition of common set elements
Robin Hasse
Read symbol from gams container
readGdxSymbol( gdx, symbol, field = "level", asMagpie = NULL, stringAsFactor = TRUE, removeDescription = TRUE )readGdxSymbol( gdx, symbol, field = "level", asMagpie = NULL, stringAsFactor = TRUE, removeDescription = TRUE )
gdx |
character, file path to GDX file |
symbol |
character, name of gams object |
field |
character, field to read (only relevant for variables) |
asMagpie |
boolean, return Magpie object. By default ( |
stringAsFactor |
logical, keep default factors from gams |
removeDescription |
logical, if TRUE, the description column of set records (element_text) is removed |
MagPIE object with data of symbol
Robin Hasse
Report aggregated quantities
reportAgg( x, name, brickSets = readBrickSets(NULL), agg = NULL, rprt = NULL, silent = TRUE )reportAgg( x, name, brickSets = readBrickSets(NULL), agg = NULL, rprt = NULL, silent = TRUE )
x |
MagPIE object, BRICK object |
name |
character, name of reporting variable. reported dimensions passed
with |
brickSets |
named list, BRICK reporting template |
agg |
named vector of dimensions to aggregate. Names are dimension names
of |
rprt |
named vector of dimensions to report individually. Names are
dimension names of |
silent |
boolean, suppress warnings and printing of dimension mapping |
To consider specific combinations of dimensions in both agg or
rprt, the combination can be given just like one dimension
separated by ..
Robin Hasse
Report quantities describing the stock of buildings
reportBuildingStock(gdx, brickSets = NULL, silent = TRUE)reportBuildingStock(gdx, brickSets = NULL, silent = TRUE)
gdx |
gams transfer container of the BRICK GDX |
brickSets |
character, BRICK reporting template |
silent |
boolean, suppress warnings and printing of dimension mapping |
Robin Hasse
Read in model results from calibration for each iteration, calculate deviation
reportCalibration(gdx, flowTargets = TRUE)reportCalibration(gdx, flowTargets = TRUE)
gdx |
path to a gdx; it is assumed that for each iteration a gdx is present with this path and the iteration number inserted at the end. |
flowTargets |
logical, if set to FALSE, the function does not expect the presence of targets for the flows |
Ricarda Rosemann
Report quantities describing the construction of new buildings
reportConstruction(gdx, brickSets = NULL, silent = TRUE)reportConstruction(gdx, brickSets = NULL, silent = TRUE)
gdx |
gams transfer container of the BRICK GDX |
brickSets |
character, BRICK reporting template |
silent |
boolean, suppress warnings and printing of dimension mapping |
Robin Hasse
Report quantities describing the demolition of buildings
reportDemolition(gdx, brickSets = NULL, silent = TRUE)reportDemolition(gdx, brickSets = NULL, silent = TRUE)
gdx |
gams transfer container of the BRICK GDX |
brickSets |
character, BRICK reporting template |
silent |
boolean, suppress warnings and printing of dimension mapping |
Robin Hasse
Report CO2 emissions from space heating
reportEmissions(gdx, brickSets = NULL, silent = TRUE)reportEmissions(gdx, brickSets = NULL, silent = TRUE)
gdx |
gams transfer container of the BRICK GDX |
brickSets |
character, BRICK reporting template |
silent |
boolean, suppress warnings and printing of dimension mapping |
Robin Hasse
Report final and useful energy demand for space heating
reportEnergy(gdx, brickSets = NULL, silent = TRUE)reportEnergy(gdx, brickSets = NULL, silent = TRUE)
gdx |
gams transfer container of the BRICK GDX |
brickSets |
character, BRICK reporting template |
silent |
boolean, suppress warnings and printing of dimension mapping |
Robin Hasse
Report quantities describing the renovation of heating systems
reportRenovation( gdx, renovatedObj = c("bs", "hs"), brickSets = NULL, silent = TRUE )reportRenovation( gdx, renovatedObj = c("bs", "hs"), brickSets = NULL, silent = TRUE )
gdx |
gams transfer container of the BRICK GDX |
renovatedObj |
character, renovation measure considered,
needs to be either |
brickSets |
character, BRICK reporting template |
silent |
boolean, suppress warnings and printing of dimension mapping |
Ricarda Rosemann
Create stacked bar plots to verify matching accuracy
showMatchingComparison(path, showTitles = TRUE)showMatchingComparison(path, showTitles = TRUE)
path |
character, path to the run |
showTitles |
logical, if TRUE, the references name and basic variable name are shown as title in each plot. No titles otherwise. |
named list of ggplot2 objects
Robin Hasse
Show the share of heating systems standing in the initial time step that have
been removed over time. The tunnel marks the allowed space between the lower
and upper limit defined in p_shareRenHSinit and the solid line shows
the value eventually chosen in the matching by v_shareRenHSinit. The
dashed line shows the extrapolation of this result to future time steps that
go beyond the temporal scope of the matching. The dotted line marks the
central value that results from an evenly distributed installation up until
the initial time steps. The central value is not considered in the
optimisation but used as supporting point in the extrapolation.
showMatchingStandingStock(path)showMatchingStandingStock(path)
path |
character, path to the run |
named list of ggplot2 objects
Robin Hasse
Visualise transitions from one state to another. This plot helps to follow the exact renovation flows, though it quickly gets very complex.
showSankey( path, fill = c("bs", "hs"), showOnlyRenovation = FALSE, filterData = NULL, maxPeriodsInRow = NULL, save = TRUE )showSankey( path, fill = c("bs", "hs"), showOnlyRenovation = FALSE, filterData = NULL, maxPeriodsInRow = NULL, save = TRUE )
path |
character, path to the run |
fill |
character, dimension mapped to fill, either |
showOnlyRenovation |
logical, if |
filterData |
named list to filter the data before plotting |
maxPeriodsInRow |
maximum number of time steps to plot in one row. If
there is more data, it is broken across multiple lines. If |
save |
control how the plot should be saved:
|
Robin Hasse