| Title: | Statistical tools for LPJmL data analysis |
|---|---|
| Description: | This package provides statistical tools for LPJmL data analysis to be used for benchmarking LPJmL outputs. |
| Authors: | David Hötten [aut, cre], Jannes Breier [aut] (ORCID: <https://orcid.org/0000-0002-9055-6904>), Christoph Müller [aut] (ORCID: <https://orcid.org/0000-0002-9491-3550>), Stephen B. Wirth [aut] (ORCID: <https://orcid.org/0000-0003-3090-3318>) |
| Maintainer: | David Hötten <[email protected]> |
| License: | AGPL-3 |
| Version: | 0.10.0 |
| Built: | 2026-05-22 09:05:11 UTC |
| Source: | https://github.com/PIK-LPJmL/lpjmlstats |
Subtract an LPJmLDataCalc object from another LPJmLDataCalc object
## S3 method for class 'LPJmLDataCalc' o1 - o2## S3 method for class 'LPJmLDataCalc' o1 - o2
o1 |
An |
o2 |
An |
An LPJmLDataCalc object.
Function to coerce (convert) an LPJmLData object into an
LPJmLDataCalc object with extended functionality.
.as_LPJmLDataCalc(obj).as_LPJmLDataCalc(obj)
obj |
LPJmLData object. For internal package development use the obj can also be an array with the dimension
|
An LPJmLDataCalc object.
Multiply an LPJmLDataCalc object by another LPJmLDataCalc object
## S3 method for class 'LPJmLDataCalc' o1 * o2## S3 method for class 'LPJmLDataCalc' o1 * o2
o1 |
An |
o2 |
An |
An LPJmLDataCalc object.
Divide an LPJmLDataCalc object by another LPJmLDataCalc object
## S3 method for class 'LPJmLDataCalc' o1 / o2## S3 method for class 'LPJmLDataCalc' o1 / o2
o1 |
An |
o2 |
An |
An LPJmLDataCalc object.
Add an LPJmLDataCalc object to another LPJmLDataCalc object
## S3 method for class 'LPJmLDataCalc' o1 + o2## S3 method for class 'LPJmLDataCalc' o1 + o2
o1 |
An |
o2 |
An |
An LPJmLDataCalc object.
Function to aggregate the full data of an LPJmLDataCalc object by
applying summary statistics along the cell and/or time dimensions.
aggregate(x, ref_area = "terr_area", ...)aggregate(x, ref_area = "terr_area", ...)
x |
|
ref_area |
string either |
... |
one or several key-value pairs. Keys represent the dimension to be aggregated and values specify the target aggregation units and the desired summary statistic. Aggregation unit and statistic are given in a list,
by the syntax If only a string is given instead of a list it is used as
the aggregation unit and the summary statistic defualts to Options for the cell dimension The aggregation units for the cell dimension can be either an LPJmlRegionData object or a string with the following options
Options for the time dimension For the time dimension these aggregation units are available:
The only available aggregation method is |
An aggregated LPJmLDataCalc object.
## Not run: # Example 1 # Load an example LPJmLDataCalc object soiln <- load_soiln_calc() # Aggregate the data to countries of the world soiln_countries <- aggregate(soiln, cell = "countries") soiln_countries$data # look at country time series # Example 2 # Load an example LPJmLDataCalc object soiln <- load_soiln_calc() # Aggregate the to global region soiln <- aggregate(soiln, cell = list(to = "global", stat = "weighted_sum")) soiln$data # look at global time series # Example 3 # Load an example LPJmLDataCalc object soiln <- load_soiln_calc() # Take the mean of the data over the full simulation period # and a weighted mean over the cells soiln <- aggregate(soiln, time = "sim_period", cell = list(to = "global", stat = "weighted_mean")) # Look at the resulting value soiln$data ## End(Not run)## Not run: # Example 1 # Load an example LPJmLDataCalc object soiln <- load_soiln_calc() # Aggregate the data to countries of the world soiln_countries <- aggregate(soiln, cell = "countries") soiln_countries$data # look at country time series # Example 2 # Load an example LPJmLDataCalc object soiln <- load_soiln_calc() # Aggregate the to global region soiln <- aggregate(soiln, cell = list(to = "global", stat = "weighted_sum")) soiln$data # look at global time series # Example 3 # Load an example LPJmLDataCalc object soiln <- load_soiln_calc() # Take the mean of the data over the full simulation period # and a weighted mean over the cells soiln <- aggregate(soiln, time = "sim_period", cell = list(to = "global", stat = "weighted_mean")) # Look at the resulting value soiln$data ## End(Not run)
Function to benchmark one or several under test LPJmL runs against a baseline run.
benchmark( baseline_dir, under_test_dirs, settings = default_settings, metric_options = NULL, author = "", description = "", pdf_report = TRUE, ilamb_report = FALSE, ... )benchmark( baseline_dir, under_test_dirs, settings = default_settings, metric_options = NULL, author = "", description = "", pdf_report = TRUE, ilamb_report = FALSE, ... )
baseline_dir |
Path to directory containing the baseline run. Can be list with single entry. The name of the entry will be used as simulation identifier in the benchmarking results and the pdf report. ! For the custom names to have an effect, all simulations (incl. under test) need to have a custom name ! |
under_test_dirs |
List of paths to directories containing the under test run results. If names are provided for the entries of the list, these will be used as simulation identifiers in the benchmarking results and the pdf report. ! For the custom names to have an effect, all simulations (incl. under test) need to have a custom name ! |
settings |
List that defines for each output which metrics to use. The list has to have the following structure:
|
metric_options |
List that defines options for the metrics. The list has to have the following structure:
|
author |
Name of the author of the benchmark. |
description |
Description of the purpose of the benchmark. |
pdf_report |
Logical, if TRUE a pdf report will be created with the create_pdf_report function. |
ilamb_report |
Logical, if TRUE a basic ILAMB report will be created |
... |
additional arguments to be passed to create_pdf_report like
|
In order for the benchmarking to work, all the output files specified in the settings have to be present in the baseline and all under test directories. All output files need to be with ".bin" extension and with meta files of ".bin.json" format. All output paths given to the function need to be distinct. In each output directory there must be a grid and a terr_area file corresponding to the outputs. For each variable the structure of the output files has to be same in each directory (i.e. same cells, same time steps, same bands).
The internal benchmarking process is structured as follows:
Create simulation table with meta information of all considered simulations and the short simulation identifiers.
Retrieve all summaries of outputs from the baseline and under test runs of the variable by applying the summary method of each metric to all lpjml outputs of variables that are designated to be evaluated with this metric, as specified in the settings. The results are organized in variable groups and stored in the var_grp_list attributes of the metrics. See Metric for details.
Add the comparison items to the variable groups, by applying the compare method of each metric to the combination of baseline summary with each under test summary of the variable groups stored in that metric.
Apply unit conversions to all data objects of the metrics, as specified in the unit conversion table. See set_lpjmlstats_settings.
A benchmarkResult object containing the numerical results of the benchmarking. This data object is basically a list of all metrics used in the benchmarking. See Metric for the way a metric structures benchmarking results. In addition the benchmarkResult object contains meta information. Of particular importance is the simulation table, which contains the simulation names, paths and the short simulation identifier that are used in the benchmarkResult object.
The function get_benchmark_meta_data can be used to retrieve the meta information.
The data structure of the benchmarkResult object is depicted here:
## Not run: # Example 1 # Most basic benchmarking with default settings benchmark("path_to_baseline_results", "path_to_under_test_results") # Example 2 # Specifying author and description, as well as filename for pdf report # is recommended. Also, it can make sense to store the benchmarkResult object # for later analysis. BM_resu <- benchmark("path_to_baseline_results", "path_to_under_test_results", author = "anonymous", description = "This is a test", output_file = "myBenchmark.pdf") saveRDS(BM_resu, "bm_results.rds") # Example 3 # Quick benchmarking that only looks at specific outputs with # specific metrics and doesn't generate pdf report. # In addition only the first 10 years are considered # which gives another significant speedup. settings <- list( vegc = c(GlobSumTimeAvgTable), soilc = c(GlobSumTimeAvgTable), # this give an aggregation to a single value for baseline and under test # and their comparison, displayed in a table mgpp = c(GlobSumTimeseries), # this gives a time series for baseline and under test # displayed as line plots mnpp = c(TimeAvgMap) # this gives a time average for baseline and under test # displayed as maps ) BM_data <- benchmark("path_to_baseline_results", "path_to_under_test_results", settings = settings, pdf_report = FALSE) # Example 4 # Benchmark soiltemp in addition to default settings # with a special metric settings <- c(default_settings, # use default settings list(msoiltemp1 = c(GlobAvgTimeAvgTable, TimeAvgMap)) # GlobAvgTimeAvgTable uses a weighted average over space # instead of the standard weighted sum ) BM_data <- benchmark("path_to_baseline_results", "path_to_under_test_results", settings = settings) # Example 5 # Benchmark multiple under test runs against the baseline BM_data <- benchmark("path_to_baseline_results", list("path_to_under_test_results1", "path_to_under_test_results2") ) # Example 6 # Benchmark with custom metric options # In this example the font size of the table of the GlobSumTimeAvgTable # metric is reduced. This may be needed if more than two under_test # runs are benchmarked, which leads to a larger table, that may not fit # within the fixed width of the pdf report. In addition, the # TimeAvgMap metric is set to highlight soilc, which means that the map of # soilc will use the complete width of the document. metric_options <- list( GlobSumTimeAvgTable = list(font_size = 5), # use larger font size in table TimeAvgMap = list(highlight = "soilc") # plots a larger map for soilc ) BM_data <- benchmark("path_to_baseline_results", "path_to_under_test_results", metric_options = metric_options) # Example 7 # Benchmark only maize harvest # The benchmarking allows to select only specific bands of an output settings <- list(`pft_harvest.pft$rainfed maize; irrigated maize` = c(GlobSumTimeAvgTable)) benchmark("path_to_baseline_results", "path_to_under_test_results", settings) # Example 8 # Benchmark only a single run # It is also possible to benchmark only a single run, by setting the # under_test_dirs argument to NULL benchmark("path_to_baseline_results", NULL) # Example 9 # Custom simulation names and ILAMB report # Custom simulation names to under test # and baseline runs can be provided by passing a list. # This only has an effect if custom names are provided # for all simulations. # The maximum number of characters is 7. # In addition an ILAMB report is created, which is a webpage # that will appear as a folder in the driectory specified # by the `output_file` argument. benchmark(list(sim1 = "path_to_baseline_results"), list(sim2 = "path_to_under_test_results"), ILAMB_report = TRUE) # Example 10 # Change metric options after benchmarking is finished # If e.g. the font size in the table or in maps is too large, # or the color scale in the maps needs to be finer, # the metric options need to be changed. However, # running a completly new benchmarking can take a long time. # This can be overcome by savin g the benchmarkResult object # and changing the metric options afterwards. BM_data <- benchmark("path_to_baseline_results", "path_to_under_test_results") # change font size of GlobSumTimeAvgTable to 5 BM_data$GlobSumTimeAvgTable$m_options$font_size <- 5 BM_data$TimeAvgMap$m_options$font_size <- 5 # add more breaks BM_data$TimeAvgMap$m_options$color_scale_n_breaks <- 6 # recreate pdf report with changed options create_pdf_report(BM_data, "my_updated_benchmark.pdf") ## End(Not run)## Not run: # Example 1 # Most basic benchmarking with default settings benchmark("path_to_baseline_results", "path_to_under_test_results") # Example 2 # Specifying author and description, as well as filename for pdf report # is recommended. Also, it can make sense to store the benchmarkResult object # for later analysis. BM_resu <- benchmark("path_to_baseline_results", "path_to_under_test_results", author = "anonymous", description = "This is a test", output_file = "myBenchmark.pdf") saveRDS(BM_resu, "bm_results.rds") # Example 3 # Quick benchmarking that only looks at specific outputs with # specific metrics and doesn't generate pdf report. # In addition only the first 10 years are considered # which gives another significant speedup. settings <- list( vegc = c(GlobSumTimeAvgTable), soilc = c(GlobSumTimeAvgTable), # this give an aggregation to a single value for baseline and under test # and their comparison, displayed in a table mgpp = c(GlobSumTimeseries), # this gives a time series for baseline and under test # displayed as line plots mnpp = c(TimeAvgMap) # this gives a time average for baseline and under test # displayed as maps ) BM_data <- benchmark("path_to_baseline_results", "path_to_under_test_results", settings = settings, pdf_report = FALSE) # Example 4 # Benchmark soiltemp in addition to default settings # with a special metric settings <- c(default_settings, # use default settings list(msoiltemp1 = c(GlobAvgTimeAvgTable, TimeAvgMap)) # GlobAvgTimeAvgTable uses a weighted average over space # instead of the standard weighted sum ) BM_data <- benchmark("path_to_baseline_results", "path_to_under_test_results", settings = settings) # Example 5 # Benchmark multiple under test runs against the baseline BM_data <- benchmark("path_to_baseline_results", list("path_to_under_test_results1", "path_to_under_test_results2") ) # Example 6 # Benchmark with custom metric options # In this example the font size of the table of the GlobSumTimeAvgTable # metric is reduced. This may be needed if more than two under_test # runs are benchmarked, which leads to a larger table, that may not fit # within the fixed width of the pdf report. In addition, the # TimeAvgMap metric is set to highlight soilc, which means that the map of # soilc will use the complete width of the document. metric_options <- list( GlobSumTimeAvgTable = list(font_size = 5), # use larger font size in table TimeAvgMap = list(highlight = "soilc") # plots a larger map for soilc ) BM_data <- benchmark("path_to_baseline_results", "path_to_under_test_results", metric_options = metric_options) # Example 7 # Benchmark only maize harvest # The benchmarking allows to select only specific bands of an output settings <- list(`pft_harvest.pft$rainfed maize; irrigated maize` = c(GlobSumTimeAvgTable)) benchmark("path_to_baseline_results", "path_to_under_test_results", settings) # Example 8 # Benchmark only a single run # It is also possible to benchmark only a single run, by setting the # under_test_dirs argument to NULL benchmark("path_to_baseline_results", NULL) # Example 9 # Custom simulation names and ILAMB report # Custom simulation names to under test # and baseline runs can be provided by passing a list. # This only has an effect if custom names are provided # for all simulations. # The maximum number of characters is 7. # In addition an ILAMB report is created, which is a webpage # that will appear as a folder in the driectory specified # by the `output_file` argument. benchmark(list(sim1 = "path_to_baseline_results"), list(sim2 = "path_to_under_test_results"), ILAMB_report = TRUE) # Example 10 # Change metric options after benchmarking is finished # If e.g. the font size in the table or in maps is too large, # or the color scale in the maps needs to be finer, # the metric options need to be changed. However, # running a completly new benchmarking can take a long time. # This can be overcome by savin g the benchmarkResult object # and changing the metric options afterwards. BM_data <- benchmark("path_to_baseline_results", "path_to_under_test_results") # change font size of GlobSumTimeAvgTable to 5 BM_data$GlobSumTimeAvgTable$m_options$font_size <- 5 BM_data$TimeAvgMap$m_options$font_size <- 5 # add more breaks BM_data$TimeAvgMap$m_options$color_scale_n_breaks <- 6 # recreate pdf report with changed options create_pdf_report(BM_data, "my_updated_benchmark.pdf") ## End(Not run)
Converts LPJmL binary output files (.bin with .bin.json metadata) to NetCDF format. This is an R implementation replacing the C bin2cdf utility.
bin2cdf( input_file, output_file, varname = NULL, use_days = FALSE, compress = 0 )bin2cdf( input_file, output_file, varname = NULL, use_days = FALSE, compress = 0 )
input_file |
Path to the input binary file or its JSON metadata file (.bin.json) |
output_file |
Path for the output NetCDF file |
varname |
Optional variable name for the NetCDF file. If NULL, uses the name from metadata. |
use_days |
If TRUE, use days since base year for time axis instead of months/years. Default is FALSE. |
compress |
Compression level for NetCDF4 (0-9). Default is 0 (no compression). |
The function reads LPJmL binary output using lpjmlkit and writes it to NetCDF format using the ncdf4 package. It preserves metadata including variable names, units, and band names.
Time axis is created based on the temporal resolution of the data:
Annual data: years or days since base year
Monthly data: months or days since base year
Daily data: days since base year
Invisibly returns the path to the created NetCDF file.
## Not run: # Convert a single file bin2cdf("output/vegc.bin.json", "output/vegc.nc") # With days time axis bin2cdf("output/mgpp.bin.json", "output/mgpp.nc", use_days = TRUE) ## End(Not run)## Not run: # Convert a single file bin2cdf("output/vegc.bin.json", "output/vegc.nc") # With days time axis bin2cdf("output/mgpp.bin.json", "output/mgpp.nc", use_days = TRUE) ## End(Not run)
Construct global region object that fully contains all cells given in a grid.
build_global_region(grid)build_global_region(grid)
grid |
An LPJmLGridData object containing the grid. |
An LPJmLRegionData object containing the global region.
CellSubsetAnnAvgTimeseries metric. See Metric for the documentation of metrics in general.
lpjmlstats::Metric -> lpjmlstats::GlobSumTimeseries -> lpjmlstats::GlobAvgTimeseries -> CellSubsetAnnAvgTimeseries
m_optionsList of metric options specific to this metric:
font_size: integer, font size of the plot (default 6)
year_subset: character vector, defines which calendar years the metric considers,
i.e., a data subset that the metric works with; e.g., c("1995", "1996") (default "1901" - "2019").
cell: cells to be subsetted (default 10000)
num_cols: integer, number of columns in the plot grid in the report (default 2)
var_subheading: logical, if TRUE, a linebreak and a subheading will
be inserted before plots for a each new variable. This is intended to visually separate
the plots of different variables and to better organize the report,
especially if the metric generates many plots for each variable. (default FALSE)
band_subheading: analogous to var_subheading but for bands (default FALSE)
descriptionDescription used in the report
titleSection header used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$compare()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()lpjmlstats::GlobSumTimeseries$arrange_plots()lpjmlstats::GlobSumTimeseries$plot()summarize()
Subset the cells and compute an annual average.
CellSubsetAnnAvgTimeseries$summarize(lpjml_data)
lpjml_dataLPJmLDataCalc object to be summarized
A summarized LPJmLDataCalc object
clone()
The objects of this class are cloneable with this method.
CellSubsetAnnAvgTimeseries$clone(deep = FALSE)
deepWhether to make a deep clone.
CellSubsetTimeseries metric. See Metric for the documentation of metrics in general.
lpjmlstats::Metric -> lpjmlstats::GlobSumTimeseries -> lpjmlstats::GlobAvgTimeseries -> lpjmlstats::CellSubsetAnnAvgTimeseries -> CellSubsetTimeseries
descriptionDescription used in the report
titleSection header used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$compare()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()lpjmlstats::GlobSumTimeseries$arrange_plots()lpjmlstats::GlobSumTimeseries$plot()summarize()
Subset the cells.
CellSubsetTimeseries$summarize(lpjml_data)
lpjml_dataLPJmLDataCalc object to be summarized
A summarized LPJmLDataCalc object
clone()
The objects of this class are cloneable with this method.
CellSubsetTimeseries$clone(deep = FALSE)
deepWhether to make a deep clone.
Function to create a pdf with a table with literature values
create_literature_pdf(output_file = "literature_values.pdf", ...)create_literature_pdf(output_file = "literature_values.pdf", ...)
output_file |
filename of the output pdf, can include directory |
... |
additional parameters passed to rmarkdown::render |
Generate a pdf report from a benchmarkResult object.
create_pdf_report(benchmark_result, output_file = "benchmark.pdf", ...)create_pdf_report(benchmark_result, output_file = "benchmark.pdf", ...)
benchmark_result |
benchmarkResult object created by the |
output_file |
file of the output pdf, including filename and directory
|
... |
additional arguments passed to |
Each metric has its own section in the report. The content of the section is generated by the plot and plot_arrange function of the metric. The metric results are displayed in the same order as they were specified in the benchmark settings.
## Not run: create_pdf_report(BM_data, "myBenchmark.pdf") ## End(Not run)## Not run: create_pdf_report(BM_data, "myBenchmark.pdf") ## End(Not run)
Default settings for the Benchmarking
default_settingsdefault_settings
An object of class list of length 28.
Function that returns the meta data of a benchmarkResult object
get_benchmark_meta_data(benchmark_result)get_benchmark_meta_data(benchmark_result)
benchmark_result |
A benchmarkResult object |
A list with the meta data of the benchmarkResult object. The list contains the author, the description and a simulation identification table. The latter is a tibble with the columns sim_paths, lpjml_version, sim_names, sim_ident and sim_type.
Retrieves plots or underlying plot data from a benchmarkResult object for specific metrics and variables.
get_plot(bm, metric = NULL, variables = NULL, data_only = FALSE)get_plot(bm, metric = NULL, variables = NULL, data_only = FALSE)
bm |
A benchmarkResult object created by the |
metric |
Character vector specifying which metric(s) to retrieve plots
for. If |
variables |
Character vector specifying which variable(s) to retrieve
plots for. If |
data_only |
Logical. If |
This function provides a convenient way to extract and inspect individual plots from a benchmarkResult object. This is useful when you want to:
Display specific plots interactively
Modify plot aesthetics
Export plots individually
Access the underlying data for custom visualizations
When data_only = TRUE, the function efficiently retrieves data directly
from the benchmark object without generating plots, which significantly
improves performance. The returned data lists include:
baseline: The baseline scenario lpjml_calc object (may be NULL)
under_test: List of all under_test scenario lpjml_calc objects (may be NULL)
compare: List of comparison data between scenarios (only included if
the metric calculates comparisons and compare data exists)
Each lpjml_calc object contains the data array and associated metadata (units, variable names, dimensions, etc.), making them suitable for custom analyses outside of ggplot.
Note: GlobSumTimeAvgTable metrics are automatically excluded
from get_plot() because their plot method returns tibbles (data tables)
rather than plot objects. To access GlobSumTimeAvgTable output, use
bm$GlobSumTimeAvgTable$plot() directly.
The function validates all inputs and will issue warnings or errors if:
The specified metric does not exist in the benchmark results
The specified variables are not available for the given metric
Invalid argument types are provided
GlobSumTimeAvgTable metrics are requested (with a warning)
If a single metric is specified: A list of plot objects (or data lists
if data_only = TRUE) for the requested variables.
If multiple metrics are specified: A named list where each element corresponds to a metric and contains a list of plots (or data lists) for that metric's variables.
## Not run: # Create a benchmark result bm_result <- benchmark("path_to_baseline", "path_to_under_test") # Get all plots for a specific metric plots <- get_plot(bm_result, metric = "TimeAvgMap") # Get plots for specific variables from a metric vegc_plot <- get_plot(bm_result, metric = "TimeAvgMap", variables = "vegc") # Get plots for multiple metrics plots <- get_plot(bm_result, metric = c("TimeAvgMap", "GlobSumTimeseries")) # Get underlying data instead of plots (returns data lists) var_data <- get_plot(bm_result, metric = "TimeAvgMap", variables = "vegc", data_only = TRUE) # Access different scenarios from data list baseline_data <- var_data$vegc$baseline # Baseline scenario (may be NULL) undertest_data <- var_data$vegc$under_test # List of under_test scenarios (may be NULL) # Access compare data if it exists (only present for metrics that calculate it) if (!is.null(var_data$vegc$compare)) { compare_data <- var_data$vegc$compare # Comparison data diff_data <- var_data$vegc$compare$diff2base # Specific comparison type } # Access lpjml_calc data and metadata if (!is.null(var_data$vegc$baseline)) { baseline_array <- var_data$vegc$baseline$data # Data array baseline_meta <- var_data$vegc$baseline$meta # Metadata (units, etc.) } # Display a specific plot plots <- get_plot(bm_result, metric = "TimeAvgMap", variables = "vegc") print(plots[[1]]) ## End(Not run)## Not run: # Create a benchmark result bm_result <- benchmark("path_to_baseline", "path_to_under_test") # Get all plots for a specific metric plots <- get_plot(bm_result, metric = "TimeAvgMap") # Get plots for specific variables from a metric vegc_plot <- get_plot(bm_result, metric = "TimeAvgMap", variables = "vegc") # Get plots for multiple metrics plots <- get_plot(bm_result, metric = c("TimeAvgMap", "GlobSumTimeseries")) # Get underlying data instead of plots (returns data lists) var_data <- get_plot(bm_result, metric = "TimeAvgMap", variables = "vegc", data_only = TRUE) # Access different scenarios from data list baseline_data <- var_data$vegc$baseline # Baseline scenario (may be NULL) undertest_data <- var_data$vegc$under_test # List of under_test scenarios (may be NULL) # Access compare data if it exists (only present for metrics that calculate it) if (!is.null(var_data$vegc$compare)) { compare_data <- var_data$vegc$compare # Comparison data diff_data <- var_data$vegc$compare$diff2base # Specific comparison type } # Access lpjml_calc data and metadata if (!is.null(var_data$vegc$baseline)) { baseline_array <- var_data$vegc$baseline$data # Data array baseline_meta <- var_data$vegc$baseline$meta # Metadata (units, etc.) } # Display a specific plot plots <- get_plot(bm_result, metric = "TimeAvgMap", variables = "vegc") print(plots[[1]]) ## End(Not run)
GlobAvgAnnAvgTimeseries metric. See Metric for the documentation of metrics in general.
lpjmlstats::Metric -> lpjmlstats::GlobSumTimeseries -> GlobAvgAnnAvgTimeseries
titleSection header used in the report
descriptionDescription used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$compare()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()lpjmlstats::GlobSumTimeseries$arrange_plots()lpjmlstats::GlobSumTimeseries$plot()summarize()
Take the mean for each year and then the global weighted mean over the cells.
GlobAvgAnnAvgTimeseries$summarize(data)
dataLPJmLDataCalc object to be summarized
A summarized LPJmLDataCalc object
clone()
The objects of this class are cloneable with this method.
GlobAvgAnnAvgTimeseries$clone(deep = FALSE)
deepWhether to make a deep clone.
GlobAvgTimeAvgTable metric. See Metric for the documentation of metrics in general.
lpjmlstats::Metric -> lpjmlstats::GlobSumTimeAvgTable -> GlobAvgTimeAvgTable
titleSection header used in the report
descriptionDescription used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()lpjmlstats::GlobSumTimeAvgTable$arrange_plots()lpjmlstats::GlobSumTimeAvgTable$compare()lpjmlstats::GlobSumTimeAvgTable$plot()summarize()
First take global weighted mean, then average over all time steps.
GlobAvgTimeAvgTable$summarize(data)
dataLPJmLDataCalc object to be summarized
A summarized LPJmLDataCalc object
clone()
The objects of this class are cloneable with this method.
GlobAvgTimeAvgTable$clone(deep = FALSE)
deepWhether to make a deep clone.
GlobAvgTimeseries metric. See Metric for the documentation of metrics in general.
lpjmlstats::Metric -> lpjmlstats::GlobSumTimeseries -> GlobAvgTimeseries
titleSection header used in the report
descriptionDescription used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$compare()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()lpjmlstats::GlobSumTimeseries$arrange_plots()lpjmlstats::GlobSumTimeseries$plot()summarize()
Take the global weighted mean over the cells.
GlobAvgTimeseries$summarize(data)
dataLPJmLDataCalc object to be summarized
A summarized LPJmLDataCalc object
clone()
The objects of this class are cloneable with this method.
GlobAvgTimeseries$clone(deep = FALSE)
deepWhether to make a deep clone.
GlobSumAnnAvgTimeseries metric. See Metric for the documentation of metrics in general.
lpjmlstats::Metric -> lpjmlstats::GlobSumTimeseries -> GlobSumAnnAvgTimeseries
titleSection header used in the report
descriptionDescription used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$compare()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()lpjmlstats::GlobSumTimeseries$arrange_plots()lpjmlstats::GlobSumTimeseries$plot()summarize()
Take the mean for each year and then the global weighted sum over the cells.
GlobSumAnnAvgTimeseries$summarize(data)
dataLPJmLDataCalc object to be summarized
A summarized LPJmLDataCalc object
clone()
The objects of this class are cloneable with this method.
GlobSumAnnAvgTimeseries$clone(deep = FALSE)
deepWhether to make a deep clone.
GlobSumAnnTimeseriesFPC metric
lpjmlstats::Metric -> lpjmlstats::GlobSumTimeseries -> lpjmlstats::GlobSumAnnAvgTimeseries -> GlobSumAnnTimeseriesFPC
titleSection header used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$compare()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()lpjmlstats::GlobSumTimeseries$arrange_plots()lpjmlstats::GlobSumTimeseries$plot()summarize()
Weigh by natural stand fraction and then do the same as GlobSumAnnAvgTimeseries
GlobSumAnnTimeseriesFPC$summarize(data)
dataLPJmLDataCalc object to be summarized
new()
initialize with an extended description
GlobSumAnnTimeseriesFPC$new()
clone()
The objects of this class are cloneable with this method.
GlobSumAnnTimeseriesFPC$clone(deep = FALSE)
deepWhether to make a deep clone.
GlobSumAnnTimeseriesPFT_harvest metric
lpjmlstats::Metric -> lpjmlstats::GlobSumTimeseries -> lpjmlstats::GlobSumAnnAvgTimeseries -> GlobSumAnnTimeseriesPFT_harvest
titleSection header used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$compare()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()lpjmlstats::GlobSumTimeseries$arrange_plots()lpjmlstats::GlobSumTimeseries$plot()summarize()
Weigh by cft_frac and then do the same as GlobSumAnnAvgTimeseries
GlobSumAnnTimeseriesPFT_harvest$summarize(data)
dataLPJmLDataCalc object to be summarized
new()
initialize with an extended description
GlobSumAnnTimeseriesPFT_harvest$new()
clone()
The objects of this class are cloneable with this method.
GlobSumAnnTimeseriesPFT_harvest$clone(deep = FALSE)
deepWhether to make a deep clone.
GlobSumTimeAvgTable metric. See Metric for the documentation of metrics in general.
lpjmlstats::Metric -> GlobSumTimeAvgTable
m_optionsList of metric options specific to this metric:
font_size: integer, font size of the table (default 7)
disp_digits: integer, number of significant digits to display (default 4)
year_subset: character vector, defines which calendar years the metric considers,
i.e., a data subset that the metric works with; e.g., c("1995", "1996") (default 1991:2000).
cell_subset: character vector, defines which cells to subset (default NULL)
titleSection header used in the report
descriptionDescription used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()summarize()
First take global weighted sum, then average over all time steps of the simulation period. The result is a scalar for each band.
GlobSumTimeAvgTable$summarize(data)
dataLPJmLDataCalc object to be summarized
A summarized LPJmLDataCalc object
compare()
Calculate difference and relative difference to the baseline.
GlobSumTimeAvgTable$compare(var_grp)
var_grpvariable group
plot()
Create a table of the results.
GlobSumTimeAvgTable$plot()
A tibble with the results
arrange_plots()
Style the table to be displayed in the report.
GlobSumTimeAvgTable$arrange_plots(table)
tableA tibble with the results
clone()
The objects of this class are cloneable with this method.
GlobSumTimeAvgTable$clone(deep = FALSE)
deepWhether to make a deep clone.
GlobSumTimeAvgTableFPC metric
lpjmlstats::Metric -> lpjmlstats::GlobSumTimeAvgTable -> GlobSumTimeAvgTableFPC
titleSection header used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()lpjmlstats::GlobSumTimeAvgTable$arrange_plots()lpjmlstats::GlobSumTimeAvgTable$compare()lpjmlstats::GlobSumTimeAvgTable$plot()summarize()
Weigh by natural stand fraction and then do the same as GlobSumTimeAvgTable
GlobSumTimeAvgTableFPC$summarize(data)
dataLPJmLDataCalc object to be summarized
new()
initialize with an extended description
GlobSumTimeAvgTableFPC$new()
clone()
The objects of this class are cloneable with this method.
GlobSumTimeAvgTableFPC$clone(deep = FALSE)
deepWhether to make a deep clone.
GlobSumTimeAvgTablePFT_harvest metric
lpjmlstats::Metric -> lpjmlstats::GlobSumTimeAvgTable -> GlobSumTimeAvgTablePFT_harvest
titleSection header used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()lpjmlstats::GlobSumTimeAvgTable$arrange_plots()lpjmlstats::GlobSumTimeAvgTable$compare()lpjmlstats::GlobSumTimeAvgTable$plot()summarize()
Weigh by cft_frac and then do the same as GlobSumTimeAvgTable
GlobSumTimeAvgTablePFT_harvest$summarize(data)
dataLPJmLDataCalc object to be summarized
new()
initialize with an extended description
GlobSumTimeAvgTablePFT_harvest$new()
clone()
The objects of this class are cloneable with this method.
GlobSumTimeAvgTablePFT_harvest$clone(deep = FALSE)
deepWhether to make a deep clone.
GlobSumTimeseries metric. See Metric for the documentation of metrics in general.
lpjmlstats::Metric -> GlobSumTimeseries
m_optionsList of metric options specific to this metric:
font_size: integer, font size of the plot (default 6)
year_subset: character vector, defines which calendar years the metric considers,
i.e., a data subset that the metric works with; e.g., c("1995", "1996") (default "1901" - "2019").
cell_subset: character vector, defines which cells to subset (default NULL)
num_cols: integer, number of columns in the plot grid in the report (default 2)
var_subheading: logical, if TRUE, a linebreak and a subheading will
be inserted before plots for a each new variable. This is intended to visually separate
the plots of different variables and to better organize the report,
especially if the metric generates many plots for each variable. (default FALSE)
band_subheading: analogous to var_subheading but for bands (default FALSE)
titleSection header used in the report
descriptionDescription used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$compare()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()summarize()
Take a global weighted sum of the output.
GlobSumTimeseries$summarize(data)
dataLPJmLDataCalc object to be summarized
A summarized LPJmLDataCalc object
plot()
Create a time series plot of the results.
GlobSumTimeseries$plot()
A list of time series ggplots
arrange_plots()
Arrange the time series plots side by side with legends pooled together in the top left
GlobSumTimeseries$arrange_plots(plotlist)
plotlistList of time series ggplots
clone()
The objects of this class are cloneable with this method.
GlobSumTimeseries$clone(deep = FALSE)
deepWhether to make a deep clone.
An extended LPJmLData class that enables arithmetic and statistics.
lpjmlkit::LPJmLData -> LPJmLDataCalc
datathe data array
.data_with_unitReturns the internal enclosed unit object !Internal method only to be used for package development!
.metaReturns the actual LPJmLMetaDataCalc object !Internal method only to be used for package development!
lpjmlkit::LPJmLData$.__set_data__()lpjmlkit::LPJmLData$.__set_grid__()lpjmlkit::LPJmLData$as_array()lpjmlkit::LPJmLData$as_raster()lpjmlkit::LPJmLData$as_terra()lpjmlkit::LPJmLData$as_tibble()lpjmlkit::LPJmLData$dim()lpjmlkit::LPJmLData$dimnames()lpjmlkit::LPJmLData$length()lpjmlkit::LPJmLData$print()lpjmlkit::LPJmLData$subset()lpjmlkit::LPJmLData$summary()lpjmlkit::LPJmLData$transform()new()
Create a new LPJmLDataCalc object; to be used internally or explicitly !Internal method only to be used for package development!
LPJmLDataCalc$new(lpjml_data)
lpjml_dataan LPJmLData object.
aggregate()
See aggregate.
LPJmLDataCalc$aggregate(ref_area = "terr_area", ...)
add_band()
Add a band to the object by applying a function to the band vector for each spacial and temporal unit
LPJmLDataCalc$add_band(band_name, fun)
band_nameName of band
funfunction
get_ref_area()
Get the reference area of the LPJmLDataCalc object. For an area density variable the reference area should be the area of each cell on which the variable is defined.
LPJmLDataCalc$get_ref_area(ref_area)
ref_areaA string that can be
terr_area terrestrial area (land area including inland water bodies)
cell_area full area of each cell
An LPJmLDataCalc object with the reference area as variable.
plot()
Plot an LPJmLDataCalc object
The function acts a wrapper of plot.LPJmLData from lpjmlkit, but allows for plotting data in more formats.
In case of non-aggregated data plot.LPJmLData is directly called. In case of aggregated data the value for each region is assigned to all pixels that belong to the region. If a pixel belong to a region only partially, the value is multiplied by the fraction of that pixel belonging to the region. If a pixel belongs to multiple regions, the sum of all respective region values (multiplied by the fractions) is taken. The pixel values are then again plotted with plot.LPJmLData.
LPJmLDataCalc$plot(...)
...Arguments passed to LPJmLData plot method.
.check_internal_integrity()
Check consistency of data and meta data !Internal method only to be used for package development!
LPJmLDataCalc$.check_internal_integrity()
.plot_aggregated()
Plot aggregated data. Performs a very simple disaggregation to create LPJmLData obj that can be plotted with plot.LPJmLData. For each pixel the values of all regions that contain the pixel are multiplied by the fractions and summed up.
LPJmLDataCalc$.plot_aggregated(...)
...Arguments to be passed to plot.LPJmLData
.add()
Addition of two LPJmLDataCalc objects !Internal method only to be used for package development!
LPJmLDataCalc$.add(lpjml_calc_obj)
lpjml_calc_objAn LPJmLData object.
.subtract()
Subtraction of two LPJmLDataCalc objects !Internal method only to be used for package development!
LPJmLDataCalc$.subtract(lpjml_calc_obj)
lpjml_calc_objAn LPJmLData object.
.multiply()
Multiplication of two LPJmLDataCalc objects !Internal method only to be used for package development!
LPJmLDataCalc$.multiply(lpjml_calc_obj)
lpjml_calc_objAn LPJmLData object.
.divide()
Division of two LPJmLDataCalc objects !Internal method only to be used for package development!
LPJmLDataCalc$.divide(lpjml_calc_obj)
lpjml_calc_objAn LPJmLData object.
.convert_unit()
Unit conversion of LPJmLDataCalc object !Internal method only to be used for package development!
LPJmLDataCalc$.convert_unit(unit)
unitA string with the unit to convert to.
.set_unit()
Set unit of LPJmLDataCalc object !Internal method only to be used for package development!
LPJmLDataCalc$.set_unit(unit_str)
unit_strA string with the unit to be set.
apply_unit_conversion_table()
Apply unit conversion from conversion table
LPJmLDataCalc$apply_unit_conversion_table(path_to_table = NULL)
path_to_tableA string with the path to the conversion table.
add_grid()
Add a grid to the LPJmLDataCalc object
Wrapper for the add_grid method of the LPJmLData class.
LPJmLDataCalc$add_grid()
clone()
The objects of this class are cloneable with this method.
LPJmLDataCalc$clone(deep = FALSE)
deepWhether to make a deep clone.
A meta data container for the LPJmLDataCalc class that extends the LPJmLMetaData such that aggregation can be tracked.
lpjmlkit::LPJmLMetaData -> LPJmLMetaDataCalc
space_aggregationboolean, Indication weather the data has been subject to space aggregation.
time_aggregationboolean, Indication weather the data has been subject to time aggregation.
band_names_dispnamed vector, versions of band names used for display, usually shorter
pos_in_var_grplist, position of the lpjml_calc inside of its var_grp.
sim_identstring, simulation identifier
namestring, hopefully model version invariant name of the variable
var_and_band_dispstring, variable name together with name of first band, e.g. soiln$200
lpjmlkit::LPJmLMetaData$.__init_grid__()lpjmlkit::LPJmLMetaData$.__set_attribute__()lpjmlkit::LPJmLMetaData$.__transform_space_format__()lpjmlkit::LPJmLMetaData$.__transform_time_format__()lpjmlkit::LPJmLMetaData$.__update_subset__()lpjmlkit::LPJmLMetaData$as_header()lpjmlkit::LPJmLMetaData$as_list()new()
Initialize the LPJmLMetaDataCalc object by copying all private attributes from an LPJmLMetaData object to private attributes of this object. !Internal method only to be used for package development!
LPJmLMetaDataCalc$new(lpjml_meta)
lpjml_metaan LPJmLMetaData object.
.__set_space_aggregation__()
Save in metadata that data is in space_aggregation format !Internal method only to be used for package development!
LPJmLMetaDataCalc$.__set_space_aggregation__(agg_method)
agg_methodstring indicating the aggregation method
.__set_time_aggregation__()
Save in metadata that data is in time_aggregation format !Internal method only to be used for package development!
LPJmLMetaDataCalc$.__set_time_aggregation__(agg_method)
agg_methodstring indicating the aggregation method
print()
Wrapper for LPJmLMetaData print method.
LPJmLMetaDataCalc$print(spaces = "", ...)
spacesstring of spaces to be printed as prefix
...additional arguments passed to LPJmLMetaData print method
.__set_sim_ident__()
Set the simulation identifier !Internal method only to be used for package development!
LPJmLMetaDataCalc$.__set_sim_ident__(sim_ident)
sim_identstring, simulation identifier
.__set_pos_in_var_grp__()
Set the position of the lpjml_calc inside of its var_grp. !Internal method only to be used for package development!
LPJmLMetaDataCalc$.__set_pos_in_var_grp__(pos_in_var_grp)
pos_in_var_grpA list with the position of the lpjml_calc inside of the var_grp. The first entry is the type; can be "baseline", "under_test" or "compare". The second entry is the compare item if of type "compare", e.g. "diff". E.g. list("under_test") or list("compare", "diff").
clone()
The objects of this class are cloneable with this method.
LPJmLMetaDataCalc$clone(deep = FALSE)
deepWhether to make a deep clone.
A class that represents one or several regions in LPJmL. Based on an LPJmL grid, a region is defined as set of grid cells together with fractions. The fractions indicate the share of each grid cell that is part of the region. (e.g. 1 = the cell belongs completely to the region, 0 = the cell does not belong to the region at all).\ The underlying data structure is a sparse matrix, where the rows represent the regions, the columns represent the grid cells and the values represent the fractions (cells not belonging to a region do not take memory as only nonzero entries are stored in a sparse matrix).
Create a new LPJmLRegionData object; only used internally.
region_matrixobject stores the region data as a sparse matrix.
gridLPJmLGridData object containing the underlying grid.
new()
!Internal method only to be used by the package itself!
LPJmLRegionData$new(grid, region_matrix)
gridLPJmLGridData object containing the underlying grid.
region_matrixobject stores the region data as a sparse matrix.
get_ncells_per_region()
Get number of cells per region.
LPJmLRegionData$get_ncells_per_region()
For partially belonging cells the fraction of the cell that belongs to the region is counted.
A vector of length nrow(region_matrix) containing the number of cells per region.
clone()
The objects of this class are cloneable with this method.
LPJmLRegionData$clone(deep = FALSE)
deepWhether to make a deep clone.
A metric is a) a structured, generic processing pipeline to calculate numerical indicators for sets of lpjml outputs as well as to display these indicators in a report, and b) a structured data container that stores the numerical indicators resulting from a).
a) A metric defines a procedure to
summarize a complex, multidimensional LPJmL output in a meaningfull, potentially opinionated way, typically involving the reduction of its time and or space dimension,
compare how this summary statistic of an output variable changes, when going from an established baseline LPJmL version or configuration to a new version or configuration currently under test,
plot the results of 1. and 2. as a figure or table and
arrange these plots in a report, (e.g. styling, side by side arrangement)
See benchmark on how these steps come into play in the benchmarking process.
b) The summarized outputs as well as comparisons that are stored a metric are grouped by the different lpjml variables. A so called variable group (var_grp) contains
the summary of the baseline output of that variable
a list of all summarized under test outputs of that variable
a list of compare items (e.g. difference, relative difference). Each compare item is a list of comparisons of the baseline summary with each under test summary using the specific method of that item.
All variable groups are stored in the var_grp_list attribute of the metric.
As the cornerstone of the benchmarking process, all metrics illuminate the change of LPJmL results from different angles, and should together provide a comprehensive picture of the effects of modifications in code or settings.
See GlobSumTimeAvgTable for a typical example of a metric.
m_optionsList of metric options Will be overwritten by the individual metric subclasses.
var_grp_listList of variable groups. Each variable group contains the summaries and the comparisons for one variable.
summarize()
Pipeline to summarize the raw data. Will be overwritten by the individual metric subclasses.
Metric$summarize(data)
dataRaw data to be summarized
compare()
Pipeline to compare the baseline summary with each under test summary stored in the metric. Will be overwritten by the individual metric subclasses.
Metric$compare(var_grp)
var_grpvariable group
plot()
Function to plot the results of the metric. Will be overwritten by the individual metric subclasses.
Metric$plot(var_grp)
var_grpvariable group
arrange_plots()
Function to arrange all plots of the metric in the respective section of the report. Will be overwritten by the individual metric subclasses.
Metric$arrange_plots(var_grp)
var_grpvariable group
capture_summary()
!Package internal method!
Metric$capture_summary(lpjml_calc, var, type)
lpjml_calcRaw data to be summarized
varVariable name
typeType of data ("baseline" or "under_test")
store_summary()
!Package internal method! Store the summary in the variable group
Metric$store_summary(summary, var, type)
summarySummary to be stored
varVariable name
typeType of data ("baseline" or "under_test")
add_comparisons()
!Package internal method! Compare and store the comparison in all variable groups
Metric$add_comparisons()
add_compare_meta()
!Package internal method! Add the position of the comparisons within the var_grp to meta
Metric$add_compare_meta(var_grp)
var_grpvariable group
transform_lpjml_calcs()
!Package internal method! Apply function to all lpjml_calcs in all eval groups and lists
Metric$transform_lpjml_calcs(fun, ...)
funFunction to apply
...Additional arguments passed to fun
generate_report_content()
!Package internal method! Generate the full report content of the metric.
Metric$generate_report_content()
print_metric_header()
!Package internal method! Function to print the metric header.
Metric$print_metric_header()
print_metric_description()
!Package internal method! Function to print the metric description.
Metric$print_metric_description()
print_year_subset()
!Package internal method! Function to print the year_subset metric option.
Metric$print_year_subset()
clone()
The objects of this class are cloneable with this method.
Metric$clone(deep = FALSE)
deepWhether to make a deep clone.
The function acts a wrapper of plot.LPJmLData from lpjmlkit, but allows for plotting data in more formats.
## S3 method for class 'LPJmLDataCalc' plot(x, ...)## S3 method for class 'LPJmLDataCalc' plot(x, ...)
x |
LPJmLDataCalc object. In case of non-aggregated data plot.LPJmLData is directly called. In case of aggregated data the value for each region is assigned to all pixels that belong to the region. If a pixel belong to a region only partially, the value is multiplied by the fraction of that pixel belonging to the region. If a pixel belongs to multiple regions, the sum of all respective region values (multiplied by the fractions) is taken. The pixel values are then again plotted with plot.LPJmLData. |
... |
Arguments passed to LPJmLData plot method. |
The COW = countries of the world data contains global country borders.
read_cow_regions()read_cow_regions()
An LPJmLRegionData object containing the cow regions.
The default grid is the standard global grid used in LPJmL.
read_def_grid()read_def_grid()
An LPJmLGridData object containing the default grid.
The function acts a wrapper of read_io from lpjmlkit,
but outputs an LPJmLDataCalc object.
read_io_calc(..., output_type = "LPJmLDataCalc")read_io_calc(..., output_type = "LPJmLDataCalc")
... |
Parameters that are passed to read_io |
output_type |
Can be either |
An LPJmLDataCalc object
This function configures various settings for the lpjmlstats package.
set_lpjmlstats_settings(...)set_lpjmlstats_settings(...)
... |
Variable arguments to specify settings. The function accepts the following options:
|
## Not run: set_lpjmlstats_settings(unit_table_path = "path/to/my_table.csv", pdf_plot_dpi = 300) ## End(Not run)## Not run: set_lpjmlstats_settings(unit_table_path = "path/to/my_table.csv", pdf_plot_dpi = 300) ## End(Not run)
Function to subset an LPJmLDataCalc object. The function acts as a wrapper
of subset.LPJmLData from lpjmlkit, but outputs an
LPJmLDataCalc object, in particular keeping its unit.
## S3 method for class 'LPJmLDataCalc' subset(x, ...)## S3 method for class 'LPJmLDataCalc' subset(x, ...)
x |
LPJmLDataCalc object. |
... |
Parameters that are passed to subset.LPJmLData. |
An LPJmLDataCalc object.
TimeAvgMap metric. See Metric for the documentation of metrics in general.
lpjmlstats::Metric -> TimeAvgMap
m_optionsList of metric options specific to this metric:
font_size: integer, font size of the map plot (default 6)
highlight: vector of strings, indicating which variables
should be highlighted in the report, i.e. receive a larger plot at the
beginning of report content of the metric.
All variables with a name that contains at least one these strings as a substring,
will not be plotted in the plotgrid (see num_cols) but before the plot grid starts.
These plots are allowed to extent to full page width. (default NULL)
scale_fill_quantiles: quantiles used to determine the lower and upper
limits for the values in the map plot (default c(0.05, 0.95))
scale_fill_n_breaks: number of breaks for each arm of the diverging
color scale (default 5)
scale_fill_tick_label_angle: integer, angle in degrees for the fill axis (colorbar)
tick labels (default 45)
year_subset: character vector, defines which calendar years the metric considers,
i.e., a data subset that the metric works with; e.g., c("1995", "1996") (default 1991:2000).
cell_subset: character vector, defines which cells to subset (default NULL)
num_cols: integer, number of columns in the plot grid in the report (default 2)
var_subheading: logical, if TRUE, a linebreak and a subheading will
be inserted before plots for a each new variable. This is intended to visually separate
the plots of different variables and to better organize the report,
especially if the metric generates many plots for each variable. (default FALSE)
band_subheading: analogous to var_subheading but for bands (default FALSE)
titleSection header used in the report
descriptionDescription used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()summarize()
Take the mean over the simulation period for each cell.
TimeAvgMap$summarize(data)
dataLPJmLDataCalc object to be summarized
A summarized LPJmLDataCalc object
compare()
Compare the baseline summary with the under test summaries by subtracting the baseline from the under test.
TimeAvgMap$compare(var_grp)
var_grpvariable group
plot()
Create a map plot with country border overlay.
TimeAvgMap$plot()
A list of map ggplots
arrange_plots()
Arrange the map plots side by side
TimeAvgMap$arrange_plots(plotlist)
plotlistList of map ggplots
clone()
The objects of this class are cloneable with this method.
TimeAvgMap$clone(deep = FALSE)
deepWhether to make a deep clone.
TimeAvgMapTreeCover metric
lpjmlstats::Metric -> lpjmlstats::TimeAvgMap -> lpjmlstats::TimeAvgMapWithAbs -> TimeAvgMapTreeCover
m_optionsSee TimeAvgMapWithAbs for the documentation of the options of this metric.
titleSection header used in the report
descriptionDescription used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()lpjmlstats::TimeAvgMapWithAbs$arrange_plots()lpjmlstats::TimeAvgMapWithAbs$compare()lpjmlstats::TimeAvgMapWithAbs$plot()summarize()
add up bands for tree fpcs
TimeAvgMapTreeCover$summarize(data)
dataLPJmLDataCalc object to be summarized
clone()
The objects of this class are cloneable with this method.
TimeAvgMapTreeCover$clone(deep = FALSE)
deepWhether to make a deep clone.
TimeAvgMapWithAbs metric. See Metric for the documentation of metrics in general.
lpjmlstats::Metric -> lpjmlstats::TimeAvgMap -> TimeAvgMapWithAbs
m_optionsList of metric options specific to this metric:
font_size: integer, font size of the map plot (default 6)
highlight: vector of strings, indicating which variables
should be highlighted in the report, i.e. receive a larger plot at the
beginning of report content of the metric.
All variables with a name that contains at least one these strings as a substring,
will not be plotted in the plotgrid (see num_cols) but before the plot grid starts.
These plots are allowed to extent to full page width. (default NULL)
scale_fill_quantiles: quantiles used to determine the lower and upper
limits for the values in the map plot (default c(0.05, 0.95))
sep_cmp_lims: logical, if TRUE not all plots of a var_grp
will have the same limits anymore, but the compare plots
have their own separate limits (default TRUE)
scale_fill_n_breaks: number of breaks for each arm of the diverging
color scale (default 5)
scale_fill_tick_label_angle: integer, angle in degrees for the fill axis (colorbar)
tick labels (default 45)
year_subset: character vector, defines which calendar years the metric considers,
i.e., a data subset that the metric works with; e.g., c("1995", "1996") (default 1991:2000).
cell_subset: character vector, defines which cells to subset (default NULL)
num_cols: integer, number of columns in the plot grid in the report (default 3)
var_subheading: logical, if TRUE, a linebreak and a subheading will
be inserted before plots for a each new variable. This is intended to visually separate
the plots of different variables and to better organize the report,
especially if the metric generates many plots for each variable. (default FALSE)
band_subheading: analogous to var_subheading but for bands (default FALSE)
titleSection header used in the report
descriptionDescription used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()lpjmlstats::TimeAvgMap$summarize()compare()
Compare the baseline summary with the under test summaries by subtracting the baseline from the under test.
TimeAvgMapWithAbs$compare(var_grp)
var_grpvariable group
plot()
Create a map plot with country border overlay.
TimeAvgMapWithAbs$plot()
A list of map ggplots
arrange_plots()
Arrange the map plots side by side
TimeAvgMapWithAbs$arrange_plots(plotlist)
plotlistList of map ggplots
clone()
The objects of this class are cloneable with this method.
TimeAvgMapWithAbs$clone(deep = FALSE)
deepWhether to make a deep clone.
TimeAvgMapWithAbsUndertest metric. See Metric for the documentation of metrics in general.
lpjmlstats::Metric -> lpjmlstats::TimeAvgMap -> lpjmlstats::TimeAvgMapWithAbs -> TimeAvgMapWithAbsUndertest
m_optionsList of metric options specific to this metric:
font_size: integer, font size of the map plot (default 6)
highlight: vector of strings, indicating which variables
should be highlighted in the report, i.e. receive a larger plot at the
beginning of report content of the metric.
All variables with a name that contains at least one these strings as a substring,
will not be plotted in the plotgrid (see num_cols) but before the plot grid starts.
These plots are allowed to extent to full page width. (default NULL)
scale_fill_quantiles: quantiles used to determine the lower and upper
limits for the values in the map plot (default c(0.05, 0.95))
sep_cmp_lims: logical, if TRUE not all plots of a var_grp
will have the same limits anymore, but the compare plots
have their own separate limits (default TRUE)
scale_fill_n_breaks: number of breaks for each arm of the diverging
color scale (default 5)
scale_fill_tick_label_angle: integer, angle in degrees for the fill axis (colorbar)
tick labels (default 45)
year_subset: character vector, defines which calendar years the metric considers,
i.e., a data subset that the metric works with; e.g., c("1995", "1996") (default 1991:2000).
cell_subset: character vector, defines which cells to subset (default NULL)
num_cols: integer, number of columns in the plot grid in the report (default 2)
var_subheading: logical, if TRUE, a linebreak and a subheading will
be inserted before plots for a each new variable. This is intended to visually separate
the plots of different variables and to better organize the report,
especially if the metric generates many plots for each variable. (default FALSE)
band_subheading: analogous to var_subheading but for bands (default FALSE)
titleSection header used in the report
descriptionDescription used in the report
lpjmlstats::Metric$add_compare_meta()lpjmlstats::Metric$add_comparisons()lpjmlstats::Metric$capture_summary()lpjmlstats::Metric$generate_report_content()lpjmlstats::Metric$print_metric_description()lpjmlstats::Metric$print_metric_header()lpjmlstats::Metric$print_year_subset()lpjmlstats::Metric$store_summary()lpjmlstats::Metric$transform_lpjml_calcs()lpjmlstats::TimeAvgMap$summarize()lpjmlstats::TimeAvgMapWithAbs$arrange_plots()lpjmlstats::TimeAvgMapWithAbs$plot()compare()
Compare the baseline summary with the under test summaries by subtracting the baseline from the under test. The baseline is then set to NULL so it is omitted when printing the plots.
TimeAvgMapWithAbsUndertest$compare(var_grp)
var_grpvariable group
clone()
The objects of this class are cloneable with this method.
TimeAvgMapWithAbsUndertest$clone(deep = FALSE)
deepWhether to make a deep clone.