diff --git a/OperationalCS.R b/OperationalCS.R index bdb960c8aca7240188c64b2f742948da91fc1247..30aa8ddd3af29a9733da632b43e7511e615b7802 100644 --- a/OperationalCS.R +++ b/OperationalCS.R @@ -20,13 +20,16 @@ source("tools/libs.R") # Create output folder and log: logger <- prepare_outputs(recipe = recipe, file = args[2], conf = conf) +folder <- logger$foldername log_file <- logger$logname logger <- logger$logger # Checks: check_conf(conf, file = args[1], logger) verifications <- check_recipe(recipe, file = args[2], conf, logger) - +# Divide recipe into single verifications recipes: +total_recipes <- divide_recipe(recipe, verifications, folder, logger) + # Go to verification code: capture.output(source("modules/verifications.R"), file = log_file, type ='message', diff --git a/recipes/seasonal_complex.yml b/recipes/seasonal_complex.yml index dd0137cd86d324373d1a8ce4682fafde702ebd75..1e0a4abca03915549000837b493ed540f7549c50 100644 --- a/recipes/seasonal_complex.yml +++ b/recipes/seasonal_complex.yml @@ -13,9 +13,11 @@ Analysis: Datasets: System: - name: system5c3s + - name: glosea5 Multimodel: False Reference: - - {name: ERA5} + - name: ERA5 + - name: ERAInterim Time: sdate: fcst_year: 2021 diff --git a/tools/divide_recipe.R b/tools/divide_recipe.R new file mode 100644 index 0000000000000000000000000000000000000000..8d12ca5fa8b2c44661793a162572a0f762b30457 --- /dev/null +++ b/tools/divide_recipe.R @@ -0,0 +1,120 @@ +# recipe: the content of the recipe +# verifications: the output from check_recipe +# folder: the name of the output folder for this run +# logger: the log file obtain from prepare_outputs +divide_recipe <- function(recipe, verifications, folder, logger) { + info(logger, "Spliting recipe in single verifications.") + beta_recipe <- list(Description = append(recipe$Description, + "split version"), + Analysis = list(Horizon = recipe$Analysis$Horizon, + Variables = NULL, + Datasets = NULL, + Time = NULL, + Region = NULL, + Regrid = recipe$Analysis$Regrid, + Workflow = recipe$Analysis$Workflow, + Output_format = + recipe$Analysis$Output_format), + Run = recipe$Run) + # duplicate recipe by Variables considering dep and indep: + all_recipes <- list(beta_recipe) + i <- 1 # to get track of the recipe number + for (indep in verifications$independent) { + all_recipes[[i]]$Analysis$Variables <- indep + i = i + 1 + all_recipes <- append(all_recipes, list(beta_recipe)) + } + for (dep in verifications$dependent) { + all_recipes[[i]]$Analysis$Variables <- dep + i = i + 1 + all_recipes <- append(all_recipes, list(beta_recipe)) + } + all_recipes <- all_recipes[-length(all_recipes)] + # duplicate recipe by Datasets: + # check Systems + if (recipe$Analysis$Datasets$Multimodel) { + for (reci in 1:length(all_recipes)) { + all_recipes[[reci]]$Analysis$Datasets <- list( + System = recipe$Analysis$Datasets$System, + Multimodel = recipe$Analysis$Datasets$Multimodel, + Reference = NULL) + } + } else { + for (sys in 1:length(recipe$Analysis$Datasets$System)) { + for (reci in 1:length(all_recipes)) { + all_recipes[[reci]]$Analysis$Datasets <- list( + System = recipe$Analysis$Datasets$System[[sys]], + Multimodel = recipe$Analysis$Datasets$Multimodel, + Reference = NULL) + } + if (sys == 1) { + recipes <- all_recipes + } else { + recipes <- append(recipes, all_recipes) + } + } + all_recipes <- recipes + rm(list = 'recipes') + } + # check References + for (ref in 1:length(recipe$Analysis$Datasets$Reference)) { + for (reci in 1:length(all_recipes)) { + all_recipes[[reci]]$Analysis$Datasets$Reference <- + recipe$Analysis$Datasets$Reference[[ref]] + } + if (ref == 1) { + recipes <- all_recipes + } else { + recipes <- append(recipes, all_recipes) + } + } + all_recipes <- recipes + # Duplicate recipe by Region + recipes <- list() + if (recipe$Analysis$Region$Aggregation) { + for (reci in 1:length(all_recipes)) { + recipes[[reci]]$Analysis$Region <- list(Aggregation = + recipe$Analysis$Region$Aggregation) + } + } + for (reg in 1:length(recipe$Analysis$Region$Regional)) { + if (length(recipe$Analysis$Region$Regional[[reg]]) == 4) { + for (reci in 1:length(all_recipes)) { + all_recipes[[reci]]$Analysis$Region$Regional <- + recipe$Analysis$Region$Regional[[reg]] + } + recipes <- append(recipes, all_recipes) + } + } + all_recipes <- recipes + rm(list = 'recipes') + if (tolower(recipe$Analysis$Horizon) == 'seasonal') { + for (month in 1:length(recipe$Analysis$Time$sdate$fcst_month)) { + for (reci in 1:length(all_recipes)) { + all_recipes[[reci]]$Analysis$Time <- list(sdate = list( + fcst_year = recipe$Analysis$Time$sdate$fcst_year, + fcst_month = recipe$Analysis$Time$sdate$fcst_month[[month]], + fcst_day = recipe$Analysis$Time$sdate$fcst_day), + hcst_start = recipe$Analysis$Time$hcst_start, + hcst_end = recipe$Analysis$Time$hcst_end, + leadtimemin = recipe$Analysis$Time$leadtimemin, + leadtimemax = recipe$Analysis$Time$leadtimemax) + } + if (month == 1) { + recipes <- all_recipes + } else { + recipes <- append(recipes, all_recipes) + } + } + all_recipes <- recipes + rm(list = 'recipes') + } # Rest of horizons + # Finally, save all recipes in saparated yaml files + for (reci in 1:length(all_recipes)) { + write_yaml(all_recipes[reci], + paste0(folder, "/logs/recipes/recipe_", reci, ".yml")) + } + text <- paste("See folder /logs/recipes/ to see the individual recipes.") + info(logger, text) + return(all_recipes) +} diff --git a/tools/libs.R b/tools/libs.R index 8d9856d7697de1c89031bcd98a1dd8afb2a32163..9ce5a2cfadbfa34351ddd4c2a22209a16394a2b7 100644 --- a/tools/libs.R +++ b/tools/libs.R @@ -25,4 +25,5 @@ library(multiApply) source(paste0(conf$code_dir, "tools/check_recipe.R")) source(paste0(conf$code_dir, "tools/check_conf.R")) source(paste0(conf$code_dir, "tools/prepare_outputs.R")) + source(paste0(conf$code_dir, "tools/divide_recipe.R")) source(paste0(conf$code_dir, "tools/add_dims.R")) # Not sure if necessary yet diff --git a/tools/prepare_outputs.R b/tools/prepare_outputs.R index 192956588f41bc4cb36bc0503c4382edbc898b7b..b8f4b756ae5de69d9b265d0284c3d04bf9ac63c6 100644 --- a/tools/prepare_outputs.R +++ b/tools/prepare_outputs.R @@ -8,6 +8,7 @@ prepare_outputs <- function(recipe, file, conf) { dir.create(file.path(conf$output_dir, folder_name, 'plots'), recursive = TRUE) dir.create(file.path(conf$output_dir, folder_name, 'outputs')) dir.create(file.path(conf$output_dir, folder_name, 'logs')) + dir.create(file.path(conf$output_dir, folder_name, 'logs', 'recipes')) file.copy(file, file.path(conf$output_dir, folder_name, 'logs')) logfile <- file.path(conf$output_dir, folder_name, 'logs', 'log.txt') # Set default behaviour of log output file: @@ -30,5 +31,6 @@ prepare_outputs <- function(recipe, file, conf) { appenders = list(file_appender(logfile, append = TRUE, layout = default_log_layout()))) } - return(list(logger = logger, logname = logfile)) + return(list(logger = logger, logname = logfile, + foldername = file.path(conf$output_dir, folder_name))) }