From ee4e06d1d771ddfe9f0a3d09853f3451a7b114c9 Mon Sep 17 00:00:00 2001 From: aho Date: Tue, 10 Oct 2023 15:35:41 +0200 Subject: [PATCH] Correct saving start message in Anomalies; wrap all the save lines in the if condition --- modules/Anomalies/Anomalies.R | 41 +++++++++++++++++-------------- modules/Calibration/Calibration.R | 29 +++++++++++----------- modules/Skill/Skill.R | 36 ++++++++++++++------------- 3 files changed, 56 insertions(+), 50 deletions(-) diff --git a/modules/Anomalies/Anomalies.R b/modules/Anomalies/Anomalies.R index 386317fb..a2f0c005 100644 --- a/modules/Anomalies/Anomalies.R +++ b/modules/Anomalies/Anomalies.R @@ -87,27 +87,30 @@ Anomalies <- function(recipe, data) { "cross-validation. The original full fields are returned as", "$hcst.full_val and $obs.full_val.")) - if (recipe$Analysis$Workflow$Anomalies$save != 'none') { - info(recipe$Run$logger, "##### ANOMALIES COMPUTED SUCCESSFULLY #####") - } + info(recipe$Run$logger, "##### ANOMALIES COMPUTED SUCCESSFULLY #####") + # Save outputs - info(recipe$Run$logger, "##### START SAVING ANOMALIES #####") - recipe$Run$output_dir <- paste0(recipe$Run$output_dir, - "/outputs/Anomalies/") - # Save forecast - if ((recipe$Analysis$Workflow$Anomalies$save %in% - c('all', 'exp_only', 'fcst_only')) && !is.null(data$fcst)) { - save_forecast(recipe = recipe, data_cube = data$fcst, type = 'fcst') - } - # Save hindcast - if (recipe$Analysis$Workflow$Anomalies$save %in% - c('all', 'exp_only')) { - save_forecast(recipe = recipe, data_cube = data$hcst, type = 'hcst') - } - # Save observation - if (recipe$Analysis$Workflow$Anomalies$save == 'all') { - save_observations(recipe = recipe, data_cube = data$obs) + if (recipe$Analysis$Workflow$Anomalies$save != 'none') { + + info(recipe$Run$logger, "##### START SAVING ANOMALIES #####") + recipe$Run$output_dir <- paste0(recipe$Run$output_dir, + "/outputs/Anomalies/") + # Save forecast + if ((recipe$Analysis$Workflow$Anomalies$save %in% + c('all', 'exp_only', 'fcst_only')) && !is.null(data$fcst)) { + save_forecast(recipe = recipe, data_cube = data$fcst, type = 'fcst') + } + # Save hindcast + if (recipe$Analysis$Workflow$Anomalies$save %in% + c('all', 'exp_only')) { + save_forecast(recipe = recipe, data_cube = data$hcst, type = 'hcst') + } + # Save observation + if (recipe$Analysis$Workflow$Anomalies$save == 'all') { + save_observations(recipe = recipe, data_cube = data$obs) + } } + } else { warn(recipe$Run$logger, paste("The Anomalies module has been called, but", "recipe parameter Analysis:Variables:anomaly is set to FALSE.", diff --git a/modules/Calibration/Calibration.R b/modules/Calibration/Calibration.R index e41565a9..80fca408 100644 --- a/modules/Calibration/Calibration.R +++ b/modules/Calibration/Calibration.R @@ -170,20 +170,21 @@ Calibration <- function(recipe, data) { # Saving if (recipe$Analysis$Workflow$Calibration$save != 'none') { info(recipe$Run$logger, "##### START SAVING CALIBRATED DATA #####") - } - ## TODO: What do we do with the full values? - recipe$Run$output_dir <- paste0(recipe$Run$output_dir, - "/outputs/Calibration/") - if ((recipe$Analysis$Workflow$Calibration$save %in% - c('all', 'exp_only', 'fcst_only')) && (!is.null(data$fcst))) { - save_forecast(recipe = recipe, data_cube = fcst_calibrated, type = 'fcst') - } - if (recipe$Analysis$Workflow$Calibration$save %in% - c('all', 'exp_only')) { - save_forecast(recipe = recipe, data_cube = hcst_calibrated, type = 'hcst') - } - if (recipe$Analysis$Workflow$Calibration$save == 'all') { - save_observations(recipe = recipe, data_cube = data$obs) + + ## TODO: What do we do with the full values? + recipe$Run$output_dir <- paste0(recipe$Run$output_dir, + "/outputs/Calibration/") + if ((recipe$Analysis$Workflow$Calibration$save %in% + c('all', 'exp_only', 'fcst_only')) && (!is.null(data$fcst))) { + save_forecast(recipe = recipe, data_cube = fcst_calibrated, type = 'fcst') + } + if (recipe$Analysis$Workflow$Calibration$save %in% + c('all', 'exp_only')) { + save_forecast(recipe = recipe, data_cube = hcst_calibrated, type = 'hcst') + } + if (recipe$Analysis$Workflow$Calibration$save == 'all') { + save_observations(recipe = recipe, data_cube = data$obs) + } } ## TODO: Sort out returns diff --git a/modules/Skill/Skill.R b/modules/Skill/Skill.R index fd27ba75..7fff7de4 100644 --- a/modules/Skill/Skill.R +++ b/modules/Skill/Skill.R @@ -437,25 +437,27 @@ Probabilities <- function(recipe, data) { if (recipe$Analysis$Workflow$Probabilities$save != 'none') { info(recipe$Run$logger, "##### START SAVING PERCENTILES AND PROBABILITY CATEGORIES #####") - } - recipe$Run$output_dir <- paste0(recipe$Run$output_dir, - "/outputs/Skill/") - # Save percentiles - if (recipe$Analysis$Workflow$Probabilities$save %in% - c('all', 'percentiles_only')) { - save_percentiles(recipe = recipe, percentiles = results$percentiles, - data_cube = data$hcst) - } - # Save probability bins - if (recipe$Analysis$Workflow$Probabilities$save %in% - c('all', 'bins_only')) { - save_probabilities(recipe = recipe, probs = results$probs, - data_cube = data$hcst, type = "hcst") - if (!is.null(results$probs_fcst)) { - save_probabilities(recipe = recipe, probs = results$probs_fcst, - data_cube = data$fcst, type = "fcst") + + recipe$Run$output_dir <- paste0(recipe$Run$output_dir, + "/outputs/Skill/") + # Save percentiles + if (recipe$Analysis$Workflow$Probabilities$save %in% + c('all', 'percentiles_only')) { + save_percentiles(recipe = recipe, percentiles = results$percentiles, + data_cube = data$hcst) + } + # Save probability bins + if (recipe$Analysis$Workflow$Probabilities$save %in% + c('all', 'bins_only')) { + save_probabilities(recipe = recipe, probs = results$probs, + data_cube = data$hcst, type = "hcst") + if (!is.null(results$probs_fcst)) { + save_probabilities(recipe = recipe, probs = results$probs_fcst, + data_cube = data$fcst, type = "fcst") + } } } + # Return results return(results) } -- GitLab