From 07b7c7d1eb4aaf63949216b5517212a5810396df Mon Sep 17 00:00:00 2001
From: Le Roux Erwan <erwan.le-roux@irstea.fr>
Date: Tue, 19 Feb 2019 16:42:21 +0100
Subject: [PATCH] [SCM] add abstract_extended_study which enable to extend any
 study by multiple inheritance

---
 ...ran_extended.py => abstract_extended_study.py} | 15 ++++-----------
 .../meteo_france_SCM_study/crocus/crocus.py       |  9 +++++++++
 .../meteo_france_SCM_study/main_visualize.py      |  8 ++++----
 .../meteo_france_SCM_study/safran/fit_safran.py   |  2 +-
 .../meteo_france_SCM_study/safran/safran.py       |  4 ++++
 5 files changed, 22 insertions(+), 16 deletions(-)
 rename experiment/meteo_france_SCM_study/{safran/safran_extended.py => abstract_extended_study.py} (91%)

diff --git a/experiment/meteo_france_SCM_study/safran/safran_extended.py b/experiment/meteo_france_SCM_study/abstract_extended_study.py
similarity index 91%
rename from experiment/meteo_france_SCM_study/safran/safran_extended.py
rename to experiment/meteo_france_SCM_study/abstract_extended_study.py
index 17cc73a3..2da5a1e8 100644
--- a/experiment/meteo_france_SCM_study/safran/safran_extended.py
+++ b/experiment/meteo_france_SCM_study/abstract_extended_study.py
@@ -1,11 +1,10 @@
 import numpy as np
 from collections import OrderedDict
 
-from experiment.meteo_france_SCM_study.safran.safran import Safran
-from utils import cached_property
+from experiment.meteo_france_SCM_study.abstract_study import AbstractStudy
 
 
-class ExtendedSafran(Safran):
+class AbstractExtendedStudy(AbstractStudy):
 
     @property
     def region_names(self):
@@ -33,15 +32,14 @@ class ExtendedSafran(Safran):
                                                 for massif_name, region_name in self.massif_name_to_region_name.items()
                                                 if region_name_loop in region_name]
             massif_ids_belong_to_the_group = [massif_id
-                                              for massif_id, massif_name in self.original_safran_massif_id_to_massif_name.items()
+                                              for massif_id, massif_name in
+                                              self.original_safran_massif_id_to_massif_name.items()
                                               if massif_name in massif_names_belong_to_the_group]
             region_name_to_massifs_ids[region_name_loop] = massif_ids_belong_to_the_group
         return region_name_to_massifs_ids
 
     """ Properties """
 
-
-
     @property
     def _year_to_daily_time_serie(self) -> OrderedDict:
         return self._year_to_extended_time_serie(aggregation_function=np.mean)
@@ -62,8 +60,3 @@ class ExtendedSafran(Safran):
 
             year_to_extended_time_serie[year] = new_time_serie
         return year_to_extended_time_serie
-
-
-
-
-
diff --git a/experiment/meteo_france_SCM_study/crocus/crocus.py b/experiment/meteo_france_SCM_study/crocus/crocus.py
index 27331668..c68a04fb 100644
--- a/experiment/meteo_france_SCM_study/crocus/crocus.py
+++ b/experiment/meteo_france_SCM_study/crocus/crocus.py
@@ -1,3 +1,4 @@
+from experiment.meteo_france_SCM_study.abstract_extended_study import AbstractExtendedStudy
 from experiment.meteo_france_SCM_study.abstract_study import AbstractStudy
 from experiment.meteo_france_SCM_study.crocus.crocus_variables import CrocusSweVariable, CrocusDepthVariable
 
@@ -19,12 +20,20 @@ class CrocusSwe(Crocus):
         super().__init__(CrocusSweVariable, altitude)
 
 
+class ExtendedCrocusSwe(AbstractExtendedStudy, CrocusSwe):
+    pass
+
+
 class CrocusDepth(Crocus):
 
     def __init__(self, altitude=1800):
         super().__init__(CrocusDepthVariable, altitude)
 
 
+class ExtendedCrocusDepth(AbstractExtendedStudy, CrocusDepth):
+    pass
+
+
 if __name__ == '__main__':
     for variable_class in [CrocusSweVariable, CrocusDepthVariable]:
         study = Crocus(variable_class=variable_class)
diff --git a/experiment/meteo_france_SCM_study/main_visualize.py b/experiment/meteo_france_SCM_study/main_visualize.py
index 822001c8..48eb5f40 100644
--- a/experiment/meteo_france_SCM_study/main_visualize.py
+++ b/experiment/meteo_france_SCM_study/main_visualize.py
@@ -1,9 +1,9 @@
 from experiment.meteo_france_SCM_study.abstract_study import AbstractStudy
-from experiment.meteo_france_SCM_study.crocus.crocus import CrocusDepth, CrocusSwe
-from experiment.meteo_france_SCM_study.safran.safran import Safran
+from experiment.meteo_france_SCM_study.crocus.crocus import CrocusDepth, CrocusSwe, ExtendedCrocusDepth, \
+    ExtendedCrocusSwe
+from experiment.meteo_france_SCM_study.safran.safran import Safran, ExtendedSafran
 from itertools import product
 
-from experiment.meteo_france_SCM_study.safran.safran_extended import ExtendedSafran
 from experiment.meteo_france_SCM_study.safran.safran_visualizer import StudyVisualizer
 
 
@@ -21,7 +21,7 @@ def load_all_studies(study_class, only_first_one=False):
 
 
 if __name__ == '__main__':
-    for study_class in [ExtendedSafran, Safran, CrocusSwe, CrocusDepth][:1]:
+    for study_class in [ExtendedSafran, ExtendedCrocusSwe, ExtendedCrocusDepth][:]:
         for study in load_all_studies(study_class, only_first_one=True):
             study_visualizer = StudyVisualizer(study)
             # study_visualizer.visualize_independent_margin_fits(threshold=[None, 20, 40, 60][0])
diff --git a/experiment/meteo_france_SCM_study/safran/fit_safran.py b/experiment/meteo_france_SCM_study/safran/fit_safran.py
index 47fe572c..7e4a8ecc 100644
--- a/experiment/meteo_france_SCM_study/safran/fit_safran.py
+++ b/experiment/meteo_france_SCM_study/safran/fit_safran.py
@@ -1,6 +1,6 @@
 import pandas as pd
 
-from experiment.meteo_france_SCM_study.safran.safran_extended import ExtendedSafran
+from experiment.meteo_france_SCM_study.safran.safran import ExtendedSafran
 from utils import VERSION
 
 
diff --git a/experiment/meteo_france_SCM_study/safran/safran.py b/experiment/meteo_france_SCM_study/safran/safran.py
index 44288118..f5877b9e 100644
--- a/experiment/meteo_france_SCM_study/safran/safran.py
+++ b/experiment/meteo_france_SCM_study/safran/safran.py
@@ -1,3 +1,4 @@
+from experiment.meteo_france_SCM_study.abstract_extended_study import AbstractExtendedStudy
 from experiment.meteo_france_SCM_study.abstract_study import AbstractStudy
 from experiment.meteo_france_SCM_study.abstract_variable import AbstractVariable
 from experiment.meteo_france_SCM_study.safran.safran_snowfall_variable import SafranSnowfallVariable
@@ -17,3 +18,6 @@ class Safran(AbstractStudy):
     def variable_name(self):
         return super().variable_name + ' cumulated over {} days'.format(self.nb_days_of_snowfall)
 
+
+class ExtendedSafran(AbstractExtendedStudy, Safran):
+    pass
-- 
GitLab