Commit 67682f8c authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[QUANTITY HYPERCUBE] order the dictionary of reduction functions. add detailed...

[QUANTITY HYPERCUBE] order the dictionary of reduction functions. add detailed plot parameter. fix plot with multiple reduction functions
parent cb559ec3
No related merge requests found
Showing with 39 additions and 18 deletions
+39 -18
......@@ -4,6 +4,8 @@ import matplotlib.pyplot as plt
from experiment.meteo_france_data.scm_models_data.visualization.hypercube_visualization.abstract_hypercube_visualizer import \
AbstractHypercubeVisualizer
from experiment.meteo_france_data.scm_models_data.visualization.study_visualization.main_study_visualizer import \
SCM_STUDY_NAME_TO_COLOR
from experiment.meteo_france_data.scm_models_data.visualization.study_visualization.study_visualizer import \
StudyVisualizer
from experiment.trend_analysis.univariate_test.abstract_univariate_test import AbstractUnivariateTest
......@@ -69,6 +71,8 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
if subtitle is None:
subtitle = self.study.variable_name[:5]
# Ensure that subtitle does not belong to this dictionary so that the plot will be normal
assert subtitle not in SCM_STUDY_NAME_TO_COLOR
return {subtitle: reduction_function_with_level}
......@@ -136,14 +140,18 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
assert isinstance(serie, pd.Series)
xlabel_values = list(serie.index)
values = list(serie.values)
if plot_title is not None:
argmax_idx = np.argmax(values)
best_year = xlabel_values[argmax_idx]
plot_title += '{}'.format(best_year)
plot_title += '{} {}'.format(subtitle, best_year)
if subtitle in SCM_STUDY_NAME_TO_COLOR:
ax, color, ylabel = ax.twinx(), SCM_STUDY_NAME_TO_COLOR[subtitle], subtitle
else:
color = 'k'
ax.set_title(plot_title)
ax.plot(xlabel_values, values)
ax.set_ylabel(ylabel)
ax.plot(xlabel_values, values, label=subtitle, color=color)
ax.set_ylabel(ylabel, color=color)
specific_title = 'Evolution of {} trends (significative or not) wrt to the {} with {}'.format(subtitle, xlabel,
self.trend_test_name)
......
......@@ -30,7 +30,7 @@ class AltitudeHypercubeVisualizerExtended(AltitudeHypercubeVisualizer):
return df
def _visualize_meta(self, visualization_function, loading_function, name_to_isin_parameters=None,
multiplication_factor_column=None):
multiplication_factor_column=None, add_detailed_plot=False):
assert name_to_isin_parameters is not None, 'this method should not be called directly'
if multiplication_factor_column is None:
......@@ -46,7 +46,8 @@ class AltitudeHypercubeVisualizerExtended(AltitudeHypercubeVisualizer):
axes = all_axes[j::multiplication_factor]
specific_title = visualization_function(axes, plot_title=name,
isin_parameters=isin_parameters,
show_or_save_to_file=False)
show_or_save_to_file=False,
add_detailed_plots=add_detailed_plot)
self.show_or_save_to_file(specific_title=specific_title)
# Altitude trends
......@@ -109,15 +110,15 @@ class AltitudeHypercubeVisualizerExtended(AltitudeHypercubeVisualizer):
d[name] = isin_parameters
return d
def vsualize_year_trend_by_regions_and_altitudes(self):
def vsualize_year_trend_by_regions_and_altitudes(self, add_detailed_plot=False):
return self._visualize_meta(visualization_function=self.visualize_year_trend_test,
loading_function=self.load_trend_test_evolution_axes_with_columns,
name_to_isin_parameters=self.massif_name_and_altitude_band_name_to_isin_parameters,
multiplication_factor_column=len(self.altitude_band_name_to_isin_parameters))
multiplication_factor_column=len(self.altitude_band_name_to_isin_parameters),
add_detailed_plot=add_detailed_plot)
class AltitudeHypercubeVisualizerBisExtended(AltitudeHypercubeVisualizerExtended, AltitudeHypercubeVisualizerBis):
pass
class AltitudeHypercubeVisualizerWithoutTrendExtended(AltitudeHypercubeVisualizerExtended,
......@@ -127,6 +128,12 @@ class AltitudeHypercubeVisualizerWithoutTrendExtended(AltitudeHypercubeVisualize
return self.isin_slicing(df=super().df_loglikelihood(), isin_parameters=isin_parameters)
# Extension
class AltitudeHypercubeVisualizerBisExtended(AltitudeHypercubeVisualizerExtended, AltitudeHypercubeVisualizerBis):
pass
class AltitudeYearHypercubeVisualizerExtended(AltitudeHypercubeVisualizerExtended, Altitude_Hypercube_Year_Visualizer):
pass
......@@ -136,5 +143,6 @@ class AltitudeYearHypercubeVisualizerExtended(AltitudeHypercubeVisualizerExtende
class QuantityHypercubeWithoutTrend(AltitudeHypercubeVisualizerWithoutTrendType, QuantityAltitudeHypercubeVisualizer):
pass
class QuantityHypercubeWithoutTrendExtended(AltitudeHypercubeVisualizerExtended, QuantityHypercubeWithoutTrend):
class QuantityHypercubeWithoutTrendExtended(AltitudeHypercubeVisualizerWithoutTrendExtended, QuantityHypercubeWithoutTrend):
pass
from collections import OrderedDict
import pandas as pd
from experiment.meteo_france_data.scm_models_data.visualization.hypercube_visualization.altitude_hypercube_visualizer import \
......@@ -11,23 +13,26 @@ class QuantityAltitudeHypercubeVisualizer(AltitudeHypercubeVisualizer):
return 'Quantity Altitude Study'
def subtitle_to_reduction_function(self, reduction_function, level=None, add_detailed_plot=False, subtitle=None):
subtitle_to_reduction_function = super().subtitle_to_reduction_function(reduction_function,
level, add_detailed_plot,
'global')
def get_function_from_tuple(tuple_for_axis_0):
def f(df_bool: pd.DataFrame):
def f(df: pd.DataFrame):
# Loc with a tuple with respect the axis 0
df_bool = df_bool.loc[tuple_for_axis_0, :].copy()
df = df.loc[tuple_for_axis_0, :].copy()
# Apply the reduction function
return reduction_function(df_bool) if level is None else reduction_function(df_bool, level-1)
s = reduction_function(df) if level is None else reduction_function(df, level - 1)
return s
return f
# Add the detailed plot, taken by loc with respect to the first index
subtitle_to_reduction_function = OrderedDict()
if add_detailed_plot:
tuples_axis_0 = self.tuple_values(idx=0)
for tuple_axis_0 in tuples_axis_0:
subtitle_to_reduction_function[tuple_axis_0] = get_function_from_tuple(tuple_axis_0)
# Add the super plot at the last rank
subtitle_to_reduction_function.update(super().subtitle_to_reduction_function(reduction_function,
level, add_detailed_plot,
'global'))
return subtitle_to_reduction_function
@property
......
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