Package 'piamPlotComparison'

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-10-22 10:20:20 UTC
Source: https://github.com/pik-piam/piamPlotComparison

Help Index


Calculate Statistics of Time Series

Description

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.

Usage

calcTimeSeriesStats(data, var, stats, from = -Inf, to = Inf)

Arguments

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.

Value

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.

Examples

## Not run: 
    calcTimeSeriesStats(
      data, \
      "Emi|CO2",
      stats = list("Net 0 Period" = function(v, p) p[which(v <= 0)[1]]))
  
## End(Not run)

Render CompareScenarios

Description

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.

Usage

compareScenarios(
  projectLibrary = NULL,
  mifScen,
  mifHist,
  outputDir = getwd(),
  outputFile = "CompareScenarios",
  outputFormat = "PDF",
  envir = new.env(),
  quiet = FALSE,
  ...
)

Arguments

projectLibrary

NULL or character(n). Default: NULL. An R reporting library containing Rmd files to be included. You can further filter the sections to be rendered using the sections YAML parameter. The Rmd files must be placed in a folder inst/compareScenarios. Files must have the format cs_NN_XXXX.Rmd to be considered. If the folder contains a file preprocessing.Rmd, it will be executed before rendering the sections.

mifScen

character(n), optionally named. Paths to scenario mifs. If the vector has names, those are used to refer to the scenarios in the output file.

mifHist

character(1). Path to historical mif.

outputDir

character(1). The directory where the output document and intermediary files are created.

outputFile

character(1). File name (without extension) of the output document to be created.

outputFormat

character(1), not case-sensitive. "html", "pdf", or "rmd".

envir

environment. The environment in which the code chunks are to be evaluated. See the argument of the same name in rmarkdown::render(). Set this to globalenv() and sections to NULL to load an preprocess data in your global environment during development.

quiet

logical(1). Suppress printing during rendering?

...

YAML parameters, see below.

Value

The value returned by rmarkdown::render().

YAML Parameters

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?

Author(s)

Christof Schoetz, Falk Benke

Examples

## 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)

Get the List of cs2 Profiles

Description

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.

Usage

getCs2Profiles(path = "./scripts/cs2/profiles.json")

Arguments

path

character(1). Path to the profiles file.

Value

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.

Author(s)

Christof Schoetz

Examples

## Not run: 
profiles <- getCs2Profiles() # load from default location
profiles <- getCs2Profiles(path = "path/to/profiles.json")

## End(Not run)

Show a Table of a Statistics Data Frame

Description

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).

Usage

showStatsTable(statsData, mainReg = getOption("mip.mainReg"))

Arguments

statsData

A data frame with the columns "model", "scenario", "region", "value", "variable", "unit", "statistic".

mainReg

character(1). The main region. Will be shown at the top of the table.

Value

A knitr_kable object. A table with columns region and one column for each scenario.

Examples

## Not run: 
  data %>%
    calculateStatisticsOfTimeSeries(
      "Emi|CO2",
      stats = list("Net 0 Period" = function(v, p) p[which(v <= 0)[1]])
    )  %>%
    showStatsTable()
  
## End(Not run)