From 47662c371753407f6d6ac80996df47bceb688992 Mon Sep 17 00:00:00 2001 From: vagudets Date: Tue, 15 Jul 2025 14:48:59 +0200 Subject: [PATCH 1/8] Same as bigpredidata --- .../bigpredidata/script_bigpredidata_oper.R | 15 ++++++-------- .../recipe_bigpredidata_oper_subseasonal.yml | 20 +++++++++++-------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/operationals/bigpredidata/script_bigpredidata_oper.R b/operationals/bigpredidata/script_bigpredidata_oper.R index 4ce1cb59..5249a8a0 100644 --- a/operationals/bigpredidata/script_bigpredidata_oper.R +++ b/operationals/bigpredidata/script_bigpredidata_oper.R @@ -9,6 +9,12 @@ recipe_file <- args[1] #recipe_file <- "/esarchive/scratch/ptrascas/R/dev-test_bigpredidata/sunset/sunset/recipes/recipe_bigpredidata_oper_test_sfcWind.yml" #recipe_file <- "/esarchive/scratch/ptrascas/R/dev-test_bigpredidata/sunset/sunset/recipes/recipe_bigpredidata_oper.yml" recipe <- read_atomic_recipe(recipe_file) + +if (recipe$Analysis$Region$name == "EU") { + recipe$Analysis$Regrid$type <- + "/gpfs/projects/bsc32/esarchive_cache/exp/ncep/cfs-v2/weekly_mean/s2s/tas_f24h/tas_20050109.nc" +} + #recipe <- prepare_outputs(recipe_file) # Load datasets data <- Loading(recipe) @@ -25,13 +31,4 @@ skill_metrics <- Crossval_metrics(recipe = recipe, data = data, Visualization(recipe = recipe, data = data, skill_metrics = skill_metrics, significance = TRUE, probabilities = data$probs) -#if (!is.null(data$fcst)) { -# # Required to plot a forecast: -# data$fcst <- res$fcst -# Visualization(recipe = recipe, data = data, skill_metrics = skill_metrics, -# significance = TRUE, probabilities = res$probs) -#} else { -# Visualization(recipe = recipe, data = data, skill_metrics = skill_metrics, -# significance = TRUE) -#} diff --git a/operationals/test/recipe_bigpredidata_oper_subseasonal.yml b/operationals/test/recipe_bigpredidata_oper_subseasonal.yml index 700c420a..45a2342a 100755 --- a/operationals/test/recipe_bigpredidata_oper_subseasonal.yml +++ b/operationals/test/recipe_bigpredidata_oper_subseasonal.yml @@ -6,9 +6,12 @@ Description: Analysis: Horizon: subseasonal # Mandatory, str: either subseasonal, seasonal, or decadal Variables: - - {name: tas, freq: weekly_mean, units: C} - - {name: prlr, freq: weekly_mean, units: mm, flux: no} - - {name: sfcWind, freq: weekly_mean} + - {name: 'tasmin', freq: 'weekly_mean', units: 'C'} + - {name: 'tasmax', freq: 'weekly_mean', units: 'C'} + - {name: 'tas', freq: 'weekly_mean', units: 'C'} + - {name: 'prlr', freq: 'weekly_mean', units: 'mm', flux: no} + - {name: 'sfcWind', freq: 'weekly_mean'} + - {name: 'rsds', freq: 'weekly_mean'} Datasets: System: - {name: 'NCEP-CFSv2', member: 'all'} @@ -26,10 +29,11 @@ Analysis: sweek_window: 9 sday_window: 3 Region: - - {name: "Iberia", latmin: 36, latmax: 44, lonmin: -10, lonmax: 5} + - {name: "Iberia", latmin: 36, latmax: 44, lonmin: -10, lonmax: 5} + - {name: "EU", latmin: 20, latmax: 80, lonmin: -20, lonmax: 40} Regrid: method: bilinear # Mandatory, str: Interpolation method. See docu. - type: "to_system" + type: "to_reference" #type: /esarchive/scratch/nmilders/gitlab/git_clones/auto-s2s/conf/grid_description.txt #'r360x180' # Mandatory, str: to_system, to_reference, or CDO-accepted grid. Workflow: Anomalies: @@ -59,7 +63,7 @@ Analysis: file_format: PNG # Final file format of the plots. Formats available: PNG, JPG, JPEG, EPS. Defaults to PDF. ncores: 16 # Optional, int: number of cores, defaults to 1 remove_NAs: TRUE # Optional, bool: Whether NAs are removed, defaults to FALSE - Output_format: scorecards + Output_format: S2S4E logo: yes Run: Loglevel: INFO @@ -70,10 +74,10 @@ Run: autosubmit: yes # fill only if using autosubmit auto_conf: - script: scripts/script_bigpredidata_oper.R # replace with the path to your script + script: operationals/bigpredidata/script_bigpredidata_oper.R # replace with the path to your script expid: a6wq # replace with your EXPID hpc_user: bsc032762 # replace with your hpc username - wallclock: 02:00 # hh:mm + wallclock: 03:00 # hh:mm processors_per_job: 24 custom_directives: platform: amd -- GitLab From 07e1ab52e7f09c49d9d2e776fe0f5973f0e4fdb9 Mon Sep 17 00:00:00 2001 From: vagudets Date: Wed, 16 Jul 2025 14:00:29 +0200 Subject: [PATCH 2/8] Use na.rm = FALSE for MergeDims() --- modules/Crossval/Crossval_calibration.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/Crossval/Crossval_calibration.R b/modules/Crossval/Crossval_calibration.R index 75765e75..48f250c9 100644 --- a/modules/Crossval/Crossval_calibration.R +++ b/modules/Crossval/Crossval_calibration.R @@ -56,10 +56,10 @@ Crossval_calibration <- function(recipe, data, correct_negative = FALSE) { if (horizon == 'subseasonal') { central_day <- (dim(exp)['sday'] + 1)/2 hcst_tr <- MergeDims(hcst_tr, merge_dims = c('sday', 'syear'), - rename_dim = 'syear', na.rm = na.rm) + rename_dim = 'syear', na.rm = FALSE) obs_tr <- MergeDims(obs_tr, merge_dims = c('sday', 'syear'), - rename_dim = 'syear', na.rm = na.rm) + rename_dim = 'syear', na.rm = FALSE) # 'sday' dim to select the central day hcst_ev <- Subset(hcst_ev, along = 'sday', indices = central_day, drop = 'selected') -- GitLab From e48741396bba3542be2adcf70b184a8d7bb29092 Mon Sep 17 00:00:00 2001 From: vagudets Date: Wed, 16 Jul 2025 14:00:39 +0200 Subject: [PATCH 3/8] Add missing weekly variables --- conf/archive_reference.yml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/conf/archive_reference.yml b/conf/archive_reference.yml index b3a75502..fa58832e 100644 --- a/conf/archive_reference.yml +++ b/conf/archive_reference.yml @@ -13,14 +13,20 @@ gpfs: "tasmin":"daily/tasmin-r1440x721cds/", "ta500":"daily_mean/ta500_f1h-r1440x721cds/"} weekly_mean: {"tas":"weekly_mean/tas_f1h-r1440x721cds/", + "tasmax":"weekly_mean/tasmax_f24h-r1440x721cds/", + "tasmin":"weekly_mean/tasmin_f24h-r1440x721cds/", "psl":"weekly_mean/psl_f1h-r1440x721cds/", "prlr":"weekly_mean/prlr_f1h-r1440x721cds/", - "sfcWind":"weekly_mean/sfcWind_f1h-r1440x721cds/"} + "sfcWind":"weekly_mean/sfcWind_f1h-r1440x721cds/", + "rsds": "weekly_mean/rsds_f1h-r1440x721cds/"} monthly_mean: {"tas":"monthly_mean/tas_f1h-r1440x721cds/", + "tasmax":"monthly_mean/tasmax_f24h-r1440x721cds/", + "tasmin":"monthly_mean/tasmin_f24h-r1440x721cds/", "tos":"monthly_mean/tos_f1h-r1440x721cds/", "psl":"monthly_mean/psl_f1h-r1440x721cds/", "prlr":"monthly_mean/prlr_f1h-r1440x721cds/", - "sfcWind":"monthly_mean/sfcWind_f1h-r1440x721cds/"} + "sfcWind":"monthly_mean/sfcWind_f1h-r1440x721cds/", + "rsds":"monthly_mean/rsds_f1h-r1440x721cds/"} calendar: "standard" reference_grid: "/gpfs/projects/bsc32/esarchive_cache/recon/ecmwf/era5/monthly_mean/tas_f1h-r1440x721cds/tas_201805.nc" land_sea_mask: "/gpfs/projects/bsc32/esarchive_cache/recon/ecmwf/era5/constant/lsm-r1440x721cds/sftof.nc" @@ -67,6 +73,7 @@ esarchive: "g300":"monthly_mean/g300_f1h-r1440x721cds/", "g500":"monthly_mean/g500_f1h-r1440x721cds/", "g850":"monthly_mean/g850_f1h-r1440x721cds/", + "hurs":"monthly_mean/hurs_f1h-r1440x721cds/", "sfcWind":"monthly_mean/sfcWind_f1h-r1440x721cds/", "tasmax":"monthly_mean/tasmax_f24h-r1440x721cds/", "tasmin":"monthly_mean/tasmin_f24h-r1440x721cds/", -- GitLab From a29f21fa4419f5399e41b4ef85f5885f29e5380d Mon Sep 17 00:00:00 2001 From: vagudets Date: Wed, 16 Jul 2025 14:01:03 +0200 Subject: [PATCH 4/8] Bugfix: include region folder in S2S4E format --- modules/Saving/R/get_dir.R | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/Saving/R/get_dir.R b/modules/Saving/R/get_dir.R index 97208b3e..be775617 100644 --- a/modules/Saving/R/get_dir.R +++ b/modules/Saving/R/get_dir.R @@ -47,6 +47,7 @@ get_dir <- function(recipe, variable, agg = "global") { } } store.freq <- recipe$Analysis$Variables$freq + outdir <- paste0(outdir, "/", region) switch(tolower(agg), "region" = {dir <- paste0(outdir, "/", system, "/", calib.method, "-", store.freq, "/", variable, -- GitLab From cac6a38f091f34d471e461e3dfdb1b9e8c620bf5 Mon Sep 17 00:00:00 2001 From: vagudets Date: Thu, 17 Jul 2025 09:20:39 +0200 Subject: [PATCH 5/8] Save only forecast probabilities --- modules/Crossval/Crossval_anomalies.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/Crossval/Crossval_anomalies.R b/modules/Crossval/Crossval_anomalies.R index c22464e0..d33aab80 100644 --- a/modules/Crossval/Crossval_anomalies.R +++ b/modules/Crossval/Crossval_anomalies.R @@ -420,12 +420,12 @@ Crossval_anomalies <- function(recipe, data) { if (recipe$Analysis$Workflow$Probabilities$save %in% c('all', 'bins_only')) { - save_probabilities(recipe = recipe, probs = probs_hcst, - data_cube = data$hcst, agg = agg, - type = "hcst") - save_probabilities(recipe = recipe, probs = probs_obs, - data_cube = data$hcst, agg = agg, - type = "obs") + # save_probabilities(recipe = recipe, probs = probs_hcst, + # data_cube = data$hcst, agg = agg, + # type = "hcst") + # save_probabilities(recipe = recipe, probs = probs_obs, + # data_cube = data$hcst, agg = agg, + # type = "obs") if (length(probs_fcst) > 0) { save_probabilities(recipe = recipe, probs = probs_fcst, data_cube = data$fcst, agg = agg, -- GitLab From d6a8837f250322bbc117c9956949e98f2edaf7f9 Mon Sep 17 00:00:00 2001 From: vagudets Date: Thu, 17 Jul 2025 16:12:36 +0200 Subject: [PATCH 6/8] Use VizMostLikelyQuantileMap and VizCombinedMap --- .../R/plot_most_likely_terciles_map.R | 9 +- .../{PlotCombinedMap.R => VizCombinedMap.R} | 121 ++++++++++++------ ...antileMap.R => VizMostLikelyQuantileMap.R} | 99 +++++--------- 3 files changed, 115 insertions(+), 114 deletions(-) rename modules/Visualization/R/tmp/{PlotCombinedMap.R => VizCombinedMap.R} (80%) rename modules/Visualization/R/tmp/{PlotMostLikelyQuantileMap.R => VizMostLikelyQuantileMap.R} (67%) diff --git a/modules/Visualization/R/plot_most_likely_terciles_map.R b/modules/Visualization/R/plot_most_likely_terciles_map.R index 67802cf1..d2d92865 100644 --- a/modules/Visualization/R/plot_most_likely_terciles_map.R +++ b/modules/Visualization/R/plot_most_likely_terciles_map.R @@ -1,11 +1,10 @@ ## Functions required for normal cat and triangles end. ## See https://earth.bsc.es/gitlab/external/cstools/-/issues/125 -source("modules/Visualization/R/tmp/PlotMostLikelyQuantileMap.R") -source("modules/Visualization/R/tmp/PlotCombinedMap.R") +source("modules/Visualization/R/tmp/VizMostLikelyQuantileMap.R") +source("modules/Visualization/R/tmp/VizCombinedMap.R") source("modules/Visualization/R/tmp/ColorBar.R") source("modules/Visualization/R/tmp/clim.palette.R") source("modules/Visualization/R/tmp/Utils.R") -source("modules/Visualization/R/tmp/PlotEquiMap.R") source("modules/Visualization/R/tmp/ColorBar_onebox.R") source("modules/Visualization/R/tmp/GradientCatsColorBar.R") @@ -192,7 +191,7 @@ plot_most_likely_terciles <- function(recipe, ## NOTE: PlotLayout() and PlotMostLikelyQuantileMap() are still being worked ## on. This option does not work with mask or dots for now. suppressWarnings( - PlotLayout(PlotMostLikelyQuantileMap, c('bin', 'longitude', 'latitude'), + PlotLayout(VizMostLikelyQuantileMap, c('bin', 'longitude', 'latitude'), cat_dim = 'bin', i_var_probs, longitude, latitude, mask = var_mask, @@ -333,7 +332,7 @@ plot_most_likely_terciles <- function(recipe, base_args$probs <- i_var_probs[i, , , ] base_args$mask <- mask_i base_args$dots <- dots_i - cb_info <- do.call(PlotMostLikelyQuantileMap, + cb_info <- do.call(VizMostLikelyQuantileMap, args = c(base_args, list(toptitle = toptitle, fileout = fileout))) diff --git a/modules/Visualization/R/tmp/PlotCombinedMap.R b/modules/Visualization/R/tmp/VizCombinedMap.R similarity index 80% rename from modules/Visualization/R/tmp/PlotCombinedMap.R rename to modules/Visualization/R/tmp/VizCombinedMap.R index e4d6d7f3..50baf418 100644 --- a/modules/Visualization/R/tmp/PlotCombinedMap.R +++ b/modules/Visualization/R/tmp/VizCombinedMap.R @@ -27,14 +27,23 @@ #'@param map_dim Optional name for the dimension of 'maps' along which the #' multiple maps are arranged. Only applies when 'maps' is provided as a #' 3-dimensional array. Takes the value 'map' by default. -#'@param brks Colour levels to be sent to PlotEquiMap. This parameter is +#'@param brks Colour levels to be sent to VizEquiMap. This parameter is #' optional and adjusted automatically by the function. -#'@param cols List of vectors of colours to be sent to PlotEquiMap for the +#'@param cols List of vectors of colours to be sent to VizEquiMap for the #' colour bar of each map. This parameter is optional and adjusted #' automatically by the function (up to 5 maps). The colours provided for each #' colour bar will be automatically interpolated to match the number of breaks. #' Each item in this list can be named, and the name will be used as title for #' the corresponding colour bar (equivalent to the parameter 'bar_titles'). +#'@param bar_limits A numeric vector of 2 indicating the range of color bar. +#' The default is NULL, and the function will decide the range automatically. +#'@param triangle_ends A logical vector of two indicating if the lower and upper +#' triangles of the color bar should be plotted. The default is +#' c(FALSE, FALSE). +#'@param col_inf A character string of recognized color name or code indicating +#' the color of the lower triangle of the color bar. The default is NULL. +#'@param col_sup A character string of recognized color name or code indicating +#' the color of the upper triangle of the color bar. The default is NULL. #'@param col_unknown_map Colour to use to paint the grid cells for which a map #' is not possible to be chosen according to 'map_select_fun' or for those #' values that go beyond 'display_range'. Takes the value 'white' by default. @@ -59,7 +68,10 @@ #'@param plot_margin Numeric vector of length 4 for the margin sizes in the #' following order: bottom, left, top, and right. If not specified, use the #' default of par("mar"), c(5.1, 4.1, 4.1, 2.1). Used as 'margin_scale' in -#' s2dv::PlotEquiMap. +#' VizEquiMap. +#'@param bar_extra_margin A numeric vector of 4 indicating the extra margins to +#' be added around the color bar, in the format c(y1, x1, y2, x2). The units +#' are margin lines. The default values are c(2, 0, 2, 0). #'@param fileout File where to save the plot. If not specified (default) a #' graphics device will pop up. Extensions allowed: eps/ps, jpeg, png, pdf, bmp #' and tiff @@ -81,10 +93,10 @@ #'@param return_leg A logical value indicating if the color bars information #' should be returned by the function. If TRUE, the function doesn't plot the #' color bars but still creates the layout with color bar areas, and the -#' arguments for GradientCatsColorBar() or ColorBar() will be returned. It is -#' convenient for users to adjust the color bars manually. The default is -#' FALSE, the color bars will be plotted directly. -#'@param ... Additional parameters to be passed on to \code{PlotEquiMap}. +#' arguments for GradientCatsColorBar() or ColorBarContinuous() will be +#' returned. It is convenient for users to adjust the color bars manually. The +#' default is FALSE, the color bars will be plotted directly. +#'@param ... Additional parameters to be passed on to \code{VizEquiMap}. #' #'@examples #'# Simple example @@ -95,7 +107,7 @@ #'lons <- seq(0, 359.5, length = 20) #'lats <- seq(-89.5, 89.5, length = 10) #'\dontrun{ -#'PlotCombinedMap(list(a, b, c), lons, lats, +#'VizCombinedMap(list(a, b, c), lons, lats, #' toptitle = 'Maximum map', #' map_select_fun = max, #' display_range = c(0, 1), @@ -110,39 +122,41 @@ #'mask <- sample(c(0,1), replace = TRUE, size = 51 * 26) #'dim(mask) <- c(lat = 26, lon = 51) #'\dontrun{ -#'PlotCombinedMap(data, lon = Lon, lat = Lat, map_select_fun = max, +#'VizCombinedMap(data, lon = Lon, lat = Lat, map_select_fun = max, #' display_range = range(data), mask = mask, #' width = 14, height = 10) #'} #' -#'@seealso \code{PlotCombinedMap} and \code{PlotEquiMap} -#' -#'@importFrom s2dv PlotEquiMap ColorBar +#'@seealso \code{VizCombinedMap} and \code{VizEquiMap} +#' +#'@import utils #'@importFrom maps map #'@importFrom graphics box image layout mtext par plot.new #'@importFrom grDevices adjustcolor bmp colorRampPalette dev.cur dev.new dev.off #' hcl jpeg pdf png postscript svg tiff #'@export -PlotCombinedMap <- function(maps, lon, lat, - map_select_fun, display_range, - map_dim = 'map', - brks = NULL, cols = NULL, - bar_limits = NULL, triangle_ends = c(F, F), col_inf = NULL, col_sup = NULL, - col_unknown_map = 'white', - mask = NULL, col_mask = 'grey', - dots = NULL, - bar_titles = NULL, legend_scale = 1, - cex_bar_titles = 1.5, - plot_margin = NULL, bar_extra_margin = c(2, 0, 2, 0), - fileout = NULL, width = 8, height = 5, - size_units = 'in', res = 100, drawleg = T, return_leg = FALSE, - ...) { +VizCombinedMap <- function(maps, lon, lat, + map_select_fun, display_range, + map_dim = 'map', + brks = NULL, cols = NULL, + bar_limits = NULL, triangle_ends = c(FALSE, FALSE), + col_inf = NULL, col_sup = NULL, + col_unknown_map = 'white', + mask = NULL, col_mask = 'grey', + dots = NULL, + bar_titles = NULL, legend_scale = 1, + cex_bar_titles = 1.5, + plot_margin = NULL, bar_extra_margin = c(2, 0, 2, 0), + fileout = NULL, width = 8, height = 5, + size_units = 'in', res = 100, drawleg = T, return_leg = FALSE, + ...) { args <- list(...) - + country.borders <- if (!is.null(args$country.borders)) args$country.borders else FALSE + args$country.borders <- NULL # Prevent duplication + # If there is any filenames to store the graphics, process them # to select the right device if (!is.null(fileout)) { - .SelectDevice <- utils::getFromNamespace(".SelectDevice", "s2dv") deviceInfo <- .SelectDevice(fileout = fileout, width = width, height = height, units = size_units, res = res) saveToFile <- deviceInfo$fun @@ -315,6 +329,10 @@ PlotCombinedMap <- function(maps, lon, lat, #---------------------- # Identify the most likely map #---------------------- + #TODO: Consider col_inf + if (!is.null(colorbar$col_inf[[1]])) { + warning("Lower triangle is not supported now. Please contact maintainer if you have this need.") + } if (!is.null(colorbar$col_sup[[1]])) { brks_norm <- vector('list', length = nmap) @@ -355,11 +373,12 @@ PlotCombinedMap <- function(maps, lon, lat, } else { brks_norm <- vector('list', length = nmap) - range_width <- display_range[2] - display_range[1] #vector('list', length = nmap) + range_width <- vector('list', length = nmap) slightly_tune_val <- vector('list', length = nmap) for (ii in 1:nmap) { brks_norm[[ii]] <- seq(0, 1, length.out = length(colorbar$brks[[ii]])) slightly_tune_val[[ii]] <- brks_norm[[ii]][2] / (length(brks_norm[[ii]]) * 2) + range_width[[ii]] <- diff(range(colorbar$brks[[ii]])) } ml_map <- apply(maps, c(lat_dim, lon_dim), function(x) { if (any(is.na(x))) { @@ -367,15 +386,16 @@ PlotCombinedMap <- function(maps, lon, lat, } else { res <- which(x == map_select_fun(x)) if (length(res) > 0) { - res <- res[1] + res <- res_ind <- res[1] if (map_select_fun(x) < display_range[1] || map_select_fun(x) > display_range[2]) { res <- -0.5 } else { - res <- res + (map_select_fun(x) - display_range[1]) / range_width - if (map_select_fun(x) == display_range[1]) { - res <- res + slightly_tune_val - } + res <- res + ((map_select_fun(x) - colorbar$brks[[res_ind]][1]) / + range_width[[res_ind]]) + if (map_select_fun(x) == colorbar$brks[[res_ind]][1]) { + res <- res + slightly_tune_val[[res_ind]] + } } } else { res <- -0.5 @@ -422,7 +442,7 @@ PlotCombinedMap <- function(maps, lon, lat, } #---------------------- - # Set colors and breaks and then PlotEquiMap + # Set colors and breaks and then VizEquiMap #---------------------- if (!is.null(colorbar$col_sup[[1]])) { tcols <- c(col_unknown_map, colorbar$cols[[1]], colorbar$col_sup[[1]]) @@ -443,10 +463,15 @@ PlotCombinedMap <- function(maps, lon, lat, if (is.null(plot_margin)) { plot_margin <- c(5, 4, 4, 2) + 0.1 # default of par()$mar } - - PlotEquiMap(var = ml_map, lon = lon, lat = lat, - brks = tbrks, cols = tcols, drawleg = FALSE, - filled.continents = FALSE, dots = dots, margin_scale = plot_margin, ...) + + country.borders.VizEquiMap <- if (!is.null(mask)) FALSE else country.borders + + do.call(VizEquiMap, c(list( + var = ml_map, lon = lon, lat = lat, + brks = tbrks, cols = tcols, drawleg = FALSE, + filled.continents = FALSE, country.borders = country.borders.VizEquiMap, + dots = dots, margin_scale = plot_margin + ), args)) #---------------------- # Add overplot on top @@ -471,9 +496,22 @@ PlotCombinedMap <- function(maps, lon, lat, coast_color <- 'black' } if (min(lon) < 0) { - map('world', interior = FALSE, add = TRUE, lwd = 1, col = coast_color) # Low resolution world map (lon -180 to 180). + map('world', interior = country.borders, add = TRUE, lwd = 1, col = coast_color) # Low resolution world map (lon -180 to 180). } else { - map('world2', interior = FALSE, add = TRUE, lwd = 1, col = coast_color) # Low resolution world map (lon 0 to 360). + map('world2', interior = country.borders, add = TRUE, lwd = 1, col = coast_color) # Low resolution world map (lon 0 to 360). + } + if (!is.null(args$shapefile)) { + if (is.list(args$shapefile)) { + shape <- args$shapefile + } else { + shape <- readRDS(file = args$shapefile) + } + shapefile_color <- if (!is.null(args$shapefile_color)) args$shapefile_color else "black" + shapefile_lwd <- if (!is.null(args$shapefile_lwd)) args$shapefile_lwd else 1 + filled.continents <- if (!is.null(args$filled.continents)) args$filled.continents else FALSE + maps::map(shape, interior = country.borders, #wrap = wrap_vec, + fill = filled.continents, add = TRUE, plot = TRUE, + lwd = shapefile_lwd, col = shapefile_color) } box() } @@ -516,6 +554,7 @@ PlotCombinedMap <- function(maps, lon, lat, plot = TRUE, draw_separators = TRUE, bar_titles = bar_titles, title_scale = cex_bar_titles, label_scale = legend_scale * 1.5, extra_margin = bar_extra_margin) + warning("The device is not off yet. Use dev.off() after plotting the color bars.") return(tmp) #NOTE: The device is not off! Can keep plotting the color bars. } diff --git a/modules/Visualization/R/tmp/PlotMostLikelyQuantileMap.R b/modules/Visualization/R/tmp/VizMostLikelyQuantileMap.R similarity index 67% rename from modules/Visualization/R/tmp/PlotMostLikelyQuantileMap.R rename to modules/Visualization/R/tmp/VizMostLikelyQuantileMap.R index a81515e9..3bd75035 100644 --- a/modules/Visualization/R/tmp/PlotMostLikelyQuantileMap.R +++ b/modules/Visualization/R/tmp/VizMostLikelyQuantileMap.R @@ -38,9 +38,9 @@ #' 'down', 'd', 'D', 'bottom', 'b', 'B', 'south', 's', 'S' (default)\cr #' 'right', 'r', 'R', 'east', 'e', 'E'\cr #' 'left', 'l', 'L', 'west', 'w', 'W' -#'@param ... Additional parameters to be sent to \code{PlotCombinedMap} and -#' \code{PlotEquiMap}. -#'@seealso \code{PlotCombinedMap} and \code{PlotEquiMap} +#'@param ... Additional parameters to be sent to \code{VizCombinedMap} and +#' \code{VizEquiMap}. +#'@seealso \code{VizCombinedMap} and \code{VizEquiMap} #'@examples #'# Simple example #'x <- array(1:(20 * 10), dim = c(lat = 10, lon = 20)) / 200 @@ -50,54 +50,24 @@ #'lons <- seq(0, 359.5, length = 20) #'lats <- seq(-89.5, 89.5, length = 10) #'\dontrun{ -#'PlotMostLikelyQuantileMap(list(a, b, c), lons, lats, -#' toptitle = 'Most likely tercile map', -#' bar_titles = paste('% of belonging to', c('a', 'b', 'c')), -#' brks = 20, width = 10, height = 8) +#'VizMostLikelyQuantileMap(list(a, b, c), lons, lats, +#' toptitle = 'Most likely tercile map', +#' bar_titles = paste('% of belonging to', c('a', 'b', 'c')), +#' brks = 20, width = 10, height = 8) #'} #' #'# More complex example -#'n_lons <- 40 -#'n_lats <- 20 -#'n_timesteps <- 100 -#'n_bins <- 4 #' #'# 1. Generation of sample data -#'lons <- seq(0, 359.5, length = n_lons) -#'lats <- seq(-89.5, 89.5, length = n_lats) -#' -#'# This function builds a 3-D gaussian at a specified point in the map. -#'make_gaussian <- function(lon, sd_lon, lat, sd_lat) { -#' w <- outer(lons, lats, function(x, y) dnorm(x, lon, sd_lon) * dnorm(y, lat, sd_lat)) -#' min_w <- min(w) -#' w <- w - min_w -#' w <- w / max(w) -#' w <- t(w) -#' names(dim(w)) <- c('lat', 'lon') -#' w -#'} -#' -#'# This function generates random time series (with values ranging 1 to 5) -#'# according to 2 input weights. -#'gen_data <- function(w1, w2, n) { -#' r <- sample(1:5, n, -#' prob = c(.05, .9 * w1, .05, .05, .9 * w2), -#' replace = TRUE) -#' r <- r + runif(n, -0.5, 0.5) -#' dim(r) <- c(time = n) -#' r -#'} -#' -#'# We build two 3-D gaussians. -#'w1 <- make_gaussian(120, 80, 20, 30) -#'w2 <- make_gaussian(260, 60, -10, 40) +#'lons <- seq(0, 359.5, length = 40) +#'lats <- seq(-89.5, 89.5, length = 20) #' -#'# We generate sample data (with dimensions time, lat, lon) according -#'# to the generated gaussians -#'sample_data <- multiApply::Apply(list(w1, w2), NULL, -#' gen_data, n = n_timesteps)$output1 +#'# Generate sample data (with dimensions time, lat, lon) +#'sample_data <- sample(1:5, 50 * 20 * 40, replace = TRUE) +#'dim(sample_data) <- c(time = 50, lat = 20, lon = 40) #' #'# 2. Binning sample data +#'n_bins <- 4 #'prob_thresholds <- 1:n_bins / n_bins #'prob_thresholds <- prob_thresholds[1:(n_bins - 1)] #'thresholds <- quantile(sample_data, prob_thresholds) @@ -105,7 +75,6 @@ #'binning <- function(x, thresholds) { #' n_samples <- length(x) #' n_bins <- length(thresholds) + 1 -#' #' thresholds <- c(thresholds, max(x)) #' result <- 1:n_bins #' lower_threshold <- min(x) - 1 @@ -113,29 +82,26 @@ #' result[i] <- sum(x > lower_threshold & x <= thresholds[i]) / n_samples #' lower_threshold <- thresholds[i] #' } -#' #' dim(result) <- c(bin = n_bins) #' result #'} +#'bins <- apply(sample_data, 2:3, binning, thresholds) +#'names(dim(bins))[1] <- "bin" #' -#'bins <- multiApply::Apply(sample_data, 'time', binning, thresholds)$output1 -#' -#'# 3. Plotting most likely quantile/bin #'\dontrun{ -#'PlotMostLikelyQuantileMap(bins, lons, lats, -#' toptitle = 'Most likely quantile map', -#' bar_titles = paste('% of belonging to', letters[1:n_bins]), -#' mask = 1 - (w1 + w2 / max(c(w1, w2))), -#' brks = 20, width = 10, height = 8) +#'VizMostLikelyQuantileMap(bins, lons, lats, +#' toptitle = 'Most likely quantile map', +#' bar_titles = paste('% of belonging to', letters[1:n_bins]), +#' brks = 20, width = 10, height = 10) #'} #'@importFrom maps map #'@importFrom graphics box image layout mtext par plot.new #'@importFrom grDevices adjustcolor bmp colorRampPalette dev.cur dev.new dev.off hcl jpeg pdf png postscript svg tiff #'@export -PlotMostLikelyQuantileMap <- function(probs, lon, lat, cat_dim = 'bin', - bar_titles = NULL, - col_unknown_cat = 'white', drawleg = T, - ...) { +VizMostLikelyQuantileMap <- function(probs, lon, lat, cat_dim = 'bin', + bar_titles = NULL, + col_unknown_cat = 'white', drawleg = T, + ...) { # Check probs error <- FALSE if (is.list(probs)) { @@ -202,22 +168,19 @@ PlotMostLikelyQuantileMap <- function(probs, lon, lat, cat_dim = 'bin', bar_titles <- c("Below normal (%)", "Normal (%)", "Above normal (%)") } else if (nprobs == 5) { bar_titles <- c("Low (%)", "Below normal (%)", - "Normal (%)", "Above normal (%)", "High (%)") + "Normal (%)", "Above normal (%)", "High (%)") } else { bar_titles <- paste0("Cat. ", 1:nprobs, " (%)") } } minimum_value <- ceiling(1 / nprobs * 10 * 1.1) * 10 - - # By now, the PlotCombinedMap function is included below in this file. - # In the future, PlotCombinedMap will be part of s2dverification and will + + # By now, the VizCombinedMap function is included below in this file. + # In the future, VizCombinedMap will be part of s2dverification and will # be properly imported. - PlotCombinedMap(probs * 100, lon, lat, map_select_fun = max, - display_range = c(minimum_value, 100), - map_dim = cat_dim, - bar_titles = bar_titles, - col_unknown_map = col_unknown_cat, - drawleg = drawleg, ...) + VizCombinedMap(probs * 100, lon, lat, map_select_fun = max, + display_range = c(minimum_value, 100), map_dim = cat_dim, + bar_titles = bar_titles, col_unknown_map = col_unknown_cat, + drawleg = drawleg, ...) } - -- GitLab From 15aa6082278f4763907e02c87647b14c36102b46 Mon Sep 17 00:00:00 2001 From: vagudets Date: Thu, 17 Jul 2025 16:12:49 +0200 Subject: [PATCH 7/8] Bigpredidata changes --- modules/Visualization/output_size.yml | 28 ++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/modules/Visualization/output_size.yml b/modules/Visualization/output_size.yml index 8d7edead..74e3f154 100644 --- a/modules/Visualization/output_size.yml +++ b/modules/Visualization/output_size.yml @@ -51,9 +51,10 @@ region: #units inches dot_size: 2 font.main: 1 bar_label_scale: 1 - plot_margin: !expr c(0,1 ,7.1,1) + plot_margin: !expr c(0, 1, 7.1,1) bar_extra_margin: !expr c(4,0,0,0) colNA: "white" + col_mask: "white" country.borders: TRUE extreme_probabilities: width: 7 @@ -83,8 +84,8 @@ region: #units inches axes_label_scale: 0.8 bar_label_scale: 1.2 bar_extra_margin: !expr c(2, 1, 0.5, 1) - dot_size: 1.7 - dot_symbol: 4 + dot_size: 1 + dot_symbol: 16 font.main: 1 colNA: "white" forecast_map: @@ -95,19 +96,22 @@ region: #units inches axes_label_scale: 0.8 bar_label_scale: 1.2 bar_extra_margin: !expr c(2, 1, 0.5, 1) - dot_symbol: 4 - dot_size: 1.7 + dot_symbol: 16 + dot_size: 1 font.main: 1 colNA: "white" most_likely_terciles: - width: 7.5 - height: 8 + width: 8 + height: 7 intylat: 2 intxlon: 2 - dot_size: 2 + dot_size: 1 + dot_symbol: 16 plot_margin: !expr c(2, 5, 7.5, 5) bar_extra_margin: !expr c(2.5, 1, 0.5, 1) # colorbar proportions colNA: "white" + col_mask: 'white' + country.borders: FALSE extreme_probabilities: width: 8 height: 7.5 @@ -115,11 +119,13 @@ region: #units inches intxlon: 2 axes_label_scale: 0.8 bar_label_scale: 1.2 - bar_extra_margin: !expr c(2, 1, 0.5, 1) - dot_symbol: 4 - dot_size: 1.7 + plot_margin: !expr c(2, 5, 7.5, 5) + bar_extra_margin: !expr c(2.5, 1, 0.5, 1) + dot_symbol: 16 + dot_size: 1 font.main: 1 colNA: "white" + country.borders: FALSE multipanel: forecast_map: width: 8.5 -- GitLab From 25530ec47ef7ef0bf1cd2f710495195a3a3d3041 Mon Sep 17 00:00:00 2001 From: vagudets Date: Thu, 17 Jul 2025 16:13:20 +0200 Subject: [PATCH 8/8] Bigpredidata testing --- operationals/bigpredidata/script_bigpredidata_oper.R | 4 ++-- operationals/test/recipe_bigpredidata_oper_subseasonal.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/operationals/bigpredidata/script_bigpredidata_oper.R b/operationals/bigpredidata/script_bigpredidata_oper.R index 5249a8a0..cec71a8b 100644 --- a/operationals/bigpredidata/script_bigpredidata_oper.R +++ b/operationals/bigpredidata/script_bigpredidata_oper.R @@ -11,8 +11,8 @@ recipe_file <- args[1] recipe <- read_atomic_recipe(recipe_file) if (recipe$Analysis$Region$name == "EU") { - recipe$Analysis$Regrid$type <- - "/gpfs/projects/bsc32/esarchive_cache/exp/ncep/cfs-v2/weekly_mean/s2s/tas_f24h/tas_20050109.nc" + recipe$Analysis$Regrid$type <- "to_system" + # "/gpfs/projects/bsc32/esarchive_cache/exp/ncep/cfs-v2/weekly_mean/s2s/tas_f24h/tas_20050109.nc" } #recipe <- prepare_outputs(recipe_file) diff --git a/operationals/test/recipe_bigpredidata_oper_subseasonal.yml b/operationals/test/recipe_bigpredidata_oper_subseasonal.yml index 45a2342a..8ae47fdf 100755 --- a/operationals/test/recipe_bigpredidata_oper_subseasonal.yml +++ b/operationals/test/recipe_bigpredidata_oper_subseasonal.yml @@ -59,7 +59,7 @@ Analysis: multi_panel: no dots: no mask_terciles: yes - shapefile: shapefiles/recintos_provinciales_inspire_peninbal_etrs89.shp + shapefile: shapefiles/bigpredidata/recintos_provinciales_inspire_peninbal_etrs89.shp file_format: PNG # Final file format of the plots. Formats available: PNG, JPG, JPEG, EPS. Defaults to PDF. ncores: 16 # Optional, int: number of cores, defaults to 1 remove_NAs: TRUE # Optional, bool: Whether NAs are removed, defaults to FALSE -- GitLab