From 48701749cbb2b5f7d0bbf9e3acfb67952a941c50 Mon Sep 17 00:00:00 2001 From: Victoria Agudetse Roures Date: Thu, 23 Feb 2023 16:48:53 +0100 Subject: [PATCH 1/4] Add startdate or initialization month to the names of the plots --- modules/Visualization/Visualization.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/Visualization/Visualization.R b/modules/Visualization/Visualization.R index a8664569..49d2c3b0 100644 --- a/modules/Visualization/Visualization.R +++ b/modules/Visualization/Visualization.R @@ -183,7 +183,7 @@ plot_skill_metrics <- function(recipe, archive, data_cube, skill_metrics, skill_significance <- NULL } # Define output file name and titles - outfile <- paste0(outdir, name, ".png") + outfile <- paste0(outdir, name, "_", tolower(init_month), ".png") toptitle <- paste(display_name, "-", data_cube$Variable$varName, "-", system_name, "-", init_month, hcst_period) months <- unique(lubridate::month(data_cube$Dates$start, @@ -275,7 +275,7 @@ plot_ensemble_mean <- function(recipe, archive, fcst, outdir) { # Define name of output file and titles if (length(start_date) == 1) { i_ensemble_mean <- ensemble_mean - outfile <- paste0(outdir, "forecast_ensemble_mean.png") + outfile <- paste0(outdir, "forecast_ensemble_mean_", start_date, ".png") } else { i_ensemble_mean <- ensemble_mean[which(start_date == i_syear), , , ] outfile <- paste0(outdir, "forecast_ensemble_mean_", i_syear, ".png") @@ -355,7 +355,8 @@ plot_most_likely_terciles <- function(recipe, archive, # Define name of output file and titles if (length(start_date) == 1) { i_probs_fcst <- probs_fcst - outfile <- paste0(outdir, "forecast_most_likely_tercile.png") + outfile <- paste0(outdir, "forecast_most_likely_tercile_", start_date, + " .png") } else { i_probs_fcst <- probs_fcst[which(start_date == i_syear), , , , ] outfile <- paste0(outdir, "forecast_most_likely_tercile_", i_syear, ".png") -- GitLab From fb08e2a3a0b84d180ce8d63271b5ff7d57899de6 Mon Sep 17 00:00:00 2001 From: Victoria Agudetse Roures Date: Tue, 14 Mar 2023 14:36:31 +0100 Subject: [PATCH 2/4] Add full month label to skill plot names --- modules/Visualization/Visualization.R | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/Visualization/Visualization.R b/modules/Visualization/Visualization.R index 49d2c3b0..22da4d36 100644 --- a/modules/Visualization/Visualization.R +++ b/modules/Visualization/Visualization.R @@ -86,9 +86,11 @@ plot_skill_metrics <- function(recipe, archive, data_cube, skill_metrics, system_name <- archive$System[[recipe$Analysis$Datasets$System$name]]$name hcst_period <- paste0(recipe$Analysis$Time$hcst_start, "-", recipe$Analysis$Time$hcst_end) - init_month <- lubridate::month(as.numeric(substr(recipe$Analysis$Time$sdate, - start = 1, stop = 2)), - label = T, abb = T) + init_month <- as.numeric(substr(recipe$Analysis$Time$sdate, + start = 1, stop = 2)) + month_label <- tolower(month.name[init_month]) + month_abbreviation <- month.abb[init_month] + # Define color palette and number of breaks according to output format ## TODO: Make separate function if (tolower(recipe$Analysis$Output_format) %in% c("scorecards", "cerise")) { @@ -183,11 +185,12 @@ plot_skill_metrics <- function(recipe, archive, data_cube, skill_metrics, skill_significance <- NULL } # Define output file name and titles - outfile <- paste0(outdir, name, "_", tolower(init_month), ".png") + outfile <- paste0(outdir, name, "-", month_label, ".png") toptitle <- paste(display_name, "-", data_cube$Variable$varName, - "-", system_name, "-", init_month, hcst_period) + "-", system_name, "-", month_abbreviation, + hcst_period) months <- unique(lubridate::month(data_cube$Dates$start, - label = T, abb = F)) + label = T, abb = F)) titles <- as.vector(months) # Plot suppressWarnings( -- GitLab From a3ddfe22125680a7da1ca6bd1c7cba754a36475e Mon Sep 17 00:00:00 2001 From: Victoria Agudetse Roures Date: Wed, 15 Mar 2023 13:21:32 +0100 Subject: [PATCH 3/4] Change seasonal unit test. Decadal WIP --- modules/Visualization/Visualization.R | 11 ++++++----- tests/testthat/test-decadal_monthly_1.R | 4 ++-- tests/testthat/test-seasonal_monthly.R | 5 +++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/modules/Visualization/Visualization.R b/modules/Visualization/Visualization.R index 22da4d36..b171f45a 100644 --- a/modules/Visualization/Visualization.R +++ b/modules/Visualization/Visualization.R @@ -6,6 +6,7 @@ source("modules/Visualization/tmp/clim.palette.R") ## TODO: Add the possibility to read the data directly from netCDF ## TODO: Adapt to multi-model case ## TODO: Add param 'raw'? +## TODO: Decadal plot names plot_data <- function(recipe, data, @@ -278,10 +279,10 @@ plot_ensemble_mean <- function(recipe, archive, fcst, outdir) { # Define name of output file and titles if (length(start_date) == 1) { i_ensemble_mean <- ensemble_mean - outfile <- paste0(outdir, "forecast_ensemble_mean_", start_date, ".png") + outfile <- paste0(outdir, "forecast_ensemble_mean-", start_date, ".png") } else { i_ensemble_mean <- ensemble_mean[which(start_date == i_syear), , , ] - outfile <- paste0(outdir, "forecast_ensemble_mean_", i_syear, ".png") + outfile <- paste0(outdir, "forecast_ensemble_mean-", i_syear, ".png") } toptitle <- paste("Forecast Ensemble Mean -", variable, "-", system_name, "- Initialization:", i_syear) @@ -358,11 +359,11 @@ plot_most_likely_terciles <- function(recipe, archive, # Define name of output file and titles if (length(start_date) == 1) { i_probs_fcst <- probs_fcst - outfile <- paste0(outdir, "forecast_most_likely_tercile_", start_date, - " .png") + outfile <- paste0(outdir, "forecast_most_likely_tercile-", start_date, + ".png") } else { i_probs_fcst <- probs_fcst[which(start_date == i_syear), , , , ] - outfile <- paste0(outdir, "forecast_most_likely_tercile_", i_syear, ".png") + outfile <- paste0(outdir, "forecast_most_likely_tercile-", i_syear, ".png") } toptitle <- paste("Most Likely Tercile -", variable, "-", system_name, "-", "Initialization:", i_syear) diff --git a/tests/testthat/test-decadal_monthly_1.R b/tests/testthat/test-decadal_monthly_1.R index b76a216c..b9d90d68 100644 --- a/tests/testthat/test-decadal_monthly_1.R +++ b/tests/testthat/test-decadal_monthly_1.R @@ -275,8 +275,8 @@ c("plots", "tas_19911101.nc", "tas_19921101.nc", "tas_19931101.nc", "tas_1994110 test_that("5. Visualization", { expect_equal( list.files(paste0(outdir, "/plots/")), -c("forecast_ensemble_mean.png", "forecast_most_likely_tercile.png", - "rpss.png") +c("forecast_ensemble_mean-20211101.png", "forecast_most_likely_tercile-20211101.png", + "rpss-november.png") ) }) diff --git a/tests/testthat/test-seasonal_monthly.R b/tests/testthat/test-seasonal_monthly.R index de03bf73..902fbe1b 100644 --- a/tests/testthat/test-seasonal_monthly.R +++ b/tests/testthat/test-seasonal_monthly.R @@ -228,8 +228,9 @@ c("plots", "tas_19931101.nc", "tas_19941101.nc", "tas_19951101.nc", test_that("5. Visualization", { expect_equal( list.files(paste0(outdir, "/plots/")), -c("crpss.png", "enscorr_specs.png", "enscorr.png", "forecast_ensemble_mean.png", - "forecast_most_likely_tercile.png", "rpss.png") +c("crpss-november.png", "enscorr_specs-november.png", "enscorr-november.png", + "forecast_ensemble_mean-20201101.png", "forecast_most_likely_tercile-20201101.png", + "rpss-november.png") ) }) -- GitLab From 2c159dad5e9cf7369f71dfebf8ee4d6798f69662 Mon Sep 17 00:00:00 2001 From: Victoria Agudetse Roures Date: Wed, 12 Apr 2023 09:54:22 +0200 Subject: [PATCH 4/4] Fix formatting and unit tests --- modules/Visualization/Visualization.R | 10 +++++----- tests/testthat/test-decadal_monthly_2.R | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/Visualization/Visualization.R b/modules/Visualization/Visualization.R index a878c5cc..c3ce7dfc 100644 --- a/modules/Visualization/Visualization.R +++ b/modules/Visualization/Visualization.R @@ -202,11 +202,11 @@ plot_skill_metrics <- function(recipe, archive, data_cube, skill_metrics, asplit(skill, MARGIN=1), # Splitting array into a list longitude, latitude, special_args = skill_significance, - dot_symbol = 20, - toptitle = toptitle, - title_scale = 0.6, - titles = titles, - filled.continents=F, + dot_symbol = 20, + toptitle = toptitle, + title_scale = 0.6, + titles = titles, + filled.continents=F, brks = brks, cols = cols, col_inf = col_inf, diff --git a/tests/testthat/test-decadal_monthly_2.R b/tests/testthat/test-decadal_monthly_2.R index a242defd..40a56abf 100644 --- a/tests/testthat/test-decadal_monthly_2.R +++ b/tests/testthat/test-decadal_monthly_2.R @@ -271,7 +271,7 @@ length(list.files(outdir)), test_that("5. Visualization", { expect_equal( all(list.files(paste0(outdir, "/plots/")) %in% -c("bss10_specs.png", "enscorr_specs.png", "forecast_ensemble_mean_2020.png", "forecast_ensemble_mean_2021.png", "forecast_most_likely_tercile_2020.png", "forecast_most_likely_tercile_2021.png", "frps_specs.png", "frps.png", "rpss_specs.png") +c("bss10_specs.png", "enscorr_specs.png", "forecast_ensemble_mean-2020.png", "forecast_ensemble_mean-2021.png", "forecast_most_likely_tercile-2020.png", "forecast_most_likely_tercile-2021.png", "frps_specs.png", "frps.png", "rpss_specs.png") ), TRUE ) -- GitLab