Commit 59b8ae9d authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[projections] add box plot without significance. refactor a bit the str for...

[projections] add box plot without significance. refactor a bit the str for the plots. add inquiry for the pattern 85 that we obtain for one couple
parent 10d1ead1
No related merge requests found
Showing with 46 additions and 37 deletions
+46 -37
...@@ -192,9 +192,7 @@ class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer): ...@@ -192,9 +192,7 @@ class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer):
if 'change' in method_name: if 'change' in method_name:
plot_name = plot_name.replace(str_for_last_year, '') plot_name = plot_name.replace(str_for_last_year, '')
add_str = ' between +${}^o\mathrm{C}$ and +${}^o\mathrm{C}$' if self.temporal_covariate_for_fit is AnomalyTemperatureTemporalCovariate \ plot_name += self.first_one_fold_fit.between_covariate_str
else ' between {} and {}'
plot_name += add_str.format(self.first_one_fold_fit.covariate_before, self.first_one_fold_fit.covariate_after, **d_temperature)
if 'relative' not in method_name: if 'relative' not in method_name:
# Put the relative score as text on the plot for the change. # Put the relative score as text on the plot for the change.
...@@ -481,7 +479,7 @@ class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer): ...@@ -481,7 +479,7 @@ class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer):
percents = 100 * nbs / nb_valid_massif_names percents = 100 * nbs / nb_valid_massif_names
return [nb_valid_massif_names] + list(percents) return [nb_valid_massif_names] + list(percents)
def all_changes(self, massif_names, relative=False): def all_changes(self, massif_names, relative=False, with_significance=True):
"""return percents which contain decrease, significant decrease, increase, significant increase percentages""" """return percents which contain decrease, significant decrease, increase, significant increase percentages"""
valid_massif_names = self.get_valid_names(massif_names) valid_massif_names = self.get_valid_names(massif_names)
changes = [] changes = []
...@@ -497,12 +495,16 @@ class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer): ...@@ -497,12 +495,16 @@ class AltitudesStudiesVisualizerForNonStationaryModels(StudyVisualizer):
changes.append(change) changes.append(change)
if change != 0: if change != 0:
non_stationary_changes.append(change) non_stationary_changes.append(change)
if one_fold.is_significant: if with_significance:
non_stationary_significant_changes.append(change) if one_fold.is_significant:
non_stationary_significant_changes.append(change)
moment = 'relative mean' if relative else 'Mean' moment = 'relative mean' if relative else 'Mean'
print('{} for {}m'.format(moment, self.altitude_group.reference_altitude), np.mean(changes)) print('{} for {}m'.format(moment, self.altitude_group.reference_altitude), np.mean(changes))
return changes, non_stationary_changes, non_stationary_significant_changes if with_significance:
return changes, non_stationary_changes, non_stationary_significant_changes
else:
return changes, non_stationary_changes
def get_valid_names(self, massif_names): def get_valid_names(self, massif_names):
valid_massif_names = set(self.massif_name_to_one_fold_fit.keys()) valid_massif_names = set(self.massif_name_to_one_fold_fit.keys())
......
...@@ -153,6 +153,15 @@ class OneFoldFit(object): ...@@ -153,6 +153,15 @@ class OneFoldFit(object):
else: else:
raise NotImplementedError raise NotImplementedError
@property
def between_covariate_str(self):
d_temperature = {'C': '{C}'}
s = ' between +${}^o\mathrm{C}$ and +${}^o\mathrm{C}$' if self.temporal_covariate_for_fit is AnomalyTemperatureTemporalCovariate \
else ' between {} and {}'
s = s.format(self.covariate_before, self.covariate_after,
**d_temperature)
return s
def relative_changes_of_moment(self, altitudes, order=1): def relative_changes_of_moment(self, altitudes, order=1):
relative_changes = [] relative_changes = []
for altitude in altitudes: for altitude in altitudes:
......
...@@ -4,6 +4,9 @@ from typing import List ...@@ -4,6 +4,9 @@ from typing import List
import numpy as np import numpy as np
import matplotlib import matplotlib
from extreme_data.meteo_france_data.adamont_data.abstract_adamont_study import AbstractAdamontStudy
matplotlib.use('Agg') matplotlib.use('Agg')
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
...@@ -180,18 +183,19 @@ def plot_shoe_plot_ratio_interval_size_against_altitude(massif_names, visualizer ...@@ -180,18 +183,19 @@ def plot_shoe_plot_ratio_interval_size_against_altitude(massif_names, visualizer
def plot_shoe_plot_changes_against_altitude(massif_names, visualizer_list: List[ def plot_shoe_plot_changes_against_altitude(massif_names, visualizer_list: List[
AltitudesStudiesVisualizerForNonStationaryModels], AltitudesStudiesVisualizerForNonStationaryModels],
relative=False): relative=False, with_significance=True):
visualizer = visualizer_list[0] visualizer = visualizer_list[0]
all_changes = [v.all_changes(massif_names, relative=relative) for v in visualizer_list] all_changes = [v.all_changes(massif_names, relative=relative, with_significance=with_significance) for v in visualizer_list]
all_changes = list(zip(*all_changes)) all_changes = list(zip(*all_changes))
labels = ['All massifs', 'Massifs with a selected model\n' labels = ['All massifs', 'Massifs with a selected model\n'
'temporally non-stationary', 'temporally non-stationary',
'Massifs with a selected model\n' 'Massifs with a selected model\n'
'temporally non-stationary and significant'] 'temporally non-stationary and significant']
# colors = ['darkmagenta', 'darkviolet', 'mediumorchid']
# colors = ['mediumblue', 'royalblue', 'lightskyblue']
colors = ['darkgreen', 'forestgreen', 'limegreen'] colors = ['darkgreen', 'forestgreen', 'limegreen']
if not with_significance:
labels = labels[:-1]
colors = colors[:-1]
nb_massifs = [len(v.get_valid_names(massif_names)) for v in visualizer_list] nb_massifs = [len(v.get_valid_names(massif_names)) for v in visualizer_list]
plt.close() plt.close()
...@@ -200,17 +204,6 @@ def plot_shoe_plot_changes_against_altitude(massif_names, visualizer_list: List[ ...@@ -200,17 +204,6 @@ def plot_shoe_plot_changes_against_altitude(massif_names, visualizer_list: List[
size = 8 size = 8
legend_fontsize = 10 legend_fontsize = 10
labelsize = 10 labelsize = 10
linewidth = 3
# x = np.array([4 * width * (i + 1) for i in range(len(nb_massifs))])
# for j, (changes, label, color) in enumerate(list(zip(all_changes, labels, colors)), -1):
# positions = x + j * width
# bplot = ax.boxplot(list(changes), positions=positions, widths=width, patch_artist=True, showmeans=True)
# for patch in bplot['boxes']:
# patch.set_facecolor(color)
# x = np.array([3 * width * (i + 1) for i in range(len(nb_massifs))])
# for j, (changes, label, color) in list(enumerate(list(zip(all_changes, labels, colors)), -1))[1:]:
# positions = x + (j + 0.5) * width
x = np.array([4 * width * (i + 1) for i in range(len(nb_massifs))]) x = np.array([4 * width * (i + 1) for i in range(len(nb_massifs))])
for j, (changes, label, color) in enumerate(list(zip(all_changes, labels, colors)), -1): for j, (changes, label, color) in enumerate(list(zip(all_changes, labels, colors)), -1):
...@@ -225,7 +218,8 @@ def plot_shoe_plot_changes_against_altitude(massif_names, visualizer_list: List[ ...@@ -225,7 +218,8 @@ def plot_shoe_plot_changes_against_altitude(massif_names, visualizer_list: List[
start = 'Relative changes' if relative else 'Changes' start = 'Relative changes' if relative else 'Changes'
unit = '\%' if relative else visualizer.study.variable_unit unit = '\%' if relative else visualizer.study.variable_unit
ax.set_ylabel('{} of {}-year return levels between 1959 and 2019 ({})'.format(start, OneFoldFit.return_period, ax.set_ylabel('{} of {}-year return levels {} ({})'.format(start, OneFoldFit.return_period,
visualizer.first_one_fold_fit.between_covariate_str,
unit), unit),
fontsize=legend_fontsize) fontsize=legend_fontsize)
ax.set_xlabel('Elevation (m)', fontsize=legend_fontsize + 5) ax.set_xlabel('Elevation (m)', fontsize=legend_fontsize + 5)
...@@ -238,9 +232,11 @@ def plot_shoe_plot_changes_against_altitude(massif_names, visualizer_list: List[ ...@@ -238,9 +232,11 @@ def plot_shoe_plot_changes_against_altitude(massif_names, visualizer_list: List[
shift = 2 * width shift = 2 * width
ax.set_xlim((min(x) - shift, max(x) + shift)) ax.set_xlim((min(x) - shift, max(x) + shift))
upper_limit_for_legend = 50 if relative else 0
lim_down, lim_up = ax.get_ylim() if not isinstance(visualizer.study, AbstractAdamontStudy):
ax.set_ylim(lim_down, lim_up + upper_limit_for_legend) upper_limit_for_legend = 50 if relative else 0
lim_down, lim_up = ax.get_ylim()
ax.set_ylim(lim_down, lim_up + upper_limit_for_legend)
# Plot a zero horizontal line # Plot a zero horizontal line
lim_left, lim_right = ax.get_xlim() lim_left, lim_right = ax.get_xlim()
......
...@@ -37,24 +37,24 @@ from extreme_data.meteo_france_data.scm_models_data.utils import Season ...@@ -37,24 +37,24 @@ from extreme_data.meteo_france_data.scm_models_data.utils import Season
def main(): def main():
study_classes = [AdamontSnowfall][:1] study_classes = [AdamontSnowfall][:1]
scenario = AdamontScenario.rcp85 scenario = AdamontScenario.rcp45
gcm_rcm_couples = get_gcm_rcm_couples(scenario) gcm_rcm_couples = get_gcm_rcm_couples(scenario)
ensemble_fit_class = [IndependentEnsembleFit] ensemble_fit_class = [IndependentEnsembleFit]
temporal_covariate_for_fit = [TimeTemporalCovariate, AnomalyTemperatureTemporalCovariate][1] temporal_covariate_for_fit = [TimeTemporalCovariate, AnomalyTemperatureTemporalCovariate][1]
set_seed_for_test() set_seed_for_test()
AbstractExtractEurocodeReturnLevel.ALPHA_CONFIDENCE_INTERVAL_UNCERTAINTY = 0.2 AbstractExtractEurocodeReturnLevel.ALPHA_CONFIDENCE_INTERVAL_UNCERTAINTY = 0.2
fast = False fast = True
if fast is None: if fast is None:
massif_names = None massif_names = None
gcm_rcm_couples = gcm_rcm_couples[:1] gcm_rcm_couples = gcm_rcm_couples[:2]
AbstractExtractEurocodeReturnLevel.NB_BOOTSTRAP = 10 AbstractExtractEurocodeReturnLevel.NB_BOOTSTRAP = 10
altitudes_list = altitudes_for_groups[1:2] altitudes_list = altitudes_for_groups[:2]
elif fast: elif fast:
AbstractExtractEurocodeReturnLevel.NB_BOOTSTRAP = 10 AbstractExtractEurocodeReturnLevel.NB_BOOTSTRAP = 10
massif_names = None massif_names = None
gcm_rcm_couples = [('EC-EARTH', 'RACMO22E')] gcm_rcm_couples = [('EC-EARTH', 'RACMO22E')]
altitudes_list = altitudes_for_groups[:1] altitudes_list = altitudes_for_groups[1:2]
else: else:
massif_names = None massif_names = None
altitudes_list = altitudes_for_groups[:] altitudes_list = altitudes_for_groups[:]
...@@ -72,8 +72,6 @@ def main_loop(gcm_rcm_couples, altitudes_list, massif_names, study_classes, ense ...@@ -72,8 +72,6 @@ def main_loop(gcm_rcm_couples, altitudes_list, massif_names, study_classes, ense
temporal_covariate_for_fit): temporal_covariate_for_fit):
assert isinstance(altitudes_list, List) assert isinstance(altitudes_list, List)
assert isinstance(altitudes_list[0], List) assert isinstance(altitudes_list[0], List)
gof_test = False
print('Goodness of fit test ?', gof_test)
print('Covariate is {}'.format(temporal_covariate_for_fit)) print('Covariate is {}'.format(temporal_covariate_for_fit))
for study_class in study_classes: for study_class in study_classes:
print('Inner loop', study_class) print('Inner loop', study_class)
...@@ -86,8 +84,6 @@ def main_loop(gcm_rcm_couples, altitudes_list, massif_names, study_classes, ense ...@@ -86,8 +84,6 @@ def main_loop(gcm_rcm_couples, altitudes_list, massif_names, study_classes, ense
ensemble_fit_classes=ensemble_fit_classes, ensemble_fit_classes=ensemble_fit_classes,
massif_names=massif_names, massif_names=massif_names,
temporal_covariate_for_fit=temporal_covariate_for_fit, temporal_covariate_for_fit=temporal_covariate_for_fit,
confidence_interval_based_on_delta_method=False,
display_only_model_that_pass_gof_test=gof_test,
remove_physically_implausible_models=True, remove_physically_implausible_models=True,
) )
visualizer.plot() visualizer.plot()
......
...@@ -101,8 +101,8 @@ class MetaVisualizerForProjectionEnsemble(object): ...@@ -101,8 +101,8 @@ class MetaVisualizerForProjectionEnsemble(object):
for independent_ensemble_fit in self.ensemble_fits(IndependentEnsembleFit) for independent_ensemble_fit in self.ensemble_fits(IndependentEnsembleFit)
] ]
plot_histogram_all_trends_against_altitudes(self.massif_names, visualizer_list, with_significance=with_significance) plot_histogram_all_trends_against_altitudes(self.massif_names, visualizer_list, with_significance=with_significance)
# for relative in [True, False]: for relative in [True, False]:
# plot_shoe_plot_changes_against_altitude(self.massif_names, visualizer_list, relative=relative) plot_shoe_plot_changes_against_altitude(self.massif_names, visualizer_list, relative=relative, with_significance=with_significance)
def ensemble_fits(self, ensemble_class): def ensemble_fits(self, ensemble_class):
return [ensemble_class_to_ensemble_fit[ensemble_class] return [ensemble_class_to_ensemble_fit[ensemble_class]
......
import datetime import datetime
import math
import os.path as op import os.path as op
import subprocess import subprocess
...@@ -12,6 +13,11 @@ for c in [' ', ':', '-']: ...@@ -12,6 +13,11 @@ for c in [' ', ':', '-']:
NB_CORES = 7 NB_CORES = 7
def batch_nb_cores(iterable, nb_cores):
batchsize = math.ceil(len(iterable) / nb_cores)
return batch(iterable, batchsize)
def batch(iterable, batchsize=1): def batch(iterable, batchsize=1):
l = len(iterable) l = len(iterable)
for ndx in range(0, l, batchsize): for ndx in range(0, l, batchsize):
......
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