diff --git a/MODULES b/MODULES index 343e4e51aaaa977001d0d848cd316db7c44c3d54..4455b9dcee6c4fa5cc3c2b74cc08bd7ff3ab15b0 100644 --- a/MODULES +++ b/MODULES @@ -45,13 +45,15 @@ elif [[ $BSC_MACHINE == "nord4" ]]; then elif [[ $BSC_MACHINE == "amd" ]]; then - module purge - module load CDO/1.9.10-foss-2019b - module load R/4.1.2-foss-2019b - module load GEOS/3.7.2-foss-2019b-Python-3.7.4 - module load GDAL/3.5.0-foss-2019b-Python-3.7.4 - module load PROJ/9.0.0-GCCcore-8.3.0 - module load Phantomjs/2.1.1 + # module purge + # module load CDO/1.9.10-foss-2019b + # module load R/4.1.2-foss-2019b + # module load GEOS/3.7.2-foss-2019b-Python-3.7.4 + # module load GDAL/3.5.0-foss-2019b-Python-3.7.4 + # module load PROJ/9.0.0-GCCcore-8.3.0 + # module load Phantomjs/2.1.1 + source /gpfs/projects/bsc32/software/suselinux/11/software/Miniconda3/4.7.10/etc/profile.d/conda.sh + conda activate /gpfs/projects/bsc32/repository/apps/conda_envs/SUNSET-env_2.0.0 elif [[ $HOSTNAME == "bsceshub02.bsc.es" ]]; then diff --git a/modules/Saving/R/get_dir.R b/modules/Saving/R/get_dir.R index 4ec62e1a702f737ce614bf65fc0d76dac8f9591f..97208b3ee484ba37d06598537c7f1991a09c3ee7 100644 --- a/modules/Saving/R/get_dir.R +++ b/modules/Saving/R/get_dir.R @@ -12,12 +12,17 @@ get_dir <- function(recipe, variable, agg = "global") { system <- gsub('.','', recipe$Analysis$Datasets$System$name, fixed = T) reference <- gsub('.','', recipe$Analysis$Datasets$Reference$name, fixed = T) calib.method <- tolower(recipe$Analysis$Workflow$Calibration$method) + if (!is.null(recipe$Analysis$Region$name)) { + region <- recipe$Analysis$Region$name + } else { + region <- "" + } if (tolower(recipe$Analysis$Output_format) == 'scorecards') { # Define output dir name accordint to Scorecards format dict <- read_yaml("conf/output_dictionaries/scorecards.yml") # system <- dict$System[[recipe$Analysis$Datasets$System$name]]$short_name - dir <- file.path(outdir, system, reference, calib.method, variable, "/") + dir <- file.path(outdir, system, reference, calib.method, region, variable, "/") } else { # Default generic output format based on FOCUS # Get startdate or hindcast period @@ -42,9 +47,6 @@ get_dir <- function(recipe, variable, agg = "global") { } } store.freq <- recipe$Analysis$Variables$freq - if (!is.null(recipe$Analysis$Region$name)) { - outdir <- paste0(outdir, "/", recipe$Analysis$Region$name) - } switch(tolower(agg), "region" = {dir <- paste0(outdir, "/", system, "/", calib.method, "-", store.freq, "/", variable, diff --git a/modules/Scorecards/R/tmp/LoadMetrics.R b/modules/Scorecards/R/tmp/LoadMetrics.R index bde6d612f3108b2baf6559cc3063364e70220640..5e050548502c4e7d9135325e93361b962c3eeb17 100644 --- a/modules/Scorecards/R/tmp/LoadMetrics.R +++ b/modules/Scorecards/R/tmp/LoadMetrics.R @@ -15,6 +15,8 @@ #'@param period A character string indicating the start and end years of the #' reference period (e.g. '1993-2016') #'@param start_months A vector indicating the numbers of the start months +#'@param region_name A character string indicating the name of the wider region +#' loaded in the recipe. If no region name, can be "" or NULL. #'@param input_path A character string indicating the path where metrics output #' files from verification suite are saved (or any other compatible files) #' @@ -30,7 +32,8 @@ #' period = '1993-2016' #' metric_names = c('rpss', 'crpss'), #' start_months = sprintf("%02d", 1:12), -#' calib_method = 'raw', +#' calib_method = 'raw', +#' region_name: 'Global', #' input_path = './scorecards_data/input_data') #'} #'@importFrom startR Start @@ -38,7 +41,7 @@ #'@export LoadMetrics <- function(input_path, system, reference, var, period, metric_names, - start_months, calib_method = NULL) { + start_months, region_name = NULL, calib_method = NULL) { # Initial checks ## system @@ -70,6 +73,16 @@ LoadMetrics <- function(input_path, system, reference, var, period, metric_names stop("Parameter 'start_months' must be a numeric vector indicating ", "the starting months.") } + if (is.null(region_name)) { + region_name <- "" + } else if (!is.character(region_name)) { + warning("Parameter 'region_name' must be a character vector of the ", + "name of the wider region.") + } else if (length(region_name) > 1) { + warning("Parameter 'region_name' must be of length 1. Only the first value ", + "will be used.") + region_name <- region_name[1] + } start_months <- sprintf("%02d", start_months) ## input_path if (!is.character(input_path)) { @@ -88,7 +101,8 @@ LoadMetrics <- function(input_path, system, reference, var, period, metric_names # Load data ## Outer (file) dimensions: var, sdate (month), system, reference ## Inner dimensions: time, region - path_pattern <- file.path("$system$", "$reference$", calib_method, var, + path_pattern <- file.path("$system$", "$reference$", calib_method, + region_name, var, paste0("scorecards_", "$system$", "_", "$reference$", "_", var, "_$var$_", period, "_s$sdate$.nc")) diff --git a/modules/Scorecards/Scorecards_plotting.R b/modules/Scorecards/Scorecards_plotting.R index f8261862b6e63af5c99c3b1d16a9ad9733f94905..de1e0aad8e953912f44b6af3487e77e192b9218f 100644 --- a/modules/Scorecards/Scorecards_plotting.R +++ b/modules/Scorecards/Scorecards_plotting.R @@ -39,11 +39,12 @@ Scorecards_plotting <- function(recipe) { calib.method <- tolower(recipe$Analysis$Workflow$Calibration$method) metrics <- unlist(strsplit(tolower(recipe$Analysis$Workflow$Scorecards$metric), ", | |,")) + region.name <- recipe$Analysis$Region$name if (recipe$Analysis$Workflow$Scorecards$start_months == 'all' || is.null(recipe$Analysis$Workflow$Scorecards$start_months)) { start.months <- as.numeric(substr(recipe$Analysis$Time$sdate, 1, 2)) - } else { + } else {recipe$Analysis$Variables$name start.months <- as.numeric(strsplit(recipe$Analysis$Workflow$Scorecards$start_months, split = ", | |,")[[1]]) if(!any(as.numeric(substr(recipe$Analysis$Time$sdate, 1,2))) %in% start.months){ @@ -135,6 +136,7 @@ Scorecards_plotting <- function(recipe) { var = var, metric_names = metrics, period = period, + region_name = region.name, start_months = as.numeric(start.months), calib_method = calib.method) attributes(aggregated_metrics)$metrics <- attr(aggregated_metrics, "FileSelectors")$dat1$var[[1]] @@ -145,6 +147,7 @@ Scorecards_plotting <- function(recipe) { var = var, metric_names = paste0(metrics, "_significance"), period = period, + region_name = region.name, start_months = as.numeric(start.months), calib_method = calib.method) diff --git a/modules/Scorecards/execute_scorecards.R b/modules/Scorecards/execute_scorecards.R index 706f348e6f3c677fa42b7ac29fe4e51b053d6aaf..5ec009b4c1169516162cdfea2b63aa288728f204 100644 --- a/modules/Scorecards/execute_scorecards.R +++ b/modules/Scorecards/execute_scorecards.R @@ -30,6 +30,8 @@ for (variable in 1:length(recipe$Analysis$Variables)) { # Assign variables scorecard_recipe$Analysis$Variables <- recipe$Analysis$Variables[[variable]] + # Flatten region + scorecard_recipe <- restructure_recipe(scorecard_recipe) # Plot Scorecards Scorecards_plotting(scorecard_recipe) } diff --git a/tools/check_recipe.R b/tools/check_recipe.R index 3a9a148ae4f9b4f9f17226748941787bdfe8ea25..f8c45af8125fe190f5f344c05f07861893cbedd7 100644 --- a/tools/check_recipe.R +++ b/tools/check_recipe.R @@ -810,10 +810,17 @@ check_recipe <- function(recipe) { } if ("Scorecards" %in% names(recipe$Analysis$Workflow)) { if (recipe$Analysis$Workflow$Scorecards$execute == TRUE) { + if (length(recipe$Analysis$Region) > 1) { + error(recipe$Run$logger, + paste0("Splitting the recipe by Region is not allowed when ", + "Scorecards are requested. Please write only one region ", + "in 'Analysis:Region' to plot Scorecards.")) + error_status <- TRUE + } if (is.null(recipe$Analysis$Workflow$Scorecards$metric)) { error(recipe$Run$logger, "Parameter 'metric' must be defined under 'Scorecards'.") - error_status <- T + error_status <- TRUE } else { sc_metrics <- strsplit(recipe$Analysis$Workflow$Scorecards$metric, ", | |,")[[1]] @@ -867,7 +874,7 @@ check_recipe <- function(recipe) { error(recipe$Run$logger, paste0("All of the metrics requested under 'Scorecards' must ", "be requested in the 'Skill' section.")) - error_status <- T + error_status <- TRUE } } } diff --git a/tools/write_autosubmit_conf.R b/tools/write_autosubmit_conf.R index 8d09734282aef45388be6a6aab72539a2781372d..8ca627e743f7fddcb4dd709c037ab6eeb04510ac 100644 --- a/tools/write_autosubmit_conf.R +++ b/tools/write_autosubmit_conf.R @@ -175,7 +175,7 @@ write_autosubmit_conf <- function(recipe, nchunks, if (recipe$Run$Terminal) { ## TODO: Change SSH message for other environments (outside BSC) info(recipe$Run$logger, - paste("Please SSH into bscesautosubmit01 or bscesautosubmit02 and run", + paste("Please SSH into bscesautosubmit03 or bscesautosubmit04 and run", "the following commands:")) info(recipe$Run$logger, paste("module load", auto_specs$module_version)) diff --git a/use_cases/ex1_2_autosubmit_scorecards/ex1_2-recipe.yml b/use_cases/ex1_2_autosubmit_scorecards/ex1_2-recipe.yml index adf53ffd9975187c80a679bbb137ba7cf3d2b54a..2aeece0dbbf2d047fcae90dc22804fd1448472c4 100644 --- a/use_cases/ex1_2_autosubmit_scorecards/ex1_2-recipe.yml +++ b/use_cases/ex1_2_autosubmit_scorecards/ex1_2-recipe.yml @@ -63,7 +63,7 @@ Analysis: Extra-tropical SH : {lon.min: 0, lon.max: 360, lat.min: -30, lat.max: -90} start_months: 'all' metric: mean_bias enscorr rpss crpss enssprerr - metric_aggregation: 'score' + metric_aggregation: 'skill' inf_to_na: TRUE # Optional, bool: set inf values in data to NA, default is FALSE table_label: NULL fileout_label: NULL col1_width: NULL diff --git a/use_cases/ex1_2_autosubmit_scorecards/ex1_2-script.R b/use_cases/ex1_2_autosubmit_scorecards/ex1_2-script.R index a8ee7effca9684b9f4f13d874bc52f1eeac96daf..810b39cbadc7b03c6ba578422df489c8bd9ec4b1 100644 --- a/use_cases/ex1_2_autosubmit_scorecards/ex1_2-script.R +++ b/use_cases/ex1_2_autosubmit_scorecards/ex1_2-script.R @@ -29,5 +29,4 @@ skill_metrics <- Skill(recipe, data) statistics <- Statistics(recipe, data) # Pre-computations required for the scorecards Scorecards_calculations(recipe, data = data, - skill_metrics = skill_metrics, - statistics = statistics) + skill_metrics = skill_metrics)