From f52524cda258d29e76c31c065846cd97eb5af28c Mon Sep 17 00:00:00 2001
From: Le Roux Erwan <erwan.le-roux@irstea.fr>
Date: Wed, 22 May 2019 18:31:08 +0200
Subject: [PATCH] [SCM][HYPERCUBE] catch more exception in
 abstract_gev_trend_test

---
 .../main_hypercube_visualization.py                    |  8 ++++----
 .../univariate_trend_test/abstract_gev_trend_test.py   |  5 ++++-
 .../univariate_trend_test/abstract_trend_test.py       | 10 ++++++----
 extreme_estimator/extreme_models/utils.py              |  3 ++-
 4 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/experiment/meteo_france_SCM_study/visualization/hypercube_visualization/main_hypercube_visualization.py b/experiment/meteo_france_SCM_study/visualization/hypercube_visualization/main_hypercube_visualization.py
index dd743e16..13f2c34c 100644
--- a/experiment/meteo_france_SCM_study/visualization/hypercube_visualization/main_hypercube_visualization.py
+++ b/experiment/meteo_france_SCM_study/visualization/hypercube_visualization/main_hypercube_visualization.py
@@ -37,10 +37,10 @@ def full_trends_with_quantity_altitude_hypercube():
     save_to_file = True
     only_first_one = False
     fast = False
-    add_detailed_plots = False
+    add_detailed_plots = True
     altitudes = ALL_ALTITUDES[3:-6]
     study_classes = SCM_STUDIES
-    for trend_test_class in [MannKendallTrendTest, GevLocationTrendTest, GevScaleTrendTest, GevShapeTrendTest][1:2]:
+    for trend_test_class in [MannKendallTrendTest, GevLocationTrendTest, GevScaleTrendTest, GevShapeTrendTest][:]:
         visualizers = [StudyVisualizer(study, temporal_non_stationarity=True, verbose=False, multiprocessing=True)
                        for study in study_iterator_global(study_classes=study_classes, only_first_one=only_first_one,
                                                           altitudes=altitudes)]
@@ -94,8 +94,8 @@ def fast_trends_with_quantity_altitude_hypercube():
 
 def main_run():
     # fast_trends_with_altitude_hypercube()
-    fast_trends_with_quantity_altitude_hypercube()
-    # full_trends_with_quantity_altitude_hypercube()
+    # fast_trends_with_quantity_altitude_hypercube()
+    full_trends_with_quantity_altitude_hypercube()
 
 
 if __name__ == '__main__':
diff --git a/experiment/trend_analysis/univariate_trend_test/abstract_gev_trend_test.py b/experiment/trend_analysis/univariate_trend_test/abstract_gev_trend_test.py
index 1b734763..eb09ead0 100644
--- a/experiment/trend_analysis/univariate_trend_test/abstract_gev_trend_test.py
+++ b/experiment/trend_analysis/univariate_trend_test/abstract_gev_trend_test.py
@@ -81,7 +81,10 @@ class AbstractGevTrendTest(AbstractTrendTest):
 
     @property
     def test_trend_strength(self):
-        return self.percentage_of_change_per_year
+        if self.crashed:
+            return 0.0
+        else:
+            return self.percentage_of_change_per_year
 
     @property
     def percentage_of_change_per_year(self):
diff --git a/experiment/trend_analysis/univariate_trend_test/abstract_trend_test.py b/experiment/trend_analysis/univariate_trend_test/abstract_trend_test.py
index 1462db94..f08e7daa 100644
--- a/experiment/trend_analysis/univariate_trend_test/abstract_trend_test.py
+++ b/experiment/trend_analysis/univariate_trend_test/abstract_trend_test.py
@@ -21,6 +21,11 @@ class AbstractTrendTest(object):
 
     SIGNIFICANCE_LEVEL = 0.05
 
+    def __init__(self, years_after_change_point, maxima_after_change_point):
+        self.years_after_change_point = years_after_change_point
+        self.maxima_after_change_point = maxima_after_change_point
+        assert len(self.years_after_change_point) == len(self.maxima_after_change_point)
+
     @classmethod
     def trend_type_to_style(cls):
         d = OrderedDict()
@@ -49,10 +54,7 @@ class AbstractTrendTest(object):
         else:
             return plt.cm.binary
 
-    def __init__(self, years_after_change_point, maxima_after_change_point):
-        self.years_after_change_point = years_after_change_point
-        self.maxima_after_change_point = maxima_after_change_point
-        assert len(self.years_after_change_point) == len(self.maxima_after_change_point)
+
 
     @property
     def n(self):
diff --git a/extreme_estimator/extreme_models/utils.py b/extreme_estimator/extreme_models/utils.py
index 7928ca73..0ba41b4a 100644
--- a/extreme_estimator/extreme_models/utils.py
+++ b/extreme_estimator/extreme_models/utils.py
@@ -55,10 +55,11 @@ class WarningWhileRunningR(Warning):
 class WarningMaximumAbsoluteValueTooHigh(Warning):
     pass
 
-class OptimizationConstants(object):
 
+class OptimizationConstants(object):
     USE_MAXIT = False
 
+
 class SafeRunException(Exception):
     pass
 
-- 
GitLab