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

[HYPERCUBE] fix starting_year minor display issues.

parent 00bd8a55
No related merge requests found
Showing with 19 additions and 16 deletions
+19 -16
...@@ -30,6 +30,12 @@ class AbstractHypercubeVisualizer(object): ...@@ -30,6 +30,12 @@ class AbstractHypercubeVisualizer(object):
self.trend_test_class = trend_test_class self.trend_test_class = trend_test_class
self.tuple_to_study_visualizer = tuple_to_study_visualizer # type: Dict[Tuple, StudyVisualizer] self.tuple_to_study_visualizer = tuple_to_study_visualizer # type: Dict[Tuple, StudyVisualizer]
if isinstance(nb_data_reduced_for_speed, bool):
self.nb_data_for_fast_mode = 7 if nb_data_reduced_for_speed else None
else:
assert isinstance(nb_data_reduced_for_speed, int)
self.nb_data_for_fast_mode = nb_data_reduced_for_speed
if exact_starting_year is not None: if exact_starting_year is not None:
assert first_starting_year is None assert first_starting_year is None
assert last_starting_year is None assert last_starting_year is None
...@@ -38,15 +44,17 @@ class AbstractHypercubeVisualizer(object): ...@@ -38,15 +44,17 @@ class AbstractHypercubeVisualizer(object):
default_first_starting_year, *_, default_last_starting_year = self.all_potential_starting_years default_first_starting_year, *_, default_last_starting_year = self.all_potential_starting_years
self.first_starting_year = first_starting_year if first_starting_year is not None else default_first_starting_year self.first_starting_year = first_starting_year if first_starting_year is not None else default_first_starting_year
self.last_starting_year = last_starting_year if last_starting_year is not None else default_last_starting_year self.last_starting_year = last_starting_year if last_starting_year is not None else default_last_starting_year
if isinstance(nb_data_reduced_for_speed, bool): # Load starting year
self.nb_data_for_fast_mode = 7 if nb_data_reduced_for_speed else None self.starting_years = [year for year in self.all_potential_starting_years
else: if self.first_starting_year <= year <= self.last_starting_year]
assert isinstance(nb_data_reduced_for_speed, int) if self.nb_data_for_fast_mode is not None:
self.nb_data_for_fast_mode = nb_data_reduced_for_speed self.starting_years = self.starting_years[:self.nb_data_for_fast_mode]
self.last_starting_year = self.starting_years[-1]
if self.verbose: if self.verbose:
print('Hypercube with parameters:') print('Hypercube with parameters:')
print('First starting year: {}, Last starting year: {}'.format(self.first_starting_year, self.last_starting_year)) print('First starting year: {}, Last starting year: {}'.format(self.first_starting_year,
self.last_starting_year))
print('Starting years:', self.starting_years) print('Starting years:', self.starting_years)
print('Trend test class:', get_display_name_from_object_type(self.trend_test_class)) print('Trend test class:', get_display_name_from_object_type(self.trend_test_class))
...@@ -60,14 +68,6 @@ class AbstractHypercubeVisualizer(object): ...@@ -60,14 +68,6 @@ class AbstractHypercubeVisualizer(object):
def all_potential_starting_years(self): def all_potential_starting_years(self):
return self.study_visualizer.starting_years return self.study_visualizer.starting_years
@cached_property
def starting_years(self):
starting_years = [year for year in self.all_potential_starting_years
if self.first_starting_year <= year <= self.last_starting_year]
if self.nb_data_for_fast_mode is not None:
starting_years = starting_years[:self.nb_data_for_fast_mode]
return starting_years
def tuple_values(self, idx): def tuple_values(self, idx):
return sorted(set([t[idx] if isinstance(t, tuple) else t for t in self.tuple_to_study_visualizer.keys()])) return sorted(set([t[idx] if isinstance(t, tuple) else t for t in self.tuple_to_study_visualizer.keys()]))
...@@ -81,11 +81,11 @@ class AbstractHypercubeVisualizer(object): ...@@ -81,11 +81,11 @@ class AbstractHypercubeVisualizer(object):
df_spatio_temporal_trend_strength = [e[idx] for e in self.df_trends_spatio_temporal] df_spatio_temporal_trend_strength = [e[idx] for e in self.df_trends_spatio_temporal]
return pd.concat(df_spatio_temporal_trend_strength, keys=list(self.tuple_to_study_visualizer.keys()), axis=0) return pd.concat(df_spatio_temporal_trend_strength, keys=list(self.tuple_to_study_visualizer.keys()), axis=0)
@cached_property @cached_property
def df_hypercube_trend_type(self) -> pd.DataFrame: def df_hypercube_trend_type(self) -> pd.DataFrame:
return self._df_hypercube_trend_meta(idx=0 return self._df_hypercube_trend_meta(idx=0
) )
@cached_property @cached_property
def df_hypercube_trend_strength(self) -> pd.DataFrame: def df_hypercube_trend_strength(self) -> pd.DataFrame:
return self._df_hypercube_trend_meta(idx=1) return self._df_hypercube_trend_meta(idx=1)
......
...@@ -143,7 +143,7 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer): ...@@ -143,7 +143,7 @@ class AltitudeHypercubeVisualizer(AbstractHypercubeVisualizer):
if plot_title is not None: if plot_title is not None:
argmax_idx = np.argmax(values) argmax_idx = np.argmax(values)
best_year = xlabel_values[argmax_idx] best_year = xlabel_values[argmax_idx]
plot_title += '{} {}'.format(subtitle, best_year) plot_title += ' (max reached in {})'.format(best_year)
if subtitle in SCM_STUDY_NAME_TO_COLOR: if subtitle in SCM_STUDY_NAME_TO_COLOR:
ax, color, ylabel = ax.twinx(), SCM_STUDY_NAME_TO_COLOR[subtitle], subtitle ax, color, ylabel = ax.twinx(), SCM_STUDY_NAME_TO_COLOR[subtitle], subtitle
......
...@@ -15,8 +15,11 @@ from collections import OrderedDict ...@@ -15,8 +15,11 @@ from collections import OrderedDict
from experiment.trend_analysis.univariate_test.abstract_gev_change_point_test import GevLocationChangePointTest from experiment.trend_analysis.univariate_test.abstract_gev_change_point_test import GevLocationChangePointTest
from spatio_temporal_dataset.coordinates.transformed_coordinates.transformation.uniform_normalization import \ from spatio_temporal_dataset.coordinates.transformed_coordinates.transformation.uniform_normalization import \
BetweenZeroAndOneNormalization, BetweenMinusOneAndOneNormalization BetweenZeroAndOneNormalization, BetweenMinusOneAndOneNormalization
from utils import get_display_name_from_object_type
SCM_STUDIES = [SafranSnowfall, CrocusSwe, CrocusDepth] SCM_STUDIES = [SafranSnowfall, CrocusSwe, CrocusDepth]
SCM_STUDY_NAME_TO_COLOR = {get_display_name_from_object_type(s): color
for s, color in zip(SCM_STUDIES, ['r', 'b', 'g'])}
SCM_EXTENDED_STUDIES = [ExtendedSafranSnowfall, ExtendedCrocusSwe, ExtendedCrocusDepth] SCM_EXTENDED_STUDIES = [ExtendedSafranSnowfall, ExtendedCrocusSwe, ExtendedCrocusDepth]
SCM_STUDY_TO_EXTENDED_STUDY = OrderedDict(zip(SCM_STUDIES, SCM_EXTENDED_STUDIES)) SCM_STUDY_TO_EXTENDED_STUDY = OrderedDict(zip(SCM_STUDIES, SCM_EXTENDED_STUDIES))
......
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