From c271db81ddef6487c98b023b279af089faeb7654 Mon Sep 17 00:00:00 2001 From: lukas leufen <l.leufen@fz-juelich.de> Date: Fri, 20 Mar 2020 13:48:31 +0100 Subject: [PATCH] bootstraps calculation can be skipped or already calculated data can be used for the boot skill scores --- src/run_modules/experiment_setup.py | 5 ++++- src/run_modules/post_processing.py | 24 +++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/run_modules/experiment_setup.py b/src/run_modules/experiment_setup.py index dd0ec361..00469066 100644 --- a/src/run_modules/experiment_setup.py +++ b/src/run_modules/experiment_setup.py @@ -38,7 +38,8 @@ class ExperimentSetup(RunEnvironment): experiment_path=None, plot_path=None, forecast_path=None, overwrite_local_data=None, sampling="daily", create_new_model=None, bootstrap_path=None, permute_data_on_training=False, transformation=None, train_min_length=None, val_min_length=None, test_min_length=None, extreme_values=None, - extremes_on_right_tail_only=None, evaluate_bootstraps=True, plot_list=None, number_of_bootstraps=None): + extremes_on_right_tail_only=None, evaluate_bootstraps=True, plot_list=None, number_of_bootstraps=None, + create_new_bootstraps=None): # create run framework super().__init__() @@ -130,6 +131,8 @@ class ExperimentSetup(RunEnvironment): # set post-processing instructions self._set_param("evaluate_bootstraps", evaluate_bootstraps, scope="general.postprocessing") + create_new_bootstraps = max([self.data_store.get("trainable", "general"), create_new_bootstraps or False]) + self._set_param("create_new_bootstraps", create_new_bootstraps, scope="general.postprocessing") self._set_param("number_of_bootstraps", number_of_bootstraps, default=20, scope="general.postprocessing") self._set_param("plot_list", plot_list, default=DEFAULT_PLOT_LIST, scope="general.postprocessing") diff --git a/src/run_modules/post_processing.py b/src/run_modules/post_processing.py index e7d4bc75..d2138cb5 100644 --- a/src/run_modules/post_processing.py +++ b/src/run_modules/post_processing.py @@ -54,12 +54,12 @@ class PostProcessing(RunEnvironment): # bootstraps if self.data_store.get("evaluate_bootstraps", "general.postprocessing"): + # bootstrap_path = self.data_store.get("bootstrap_path", "general.postprocessing") + # number_of_bootstraps = self.data_store.get("number_of_bootstraps", "general.postprocessing") + # BootStraps(self.test_data, bootstrap_path, number_of_bootstraps) with TimeTracking(name="split (refac_1): create_boot_straps_refac_2()"): - bootstrap_path = self.data_store.get("bootstrap_path", "general.postprocessing") - number_of_bootstraps = self.data_store.get("number_of_bootstraps", "general.postprocessing") - BootStraps(self.test_data, bootstrap_path, number_of_bootstraps) - self.create_boot_straps() - self.bootstrap_skill_scores = self.calculate_bootstrap_skill_scores() + create_new_bootstraps = self.data_store.get("create_new_bootstraps", "general.postprocessing") + self.bootstrap_postprocessing(create_new_bootstraps) # skill scores self.skill_scores = self.calculate_skill_scores() @@ -67,6 +67,20 @@ class PostProcessing(RunEnvironment): # plotting self.plot() + def bootstrap_postprocessing(self, create_new_bootstraps, _iter=0): + try: + if create_new_bootstraps: + self.create_boot_straps() + self.bootstrap_skill_scores = self.calculate_bootstrap_skill_scores() + except FileNotFoundError: + if _iter != 0: + raise RuntimeError("bootstrap_postprocessing is called for the 2nd time. This means, that calling" + "create_boot_straps() couldn't solve the FileNotFoundError. Therefore, please check" + "manually the reason for the failure.") + logging.info("Couldn't load all files, restart bootstrap postprocessing with create_new_bootstraps=True.") + self.bootstrap_postprocessing(True, _iter=1) + + def create_boot_straps(self): # forecast with TimeTracking(name="boot predictions"): -- GitLab