diff --git a/experiment/meteo_france_SCM_study/massif.py b/experiment/meteo_france_SCM_study/massif.py index 1fad20c9442bcf9679c118bdf65d716e4f0c2bda..92456e2cc03729b2c34fe5fd9ff4d12c12d5f80d 100644 --- a/experiment/meteo_france_SCM_study/massif.py +++ b/experiment/meteo_france_SCM_study/massif.py @@ -1,14 +1,16 @@ from utils import first -MASSIF_NAMES_1800 = ['Pelvoux', 'Queyras', 'Mont-Blanc', 'Aravis', 'Haute-Tarentaise', 'Vercors', 'Alpes-Azur', - 'Oisans', - 'Mercantour', 'Chartreuse', 'Haute-Maurienne', 'Belledonne', 'Thabor', 'Parpaillon', 'Bauges', - 'Chablais', 'Ubaye', 'Grandes-Rousses', 'Devoluy', 'Champsaur', 'Vanoise', 'Beaufortain', - 'Maurienne'] +MASSIF_NAMES_1800 = ['Chablais', 'Aravis', 'Mont-Blanc', 'Bauges', 'Beaufortain', + 'Haute-Tarentaise', 'Chartreuse', 'Belledonne', 'Maurienne', 'Vanoise', + 'Haute-Maurienne', 'Grandes-Rousses', 'Thabor', 'Vercors', 'Oisans', + 'Pelvoux', 'Queyras', 'Devoluy', 'Champsaur', 'Parpaillon', 'Ubaye', + 'Alpes-Azur', 'Mercantour'] # Some massif like Chartreuse do not have massif whose altitude is higher or equal to 2400 -MASSIF_NAMES_2400 = ['Pelvoux', 'Queyras', 'Mont-Blanc', 'Aravis', 'Haute-Tarentaise', 'Vercors', 'Alpes-Azur', 'Oisans' - , 'Mercantour', 'Haute-Maurienne', 'Belledonne', 'Thabor', 'Parpaillon', 'Chablais', 'Ubaye', 'Grandes-Rousses', - 'Devoluy', 'Champsaur', 'Vanoise', 'Beaufortain', 'Maurienne'] +MASSIF_NAMES_2400 = ['Chablais', 'Aravis', 'Mont-Blanc', 'Beaufortain', 'Haute-Tarentaise', + 'Belledonne', 'Maurienne', 'Vanoise', 'Haute-Maurienne', + 'Grandes-Rousses', 'Thabor', 'Vercors', 'Oisans', 'Pelvoux', 'Queyras', + 'Devoluy', 'Champsaur', 'Parpaillon', 'Ubaye', 'Alpes-Azur', + 'Mercantour'] class Massif(object): @@ -32,6 +34,9 @@ def safran_massif_names_from_datasets(datasets, altitude): # Assert the all the datasets have the same indexing for the massif assert len(set([dataset.massifsList for dataset in datasets])) == 1 # List of the name of the massif used by all the SAFRAN datasets - safran_names = [Massif.from_str(massif_str).name for massif_str in first(datasets).massifsList.split('/')] + massifs = [Massif.from_str(massif_str) for massif_str in first(datasets).massifsList.split('/')] + # IMPORTANT: Sort the massif names + massifs = sorted(massifs, key=lambda massif: massif.id) + safran_names = [massif.name for massif in massifs] assert reference_massif_list == safran_names, '{} \n{}'.format(reference_massif_list, safran_names) return reference_massif_list diff --git a/experiment/meteo_france_SCM_study/safran/safran.py b/experiment/meteo_france_SCM_study/safran/safran.py index 9b465db71e1b0371f9a371a57800643302194e96..6b390fe31f0fb48fc812d32acf766072c2a383a0 100644 --- a/experiment/meteo_france_SCM_study/safran/safran.py +++ b/experiment/meteo_france_SCM_study/safran/safran.py @@ -58,10 +58,12 @@ class SafranTemperature(Safran): if __name__ == '__main__': - study = SafranSnowfall() + study = SafranSnowfall(altitude=2400) + for year, dataset in study.year_to_dataset_ordered_dict.items(): + print('{}: {}'.format(year, dataset.massifsList)) d = study.year_to_dataset_ordered_dict[1958] - print(d.variables['time']) + # print(d.variables['time']) # print(study.year_to_daily_time_serie[1958].shape) # print(len(d.variables['time'])) - print(study.year_to_annual_total) - print(study.df_annual_total) + # print(study.year_to_annual_total) + print(study.df_annual_total.columns) diff --git a/test/test_experiment/test_meteo_france_SCM_study/test_SCM_study.py b/test/test_experiment/test_meteo_france_SCM_study/test_SCM_study.py index 96d46e9c8a036314fa777a5f2a4a43cc96e9bae3..93607b0f7fa5b74541914594eb607a9868af7c55 100644 --- a/test/test_experiment/test_meteo_france_SCM_study/test_SCM_study.py +++ b/test/test_experiment/test_meteo_france_SCM_study/test_SCM_study.py @@ -5,21 +5,13 @@ import pandas as pd from experiment.meteo_france_SCM_study.crocus.crocus import ExtendedCrocusSwe from experiment.meteo_france_SCM_study.visualization.study_visualization.main_study_visualizer import study_iterator -from experiment.meteo_france_SCM_study.safran.safran import SafranSnowfall, ExtendedSafranSnowfall +from experiment.meteo_france_SCM_study.safran.safran import SafranSnowfall, ExtendedSafranSnowfall, SafranTemperature, \ + SafranPrecipitation from experiment.meteo_france_SCM_study.visualization.study_visualization.study_visualizer import StudyVisualizer from test.test_utils import load_scm_studies -class TestSCMStudy(unittest.TestCase): - - def setUp(self) -> None: - super().setUp() - self.study = SafranSnowfall() - - def test_massif_safran(self): - df_centroid = pd.read_csv(op.join(self.study.map_full_path, 'coordonnees_massifs_alpes.csv')) - # Assert that the massif names are the same between SAFRAN and the coordinate file - assert not set(self.study.safran_massif_names).symmetric_difference(set(df_centroid['NOM'])) +class TestSCMAllStudy(unittest.TestCase): def test_extended_run(self): for study_class in [ExtendedSafranSnowfall, ExtendedCrocusSwe]: @@ -37,5 +29,69 @@ class TestSCMStudy(unittest.TestCase): msg="current time serie length for {} is {}".format(study.__repr__(), len(time_serie))) +class TestSCMStudy(unittest.TestCase): + + def setUp(self) -> None: + super().setUp() + self.study = None + + def check(self, massif_name_to_value_to_check): + df_annual_total = self.study.df_annual_total + for massif_name, value in massif_name_to_value_to_check.items(): + found_value = df_annual_total.loc[:, massif_name].mean() + self.assertEqual(value, self.round(found_value)) + + def round(self, f): + raise NotImplementedError + + +class TestSCMSafranSnowfall(TestSCMStudy): + + def setUp(self) -> None: + super().setUp() + self.study = SafranSnowfall() + + def test_massif_safran(self): + df_centroid = pd.read_csv(op.join(self.study.map_full_path, 'coordonnees_massifs_alpes.csv')) + # Assert that the massif names are the same between SAFRAN and the coordinate file + assert not set(self.study.safran_massif_names).symmetric_difference(set(df_centroid['NOM'])) + + +class TestSCMPrecipitation(TestSCMStudy): + + def setUp(self) -> None: + super().setUp() + self.study = SafranPrecipitation(altitude=1800, year_min=1958, year_max=2002) + + # def test_durand(self): + # # Test based on Durand paper + # # Test for the mean temperature between 1958 and 2002 + # self.check({ + # "Mercantour": 1340, + # 'Chablais': 1928, + # }) + + def round(self, f): + return int(f) + + +class TestSafranTemperature(TestSCMStudy): + + def setUp(self): + super().setUp() + self.study = SafranTemperature(altitude=1800, year_min=1958, year_max=2002) + + def test_durand(self): + # Test based on Durand paper + # Test for the mean temperature between 1958 and 2002 + self.check({ + "Mercantour": 5.1, + 'Chablais': 3.4, + }) + + def round(self, f): + return round(f, 1) + + if __name__ == '__main__': unittest.main()