From 35bbb19fcf27cc61c800bc131528bb66d0568c98 Mon Sep 17 00:00:00 2001 From: leufen1 <l.leufen@fz-juelich.de> Date: Mon, 18 Oct 2021 12:00:11 +0200 Subject: [PATCH] uncertainty estimate is now a class attribute and is parsed to plot routine --- mlair/run_modules/post_processing.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mlair/run_modules/post_processing.py b/mlair/run_modules/post_processing.py index 28b26709..4fedc836 100644 --- a/mlair/run_modules/post_processing.py +++ b/mlair/run_modules/post_processing.py @@ -85,12 +85,14 @@ class PostProcessing(RunEnvironment): self.window_lead_time = extract_value(self.data_store.get("output_shape", "model")) self.skill_scores = None self.feature_importance_skill_scores = None + self.uncertainty_estimate = None self.competitor_path = self.data_store.get("competitor_path") self.competitors = to_list(self.data_store.get_default("competitors", default=[])) self.forecast_indicator = "nn" self.observation_indicator = "obs" self.ahead_dim = "ahead" self.boot_var_dim = "boot_var" + self.uncertainty_estimate_boot_dim = "boots" self.model_type_dim = "type" self.index_dim = "index" self._run() @@ -140,9 +142,9 @@ class PostProcessing(RunEnvironment): evaluate_competitors = self.data_store.get_default("evaluate_competitors", default=True) block_mse = self.calculate_block_mse(evaluate_competitors=evaluate_competitors, separate_ahead=separate_ahead, block_length=block_length) - res = statistics.create_n_bootstrap_realizations(block_mse, self.index_dim, self.model_type_dim, - n_boots=n_boots) - res + self.uncertainty_estimate = statistics.create_n_bootstrap_realizations( + block_mse, dim_name_time=self.index_dim, dim_name_model=self.model_type_dim, + dim_name_boots=self.uncertainty_estimate_boot_dim, n_boots=n_boots) def calculate_block_mse(self, evaluate_competitors=True, separate_ahead=False, block_length="1m"): path = self.data_store.get("forecast_path") @@ -542,10 +544,11 @@ class PostProcessing(RunEnvironment): f"\n{sys.exc_info()[0]}\n{sys.exc_info()[1]}\n{sys.exc_info()[2]}") try: - if "PlotSampleUncertaintyFromBootstrap" in plot_list: - PlotSampleUncertaintyFromBootstrap(data=None, plot_folder=self.plot_path, - model_type_dim=self.model_type_dim, - error_measure="mean squared error", error_unit=r"ppb^2") + if "PlotSampleUncertaintyFromBootstrap" in plot_list and self.uncertainty_estimate is not None: + PlotSampleUncertaintyFromBootstrap( + data=self.uncertainty_estimate, plot_folder=self.plot_path, model_type_dim=self.model_type_dim, + dim_name_boots=self.uncertainty_estimate_boot_dim, error_measure="mean squared error", + error_unit=r"ppb^2") except Exception as e: logging.error(f"Could not create plot PlotSampleUncertaintyFromBootstrap due to the following error: {e}" f"\n{sys.exc_info()[0]}\n{sys.exc_info()[1]}\n{sys.exc_info()[2]}") -- GitLab