diff --git a/experiment/paper_past_snow_loads/check_mle_convergence_for_trends/study_visualizer_for_shape_repartition.py b/experiment/paper_past_snow_loads/check_mle_convergence_for_trends/study_visualizer_for_shape_repartition.py index 729f7c538ce56f0622d9e3be3ae69d5823376e2c..0a25e17896e9a627e57846f3185fe0e7fa8d18f1 100644 --- a/experiment/paper_past_snow_loads/check_mle_convergence_for_trends/study_visualizer_for_shape_repartition.py +++ b/experiment/paper_past_snow_loads/check_mle_convergence_for_trends/study_visualizer_for_shape_repartition.py @@ -10,18 +10,8 @@ from experiment.trend_analysis.abstract_score import MeanScore class StudyVisualizerForShape(StudyVisualizerForNonStationaryTrends): - def __init__(self, study: AbstractStudy, show=True, save_to_file=False, only_one_graph=False, only_first_row=False, - vertical_kde_plot=False, year_for_kde_plot=None, plot_block_maxima_quantiles=False, - temporal_non_stationarity=False, transformation_class=None, verbose=False, multiprocessing=False, - complete_non_stationary_trend_analysis=False, normalization_under_one_observations=True, - score_class=MeanScore, uncertainty_methods=None, non_stationary_contexts=None, - uncertainty_massif_names=None, effective_temporal_covariate=2017, relative_change_trend_plot=True): - 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, - normalization_under_one_observations, score_class, uncertainty_methods, - non_stationary_contexts, uncertainty_massif_names, effective_temporal_covariate, - relative_change_trend_plot) + def __init__(self, study: AbstractStudy, **kwargs): + super().__init__(study, **kwargs) @cached_property def massif_name_to_unconstrained_shape_parameter(self): diff --git a/experiment/paper_past_snow_loads/paper_main_utils.py b/experiment/paper_past_snow_loads/paper_main_utils.py index 510dcdec4cef196ea82c6718fecc8f755cec563e..f41fb8181f7abf03323e8b5ab7d6bd3f483153f3 100644 --- a/experiment/paper_past_snow_loads/paper_main_utils.py +++ b/experiment/paper_past_snow_loads/paper_main_utils.py @@ -2,15 +2,18 @@ from collections import OrderedDict from experiment.paper_past_snow_loads.study_visualizer_for_non_stationary_trends import \ StudyVisualizerForNonStationaryTrends +from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ + TemporalMarginFitMethod def load_altitude_to_visualizer(altitudes, massif_names, non_stationary_uncertainty, study_class, uncertainty_methods, study_visualizer_class=StudyVisualizerForNonStationaryTrends, save_to_file=True): + fit_method = TemporalMarginFitMethod.extremes_fevd_gmle altitude_to_visualizer = OrderedDict() for altitude in altitudes: altitude_to_visualizer[altitude] = study_visualizer_class( study=study_class(altitude=altitude), multiprocessing=True, save_to_file=save_to_file, uncertainty_massif_names=massif_names, uncertainty_methods=uncertainty_methods, - non_stationary_contexts=non_stationary_uncertainty) + non_stationary_contexts=non_stationary_uncertainty, fit_method=fit_method) return altitude_to_visualizer diff --git a/experiment/paper_past_snow_loads/result_trends_and_return_levels/main_result_trends_and_return_levels.py b/experiment/paper_past_snow_loads/result_trends_and_return_levels/main_result_trends_and_return_levels.py index 57022684050fafd87a002514aec4d721bad38f03..5987b7a627c913707b585524afa548c71254d596 100644 --- a/experiment/paper_past_snow_loads/result_trends_and_return_levels/main_result_trends_and_return_levels.py +++ b/experiment/paper_past_snow_loads/result_trends_and_return_levels/main_result_trends_and_return_levels.py @@ -83,8 +83,8 @@ def major_result(): uncertainty_methods = [ConfidenceIntervalMethodFromExtremes.my_bayes, ConfidenceIntervalMethodFromExtremes.ci_mle][1:] massif_names = None - study_classes = paper_study_classes[:2] - study_classes = [CrocusSnowLoad3Days, CrocusSnowLoad5Days, CrocusSnowLoad7Days][::-1] + study_classes = paper_study_classes[:1] + # study_classes = [CrocusSnowLoad3Days, CrocusSnowLoad5Days, CrocusSnowLoad7Days][::-1] for study_class in study_classes: if study_class == CrocusSnowLoadEurocode: non_stationary_uncertainty = [False] diff --git a/experiment/paper_past_snow_loads/study_visualizer_for_non_stationary_trends.py b/experiment/paper_past_snow_loads/study_visualizer_for_non_stationary_trends.py index 998a8126cc6fdb2889859bf816460236921ee2f5..f6bae071d5135512782a769af2e20a60c5fa29fe 100644 --- a/experiment/paper_past_snow_loads/study_visualizer_for_non_stationary_trends.py +++ b/experiment/paper_past_snow_loads/study_visualizer_for_non_stationary_trends.py @@ -2,7 +2,7 @@ from collections import OrderedDict import matplotlib.pyplot as plt from multiprocessing.pool import Pool -from typing import Dict +from typing import Dict, List import numpy as np from cached_property import cached_property @@ -48,12 +48,14 @@ class StudyVisualizerForNonStationaryTrends(StudyVisualizer): uncertainty_massif_names=None, effective_temporal_covariate=2017, relative_change_trend_plot=True, - non_stationary_trend_test_to_marker=None): + non_stationary_trend_test_to_marker=None, + fit_method=None): 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, normalization_under_one_observations, score_class) # Add some attributes + self.fit_method = fit_method self.non_stationary_trend_test_to_marker = non_stationary_trend_test_to_marker self.relative_change_trend_plot = relative_change_trend_plot self.effective_temporal_covariate = effective_temporal_covariate @@ -118,7 +120,12 @@ class StudyVisualizerForNonStationaryTrends(StudyVisualizer): quantile_level = self.massif_name_to_eurocode_quantile_level_in_practice[massif_name] non_stationary_trend_test = [ t(years=x, maxima=y, starting_year=starting_year, quantile_level=quantile_level) - for t in self.non_stationary_trend_test] + for t in self.non_stationary_trend_test] # type: List[AbstractGevTrendTest] + # Set appropriate fit method for all objects (#todo: set this parameter directly in the init function) + if self.fit_method is not None: + for t in non_stationary_trend_test: + t.fit_method = self.fit_method + # Extract trend_test_that_minimized_aic = sorted(non_stationary_trend_test, key=lambda t: t.aic)[0] massif_name_to_trend_test_that_minimized_aic[massif_name] = trend_test_that_minimized_aic return massif_name_to_trend_test_that_minimized_aic @@ -131,7 +138,10 @@ class StudyVisualizerForNonStationaryTrends(StudyVisualizer): @cached_property def _max_abs_change(self): - return self.global_max_abs_change if self.global_max_abs_change is not None else self.max_abs_change + max_abs_change = self.global_max_abs_change if self.global_max_abs_change is not None else self.max_abs_change + if max_abs_change == 0: + max_abs_change = 1e-10 + return max_abs_change def plot_trends(self, max_abs_tdrl=None, add_colorbar=True): if max_abs_tdrl is not None: