From 5a280cb88c1567b9d592674005b5dd56cec39d3e Mon Sep 17 00:00:00 2001
From: Le Roux Erwan <erwan.le-roux@irstea.fr>
Date: Thu, 25 Jul 2019 17:27:46 +0200
Subject: [PATCH] [EUROCODE DATA] add eurocode regions, and mapping between
 massifs and departement, and mapping between departement and eurocode region.

---
 experiment/eurocode_data/__init__.py          |  0
 .../departementalpesfrancaises.py             | 82 +++++++++++++++++++
 experiment/eurocode_data/region_eurocode.py   | 16 ++++
 .../scm_models_data/abstract_study.py         |  1 +
 .../scm_models_data/safran/safran.py          | 12 ++-
 5 files changed, 108 insertions(+), 3 deletions(-)
 create mode 100644 experiment/eurocode_data/__init__.py
 create mode 100644 experiment/eurocode_data/departementalpesfrancaises.py
 create mode 100644 experiment/eurocode_data/region_eurocode.py

diff --git a/experiment/eurocode_data/__init__.py b/experiment/eurocode_data/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/experiment/eurocode_data/departementalpesfrancaises.py b/experiment/eurocode_data/departementalpesfrancaises.py
new file mode 100644
index 00000000..d36d9f41
--- /dev/null
+++ b/experiment/eurocode_data/departementalpesfrancaises.py
@@ -0,0 +1,82 @@
+from enum import Enum
+
+from experiment.eurocode_data.region_eurocode import AbstractRegionType, E, C2, C1
+
+
+class AbstractDepartementAlpesFrancaises(object):
+
+    def __init__(self, region: type):
+        self.region = region()  # type: AbstractRegionType
+
+
+class HauteSavoie(AbstractDepartementAlpesFrancaises):
+
+    def __init__(self):
+        super().__init__(E)
+
+
+class Savoie(AbstractDepartementAlpesFrancaises):
+
+    def __init__(self):
+        super().__init__(E)
+
+
+class Isere(AbstractDepartementAlpesFrancaises):
+
+    def __init__(self):
+        super().__init__(C2)
+
+
+class HautesAlpes(AbstractDepartementAlpesFrancaises):
+
+    def __init__(self):
+        super().__init__(C1)
+
+
+class AlpesMaritimes(AbstractDepartementAlpesFrancaises):
+
+    def __init__(self):
+        super().__init__(C1)
+
+
+class AlpesDeHauteProvence(AbstractDepartementAlpesFrancaises):
+
+    def __init__(self):
+        super().__init__(C1)
+
+
+class Drome(AbstractDepartementAlpesFrancaises):
+
+    def __init__(self):
+        super().__init__(C2)
+
+
+"""
+Quand c'est à cheval, je mets les deux massifs
+Quand juste un bout du massif est dans un autre departement 
+(Chartreuse, Belledonne sont un peu en Savoie
+"""
+massif_name_to_departements = {
+    'Chablais': [HauteSavoie],
+    'Aravis': [HauteSavoie, Savoie],
+    'Mont-Blanc': [HauteSavoie],
+    'Bauges': [HauteSavoie, Savoie],
+    'Beaufortain': [HauteSavoie, Savoie],
+    'Haute-Tarentaise': [Savoie],
+    'Chartreuse': [Isere],
+    'Belledonne': [Isere],
+    'Maurienne': [Savoie],
+    'Vanoise': [Savoie],
+    'Haute-Maurienne': [Savoie],
+    'Grandes-Rousses': [Isere, Savoie],
+    'Thabor': [HauteSavoie],
+    'Vercors': [Isere, Drome],
+    'Oisans': [Isere, HautesAlpes],
+    'Pelvoux': [Isere, HautesAlpes],
+    'Queyras': [HautesAlpes],
+    'Devoluy': [Drome, Isere, HautesAlpes],
+    'Champsaur': [HautesAlpes],
+    'Parpaillon': [HautesAlpes, AlpesDeHauteProvence],
+    'Ubaye': [AlpesDeHauteProvence],
+    'Haut_Var-Haut_Verdon': [AlpesDeHauteProvence],
+    'Mercantour': [AlpesMaritimes, AlpesDeHauteProvence]}
diff --git a/experiment/eurocode_data/region_eurocode.py b/experiment/eurocode_data/region_eurocode.py
new file mode 100644
index 00000000..5ede49c6
--- /dev/null
+++ b/experiment/eurocode_data/region_eurocode.py
@@ -0,0 +1,16 @@
+
+
+class AbstractRegionType(object):
+    pass
+
+
+class C1(AbstractRegionType):
+    pass
+
+
+class C2(AbstractRegionType):
+    pass
+
+
+class E(AbstractRegionType):
+    pass
\ No newline at end of file
diff --git a/experiment/meteo_france_data/scm_models_data/abstract_study.py b/experiment/meteo_france_data/scm_models_data/abstract_study.py
index 7c85b8d6..121eec14 100644
--- a/experiment/meteo_france_data/scm_models_data/abstract_study.py
+++ b/experiment/meteo_france_data/scm_models_data/abstract_study.py
@@ -43,6 +43,7 @@ class AbstractStudy(object):
     Les fichiers netcdf de SAFRAN et CROCUS sont autodocumentés (on peut les comprendre avec ncdump -h notamment).
     """
     REANALYSIS_FOLDER = 'SAFRAN_montagne-CROCUS_2019/alp_flat/reanalysis'
+    # REANALYSIS_FOLDER = 'SAFRAN_montagne-CROCUS_2019/postes/reanalysis'
 
     def __init__(self, variable_class: type, altitude: int = 1800, year_min=1000, year_max=3000,
                  multiprocessing=True):
diff --git a/experiment/meteo_france_data/scm_models_data/safran/safran.py b/experiment/meteo_france_data/scm_models_data/safran/safran.py
index 173fbfb3..a45199aa 100644
--- a/experiment/meteo_france_data/scm_models_data/safran/safran.py
+++ b/experiment/meteo_france_data/scm_models_data/safran/safran.py
@@ -67,13 +67,20 @@ if __name__ == '__main__':
     study = SafranSnowfall()
     # d = study.year_to_dataset_ordered_dict[1958]
     # print(d.variables)
+    print(study.study_massif_names)
+    d = {
+        name: '' for name in study.study_massif_names
+    }
+    print(d)
     for i in range(1958, 1959):
         d = study.year_to_dataset_ordered_dict[i]
+        # variable = 'station'
+        # print(np.array(d.variables[variable]))
         variable = 'Tair'
         a = np.mean(np.array(d.variables[variable]), axis=1)
-        d = study.year_to_dataset_ordered_dict[i+1]
+        d = study.year_to_dataset_ordered_dict[i + 1]
         b = np.mean(np.array(d.variables[variable]), axis=1)
-        print(a[-1] - b[0])
+        # print(a[-1] - b[0])
     # print(d.variables['time'])
     # print(study.all_massif_names)
     # print(study.massif_name_to_altitudes)
@@ -84,7 +91,6 @@ if __name__ == '__main__':
     # print(study.year_to_annual_total)
     # print(study.df_annual_total.columns)
 
-
     # for i in range(1958, 2016):
     #     d = study.year_to_dataset_ordered_dict[i]
     #     variable = 'Tair'
-- 
GitLab