From 81d609481ee304ce5ac788c4315b2d83dceb8d40 Mon Sep 17 00:00:00 2001
From: leufen1 <l.leufen@fz-juelich.de>
Date: Tue, 19 Oct 2021 14:48:11 +0200
Subject: [PATCH] block length and n boots weren't load properly in post
 processing and used only defaults, fixed now

---
 mlair/plotting/postprocessing_plotting.py | 7 +++++--
 mlair/run_modules/post_processing.py      | 8 +++++---
 2 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/mlair/plotting/postprocessing_plotting.py b/mlair/plotting/postprocessing_plotting.py
index 33150fae..2afb5f08 100644
--- a/mlair/plotting/postprocessing_plotting.py
+++ b/mlair/plotting/postprocessing_plotting.py
@@ -1003,13 +1003,15 @@ class PlotSeparationOfScales(AbstractPlotClass):  # pragma: no cover
 class PlotSampleUncertaintyFromBootstrap(AbstractPlotClass):  # pragma: no cover
 
     def __init__(self, data: xr.DataArray, plot_folder: str = ".", model_type_dim: str = "type",
-                 error_measure: str = "mse", error_unit: str = None, dim_name_boots: str = 'boots'):
+                 error_measure: str = "mse", error_unit: str = None, dim_name_boots: str = 'boots',
+                 block_length: str = None):
         super().__init__(plot_folder, "sample_uncertainty_from_bootstrap")
         default_name = self.plot_name
         self.model_type_dim = model_type_dim
         self.error_measure = error_measure
         self.dim_name_boots = dim_name_boots
         self.error_unit = error_unit
+        self.block_length = block_length
         self.prepare_data(data)
         self._plot(orientation="v")
 
@@ -1061,7 +1063,8 @@ class PlotSampleUncertaintyFromBootstrap(AbstractPlotClass):  # pragma: no cover
             ax.set_xlabel(f"{self.error_measure} (in {self.error_unit})")
         else:
             raise ValueError(f"orientation must be `v' or `h' but is: {orientation}")
-        text_box = AnchoredText(f"n={n_boots}", frameon=True, loc=1, pad=0.5)
+        text = f"n={n_boots}" if self.block_length is None else f"{self.block_length}, n={n_boots}"
+        text_box = AnchoredText(text, frameon=True, loc=1, pad=0.5)
         plt.setp(text_box.patch, edgecolor='k', facecolor='w')
         ax.add_artist(text_box)
         plt.setp(ax.lines, color='k')
diff --git a/mlair/run_modules/post_processing.py b/mlair/run_modules/post_processing.py
index 22593d8b..1de27067 100644
--- a/mlair/run_modules/post_processing.py
+++ b/mlair/run_modules/post_processing.py
@@ -141,8 +141,9 @@ class PostProcessing(RunEnvironment):
         analyzed model to quantify which model might be superior compared to others.
         """
         n_boots = self.data_store.get_default("n_boots", default=1000, scope="uncertainty_estimate")
-        block_length = self.data_store.get_default("block_length", default="1m")
-        evaluate_competitors = self.data_store.get_default("evaluate_competitors", default=True)
+        block_length = self.data_store.get_default("block_length", default="1m", scope="uncertainty_estimate")
+        evaluate_competitors = self.data_store.get_default("evaluate_competitors", default=True,
+                                                           scope="uncertainty_estimate")
         block_mse = self.calculate_block_mse(evaluate_competitors=evaluate_competitors, separate_ahead=separate_ahead,
                                              block_length=block_length)
         self.uncertainty_estimate = statistics.create_n_bootstrap_realizations(
@@ -573,10 +574,11 @@ class PostProcessing(RunEnvironment):
 
         try:
             if "PlotSampleUncertaintyFromBootstrap" in plot_list and self.uncertainty_estimate is not None:
+                block_length= self.data_store.get_default("block_length", default="1m", scope="uncertainty_estimate")
                 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$")
+                    error_unit=r"ppb$^2$", block_length=block_length)
         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