From 2d09972a716509d9b3415af69906504e3b357e23 Mon Sep 17 00:00:00 2001 From: vagudets Date: Fri, 3 May 2024 16:15:11 +0200 Subject: [PATCH] Add Visualization:NA_color option to recipe --- modules/Visualization/R/plot_ensemble_mean.R | 3 +++ modules/Visualization/R/plot_metrics.R | 3 +++ tools/check_recipe.R | 11 +++++++++++ 3 files changed, 17 insertions(+) diff --git a/modules/Visualization/R/plot_ensemble_mean.R b/modules/Visualization/R/plot_ensemble_mean.R index 59881864..bada0a6e 100644 --- a/modules/Visualization/R/plot_ensemble_mean.R +++ b/modules/Visualization/R/plot_ensemble_mean.R @@ -53,6 +53,8 @@ plot_ensemble_mean <- function(recipe, fcst, mask = NULL, dots = NULL, outdir, o palette = "RdBu" rev = T } + # Define NA color + colNA <- recipe$Analysis$Workflow$Visualization$NA_color # Define brks, centered around zero in the case of anomalies if (grepl("anomaly", var_long_name)) { variable <- paste(variable, "anomaly") @@ -138,6 +140,7 @@ plot_ensemble_mean <- function(recipe, fcst, mask = NULL, dots = NULL, outdir, o titles = titles, units = units, cols = cols, + colNA = colNA, brks = brks, fileout = paste0(outfile, ".pdf"), bar_label_digits = 4, diff --git a/modules/Visualization/R/plot_metrics.R b/modules/Visualization/R/plot_metrics.R index 92b707fa..5efaa45b 100644 --- a/modules/Visualization/R/plot_metrics.R +++ b/modules/Visualization/R/plot_metrics.R @@ -58,6 +58,8 @@ plot_metrics <- function(recipe, data_cube, metrics, diverging_palette <- "bluered" sequential_palette <- "Reds" } + # Define NA color + colNA <- recipe$Analysis$Workflow$Visualization$NA_color # Group different metrics by type skill_scores <- c("rpss", "bss90", "bss10", "frpss", "crpss", "mean_bias_ss", "enscorr", "rpss_specs", "bss90_specs", "bss10_specs", @@ -242,6 +244,7 @@ plot_metrics <- function(recipe, data_cube, metrics, title_scale = 0.6, filled.continents = F, brks = brks, cols = cols, col_inf = col_inf, col_sup = col_sup, + colNA = colNA, units = units, font.main = 2, bar_label_digits = 3, bar_label_scale = 1.5, axes_label_scale = 1, width = 8, height = 5) diff --git a/tools/check_recipe.R b/tools/check_recipe.R index 42cb832c..ce411a73 100644 --- a/tools/check_recipe.R +++ b/tools/check_recipe.R @@ -612,6 +612,17 @@ check_recipe <- function(recipe) { paste0("Visualization:projection not specified for the plots, the ", "default projection is cylindrical equidistant.")) } + # Check NA color + if (is.null(recipe$Analysis$Workflow$Visualization$NA_color)) { + warn(recipe$Run$logger, + paste0("Visualization:NA_color not specified for the plots, the ", + "default color is pink.")) + recipe$Analysis$Workflow$Visualization$NA_color <- "pink" + } else if (!.IsColor(recipe$Analysis$Workflow$Visualization$NA_color)) { + error(recipe$Run$logger, + paste0("Visualization:NA_color value is not a valid color.")) + error_status <- TRUE + } ## TODO: Add significance? if ("most_likely_terciles" %in% plots) { if (is.null(recipe$Analysis$Workflow$Visualization$mask_terciles)) { -- GitLab