Commit b100cc64 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[POSTER] last commit for the final poster plot for IMSC 2019

parent 80879176
No related merge requests found
Showing with 100 additions and 34 deletions
+100 -34
...@@ -100,7 +100,7 @@ class AbstractHypercubeVisualizer(object): ...@@ -100,7 +100,7 @@ class AbstractHypercubeVisualizer(object):
def study_title(self): def study_title(self):
return self.study.title return self.study.title
def show_or_save_to_file(self, specific_title=''): def show_or_save_to_file(self, specific_title='', tight=False):
if self.save_to_file: if self.save_to_file:
main_title, *_ = '_'.join(self.study_title.split()).split('/') main_title, *_ = '_'.join(self.study_title.split()).split('/')
filename = "{}/{}/".format(VERSION_TIME, main_title) filename = "{}/{}/".format(VERSION_TIME, main_title)
...@@ -109,7 +109,10 @@ class AbstractHypercubeVisualizer(object): ...@@ -109,7 +109,10 @@ class AbstractHypercubeVisualizer(object):
dirname = op.dirname(filepath) dirname = op.dirname(filepath)
if not op.exists(dirname): if not op.exists(dirname):
os.makedirs(dirname, exist_ok=True) os.makedirs(dirname, exist_ok=True)
plt.savefig(filepath) if tight:
plt.savefig(filepath, bbox_inches='tight', pad_inches=-0.03)
else:
plt.savefig(filepath)
else: else:
plt.show() plt.show()
plt.close() plt.close()
......
import numpy as np import numpy as np
import pandas as pd import pandas as pd
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter, ScalarFormatter
from experiment.meteo_france_data.scm_models_data.visualization.hypercube_visualization.abstract_hypercube_visualizer import \ from experiment.meteo_france_data.scm_models_data.visualization.hypercube_visualization.abstract_hypercube_visualizer import \
AbstractHypercubeVisualizer AbstractHypercubeVisualizer
...@@ -14,6 +15,12 @@ ALTITUDES_XLABEL = 'altitudes' ...@@ -14,6 +15,12 @@ ALTITUDES_XLABEL = 'altitudes'
STARTING_YEARS_XLABEL = 'starting years' STARTING_YEARS_XLABEL = 'starting years'
from math import log10, floor
def round_sig(x, sig=2):
return round(x, sig - int(floor(log10(abs(x)))) - 1)
def make_patch_spines_invisible(ax): def make_patch_spines_invisible(ax):
ax.set_frame_on(True) ax.set_frame_on(True)
...@@ -102,7 +109,8 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer): ...@@ -102,7 +109,8 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
def visualize_trend_test_evolution(self, reduction_function, xlabel, xlabel_values, axes=None, marker='o', def visualize_trend_test_evolution(self, reduction_function, xlabel, xlabel_values, axes=None, marker='o',
subtitle='', isin_parameters=None, subtitle='', isin_parameters=None,
plot_title=None, idx_reduction=None): plot_title=None, idx_reduction=None,
poster_plot=False):
# Plot in one graph several graph that correspond to the same trend_type # Plot in one graph several graph that correspond to the same trend_type
trend_type_to_series = self.trend_type_to_series(reduction_function, isin_parameters) trend_type_to_series = self.trend_type_to_series(reduction_function, isin_parameters)
...@@ -153,13 +161,14 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer): ...@@ -153,13 +161,14 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
ax_reversed, color = ax.twinx(), SCM_STUDY_NAME_TO_COLOR[subtitle] ax_reversed, color = ax.twinx(), SCM_STUDY_NAME_TO_COLOR[subtitle]
ylabel = 'mean logLik for ' + SCM_STUDY_NAME_TO_ABBREVIATION[subtitle] ylabel = 'mean logLik for ' + SCM_STUDY_NAME_TO_ABBREVIATION[subtitle]
ax.plot([], [], label=ylabel, color=color) ax.plot([], [], label=ylabel, color=color)
ax_reversed.plot(xlabel_values, values, label=ylabel, color=color) linewidth = 10 if poster_plot else None
ax_reversed.set_ylabel(ylabel, color=color) ax_reversed.plot(xlabel_values, values, label=ylabel, color=color, linewidth=linewidth)
ax_reversed.axvline(x=best_year, color=color, linestyle='--') fontsize = 30 if poster_plot else None
ax_reversed.set_ylabel(ylabel, color=color, fontsize=fontsize, labelpad=-20)
ax_reversed.axvline(x=best_year, color=color, linestyle='--', linewidth=linewidth)
# Offset the right spine of par2. The ticks and label have already been # Offset the right spine of par2. The ticks and label have already been
# placed on the right by twinx above. # placed on the right by twinx above.
factor = SCM_STUDIES_NAMES.index(subtitle)
position = 1 + idx_reduction * 0.08 position = 1 + idx_reduction * 0.08
if idx_reduction > 0: if idx_reduction > 0:
ax_reversed.spines["right"].set_position(("axes", position)) ax_reversed.spines["right"].set_position(("axes", position))
...@@ -169,11 +178,21 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer): ...@@ -169,11 +178,21 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
make_patch_spines_invisible(ax_reversed) make_patch_spines_invisible(ax_reversed)
# Second, show the right spine. # Second, show the right spine.
ax_reversed.spines["right"].set_visible(True) ax_reversed.spines["right"].set_visible(True)
if poster_plot:
# ax_reversed.yaxis.set_major_formatter(FormatStrFormatter('%.1f'))
ax_reversed.yaxis.set_major_formatter(ScalarFormatter(useMathText=True))
# ax_reversed.tick_params(axis='both', which='major', labelsize=15)
ax_reversed.tick_params(axis='y', which='major', labelsize=25)
# ax.tick_params(axis='x', which='major', labelsize=20)
ax.tick_params(axis='x', which='major', labelsize=25)
ax_reversed.yaxis.set_ticks([np.round(min(values), 1), np.round(max(values), 1)])
else: else:
ax.set_title(plot_title) ax.set_title(plot_title)
# ax.legend() # ax.legend()
# Common things to all the graph # Common things to all the graph
ax.set_xlabel(xlabel) if not poster_plot:
ax.set_xlabel(xlabel)
plt.setp(ax.get_yticklabels(), visible=False) plt.setp(ax.get_yticklabels(), visible=False)
specific_title = self.specific_title_trend_evolution(subtitle, xlabel, loglik_title=len(axes_remaining) > 0) specific_title = self.specific_title_trend_evolution(subtitle, xlabel, loglik_title=len(axes_remaining) > 0)
...@@ -190,7 +209,8 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer): ...@@ -190,7 +209,8 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
# percents = [np.round(p) for p in percents] # percents = [np.round(p) for p in percents]
# specific_title += 'Total ' if xlabel == STARTING_YEARS_XLABEL else 'Mean ' # specific_title += 'Total ' if xlabel == STARTING_YEARS_XLABEL else 'Mean '
# specific_title += 'all trend {}, all significative trends: {} (+:{} -{})'.format(*percents) # specific_title += 'all trend {}, all significative trends: {} (+:{} -{})'.format(*percents)
plt.suptitle(specific_title) if not poster_plot:
plt.suptitle(specific_title)
return specific_title, best_year return specific_title, best_year
...@@ -270,21 +290,25 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer): ...@@ -270,21 +290,25 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
massif_to_value = dict(serie) massif_to_value = dict(serie)
massif_to_color.update({k: color for k, v in massif_to_value.items() if not np.isnan(v)}) massif_to_color.update({k: color for k, v in massif_to_value.items() if not np.isnan(v)})
self.study.visualize_study(ax, massif_name_to_color=massif_to_color, show=False) self.study.visualize_study(ax, massif_name_to_color=massif_to_color, show=False,
if plot_title is not None: show_label=False, scaled=True)
ax.set_title(plot_title)
# ax('scaled')
# if plot_title is not None:
# ax.set_title(plot_title)
title = self.set_trend_test_reparition_title(subtitle, set=False)
# row_title = self.get_title_plot(xlabel='massifs', ax_idx=i) # row_title = self.get_title_plot(xlabel='massifs', ax_idx=i)
# StudyVisualizer.clean_axes_write_title_on_the_left(axes_row, row_title, left_border=None) # StudyVisualizer.clean_axes_write_title_on_the_left(axes_row, row_title, left_border=None)
title = self.set_trend_test_reparition_title(subtitle)
return title return title
def set_trend_test_reparition_title(self, subtitle): def set_trend_test_reparition_title(self, subtitle, set=True):
# Global information # Global information
title = 'Repartition of {} trends'.format(subtitle) title = 'Repartition of {} trends'.format(subtitle)
title += ' at altitude={}m for the starting_year={}'.format(self.altitudes[0], self.starting_years[0]) title += ' at altitude={}m for the starting_year={}'.format(self.altitudes[0], self.starting_years[0])
plt.suptitle(title) if set:
plt.suptitle(title)
return title return title
def load_axes_for_trend_test_repartition(self, nb_rows, nb_columns=None): def load_axes_for_trend_test_repartition(self, nb_rows, nb_columns=None):
...@@ -311,7 +335,8 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer): ...@@ -311,7 +335,8 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
def visualize_year_trend_test(self, axes=None, marker='o', add_detailed_plots=False, plot_title=None, def visualize_year_trend_test(self, axes=None, marker='o', add_detailed_plots=False, plot_title=None,
isin_parameters=None, isin_parameters=None,
show_or_save_to_file=True, show_or_save_to_file=True,
subtitle_specified=None): subtitle_specified=None,
poster_plot=False):
if axes is None: if axes is None:
axes = self.load_trend_test_evolution_axes(self.nb_rows) axes = self.load_trend_test_evolution_axes(self.nb_rows)
else: else:
...@@ -330,12 +355,14 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer): ...@@ -330,12 +355,14 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
subtitle=subtitle, subtitle=subtitle,
isin_parameters=isin_parameters, isin_parameters=isin_parameters,
plot_title=plot_title, plot_title=plot_title,
idx_reduction=idx_reduction idx_reduction=idx_reduction,
poster_plot=poster_plot
) )
results.append((specific_title, best_year, subtitle)) results.append((specific_title, best_year, subtitle))
if show_or_save_to_file: if show_or_save_to_file:
last_specific_title = results[-1][0] last_specific_title = results[-1][0]
self.show_or_save_to_file(specific_title=last_specific_title) self.show_or_save_to_file(specific_title=last_specific_title,
)
return results return results
@staticmethod @staticmethod
...@@ -397,6 +424,6 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer): ...@@ -397,6 +424,6 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
isin_parameters=isin_parameters, isin_parameters=isin_parameters,
plot_title=plot_title) plot_title=plot_title)
if show_or_save_to_file: if show_or_save_to_file:
self.show_or_save_to_file(specific_title=last_title) self.show_or_save_to_file(specific_title=last_title, tight=True)
return last_title return last_title
...@@ -44,7 +44,7 @@ def get_fast_quantity_visualizer(quantity_hypercube_class, altitude=1800, study_ ...@@ -44,7 +44,7 @@ def get_fast_quantity_visualizer(quantity_hypercube_class, altitude=1800, study_
def main_mean_log_likelihood_poster_1(): def main_mean_log_likelihood_poster_1():
# Simply the main graph # Simply the main graph
res = get_fast_quantity_visualizer(QuantityHypercubeWithoutTrend).visualize_year_trend_test(add_detailed_plots=True) res = get_fast_quantity_visualizer(QuantityHypercubeWithoutTrend).visualize_year_trend_test(add_detailed_plots=True, poster_plot=True)
# get_fast_quantity_visualizer(QuantityHypercubeWithoutTrendExtended).vsualize_year_trend_by_regions_and_altitudes( # get_fast_quantity_visualizer(QuantityHypercubeWithoutTrendExtended).vsualize_year_trend_by_regions_and_altitudes(
# add_detailed_plot=True) # add_detailed_plot=True)
# get_fast_altitude_visualizer(AltitudeHypercubeVisualizerWithoutTrendExtended).vsualize_year_trend_by_regions_and_altitudes() # get_fast_altitude_visualizer(AltitudeHypercubeVisualizerWithoutTrendExtended).vsualize_year_trend_by_regions_and_altitudes()
...@@ -59,8 +59,8 @@ def main_percentage_trend_poster_2(): ...@@ -59,8 +59,8 @@ def main_percentage_trend_poster_2():
def main_run(): def main_run():
# main_mean_log_likelihood_poster_1() main_mean_log_likelihood_poster_1()
main_percentage_trend_poster_2() # main_percentage_trend_poster_2()
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -8,7 +8,7 @@ from experiment.meteo_france_data.scm_models_data.visualization.hypercube_visual ...@@ -8,7 +8,7 @@ from experiment.meteo_france_data.scm_models_data.visualization.hypercube_visual
from experiment.meteo_france_data.scm_models_data.visualization.hypercube_visualization.utils_hypercube import \ from experiment.meteo_france_data.scm_models_data.visualization.hypercube_visualization.utils_hypercube import \
load_altitude_visualizer load_altitude_visualizer
from experiment.meteo_france_data.scm_models_data.visualization.study_visualization.main_study_visualizer import \ from experiment.meteo_france_data.scm_models_data.visualization.study_visualization.main_study_visualizer import \
SCM_STUDIES, altitude_massif_name_and_study_class_for_poster SCM_STUDIES, altitude_massif_name_and_study_class_for_poster, SCM_STUDIES_NAMES, SCM_STUDY_NAME_TO_SCM_STUDY
from utils import get_display_name_from_object_type from utils import get_display_name_from_object_type
POSTER_ALTITUDES = [900, 1800, 2700] POSTER_ALTITUDES = [900, 1800, 2700]
...@@ -37,12 +37,14 @@ def fast_poster(): ...@@ -37,12 +37,14 @@ def fast_poster():
def full_poster(): def full_poster():
for altitude in POSTER_ALTITUDES[:]: for altitude in POSTER_ALTITUDES[:]:
study_classes = SCM_STUDIES[:] study_classes = SCM_STUDIES[:]
results = get_full_quantity_visualizer(QuantityHypercubeWithoutTrend, visualizer = get_full_quantity_visualizer(QuantityHypercubeWithoutTrend, altitude=altitude,
altitude=altitude, study_classes=study_classes)
study_classes=study_classes).visualize_year_trend_test( results = visualizer.visualize_year_trend_test(
add_detailed_plots=True) add_detailed_plots=True)
study_class_to_year = dict(zip(study_classes, [t[1] for t in results])) study_name_to_year = dict(zip(visualizer.quantities, [t[1] for t in results]))
for study_class, exact_year in study_class_to_year.items(): for study_name, exact_year in study_name_to_year.items():
print(study_name, exact_year)
study_class = SCM_STUDY_NAME_TO_SCM_STUDY[study_name]
spatial_visualizer = get_full_altitude_visualizer(AltitudeHypercubeVisualizerBisExtended, [study_class], spatial_visualizer = get_full_altitude_visualizer(AltitudeHypercubeVisualizerBisExtended, [study_class],
exact_starting_year=exact_year, altitude=altitude) exact_starting_year=exact_year, altitude=altitude)
spatial_visualizer.visualize_massif_trend_test_one_altitude() spatial_visualizer.visualize_massif_trend_test_one_altitude()
...@@ -58,5 +60,5 @@ def example_for_the_starting_years(): ...@@ -58,5 +60,5 @@ def example_for_the_starting_years():
if __name__ == '__main__': if __name__ == '__main__':
full_poster() # full_poster()
# example_for_the_starting_years() example_for_the_starting_years()
...@@ -20,6 +20,7 @@ from utils import get_display_name_from_object_type ...@@ -20,6 +20,7 @@ from utils import get_display_name_from_object_type
SCM_STUDIES = [SafranSnowfall, CrocusSwe, CrocusDepth] SCM_STUDIES = [SafranSnowfall, CrocusSwe, CrocusDepth]
SCM_STUDIES_NAMES = [get_display_name_from_object_type(k) for k in SCM_STUDIES] SCM_STUDIES_NAMES = [get_display_name_from_object_type(k) for k in SCM_STUDIES]
SCM_STUDY_NAME_TO_SCM_STUDY = dict(zip(SCM_STUDIES_NAMES, SCM_STUDIES))
SCM_STUDY_CLASS_TO_ABBREVIATION = { SCM_STUDY_CLASS_TO_ABBREVIATION = {
SafranSnowfall: 'SF3', SafranSnowfall: 'SF3',
CrocusSwe: 'SWE', CrocusSwe: 'SWE',
...@@ -28,7 +29,7 @@ SCM_STUDY_CLASS_TO_ABBREVIATION = { ...@@ -28,7 +29,7 @@ SCM_STUDY_CLASS_TO_ABBREVIATION = {
altitude_massif_name_and_study_class_for_poster = [ altitude_massif_name_and_study_class_for_poster = [
(900, 'Chartreuse', CrocusSwe), (900, 'Chartreuse', CrocusSwe),
(1800, 'Vercors', CrocusDepth), (1800, 'Vanoise', CrocusDepth),
(2700, 'Parpaillon', SafranSnowfall), (2700, 'Parpaillon', SafranSnowfall),
] ]
...@@ -240,7 +241,8 @@ def max_graph_annual_maxima_poster(): ...@@ -240,7 +241,8 @@ def max_graph_annual_maxima_poster():
multiprocessing=True) multiprocessing=True)
snow_abbreviation = SCM_STUDY_CLASS_TO_ABBREVIATION[study_class] snow_abbreviation = SCM_STUDY_CLASS_TO_ABBREVIATION[study_class]
color = SCM_STUDY_CLASS_TO_COLOR[study_class] color = SCM_STUDY_CLASS_TO_COLOR[study_class]
study_visualizer.visualize_max_graphs_poster(massif_name, altitude, snow_abbreviation, color) # study_visualizer.visualize_max_graphs_poster(massif_name, altitude, snow_abbreviation, color)
study_visualizer.visualize_gev_graphs_poster(massif_name, altitude, snow_abbreviation, color)
def altitude_analysis(): def altitude_analysis():
......
...@@ -602,6 +602,36 @@ class StudyVisualizer(VisualizationParameters): ...@@ -602,6 +602,36 @@ class StudyVisualizer(VisualizationParameters):
self.show_or_save_to_file(add_classic_title=False, no_title=True) self.show_or_save_to_file(add_classic_title=False, no_title=True)
ax.clear() ax.clear()
@staticmethod
def round_sig(x, sig=2):
return round(x, sig - int(math.floor(math.log10(abs(x)))) - 1)
def visualize_gev_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()
_, y = self.smooth_maxima_x_y(massif_names.index(massif_name))
d = IsmevGevFit(x_gev=y).gev_params
# Round up
d = {k: self.round_sig(v, 2) for k, v in d.items()}
print(d)
gev_param = GevParams.from_dict(d)
x_gev = np.linspace(0.0, 1.5 * max(y), num=1000)
y_gev = [gev_param.density(x) for x in x_gev]
ax.plot(x_gev, y_gev, color=color, linewidth=5)
ax.set_xlabel('y = annual maxima of {} (in {})'.format(snow_abbreviation, self.study.variable_unit), color=color, fontsize=15)
ax.set_ylabel('$f_{GEV}' + '(y|\mu={},\sigma={},\zeta={})$'.format(*gev_param.to_array()), fontsize=15)
ax.tick_params(axis='both', which='major', labelsize=13)
# self.visualize_massif_graphs(self.visualize_mean_and_max_graph,
# specified_massif_ids=specified_massif_ids)
plot_name = 'Gev annual maxima of {} in {} at {}m'.format(snow_abbreviation, massif_name, altitude)
self.plot_name = plot_name
self.show_or_save_to_file(add_classic_title=False, no_title=True)
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'
...@@ -735,7 +765,9 @@ class StudyVisualizer(VisualizationParameters): ...@@ -735,7 +765,9 @@ 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, add_classic_title=True, no_title=False): def show_or_save_to_file(self, add_classic_title=True, no_title=False, tight_layout=False):
if tight_layout:
plt.tight_layout()
assert self.plot_name is not None assert self.plot_name is not None
if add_classic_title: if add_classic_title:
title = self.study.title title = self.study.title
......
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