diff --git a/modules/Visualization/Visualization.R b/modules/Visualization/Visualization.R index 6aa6b3134d8ece2e176d3f303253c90ae63d7d3b..c3ce7dfc9674a562e1620a1f96a81fabcdcdad7a 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, @@ -86,9 +87,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")) { @@ -182,11 +185,16 @@ plot_skill_metrics <- function(recipe, archive, data_cube, skill_metrics, skill_significance <- NULL } # Define output file name and titles - outfile <- paste0(outdir, name, ".png") + if (tolower(recipe$Analysis$Horizon) == "seasonal") { + outfile <- paste0(outdir, name, "-", month_label, ".png") + } else { + outfile <- paste0(outdir, name, ".png") + } toptitle <- paste(display_name, "-", data_cube$attrs$Variable$varName, - "-", system_name, "-", init_month, hcst_period) + "-", system_name, "-", month_abbreviation, + hcst_period) months <- unique(lubridate::month(data_cube$attrs$Dates, - label = T, abb = F)) + label = T, abb = F)) titles <- as.vector(months) # Plot suppressWarnings( @@ -194,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, @@ -274,10 +282,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.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) @@ -354,10 +362,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.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 c25d953ba30773c63f7038ce8d314830d36cee0c..899740cc4caa076176420f7c4560ffc53cc37eb6 100644 --- a/tests/testthat/test-decadal_monthly_1.R +++ b/tests/testthat/test-decadal_monthly_1.R @@ -280,7 +280,7 @@ length(list.files(outdir)), test_that("5. Visualization", { expect_equal( all(list.files(paste0(outdir, "/plots/")) %in% -c("forecast_ensemble_mean.png", "forecast_most_likely_tercile.png", +c("forecast_ensemble_mean-2021.png", "forecast_most_likely_tercile-2021.png", "rpss.png")), TRUE ) diff --git a/tests/testthat/test-decadal_monthly_2.R b/tests/testthat/test-decadal_monthly_2.R index a242defd3ac8ae150f4332de20a1cc41e0c42501..40a56abf37a826fe268d14560390aa9f6e1f0c2b 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 ) diff --git a/tests/testthat/test-seasonal_monthly.R b/tests/testthat/test-seasonal_monthly.R index f05efc9422d9b3237488d8ee248ec692093efa12..40f565c438f465d026729f162b8a7a244d8cff2a 100644 --- a/tests/testthat/test-seasonal_monthly.R +++ b/tests/testthat/test-seasonal_monthly.R @@ -233,8 +233,9 @@ length(list.files(outdir)), test_that("5. Visualization", { expect_equal( all(list.files(paste0(outdir, "/plots/")) %in% -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")), TRUE ) expect_equal(