Commit 2de146e9 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[HYPERCUBE] add maxima plot for poster. rename some unit for the variable

parent c534319a
No related merge requests found
Showing with 69 additions and 19 deletions
+69 -19
...@@ -46,6 +46,7 @@ class AbstractStudy(object): ...@@ -46,6 +46,7 @@ class AbstractStudy(object):
def __init__(self, variable_class: type, altitude: int = 1800, year_min=1000, year_max=3000, def __init__(self, variable_class: type, altitude: int = 1800, year_min=1000, year_max=3000,
multiprocessing=True): multiprocessing=True):
assert isinstance(altitude, int), type(altitude)
assert altitude in ALTITUDES, altitude assert altitude in ALTITUDES, altitude
self.altitude = altitude self.altitude = altitude
self.model_name = None self.model_name = None
......
...@@ -12,7 +12,7 @@ class CrocusVariable(AbstractVariable): ...@@ -12,7 +12,7 @@ class CrocusVariable(AbstractVariable):
class CrocusSweVariable(CrocusVariable): class CrocusSweVariable(CrocusVariable):
NAME = 'Snow Water Equivalent' NAME = 'Snow Water Equivalent'
UNIT = 'kg per m2 or mm' UNIT = 'kg per square meter'
@classmethod @classmethod
def keyword(cls): def keyword(cls):
......
...@@ -22,7 +22,7 @@ class SafranSnowfallVariable(AbstractVariable): ...@@ -22,7 +22,7 @@ class SafranSnowfallVariable(AbstractVariable):
""" """
NAME = 'Snowfall' NAME = 'Snowfall'
UNIT = 'kg per m2 or mm' UNIT = 'mm'
@classmethod @classmethod
def keyword(cls): def keyword(cls):
......
...@@ -7,7 +7,8 @@ from experiment.trend_analysis.abstract_score import MannKendall ...@@ -7,7 +7,8 @@ from experiment.trend_analysis.abstract_score import MannKendall
from experiment.meteo_france_data.scm_models_data.abstract_study import AbstractStudy from experiment.meteo_france_data.scm_models_data.abstract_study import AbstractStudy
from experiment.meteo_france_data.scm_models_data.crocus.crocus import CrocusDepth, CrocusSwe, ExtendedCrocusDepth, \ from experiment.meteo_france_data.scm_models_data.crocus.crocus import CrocusDepth, CrocusSwe, ExtendedCrocusDepth, \
ExtendedCrocusSwe, CrocusDaysWithSnowOnGround ExtendedCrocusSwe, CrocusDaysWithSnowOnGround
from experiment.meteo_france_data.scm_models_data.safran.safran import SafranSnowfall, ExtendedSafranSnowfall, SafranRainfall, \ from experiment.meteo_france_data.scm_models_data.safran.safran import SafranSnowfall, ExtendedSafranSnowfall, \
SafranRainfall, \
SafranTemperature, SafranTotalPrecip SafranTemperature, SafranTotalPrecip
from collections import OrderedDict from collections import OrderedDict
...@@ -23,16 +24,27 @@ SCM_STUDY_CLASS_TO_ABBREVIATION = { ...@@ -23,16 +24,27 @@ SCM_STUDY_CLASS_TO_ABBREVIATION = {
CrocusSwe: 'SWE', CrocusSwe: 'SWE',
CrocusDepth: 'SD', CrocusDepth: 'SD',
} }
SCM_STUDY_NAME_TO_ABBREVIATION = {get_display_name_from_object_type(k): v for k, v in SCM_STUDY_CLASS_TO_ABBREVIATION.items()}
altitude_massif_name_and_study_class_for_poster = [
(900, 'Chartreuse', CrocusSwe),
(1800, 'Vercors', CrocusDepth),
(2700, 'Parpaillon', SafranSnowfall),
]
SCM_STUDY_NAME_TO_ABBREVIATION = {get_display_name_from_object_type(k): v for k, v in
SCM_STUDY_CLASS_TO_ABBREVIATION.items()}
SCM_COLORS = ['tab:orange', 'y', 'tab:purple']
SCM_STUDY_CLASS_TO_COLOR = dict(zip(SCM_STUDIES, SCM_COLORS))
SCM_STUDY_NAME_TO_COLOR = {get_display_name_from_object_type(s): color SCM_STUDY_NAME_TO_COLOR = {get_display_name_from_object_type(s): color
for s, color in zip(SCM_STUDIES, ['tab:orange', 'y', 'tab:purple'])} for s, color in zip(SCM_STUDIES, SCM_COLORS)}
SCM_EXTENDED_STUDIES = [ExtendedSafranSnowfall, ExtendedCrocusSwe, ExtendedCrocusDepth] SCM_EXTENDED_STUDIES = [ExtendedSafranSnowfall, ExtendedCrocusSwe, ExtendedCrocusDepth]
SCM_STUDY_TO_EXTENDED_STUDY = OrderedDict(zip(SCM_STUDIES, SCM_EXTENDED_STUDIES)) SCM_STUDY_TO_EXTENDED_STUDY = OrderedDict(zip(SCM_STUDIES, SCM_EXTENDED_STUDIES))
ALL_ALTITUDES = [0, 300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000, 3300, 3600, 3900, 4200, 4500, 4800] ALL_ALTITUDES = [0, 300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000, 3300, 3600, 3900, 4200, 4500, 4800]
ALTITUDES_LOW_MIDDLE_HIGH = [900, 1800, 2700] ALTITUDES_LOW_MIDDLE_HIGH = [900, 1800, 2700]
ALL_ALTITUDES_WITHOUT_NAN = [300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000, 3300, 3600, 3900, 4200, 4500, 4800] ALL_ALTITUDES_WITHOUT_NAN = [300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000, 3300, 3600, 3900, 4200, 4500,
4800]
full_altitude_with_at_least_2_stations = [0, 300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000, 3300, 3600, 3900, full_altitude_with_at_least_2_stations = [0, 300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000, 3300, 3600, 3900,
4200] 4200]
ALL_ALTITUDES_WITH_20_STATIONS_AT_LEAST = ALL_ALTITUDES[3:-6][:] ALL_ALTITUDES_WITH_20_STATIONS_AT_LEAST = ALL_ALTITUDES[3:-6][:]
...@@ -41,7 +53,7 @@ ALL_STUDIES = SCM_STUDIES + [SafranTemperature, SafranRainfall] ...@@ -41,7 +53,7 @@ ALL_STUDIES = SCM_STUDIES + [SafranTemperature, SafranRainfall]
def study_iterator_global(study_classes, only_first_one=False, verbose=True, altitudes=None, nb_days=None) -> \ def study_iterator_global(study_classes, only_first_one=False, verbose=True, altitudes=None, nb_days=None) -> \
List[AbstractStudy]: List[AbstractStudy]:
for study_class in study_classes: for study_class in study_classes:
for study in study_iterator(study_class, only_first_one, verbose, altitudes, nb_days): for study in study_iterator(study_class, only_first_one, verbose, altitudes, nb_days):
yield study yield study
...@@ -49,7 +61,8 @@ List[AbstractStudy]: ...@@ -49,7 +61,8 @@ List[AbstractStudy]:
break break
def study_iterator(study_class, only_first_one=False, verbose=True, altitudes=None, nb_consecutive_days=3) -> List[AbstractStudy]: def study_iterator(study_class, only_first_one=False, verbose=True, altitudes=None, nb_consecutive_days=3) -> List[
AbstractStudy]:
# Default argument # Default argument
altis = [1800] if altitudes is None else altitudes altis = [1800] if altitudes is None else altitudes
...@@ -126,8 +139,10 @@ def all_normal_vizu(): ...@@ -126,8 +139,10 @@ def all_normal_vizu():
study_visualizer = StudyVisualizer(study, save_to_file=True, temporal_non_stationarity=True) study_visualizer = StudyVisualizer(study, save_to_file=True, temporal_non_stationarity=True)
study_visualizer.visualize_all_mean_and_max_graphs() study_visualizer.visualize_all_mean_and_max_graphs()
def case_study(): def case_study():
for study in study_iterator(study_class=SafranSnowfall, only_first_one=False, altitudes=[2100], nb_consecutive_days=3): for study in study_iterator(study_class=SafranSnowfall, only_first_one=False, altitudes=[2100],
nb_consecutive_days=3):
study_visualizer = StudyVisualizer(study, save_to_file=False, temporal_non_stationarity=False) study_visualizer = StudyVisualizer(study, save_to_file=False, temporal_non_stationarity=False)
study_visualizer.visualize_all_mean_and_max_graphs() study_visualizer.visualize_all_mean_and_max_graphs()
massif_id = study.study_massif_names.index('Chablais') massif_id = study.study_massif_names.index('Chablais')
...@@ -149,11 +164,14 @@ def scores_vizu(): ...@@ -149,11 +164,14 @@ def scores_vizu():
def all_scores_vizu(): def all_scores_vizu():
save_to_file = True save_to_file = True
only_first_one = False only_first_one = False
for study in study_iterator_global(study_classes=[SafranSnowfall], only_first_one=only_first_one, altitudes=ALL_ALTITUDES): for study in study_iterator_global(study_classes=[SafranSnowfall], only_first_one=only_first_one,
study_visualizer = StudyVisualizer(study, save_to_file=save_to_file, temporal_non_stationarity=True, verbose=True) altitudes=ALL_ALTITUDES):
study_visualizer = StudyVisualizer(study, save_to_file=save_to_file, temporal_non_stationarity=True,
verbose=True)
# study_visualizer.visualize_all_mean_and_max_graphs() # study_visualizer.visualize_all_mean_and_max_graphs()
study_visualizer.visualize_all_score_wrt_starting_year() study_visualizer.visualize_all_score_wrt_starting_year()
def complete_analysis(only_first_one=False): def complete_analysis(only_first_one=False):
"""An overview of everything that is possible with study OR extended study""" """An overview of everything that is possible with study OR extended study"""
for study_class, extended_study_class in list(SCM_STUDY_TO_EXTENDED_STUDY.items())[:]: for study_class, extended_study_class in list(SCM_STUDY_TO_EXTENDED_STUDY.items())[:]:
...@@ -191,13 +209,14 @@ def trend_analysis(): ...@@ -191,13 +209,14 @@ def trend_analysis():
study_visualizer.df_trend_spatio_temporal(GevLocationChangePointTest, study_visualizer.df_trend_spatio_temporal(GevLocationChangePointTest,
starting_years=[1958, 1980], nb_massif_for_fast_mode=2) starting_years=[1958, 1980], nb_massif_for_fast_mode=2)
def maxima_analysis(): def maxima_analysis():
save_to_file = False save_to_file = False
only_first_one = True only_first_one = True
durand_altitude = [1800] durand_altitude = [1800]
altitudes = durand_altitude altitudes = durand_altitude
normalization_class = BetweenZeroAndOneNormalization normalization_class = BetweenZeroAndOneNormalization
study_classes = [ SafranSnowfall][:] study_classes = [SafranSnowfall][:]
for study in study_iterator_global(study_classes, only_first_one=only_first_one, altitudes=altitudes): for study in study_iterator_global(study_classes, only_first_one=only_first_one, altitudes=altitudes):
study_visualizer = StudyVisualizer(study, save_to_file=save_to_file, study_visualizer = StudyVisualizer(study, save_to_file=save_to_file,
transformation_class=normalization_class, transformation_class=normalization_class,
...@@ -208,7 +227,19 @@ def maxima_analysis(): ...@@ -208,7 +227,19 @@ def maxima_analysis():
score_class=MannKendall) score_class=MannKendall)
study_visualizer.visualize_all_score_wrt_starting_year() study_visualizer.visualize_all_score_wrt_starting_year()
# study_visualizer.visualize_all_independent_temporal_trend() # study_visualizer.visualize_all_independent_temporal_trend()
# study_visualizer.visualize_all_mean_and_max_graphs() study_visualizer.visualize_all_mean_and_max_graphs()
def max_graph_annual_maxima_poster():
save_to_file = True
for altitude, massif_name, study_class in altitude_massif_name_and_study_class_for_poster:
for study in study_iterator_global([study_class], altitudes=[altitude]):
study_visualizer = StudyVisualizer(study, save_to_file=save_to_file,
verbose=True,
multiprocessing=True)
snow_abbreviation = SCM_STUDY_CLASS_TO_ABBREVIATION[study_class]
color = SCM_STUDY_CLASS_TO_COLOR[study_class]
study_visualizer.visualize_max_graphs_poster(massif_name, altitude, snow_abbreviation, color)
def altitude_analysis(): def altitude_analysis():
...@@ -222,7 +253,8 @@ def main_run(): ...@@ -222,7 +253,8 @@ def main_run():
# normal_visualization(temporal_non_stationarity=True) # normal_visualization(temporal_non_stationarity=True)
# trend_analysis() # trend_analysis()
altitude_analysis() # altitude_analysis()
max_graph_annual_maxima_poster()
# case_study() # case_study()
# all_scores_vizu() # all_scores_vizu()
# maxima_analysis() # maxima_analysis()
......
...@@ -432,7 +432,6 @@ class StudyVisualizer(VisualizationParameters): ...@@ -432,7 +432,6 @@ class StudyVisualizer(VisualizationParameters):
else: else:
massif_names = sample(self.study.study_massif_names, k=self.nb_massif_for_change_point_test) massif_names = sample(self.study.study_massif_names, k=self.nb_massif_for_change_point_test)
for massif_id, massif_name in enumerate(massif_names): for massif_id, massif_name in enumerate(massif_names):
years, smooth_maxima = self.smooth_maxima_x_y(massif_id) years, smooth_maxima = self.smooth_maxima_x_y(massif_id)
gev_change_point_test_results = compute_gev_change_point_test_results(self.multiprocessing, smooth_maxima, gev_change_point_test_results = compute_gev_change_point_test_results(self.multiprocessing, smooth_maxima,
...@@ -459,7 +458,7 @@ class StudyVisualizer(VisualizationParameters): ...@@ -459,7 +458,7 @@ class StudyVisualizer(VisualizationParameters):
trend_test_class_for_change_point_test, trend_test_class_for_change_point_test,
starting_years_for_change_point_test, starting_years_for_change_point_test,
nb_massif_for_change_point_test, nb_massif_for_change_point_test,
sample_one_massif_from_each_region) sample_one_massif_from_each_region)
for massif_name, gev_change_point_test_results in massif_name_to_gev_change_point_test_results.items(): for massif_name, gev_change_point_test_results in massif_name_to_gev_change_point_test_results.items():
trend_test_res, best_idxs = gev_change_point_test_results trend_test_res, best_idxs = gev_change_point_test_results
trend_test_res = [(a, b, c) if i in best_idxs else (np.nan, np.nan, c) trend_test_res = [(a, b, c) if i in best_idxs else (np.nan, np.nan, c)
...@@ -586,6 +585,21 @@ class StudyVisualizer(VisualizationParameters): ...@@ -586,6 +585,21 @@ class StudyVisualizer(VisualizationParameters):
self.plot_name = plot_name self.plot_name = plot_name
self.show_or_save_to_file() self.show_or_save_to_file()
def visualize_max_graphs_poster(self, massif_name, altitude, snow_abbreviation, color):
massif_names = self.study.study_massif_names
# Display the graph of the max on top
ax = plt.gca()
x, y = self.smooth_maxima_x_y(massif_names.index(massif_name))
ax.plot(x, y, color=color)
ax.set_ylabel('{} (in {})'.format(snow_abbreviation, self.study.variable_unit), color=color)
ax.xaxis.set_ticks(x[2::10])
# self.visualize_massif_graphs(self.visualize_mean_and_max_graph,
# specified_massif_ids=specified_massif_ids)
plot_name = 'Annual maxima of {} in {} at {}'.format(snow_abbreviation, massif_name, altitude)
self.plot_name = plot_name
self.show_or_save_to_file(add_classic_title=False)
ax.clear()
def visualize_mean_and_max_graph(self, ax, massif_id): def visualize_mean_and_max_graph(self, ax, massif_id):
# Display the graph of the max on top # Display the graph of the max on top
color_maxima = 'r' color_maxima = 'r'
...@@ -719,10 +733,13 @@ class StudyVisualizer(VisualizationParameters): ...@@ -719,10 +733,13 @@ class StudyVisualizer(VisualizationParameters):
label_function(full_title) label_function(full_title)
ax0.tick_params(axis=u'both', which=u'both', length=0) ax0.tick_params(axis=u'both', which=u'both', length=0)
def show_or_save_to_file(self): def show_or_save_to_file(self, add_classic_title=True):
assert self.plot_name is not None assert self.plot_name is not None
title = self.study.title if add_classic_title:
title += '\n' + self.plot_name title = self.study.title
title += '\n' + self.plot_name
else:
title = self.plot_name
if self.only_one_graph: if self.only_one_graph:
plt.suptitle(self.plot_name) plt.suptitle(self.plot_name)
else: else:
......
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