Skip to content

Commit

Permalink
Merge pull request #7 from ricardarosemann/color-calibration
Browse files Browse the repository at this point in the history
Brick color scheme in calibration plots and other small changes
  • Loading branch information
ricardarosemann authored Jun 19, 2024
2 parents 5bb270e + 338db04 commit e7d203f
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ValidationKey: '814793'
ValidationKey: '834834'
AutocreateReadme: yes
AcceptedWarnings:
- 'Warning: package ''.*'' was built under R version'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ cff-version: 1.2.0
message: If you use this software, please cite it using the metadata from this file.
type: software
title: 'reportbrick: Reporting package for BRICK'
version: 0.4.1
date-released: '2024-05-30'
version: 0.4.2
date-released: '2024-06-03'
abstract: 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:
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: reportbrick
Title: Reporting package for BRICK
Version: 0.4.1
Date: 2024-05-30
Version: 0.4.2
Date: 2024-06-03
Authors@R: c(
person("Robin", "Hasse", , "robin.hasse@pik-potsdam.de",
role = c("aut", "cre"),
Expand All @@ -21,7 +21,7 @@ Imports:
knitr,
madrat,
magclass,
mip (>= 0.148.17),
mip (>= 0.148.18),
piamPlotComparison,
piamutils (>= 0.0.9),
purrr,
Expand Down
2 changes: 1 addition & 1 deletion R/plotBRICKcalib.R → R/plotBRICKCalib.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ plotBRICKCalib <- function(path = ".", cal = "BRICK_calibration_report.csv",
render(
file.path(finalOutputDir, "plotsCalibration.Rmd"),
output_dir = finalOutputDir,
output_file = paste0("CES_calibration_report_", outName, ".pdf"),
output_file = paste0("BRICK_calibration_report_", outName, ".pdf"),
output_format = "pdf_document",
params = yamlParams
)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Reporting package for BRICK

R package **reportbrick**, version **0.4.1**
R package **reportbrick**, version **0.4.2**

[![CRAN status](https://www.r-pkg.org/badges/version/reportbrick)](https://cran.r-project.org/package=reportbrick) [![R build status](https://github.com/pik-piam/reportbrick/workflows/check/badge.svg)](https://github.com/pik-piam/reportbrick/actions) [![codecov](https://codecov.io/gh/pik-piam/reportbrick/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/reportbrick) [![r-universe](https://pik-piam.r-universe.dev/badges/reportbrick)](https://pik-piam.r-universe.dev/builds)

Expand Down Expand Up @@ -38,7 +38,7 @@ In case of questions / problems please contact Robin Hasse <robin.hasse@pik-pots

To cite package **reportbrick** in publications use:

Hasse R, Rosemann R (2024). _reportbrick: Reporting package for BRICK_. R package version 0.4.1, <https://github.com/pik-piam/reportbrick>.
Hasse R, Rosemann R (2024). _reportbrick: Reporting package for BRICK_. R package version 0.4.2, <https://github.com/pik-piam/reportbrick>.

A BibTeX entry for LaTeX users is

Expand All @@ -47,7 +47,7 @@ A BibTeX entry for LaTeX users is
title = {reportbrick: Reporting package for BRICK},
author = {Robin Hasse and Ricarda Rosemann},
year = {2024},
note = {R package version 0.4.1},
note = {R package version 0.4.2},
url = {https://github.com/pik-piam/reportbrick},
}
```
30 changes: 21 additions & 9 deletions inst/plotsCalibrationReporting/plotsCalibration.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ output:
params:
docTitle: "BRICK calibration report"
cal: "BRICK_calibration_report.csv"
path: "C:\\Users\\ricardar\\Documents\\Results\\BRICK\\calibration-tests\\extrElec-vin\\lowEhp1-2010-30Iter0_1A"
path: ""
scenNames: NULL
savePlots: TRUE
savePlots: false
name: ""
---

```{r setup, include=FALSE}
library(dplyr) #nolint: undesirable_function_linter.
# nolint start: undesirable_function_linter.
library(dplyr, include.only = c("%>%", "across", "any_of", ".data", "filter", "mutate",
"select", "where"))
# nolint end
knitr::opts_chunk$set(
echo = FALSE,
Expand All @@ -34,8 +38,8 @@ filePath <- file.path(params$path, params$cal)
# Check if at least one file in the given paths exists
if (!any(file.exists(filePath))) {
message("No BRICK_calibration_report.csv file found",
"BRICK_calibration_calibration.csv is normally produced during calibration runs.")
message("No BRICK_calibration_report.csv file found.\n",
"BRICK_calibration_report.csv is normally produced during calibration runs.")
knitr::knit_exit()
}
Expand All @@ -50,18 +54,26 @@ outPath <- dirname(filePath[1])
# Standard procedure to write a calibration plot
.createCalibrationPlot <- function(data, varName, outPath, outName = "",
color = NULL, savePlots = FALSE) {
color = NULL, facets = c("loc", "typ"),
yToZero = TRUE, savePlots = FALSE) {
# Extract the data
plData <- data %>%
filter(.data[["variable"]] == varName) %>%
filter(.data[["variable"]] %in% varName) %>%
select(where(~ any(!is.na(.x))))
# Read color map if available and rename corresponding entries
if (!is.null(color)) {
colorMap <- unlist(readBrickSets(NULL)[[color]][["elements"]])
plData <- plData %>%
mutate(across(any_of(color), ~ factor(colorMap[.x], levels = colorMap)))
}
# Create the plots
plList <- mip::mipIterations(plData, returnGgplots = TRUE, xAxis = "iteration",
color = color, facets = c("loc", "typ"),
color = color, facets = facets,
slider = NULL, facetScales = "free")
# Modify, save and show the plots
purrr::walk(plList, function(pl) {
pl <- pl + ggplot2::expand_limits(y = 0)
if (isTRUE(yToZero)) pl <- pl + ggplot2::expand_limits(y = 0)
if (!is.null(color)) pl <- pl + ggplot2::scale_colour_manual(values = mip::plotstyle(colorMap))
# Currently, this overwrites previous plots so that only the last one remains
if (isTRUE(savePlots)) {
ggplot2::ggsave(file.path(outPath, paste0(paste(varName, outName, sep = "_"), ".png")), pl)
Expand Down
2 changes: 1 addition & 1 deletion man/plotBRICKCalib.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e7d203f

Please sign in to comment.