Commit 7ee3d7cd authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[SCM] fix major issue of wrong permutation of safran names. add test.

parent f9573477
No related merge requests found
Showing with 87 additions and 24 deletions
+87 -24
from utils import first from utils import first
MASSIF_NAMES_1800 = ['Pelvoux', 'Queyras', 'Mont-Blanc', 'Aravis', 'Haute-Tarentaise', 'Vercors', 'Alpes-Azur', MASSIF_NAMES_1800 = ['Chablais', 'Aravis', 'Mont-Blanc', 'Bauges', 'Beaufortain',
'Oisans', 'Haute-Tarentaise', 'Chartreuse', 'Belledonne', 'Maurienne', 'Vanoise',
'Mercantour', 'Chartreuse', 'Haute-Maurienne', 'Belledonne', 'Thabor', 'Parpaillon', 'Bauges', 'Haute-Maurienne', 'Grandes-Rousses', 'Thabor', 'Vercors', 'Oisans',
'Chablais', 'Ubaye', 'Grandes-Rousses', 'Devoluy', 'Champsaur', 'Vanoise', 'Beaufortain', 'Pelvoux', 'Queyras', 'Devoluy', 'Champsaur', 'Parpaillon', 'Ubaye',
'Maurienne'] 'Alpes-Azur', 'Mercantour']
# Some massif like Chartreuse do not have massif whose altitude is higher or equal to 2400 # 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' MASSIF_NAMES_2400 = ['Chablais', 'Aravis', 'Mont-Blanc', 'Beaufortain', 'Haute-Tarentaise',
, 'Mercantour', 'Haute-Maurienne', 'Belledonne', 'Thabor', 'Parpaillon', 'Chablais', 'Ubaye', 'Grandes-Rousses', 'Belledonne', 'Maurienne', 'Vanoise', 'Haute-Maurienne',
'Devoluy', 'Champsaur', 'Vanoise', 'Beaufortain', 'Maurienne'] 'Grandes-Rousses', 'Thabor', 'Vercors', 'Oisans', 'Pelvoux', 'Queyras',
'Devoluy', 'Champsaur', 'Parpaillon', 'Ubaye', 'Alpes-Azur',
'Mercantour']
class Massif(object): class Massif(object):
...@@ -32,6 +34,9 @@ def safran_massif_names_from_datasets(datasets, altitude): ...@@ -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 the all the datasets have the same indexing for the massif
assert len(set([dataset.massifsList for dataset in datasets])) == 1 assert len(set([dataset.massifsList for dataset in datasets])) == 1
# List of the name of the massif used by all the SAFRAN datasets # 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) assert reference_massif_list == safran_names, '{} \n{}'.format(reference_massif_list, safran_names)
return reference_massif_list return reference_massif_list
...@@ -58,10 +58,12 @@ class SafranTemperature(Safran): ...@@ -58,10 +58,12 @@ class SafranTemperature(Safran):
if __name__ == '__main__': 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] 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(study.year_to_daily_time_serie[1958].shape)
# print(len(d.variables['time'])) # print(len(d.variables['time']))
print(study.year_to_annual_total) # print(study.year_to_annual_total)
print(study.df_annual_total) print(study.df_annual_total.columns)
...@@ -5,21 +5,13 @@ import pandas as pd ...@@ -5,21 +5,13 @@ import pandas as pd
from experiment.meteo_france_SCM_study.crocus.crocus import ExtendedCrocusSwe 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.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 experiment.meteo_france_SCM_study.visualization.study_visualization.study_visualizer import StudyVisualizer
from test.test_utils import load_scm_studies from test.test_utils import load_scm_studies
class TestSCMStudy(unittest.TestCase): class TestSCMAllStudy(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']))
def test_extended_run(self): def test_extended_run(self):
for study_class in [ExtendedSafranSnowfall, ExtendedCrocusSwe]: for study_class in [ExtendedSafranSnowfall, ExtendedCrocusSwe]:
...@@ -37,5 +29,69 @@ class TestSCMStudy(unittest.TestCase): ...@@ -37,5 +29,69 @@ class TestSCMStudy(unittest.TestCase):
msg="current time serie length for {} is {}".format(study.__repr__(), len(time_serie))) 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__': if __name__ == '__main__':
unittest.main() unittest.main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment