Title: | Create comparison plots for your model results |
---|---|
Description: | A frameworks to create comparison plots for your model results. |
Authors: | Falk Benke [aut, cre], Christof Schoetz [aut] |
Maintainer: | Falk Benke <[email protected]> |
License: | LGPL-3 |
Version: | 0.0.16 |
Built: | 2024-11-21 05:52:50 UTC |
Source: | https://github.com/pik-piam/piamPlotComparison |
Take a quitte object and calculate given summary statistics of the time series of given variables in the quitte object. Return the result for each model, scenario, region, variable, and statistic in a data frame.
calcTimeSeriesStats(data, var, stats, from = -Inf, to = Inf)
calcTimeSeriesStats(data, var, stats, from = -Inf, to = Inf)
data |
A quitte object. |
var |
character(n). The names of the variables to calculate the statistics on. |
stats |
A named list of functions with two arguments. Each function will be called with the vector of values as the first argument and the vector of corresponding periods as the second argument. |
from , to
|
Optional variables to filter the time series by period. |
A data frame with columns model, scenario, region, variable, value,
statistic, unit. "value" contains the calculated statistics. "statistic" is
name of the statistics, i.e., the name of the function in the argument
stats
. The "unit" is the unit of the original variable and not
necessarily the correct unit for the calculated statistics.
## Not run: calcTimeSeriesStats( data, \ "Emi|CO2", stats = list("Net 0 Period" = function(v, p) p[which(v <= 0)[1]])) ## End(Not run)
## Not run: calcTimeSeriesStats( data, \ "Emi|CO2", stats = list("Net 0 Period" = function(v, p) p[which(v <= 0)[1]])) ## End(Not run)
Renders the *.Rmd-files associated to CompareScenarios. In the Rmds, scenario- and historical .mif-files are loaded. Then plots are created from this data. The result may be rendered to PDF or HTML. Alternatively one can choose Rmd as output format and obtain a copy of the *.Rmd-files.
compareScenarios( projectLibrary = NULL, mifScen, mifHist, outputDir = getwd(), outputFile = "CompareScenarios", outputFormat = "PDF", envir = new.env(), quiet = FALSE, ... )
compareScenarios( projectLibrary = NULL, mifScen, mifHist, outputDir = getwd(), outputFile = "CompareScenarios", outputFormat = "PDF", envir = new.env(), quiet = FALSE, ... )
projectLibrary |
|
mifScen |
|
mifHist |
|
outputDir |
|
outputFile |
|
outputFormat |
|
envir |
|
quiet |
|
... |
YAML parameters, see below. |
The value returned by rmarkdown::render()
.
cfgScen
character(n) or NULL
.
Paths to config.Rdata files containing the cfg
object for each
scenario. The paths must be provided in the same order as mifScen
.
If provided, some information gathered from these files is
shown at the beginning of the output document.
docTitle
character(n) or NULL
.
Title of the document. Defaults to 'Compare Scenarios'
yearsScen
numeric(n)
.
Default: c(seq(2005, 2060, 5), seq(2070, 2100, 10))
.
Years to show for scenario data.
yearsHist
numeric(n)
.
Default: c(seq(1960, 2020, 1), seq(2025, 2100, 5))
.
Years to show for historical data.
yearsBarPlot
numeric(n)
.
Default: c(2010, 2030, 2050, 2100)
.
Years to show in bar plots of scenario data.
yearRef
numeric(1)
.
Default: 2020
.
A reference year used to show relative values in Kaya decomposition.
reg
NULL
or character(n)
.
Default: NULL
.
Regions to show. NULL
means all.
modelsHistExclude
character(n) or NULL
.
Default: c()
.
Models in historical data to exclude.
sections
character(n) or numeric(n) or NULL
.
Default: "all"
.
Names or numbers of sections to include.
Use "all"
to include all available sections.
Use NULL
to not include any section
(useful in combination with parameter envir
).
userSectionPath
NULL
or character(n)
.
Default: NULL
.
Path to a *.Rmd-file that may be included as additional section.
mainReg
character(1)
.
Default: "World"
.
A region for which larger plots are shown.
figWidth, figHeight
numeric(1)
.
Default: 15
and 10
, respectively.
Size of plots in inches.
warning
logical(1)
.
Default: TRUE
.
Show warnings in output?
Christof Schoetz, Falk Benke
## Not run: # Simple use. Creates PDF: compareScenarios( projectLibrary = "mylib", mifScen = c("path/to/Base.mif", "path/to/NDC.mif"), mifHist = "path/to/historical.mif", outputFile = "CompareScenariosExample") # More complex use. Creates folder with Rmds: compareScenarios( projectLibrary = "mylib", mifScen = c(ScenarioName1 = "path/to/scen1.mif", ScenarioName2 = "path/to/scen2.mif"), mifHist = "path/to/historical.mif", cfgScen = c("path/to/scen1/config.RData", "path/to/scen2/config.RData"), outputDir = "path/to/output", outputFormat = "Rmd", outputFile = format(Sys.time(), "compScen_%Y%m%d-%H%M%S"), warning = FALSE, sections = c(0, 2, 3, 99), userSectionPath = "path/to/myPlots.Rmd") # Use in development. Load data into global environment: compareScenarios( projectLibrary = "mylib", mifScen = c("path/to/scen1.mif", "path/to/scen2.mif"), mifHist = "path/to/historical.mif", outputFile = format(Sys.time(), "cs2_load_%Y%m%d-%H%M%S"), sections = NULL, envir = globalenv()) ## End(Not run)
## Not run: # Simple use. Creates PDF: compareScenarios( projectLibrary = "mylib", mifScen = c("path/to/Base.mif", "path/to/NDC.mif"), mifHist = "path/to/historical.mif", outputFile = "CompareScenariosExample") # More complex use. Creates folder with Rmds: compareScenarios( projectLibrary = "mylib", mifScen = c(ScenarioName1 = "path/to/scen1.mif", ScenarioName2 = "path/to/scen2.mif"), mifHist = "path/to/historical.mif", cfgScen = c("path/to/scen1/config.RData", "path/to/scen2/config.RData"), outputDir = "path/to/output", outputFormat = "Rmd", outputFile = format(Sys.time(), "compScen_%Y%m%d-%H%M%S"), warning = FALSE, sections = c(0, 2, 3, 99), userSectionPath = "path/to/myPlots.Rmd") # Use in development. Load data into global environment: compareScenarios( projectLibrary = "mylib", mifScen = c("path/to/scen1.mif", "path/to/scen2.mif"), mifHist = "path/to/historical.mif", outputFile = format(Sys.time(), "cs2_load_%Y%m%d-%H%M%S"), sections = NULL, envir = globalenv()) ## End(Not run)
A list of arguments to compareScenarios
is called a (cs2-)
profile. This function loads a list of such profiles from a file. The default
argument is set such that the default profiles file of REMIND is loaded.
getCs2Profiles(path = "./scripts/cs2/profiles.json")
getCs2Profiles(path = "./scripts/cs2/profiles.json")
path |
|
A named list of profiles. The names are the names of the respective
profile. Each profile is a named list. Those names correspond to arguments
of compareScenarios
.
Christof Schoetz
## Not run: profiles <- getCs2Profiles() # load from default location profiles <- getCs2Profiles(path = "path/to/profiles.json") ## End(Not run)
## Not run: profiles <- getCs2Profiles() # load from default location profiles <- getCs2Profiles(path = "path/to/profiles.json") ## End(Not run)
Take the output of calcTimeSeriesStats
(a data frame) and show
it as a kable table. Only results from model REMIND are shown. It is assumed
that the input argument only contains a single statistic of a single variable
(but multiple regions and scenarios). The caption of the resulting table is
created from the entries of the columns variable, unit, and statistic in the
first row (should be the same in all rows).
showStatsTable(statsData, mainReg = getOption("mip.mainReg"))
showStatsTable(statsData, mainReg = getOption("mip.mainReg"))
statsData |
A data frame with the columns "model", "scenario", "region", "value", "variable", "unit", "statistic". |
mainReg |
|
A knitr_kable
object. A table with columns region and one
column for each scenario.
## Not run: data %>% calculateStatisticsOfTimeSeries( "Emi|CO2", stats = list("Net 0 Period" = function(v, p) p[which(v <= 0)[1]]) ) %>% showStatsTable() ## End(Not run)
## Not run: data %>% calculateStatisticsOfTimeSeries( "Emi|CO2", stats = list("Net 0 Period" = function(v, p) p[which(v <= 0)[1]]) ) %>% showStatsTable() ## End(Not run)