Commit 5560ff21 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[HYPERCUBE VISUALIZER] deativate strength visualization. fix spatial...

[HYPERCUBE VISUALIZER] deativate strength visualization. fix spatial visualization having np.nan values
parent 11f481df
No related merge requests found
Showing with 55 additions and 48 deletions
+55 -48
......@@ -237,7 +237,7 @@ class AbstractStudy(object):
norm = Normalize(vmin, vmax)
create_colorbase_axis(ax, label, cmap, norm)
m = cm.ScalarMappable(norm=norm, cmap=cmap)
colors = [m.to_rgba(value) for value in values]
colors = [m.to_rgba(value) if not np.isnan(value) else 'w' for value in values]
massif_name_to_fill_kwargs = {massif_name: {'color': color} for massif_name, color in
zip(massif_names, colors)}
......
......@@ -18,9 +18,9 @@ class AbstractHypercubeVisualizer(object):
def __init__(self, tuple_to_study_visualizer: Dict[Tuple, StudyVisualizer],
trend_test_class,
fast=False,
nb_data_reduced_for_speed=False,
save_to_file=False):
self.nb_data_for_fast_mode = 7 if fast else None
self.nb_data_for_fast_mode = 7 if nb_data_reduced_for_speed else None
self.save_to_file = save_to_file
self.trend_test_class = trend_test_class
self.tuple_to_study_visualizer = tuple_to_study_visualizer # type: Dict[Tuple, StudyVisualizer]
......
......@@ -39,11 +39,12 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
assert isinstance(s_trend_type_percentage, pd.Series)
assert not isinstance(s_trend_type_percentage.index, pd.MultiIndex)
s_trend_type_percentage *= 100
# Reduce df_strength to a serie s_trend_strength
df_strength = self.df_hypercube_trend_strength[df_bool]
s_trend_strength = reduction_function(df_strength)
# Group result
series = [s_trend_type_percentage, s_trend_strength]
series = [s_trend_type_percentage]
# # Reduce df_strength to a serie s_trend_strength
# df_strength = self.df_hypercube_trend_strength[df_bool]
# s_trend_strength = reduction_function(df_strength)
# # Group result
# series = [s_trend_type_percentage, s_trend_strength]
return series, df_bool
def subtitle_to_reduction_function(self, reduction_function, level=None, add_detailed_plot=False, subtitle=None):
......@@ -112,8 +113,8 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
vmin = min([s.min() for s in trend_type_to_serie.values()])
vmax = max(vmax, 0.01)
for ax, trend_type in zip(axes_row, self.display_trend_types):
s_percentages = trend_type_to_serie[trend_type]
massif_to_value = dict(s_percentages)
serie = trend_type_to_serie[trend_type]
massif_to_value = dict(serie)
cmap = self.trend_test_class.get_cmap_from_trend_type(trend_type)
self.study.visualize_study(ax, massif_to_value, show=False, cmap=cmap, label=None, vmax=vmax, vmin=vmin)
ax.set_title(trend_type)
......@@ -167,32 +168,3 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
self.visualize_trend_test_repartition(reduction_function, axes, subtitle=subtitle)
class Altitude_Hypercube_Year_Visualizer(AltitudeHypercubeVisualizer):
def get_title_plot(self, xlabel, ax_idx=None):
if ax_idx == self.nb_axes - 1:
return 'mean starting year'
return super().get_title_plot(xlabel, ax_idx)
@property
def nb_axes(self):
return super().nb_axes + 1
@staticmethod
def index_reduction(df, level):
# Take the sum with respect to the years, replace any missing data with np.nan
df = df.sum(axis=1).replace(0.0, np.nan)
# Take the mean with respect to the level of interest
return df.mean(level=level)
def trend_type_reduction(self, reduction_function, display_trend_type):
series, df_bool = super().trend_type_reduction(reduction_function, display_trend_type)
# Create df argmax
df = df_bool.copy()
df = (df * df.columns)[df_bool]
# Reduce and append
serie = reduction_function(df)
series.append(serie)
return series, df_bool
import numpy as np
from experiment.meteo_france_data.visualization.hypercube_visualization.altitude_hypercube_visualizer import \
AltitudeHypercubeVisualizer
class Altitude_Hypercube_Year_Visualizer(AltitudeHypercubeVisualizer):
def get_title_plot(self, xlabel, ax_idx=None):
if ax_idx == self.nb_axes - 1:
return 'mean starting year'
return super().get_title_plot(xlabel, ax_idx)
@property
def nb_axes(self):
return super().nb_axes + 1
@staticmethod
def index_reduction(df, level):
# Take the sum with respect to the years, replace any missing data with np.nan
df = df.sum(axis=1).replace(0.0, np.nan)
# Take the mean with respect to the level of interest
return df.mean(level=level)
def trend_type_reduction(self, reduction_function, display_trend_type):
series, df_bool = super().trend_type_reduction(reduction_function, display_trend_type)
# Create df argmax
df = df_bool.copy()
df = (df * df.columns)[df_bool]
# Reduce and append
serie = reduction_function(df)
series.append(serie)
return series, df_bool
......@@ -3,7 +3,9 @@ from itertools import product
from collections import OrderedDict
from experiment.meteo_france_data.visualization.hypercube_visualization.altitude_hypercube_visualizer import \
AltitudeHypercubeVisualizer, Altitude_Hypercube_Year_Visualizer
AltitudeHypercubeVisualizer
from experiment.meteo_france_data.visualization.hypercube_visualization.altitude_year_hypercube_visualizer import \
Altitude_Hypercube_Year_Visualizer
from experiment.meteo_france_data.visualization.hypercube_visualization.quantity_altitude_visualizer import \
QuantityAltitudeHypercubeVisualizer
from experiment.meteo_france_data.visualization.study_visualization.main_study_visualizer import ALL_ALTITUDES, \
......@@ -77,7 +79,7 @@ def fast_altitude_year_hypercube():
fast = True
altitudes = ALL_ALTITUDES[2:4]
for study_class in SCM_STUDIES[:1]:
for trend_test_class in [GevLocationChangePointTest, GevScaleChangePointTest, GevShapeChangePointTest][1:2]:
for trend_test_class in [GevLocationChangePointTest, GevScaleChangePointTest, GevShapeChangePointTest][:1]:
visualizers = [StudyVisualizer(study, temporal_non_stationarity=True, verbose=False, multiprocessing=True)
for study in study_iterator(study_class=study_class, only_first_one=only_first_one,
altitudes=altitudes)]
......@@ -85,14 +87,14 @@ def fast_altitude_year_hypercube():
visualizer = Altitude_Hypercube_Year_Visualizer(altitude_to_visualizer, save_to_file=save_to_file,
trend_test_class=trend_test_class, fast=fast)
visualizer.visualize_year_trend_test()
visualizer.visualize_massif_trend_test()
visualizer.visualize_altitude_trend_test()
# visualizer.visualize_massif_trend_test()
# visualizer.visualize_altitude_trend_test()
def full_altitude_year_hypercube():
save_to_file = False
save_to_file = True
only_first_one = False
fast = False
nb_data_reduced_for_speed = False
altitudes = ALL_ALTITUDES[3:-6]
for study_class in SCM_STUDIES[:1]:
for trend_test_class in [GevLocationChangePointTest, GevScaleChangePointTest,
......@@ -104,7 +106,7 @@ def full_altitude_year_hypercube():
altitude_to_visualizer = OrderedDict(zip(altitudes, visualizers))
visualizer = Altitude_Hypercube_Year_Visualizer(altitude_to_visualizer,
save_to_file=save_to_file,
trend_test_class=trend_test_class, fast=fast)
trend_test_class=trend_test_class, nb_data_reduced_for_speed=nb_data_reduced_for_speed)
visualizer.visualize_year_trend_test()
visualizer.visualize_massif_trend_test()
visualizer.visualize_altitude_trend_test()
......@@ -132,8 +134,8 @@ def fast_quantity_altitude_hypercube():
def main_run():
# fast_altitude_hypercube()
fast_altitude_year_hypercube()
# full_altitude_year_hypercube()
# fast_altitude_year_hypercube()
full_altitude_year_hypercube()
# fast_quantity_altitude_hypercube()
# full_quantity_altitude_hypercube()
......
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