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

[HYPERCUBE VISUALIZER] add kwargs argument to reduction function for more flexibility

parent 5560ff21
No related merge requests found
Showing with 17 additions and 13 deletions
+17 -13
......@@ -48,8 +48,8 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
return series, df_bool
def subtitle_to_reduction_function(self, reduction_function, level=None, add_detailed_plot=False, subtitle=None):
def reduction_function_with_level(df_bool):
return reduction_function(df_bool) if level is None else reduction_function(df_bool, level)
def reduction_function_with_level(df_bool, **kwargs):
return reduction_function(df_bool, **kwargs) if level is None else reduction_function(df_bool, level, **kwargs)
if subtitle is None:
subtitle = self.study.variable_name
......@@ -136,7 +136,7 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
return 1
def visualize_year_trend_test(self, axes=None, marker='o', add_detailed_plots=False):
def year_reduction(df):
def year_reduction(df, **kwargs):
# Take the mean with respect to all the first axis indices
return df.mean(axis=0)
......
......@@ -16,9 +16,13 @@ class Altitude_Hypercube_Year_Visualizer(AltitudeHypercubeVisualizer):
return super().nb_axes + 1
@staticmethod
def index_reduction(df, level):
def index_reduction(df, level, **kwargs):
replace_zero_with_nan = kwargs.get('replace_zero_with_nan')
# 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)
if replace_zero_with_nan:
df = df.sum(axis=1).replace(0.0, np.nan)
else:
df = df.sum(axis=1)
# Take the mean with respect to the level of interest
return df.mean(level=level)
......@@ -28,6 +32,6 @@ class Altitude_Hypercube_Year_Visualizer(AltitudeHypercubeVisualizer):
df = df_bool.copy()
df = (df * df.columns)[df_bool]
# Reduce and append
serie = reduction_function(df)
serie = reduction_function(df, replace_zero_with_nan=True)
series.append(serie)
return series, df_bool
......@@ -76,8 +76,8 @@ def fast_altitude_hypercube():
def fast_altitude_year_hypercube():
save_to_file = False
only_first_one = False
fast = True
altitudes = ALL_ALTITUDES[2:4]
nb_data_reduced_for_speed = True
altitudes = [ALL_ALTITUDES[3], ALL_ALTITUDES[-7]]
for study_class in SCM_STUDIES[:1]:
for trend_test_class in [GevLocationChangePointTest, GevScaleChangePointTest, GevShapeChangePointTest][:1]:
visualizers = [StudyVisualizer(study, temporal_non_stationarity=True, verbose=False, multiprocessing=True)
......@@ -85,10 +85,10 @@ def fast_altitude_year_hypercube():
altitudes=altitudes)]
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()
visualizer.visualize_massif_trend_test()
visualizer.visualize_altitude_trend_test()
def full_altitude_year_hypercube():
......@@ -134,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