From e8b75730b06ccda3257a45f7563f97bb9a71c7d0 Mon Sep 17 00:00:00 2001
From: leufen1 <l.leufen@fz-juelich.de>
Date: Tue, 20 Jul 2021 16:32:59 +0200
Subject: [PATCH] changed filter logging, added try statement on plotting

---
 mlair/helpers/filter.py                         |  3 ++-
 mlair/helpers/time_tracking.py                  |  5 +++--
 mlair/model_modules/fully_connected_networks.py |  6 +++---
 mlair/plotting/postprocessing_plotting.py       |  7 ++++---
 mlair/run_modules/post_processing.py            | 12 ++++++++----
 5 files changed, 20 insertions(+), 13 deletions(-)

diff --git a/mlair/helpers/filter.py b/mlair/helpers/filter.py
index a551bec4..a63cef97 100644
--- a/mlair/helpers/filter.py
+++ b/mlair/helpers/filter.py
@@ -408,7 +408,8 @@ class ClimateFIRFilter:
                     continue
 
                 logging.debug(f"{data.coords['Stations'].values[0]} ({var}): start filter convolve")
-                with TimeTracking(name=f"{data.coords['Stations'].values[0]} ({var}): filter convolve"):
+                with TimeTracking(name=f"{data.coords['Stations'].values[0]} ({var}): filter convolve",
+                                  logging_level=logging.DEBUG):
                     filt = xr.apply_ufunc(fir_filter_convolve, filter_input_data,
                                           input_core_dims=[[new_dim]],
                                           output_core_dims=[[new_dim]],
diff --git a/mlair/helpers/time_tracking.py b/mlair/helpers/time_tracking.py
index c85a6a04..3105ebcd 100644
--- a/mlair/helpers/time_tracking.py
+++ b/mlair/helpers/time_tracking.py
@@ -68,11 +68,12 @@ class TimeTracking(object):
     The only disadvantage of the latter implementation is, that the duration is logged but not returned.
     """
 
-    def __init__(self, start=True, name="undefined job"):
+    def __init__(self, start=True, name="undefined job", logging_level=logging.INFO):
         """Construct time tracking and start if enabled."""
         self.start = None
         self.end = None
         self._name = name
+        self._logging = {logging.INFO: logging.info, logging.DEBUG: logging.debug}.get(logging_level, logging.info)
         if start:
             self._start()
 
@@ -128,4 +129,4 @@ class TimeTracking(object):
     def __exit__(self, exc_type, exc_val, exc_tb) -> None:
         """Stop time tracking on exit and log info about passed time."""
         self.stop()
-        logging.info(f"{self._name} finished after {self}")
\ No newline at end of file
+        self._logging(f"{self._name} finished after {self}")
diff --git a/mlair/model_modules/fully_connected_networks.py b/mlair/model_modules/fully_connected_networks.py
index 21455383..03380333 100644
--- a/mlair/model_modules/fully_connected_networks.py
+++ b/mlair/model_modules/fully_connected_networks.py
@@ -374,7 +374,7 @@ class BranchedInputFCN(AbstractModelClass):
         print(self.model.summary())
 
     def set_compile_options(self):
-        # self.compile_options = {"loss": [keras.losses.mean_squared_error],
-        #                         "metrics": ["mse", "mae", var_loss]}
-        self.compile_options = {"loss": [custom_loss([keras.losses.mean_squared_error, var_loss], loss_weights=[2, 1])],
+        self.compile_options = {"loss": [keras.losses.mean_squared_error],
                                 "metrics": ["mse", "mae", var_loss]}
+        # self.compile_options = {"loss": [custom_loss([keras.losses.mean_squared_error, var_loss], loss_weights=[2, 1])],
+        #                         "metrics": ["mse", "mae", var_loss]}
diff --git a/mlair/plotting/postprocessing_plotting.py b/mlair/plotting/postprocessing_plotting.py
index eef9208a..fe658b09 100644
--- a/mlair/plotting/postprocessing_plotting.py
+++ b/mlair/plotting/postprocessing_plotting.py
@@ -644,9 +644,10 @@ class PlotBootstrapSkillScore(AbstractPlotClass):
         else:
             self._plot()
             self._save()
-            self.plot_name += '_separated'
-            self._plot(separate_vars=separate_vars)
-            self._save(bbox_inches='tight')
+            if len(set(separate_vars).intersection(self._data[self._x_name].unique())) > 0:
+                self.plot_name += '_separated'
+                self._plot(separate_vars=separate_vars)
+                self._save(bbox_inches='tight')
 
     @staticmethod
     def _set_bootstrap_type(boot_type):
diff --git a/mlair/run_modules/post_processing.py b/mlair/run_modules/post_processing.py
index df8a7d5e..539a15ab 100644
--- a/mlair/run_modules/post_processing.py
+++ b/mlair/run_modules/post_processing.py
@@ -342,10 +342,14 @@ class PostProcessing(RunEnvironment):
             if (self.bootstrap_skill_scores is not None) and ("PlotBootstrapSkillScore" in plot_list):
                 for boot_type, boot_data in self.bootstrap_skill_scores.items():
                     for boot_method, boot_skill_score in boot_data.items():
-                        PlotBootstrapSkillScore(boot_skill_score, plot_folder=self.plot_path,
-                                                model_setup=self.forecast_indicator, sampling=self._sampling,
-                                                ahead_dim=self.ahead_dim, separate_vars=to_list(self.target_var),
-                                                bootstrap_type=boot_type, bootstrap_method=boot_method)
+                        try:
+                            PlotBootstrapSkillScore(boot_skill_score, plot_folder=self.plot_path,
+                                                    model_setup=self.forecast_indicator, sampling=self._sampling,
+                                                    ahead_dim=self.ahead_dim, separate_vars=to_list(self.target_var),
+                                                    bootstrap_type=boot_type, bootstrap_method=boot_method)
+                        except Exception as e:
+                            logging.error(f"Could not create plot PlotBootstrapSkillScore ({boot_type}, {boot_method}) "
+                                          f"due to the following error: {e}")
         except Exception as e:
             logging.error(f"Could not create plot PlotBootstrapSkillScore due to the following error: {e}")
 
-- 
GitLab