diff --git a/extreme_data/meteo_france_data/scm_models_data/abstract_study.py b/extreme_data/meteo_france_data/scm_models_data/abstract_study.py index 32d1fcfbffe95d0685a97337d2db17ca6e37cd16..0ea553492616660b523ab9114aadbac99217627d 100644 --- a/extreme_data/meteo_france_data/scm_models_data/abstract_study.py +++ b/extreme_data/meteo_france_data/scm_models_data/abstract_study.py @@ -492,6 +492,7 @@ class AbstractStudy(object): massif_name_to_marker_style=None, marker_style_to_label_name=None, ticks_values_and_labels=None, + massif_name_to_text=None, fontsize_label=15, ): if ax is None: @@ -563,8 +564,11 @@ class AbstractStudy(object): for _, row in masssif_coordinate_for_display.df_all_coordinates.iterrows(): x, y = list(row) massif_name = row.name - value = massif_name_to_value[massif_name] - str_value = str(value) + if massif_name_to_text is None: + value = massif_name_to_value[massif_name] + str_value = str(value) + else: + str_value = massif_name_to_text[massif_name] ax.text(x, y, str_value, horizontalalignment='center', verticalalignment='center', fontsize=fontsize) if scaled: diff --git a/extreme_trend/trend_test_three_parameters/gev_trend_test_three_parameters.py b/extreme_trend/trend_test_three_parameters/gev_trend_test_three_parameters.py index caaed063997b9531984cf46771bb90b7d3971440..dc411f3a0e68dec565f13a5b7db8ff333916edc3 100644 --- a/extreme_trend/trend_test_three_parameters/gev_trend_test_three_parameters.py +++ b/extreme_trend/trend_test_three_parameters/gev_trend_test_three_parameters.py @@ -21,8 +21,8 @@ class GevLocationAndScaleAndShapeTrendTest(GevTrendTestThreeParameters): def __init__(self, years, maxima, starting_year, quantile_level=EUROCODE_QUANTILE, fit_method=MarginFitMethod.extremes_fevd_mle): super().__init__(years, maxima, starting_year, - unconstrained_model_class=StationaryTemporalModel, - constrained_model_class=NonStationaryLocationAndScaleAndShapeTemporalModel, + unconstrained_model_class=NonStationaryLocationAndScaleAndShapeTemporalModel, + constrained_model_class=StationaryTemporalModel, quantile_level=quantile_level, fit_method=fit_method) diff --git a/projects/contrasting_trends_in_snow_loads/article2_snowfall_versus_time_and_altitude/main_snowfall_article.py b/projects/contrasting_trends_in_snow_loads/article2_snowfall_versus_time_and_altitude/main_snowfall_article.py index 06759a89d404ad0c400bdd248074d6e9eee0cbc7..db109f2409d22ee876260cd97c0d4eefaa774d56 100644 --- a/projects/contrasting_trends_in_snow_loads/article2_snowfall_versus_time_and_altitude/main_snowfall_article.py +++ b/projects/contrasting_trends_in_snow_loads/article2_snowfall_versus_time_and_altitude/main_snowfall_article.py @@ -72,7 +72,7 @@ def intermediate_result(altitudes, massif_names=None, _ = compute_minimized_aic(visualizer) # Plots - # validation_plot(altitude_to_visualizer, order_derivative=0) + validation_plot(altitude_to_visualizer, order_derivative=0) # validation_plot(altitude_to_visualizer, order_derivative=1) plot_snowfall_mean(altitude_to_visualizer) # plot_snowfall_time_derivative_mean(altitude_to_visualizer) @@ -86,7 +86,9 @@ def major_result(): model_subsets_for_uncertainty = None altitudes = paper_altitudes altitudes = [300, 600, 900, 1200, 1500, 1800, 2100, 2400, 2700, 3000, 3300, 3600, 3900] - altitudes = [900, 1200] + # altitudes = [900, 1200] + draft_altitudes = [900, 1200, 1500, 1800, 2100, 2400, 2700, 3000] + altitudes = draft_altitudes for study_class in study_classes: intermediate_result(altitudes, massif_names, model_subsets_for_uncertainty, diff --git a/projects/contrasting_trends_in_snow_loads/article2_snowfall_versus_time_and_altitude/study_visualizer_for_mean_values.py b/projects/contrasting_trends_in_snow_loads/article2_snowfall_versus_time_and_altitude/study_visualizer_for_mean_values.py index ca2cfce6219d7631929ed5824840aa2d88c71269..ab0586f6297cce52cab139f77d2c50764af7fba1 100644 --- a/projects/contrasting_trends_in_snow_loads/article2_snowfall_versus_time_and_altitude/study_visualizer_for_mean_values.py +++ b/projects/contrasting_trends_in_snow_loads/article2_snowfall_versus_time_and_altitude/study_visualizer_for_mean_values.py @@ -1,3 +1,5 @@ +from typing import Dict + import matplotlib.pyplot as plt import numpy as np from cached_property import cached_property @@ -5,7 +7,9 @@ from cached_property import cached_property from extreme_data.eurocode_data.utils import YEAR_OF_INTEREST_FOR_RETURN_LEVEL from extreme_data.meteo_france_data.scm_models_data.abstract_study import AbstractStudy from extreme_fit.model.margin_model.utils import MarginFitMethod +from extreme_trend.abstract_gev_trend_test import AbstractGevTrendTest from extreme_trend.visualizers.study_visualizer_for_non_stationary_trends import StudyVisualizerForNonStationaryTrends +from projects.exceeding_snow_loads.utils import NON_STATIONARY_TREND_TEST_PAPER_2 class StudyVisualizerForMeanValues(StudyVisualizerForNonStationaryTrends): @@ -19,6 +23,10 @@ class StudyVisualizerForMeanValues(StudyVisualizerForNonStationaryTrends): non_stationary_trend_test_to_marker=None, fit_method=MarginFitMethod.extremes_fevd_mle, select_only_acceptable_shape_parameter=True, fit_gev_only_on_non_null_maxima=False, fit_only_time_series_with_ninety_percent_of_non_null_values=True): + + # Change the type of models used in the study + non_stationary_trend_test_to_marker = {c: '' for c in NON_STATIONARY_TREND_TEST_PAPER_2} + super().__init__(study, show, save_to_file, only_one_graph, only_first_row, vertical_kde_plot, year_for_kde_plot, plot_block_maxima_quantiles, temporal_non_stationarity, transformation_class, verbose, multiprocessing, complete_non_stationary_trend_analysis, @@ -26,11 +34,19 @@ class StudyVisualizerForMeanValues(StudyVisualizerForNonStationaryTrends): uncertainty_massif_names, effective_temporal_covariate, relative_change_trend_plot, non_stationary_trend_test_to_marker, fit_method, select_only_acceptable_shape_parameter, fit_gev_only_on_non_null_maxima, fit_only_time_series_with_ninety_percent_of_non_null_values) - + assert len(self.non_stationary_trend_test) == len(NON_STATIONARY_TREND_TEST_PAPER_2) def plot_abstract_fast(self, massif_name_to_value, label, graduation=10.0, cmap=plt.cm.coolwarm, add_x_label=True, negative_and_positive_values=True): - super().plot_abstract(massif_name_to_value, label, label, self.fit_method, graduation, cmap, add_x_label, negative_and_positive_values) + super().plot_abstract(massif_name_to_value, label, label, self.fit_method, graduation, cmap, add_x_label, + negative_and_positive_values) + + # Override the main dict massif_name_to_trend_test_that_minimized_aic + + @property + def massif_name_to_trend_test_that_minimized_aic(self) -> Dict[str, AbstractGevTrendTest]: + return {m: t for m, t in super().massif_name_to_trend_test_that_minimized_aic.items() + if t.goodness_of_fit_anderson_test} # Study of the mean @@ -55,7 +71,7 @@ class StudyVisualizerForMeanValues(StudyVisualizerForNonStationaryTrends): for massif_name in self.massif_name_to_trend_test_that_minimized_aic.keys(): e = self.massif_name_to_empirical_mean[massif_name] m = self.massif_name_to_model_mean[massif_name] - relative_diference = 100 * (m-e) / e + relative_diference = 100 * (m - e) / e massif_name_to_relative_difference[massif_name] = relative_diference return massif_name_to_relative_difference @@ -66,7 +82,7 @@ class StudyVisualizerForMeanValues(StudyVisualizerForNonStationaryTrends): massif_name_to_empirical_value = {} for massif_name, maxima in self.study.massif_name_to_annual_maxima.items(): index = self.study.ordered_years.index(1989) - maxima_before, maxima_after = maxima[:index+1], maxima[index+1:] + maxima_before, maxima_after = maxima[:index + 1], maxima[index + 1:] massif_name_to_empirical_value[massif_name] = np.mean(maxima_after) / np.mean(maxima_before) return massif_name_to_empirical_value @@ -85,6 +101,6 @@ class StudyVisualizerForMeanValues(StudyVisualizerForNonStationaryTrends): for massif_name in self.massif_name_to_trend_test_that_minimized_aic.keys(): e = self.massif_name_to_change_ratio_in_empirical_mean[massif_name] m = self.massif_name_to_change_ratio_in_model_mean[massif_name] - relative_diference = 100 * (m-e) / e + relative_diference = 100 * (m - e) / e massif_name_to_relative_difference[massif_name] = relative_diference - return massif_name_to_relative_difference \ No newline at end of file + return massif_name_to_relative_difference