diff --git a/experiment/meteo_france_SCM_study/abstract_study.py b/experiment/meteo_france_SCM_study/abstract_study.py index 82c6dc5c604d9d576564b587c52be124837a8e75..12847bb18d8869bdf8d504b2da74abf83a64ef1e 100644 --- a/experiment/meteo_france_SCM_study/abstract_study.py +++ b/experiment/meteo_france_SCM_study/abstract_study.py @@ -138,9 +138,7 @@ class AbstractStudy(object): massif_name = self.coordinate_id_to_massif_name[coordinate_id] fill_kwargs = massif_name_to_fill_kwargs[massif_name] if massif_name_to_fill_kwargs is not None else {} ax.fill(*l, **fill_kwargs) - ax.scatter(self.massifs_coordinates.x_coordinates, self.massifs_coordinates.y_coordinates) - ax.axis('off') - + ax.scatter(self.massifs_coordinates.x_coordinates, self.massifs_coordinates.y_coordinates, s=1) if show: plt.show() diff --git a/experiment/meteo_france_SCM_study/crocus/crocus.py b/experiment/meteo_france_SCM_study/crocus/crocus.py index d6f3e21554a43eea43ea0a6c952c50028190ed7a..2d8c031feeb666b277a552f9e66dd4259a94be72 100644 --- a/experiment/meteo_france_SCM_study/crocus/crocus.py +++ b/experiment/meteo_france_SCM_study/crocus/crocus.py @@ -20,11 +20,13 @@ class Crocus(AbstractStudy): suffix = '' if self.altitude == 2400 else ' average of data observed every 6 hours' return super().variable_name + suffix + class CrocusSwe(Crocus): def __init__(self, altitude=1800): super().__init__(CrocusSweVariable, altitude) + class ExtendedCrocusSwe(AbstractExtendedStudy, CrocusSwe): pass diff --git a/experiment/meteo_france_SCM_study/main_visualize.py b/experiment/meteo_france_SCM_study/main_visualize.py index f425c927a0b7330a897888943a3f6fa6f7dff896..714fb36f925b07cd9bc2e468d6d1919411c75242 100644 --- a/experiment/meteo_france_SCM_study/main_visualize.py +++ b/experiment/meteo_france_SCM_study/main_visualize.py @@ -35,9 +35,9 @@ def study_iterator(study_class, only_first_one=False, both_altitude=False, verbo def extended_visualization(): save_to_file = True only_first_one = True - for study_class in SCM_EXTENDED_STUDIES[:1]: + for study_class in SCM_EXTENDED_STUDIES[:]: for study in study_iterator(study_class, only_first_one=only_first_one): - study_visualizer = StudyVisualizer(study, save_to_file=save_to_file, only_one_graph=True, year_for_kde_plot=1958, vertical_kde_plot=True) + study_visualizer = StudyVisualizer(study, save_to_file=save_to_file, only_one_graph=True, plot_block_maxima_quantiles=True) # study_visualizer.visualize_all_mean_and_max_graphs() study_visualizer.visualize_all_experimental_law() # for study_class in SCM_EXTENDED_STUDIES[:]: @@ -54,7 +54,7 @@ def normal_visualization(): for study in study_iterator(study_class, only_first_one=only_first_one): study_visualizer = StudyVisualizer(study, save_to_file=save_to_file) # study_visualizer.visualize_independent_margin_fits(threshold=[None, 20, 40, 60][0]) - study_visualizer.visualize_linear_margin_fit(only_first_max_stable=only_first_one) + study_visualizer.visualize_linear_margin_fit(only_first_max_stable=False) def complete_analysis(only_first_one=False): @@ -73,6 +73,6 @@ def complete_analysis(only_first_one=False): if __name__ == '__main__': - # normal_visualization() - extended_visualization() + normal_visualization() + # extended_visualization() # complete_analysis() diff --git a/experiment/meteo_france_SCM_study/safran/safran_visualizer.py b/experiment/meteo_france_SCM_study/safran/safran_visualizer.py index 33ad82682c102ede11fa388fcaa8d47b8302bacc..bfbb7cdde6f544b76ab5f9a89afb1a8f5a4a72f9 100644 --- a/experiment/meteo_france_SCM_study/safran/safran_visualizer.py +++ b/experiment/meteo_france_SCM_study/safran/safran_visualizer.py @@ -43,14 +43,18 @@ class StudyVisualizer(object): self.year_for_kde_plot = year_for_kde_plot self.plot_block_maxima_quantiles = plot_block_maxima_quantiles - self.show = False if self.save_to_file else show self.window_size_for_smoothing = 21 + + # PLOT ARGUMENTS + self.show = False if self.save_to_file else show if self.only_one_graph: self.figsize = (6.0, 4.0) elif self.only_first_row: self.figsize = (8.0, 6.0) else: self.figsize = (16.0, 10.0) + self.subplot_space = 0.05 + self.coef_zoom_map = 0 @property def observations(self): @@ -74,7 +78,7 @@ class StudyVisualizer(object): nb_columns = 5 nb_rows = 1 if self.only_first_row else math.ceil(len(self.study.safran_massif_names) / nb_columns) fig, axes = plt.subplots(nb_rows, nb_columns, figsize=self.figsize) - fig.subplots_adjust(hspace=1.0, wspace=1.0) + fig.subplots_adjust(hspace=self.subplot_space, wspace=self.subplot_space) if self.only_first_row: for massif_id, massif_name in enumerate(self.study.safran_massif_names[:nb_columns]): ax = axes[massif_id] @@ -149,13 +153,16 @@ class StudyVisualizer(object): xlabel = 'x = {}'.format(self.study.title) if self.only_one_graph else 'x' label_function = ax.set_ylabel if self.vertical_kde_plot else ax.set_xlabel label_function(xlabel) - sorted_x_levels = sorted(list([x_level for x_level, _ in name_to_xlevel_and_color.values()])) # Take all the ticks + # sorted_x_levels = sorted(list([x_level for x_level, _ in name_to_xlevel_and_color.values()])) # extraticks = [float(float_to_str_with_only_some_significant_digits(x, nb_digits=2)) # for x in sorted_x_levels] # Display only some specific ticks - extraticks = [name_to_xlevel_and_color['mean'][0], name_to_xlevel_and_color[AbstractParams.QUANTILE_100][0]] + extraticks_names = ['mean', AbstractParams.QUANTILE_100] + if self.plot_block_maxima_quantiles: + extraticks_names += [name for name in name_to_xlevel_and_color.keys() if BLOCK_MAXIMA_DISPLAY_NAME in name] + extraticks = [name_to_xlevel_and_color[name][0] for name in extraticks_names] set_ticks_function = ax.set_yticks if self.vertical_kde_plot else ax.set_xticks # Round up the ticks with a given number of significative digits @@ -192,13 +199,15 @@ class StudyVisualizer(object): ax.set_title(self.study.safran_massif_names[massif_id]) def visualize_linear_margin_fit(self, only_first_max_stable=False): - self.plot_name = 'Full Likelihood with Linear marginals and max stable dependency structure' default_covariance_function = CovarianceFunction.cauchy + plot_name = 'Full Likelihood with Linear marginals and max stable dependency structure' + plot_name += '\n(with {} covariance structure when a covariance is needed)'.format(str(default_covariance_function).split('.')[-1]) + self.plot_name = plot_name max_stable_models = load_test_max_stable_models(default_covariance_function=default_covariance_function) if only_first_max_stable: max_stable_models = max_stable_models[:1] fig, axes = plt.subplots(len(max_stable_models) + 1, len(GevParams.SUMMARY_NAMES), figsize=self.figsize) - fig.subplots_adjust(hspace=1.0, wspace=1.0) + fig.subplots_adjust(hspace=self.subplot_space, wspace=self.subplot_space) margin_class = LinearAllParametersAllDimsMarginModel # Plot the smooth margin only margin_model = margin_class(coordinates=self.coordinates) @@ -209,16 +218,44 @@ class StudyVisualizer(object): margin_model = margin_class(coordinates=self.coordinates) estimator = FullEstimatorInASingleStepWithSmoothMargin(self.dataset, margin_model, max_stable_model) title = get_display_name_from_object_type(type(max_stable_model)) - if isinstance(max_stable_model, AbstractMaxStableModelWithCovarianceFunction): - title += ' ' + str(default_covariance_function).split('.')[-1] + # if isinstance(max_stable_model, AbstractMaxStableModelWithCovarianceFunction): + # title += ' ' + str(default_covariance_function).split('.')[-1] self.fit_and_visualize_estimator(estimator, axes[i], title=title) + # Add the label self.show_or_save_to_file() def fit_and_visualize_estimator(self, estimator, axes=None, title=None): estimator.fit() - axes = estimator.margin_function_fitted.visualize_function(show=False, axes=axes, title=title) + + margin_fct = estimator.margin_function_fitted + axes = margin_fct.visualize_function(show=False, axes=axes, title='') + + def get_lim_array(ax): + return np.array([np.array(ax.get_xlim()), np.array(ax.get_ylim())]) + for ax in axes: + old_lim = get_lim_array(ax) self.study.visualize(ax, fill=False, show=False) + new_lim = get_lim_array(ax) + assert 0 <= self.coef_zoom_map <= 1 + updated_lim = new_lim * self.coef_zoom_map + (1 - self.coef_zoom_map) * old_lim + for i, method in enumerate([ax.set_xlim, ax.set_ylim]): + method(updated_lim[i, 0], updated_lim[i, 1]) + ax.tick_params(axis=u'both', which=u'both', length=0) + ax.spines['top'].set_visible(False) + ax.spines['right'].set_visible(False) + ax.spines['bottom'].set_visible(False) + ax.spines['left'].set_visible(False) + ax.get_xaxis().set_visible(False) + ax.get_yaxis().set_visible(False) + ax.set_aspect('equal') + ax0 = axes[0] + ax0.get_yaxis().set_visible(True) + # todo: manage to remove ticks on ylabel + # finally it's good because it differntiate it from the other labels + # maybe i could put it in bold + ax0.set_ylabel(title) + ax0.tick_params(axis=u'both', which=u'both', length=0) def show_or_save_to_file(self): assert self.plot_name is not None @@ -252,7 +289,7 @@ class StudyVisualizer(object): if axes is None: fig, axes = plt.subplots(1, len(params_names)) - fig.subplots_adjust(hspace=1.0, wspace=1.0) + fig.subplots_adjust(hspace=self.subplot_space, wspace=self.subplot_space) for i, gev_param_name in enumerate(params_names): ax = axes[i] diff --git a/extreme_estimator/margin_fits/plot/create_shifted_cmap.py b/extreme_estimator/margin_fits/plot/create_shifted_cmap.py index db147f9cb422b43a8e343e7f57a63a082fe1fe85..64af9bf97b34ae4e06b6533229631224514a2c9a 100644 --- a/extreme_estimator/margin_fits/plot/create_shifted_cmap.py +++ b/extreme_estimator/margin_fits/plot/create_shifted_cmap.py @@ -30,7 +30,7 @@ def plot_extreme_param(ax, gev_param_name, values): shifted_cmap = shiftedColorMap(cmap, midpoint=midpoint, name='shifted') norm = mpl.colors.Normalize(vmin=vmin, vmax=vmax) divider = make_axes_locatable(ax) - cax = divider.append_axes('right', size='5%', pad=0.05) + cax = divider.append_axes('right', size='5%', pad=0.03) cb = cbar.ColorbarBase(cax, cmap=shifted_cmap, norm=norm) cb.set_label(gev_param_name) return norm, shifted_cmap