diff --git a/experiment/eurocode_data/departementalpesfrancaises.py b/experiment/eurocode_data/departementalpesfrancaises.py index d36d9f41eb9dfc7c229ee3bc9a80fb9005bd9967..4b30db0599a1e7e8d7560ea46b6b5a63c4b9023e 100644 --- a/experiment/eurocode_data/departementalpesfrancaises.py +++ b/experiment/eurocode_data/departementalpesfrancaises.py @@ -51,11 +51,6 @@ class Drome(AbstractDepartementAlpesFrancaises): super().__init__(C2) -""" -Quand c'est à cheval, je mets les deux massifs -Quand juste un bout du massif est dans un autre departement -(Chartreuse, Belledonne sont un peu en Savoie -""" massif_name_to_departements = { 'Chablais': [HauteSavoie], 'Aravis': [HauteSavoie, Savoie], @@ -63,8 +58,8 @@ massif_name_to_departements = { 'Bauges': [HauteSavoie, Savoie], 'Beaufortain': [HauteSavoie, Savoie], 'Haute-Tarentaise': [Savoie], - 'Chartreuse': [Isere], - 'Belledonne': [Isere], + 'Chartreuse': [Isere, Savoie], + 'Belledonne': [Isere, Savoie], 'Maurienne': [Savoie], 'Vanoise': [Savoie], 'Haute-Maurienne': [Savoie], diff --git a/experiment/meteo_france_data/scm_models_data/abstract_study.py b/experiment/meteo_france_data/scm_models_data/abstract_study.py index 121eec14347aaffade3929a54215abfccca1ea06..424398e0fc25bf37f87854d6d096fa1b9d401c68 100644 --- a/experiment/meteo_france_data/scm_models_data/abstract_study.py +++ b/experiment/meteo_france_data/scm_models_data/abstract_study.py @@ -229,7 +229,7 @@ class AbstractStudy(object): def visualize_study(cls, ax=None, massif_name_to_value: Union[None, Dict[str, float]] = None, show=True, fill=True, replace_blue_by_white=True, label=None, add_text=False, cmap=None, vmax=100, vmin=0, - default_color_for_missing_massif='grey', + default_color_for_missing_massif='gainsboro', default_color_for_nan_values='w', massif_name_to_color=None, show_label=True, diff --git a/experiment/meteo_france_data/scm_models_data/visualization/study_visualization/main_study_visualizer.py b/experiment/meteo_france_data/scm_models_data/visualization/study_visualization/main_study_visualizer.py index 4bc1d621192865c7e484e12392130092a1c87a2b..11fb476c616337024b59fcd022bf0693293c7b5c 100644 --- a/experiment/meteo_france_data/scm_models_data/visualization/study_visualization/main_study_visualizer.py +++ b/experiment/meteo_france_data/scm_models_data/visualization/study_visualization/main_study_visualizer.py @@ -24,7 +24,7 @@ SCM_STUDY_NAME_TO_SCM_STUDY = dict(zip(SCM_STUDIES_NAMES, SCM_STUDIES)) SCM_STUDY_CLASS_TO_ABBREVIATION = { SafranSnowfall: 'SF3', CrocusTotalSwe: 'TSWE', - CrocusRecentSwe: 'RSWE', + CrocusRecentSwe: 'SWE3', CrocusDepth: 'SD', } diff --git a/experiment/meteo_france_data/stations_data/visualization/comparisons_visualization/comparisons_visualization.py b/experiment/meteo_france_data/stations_data/visualization/comparisons_visualization/comparisons_visualization.py index 4e1b2427d660924c5e51acb65736c86c06b4fe22..5ee81c4f3b970006e3b8a686dd380e3e4659775e 100644 --- a/experiment/meteo_france_data/stations_data/visualization/comparisons_visualization/comparisons_visualization.py +++ b/experiment/meteo_france_data/stations_data/visualization/comparisons_visualization/comparisons_visualization.py @@ -14,7 +14,6 @@ from experiment.meteo_france_data.scm_models_data.visualization.study_visualizat VisualizationParameters from experiment.meteo_france_data.stations_data.comparison_analysis import ComparisonAnalysis, MASSIF_COLUMN_NAME, \ REANALYSE_STR, ALTITUDE_COLUMN_NAME, STATION_COLUMN_NAME -from experiment.trend_analysis.univariate_test.abstract_gev_trend_test import GevLocationChangePointTest from experiment.trend_analysis.univariate_test.abstract_univariate_test import AbstractUnivariateTest from experiment.trend_analysis.univariate_test.utils import compute_gev_change_point_test_results from extreme_estimator.extreme_models.result_from_fit import ResultFromIsmev @@ -259,21 +258,3 @@ class ComparisonsVisualization(VisualizationParameters): ax.grid() ax.plot(years, maxima, label=label, color=plot_color) return ordered_dict - - def visualize_gev(self): - return self._visualize_main(self.plot_gev) - - def plot_gev(self, ax, ax2, years, maxima, label, plot_color): - # todo should I normalize here ? - # fit gev - data = maxima - res = safe_run_r_estimator(function=r('gev.fit'), xdat=ro.FloatVector(data), - use_start=True) - res = ResultFromIsmev(res, {}) - gev_params = res.constant_gev_params - - lim = 1.5 * max(data) - x = np.linspace(0, lim, 1000) - y = gev_params.density(x) - # display the gev distribution that was obtained - ax.plot(x, y, label=label, color=plot_color) diff --git a/experiment/paper1_steps/hard extreme evolution - annual maxima/main1_good_stationary_gev_fit.py b/experiment/paper1_steps/hard extreme evolution - annual maxima/main1_good_stationary_gev_fit.py index 0cfb9bcb7e9af08f6615c7de2f6a75093beaaef0..935d017c241bc17f1c98add8b6280387e9f21203 100644 --- a/experiment/paper1_steps/hard extreme evolution - annual maxima/main1_good_stationary_gev_fit.py +++ b/experiment/paper1_steps/hard extreme evolution - annual maxima/main1_good_stationary_gev_fit.py @@ -8,14 +8,15 @@ from experiment.meteo_france_data.scm_models_data.visualization.study_visualizat def maxima_analysis(): save_to_file = False only_first_one = False - durand_altitude = [900, 1500, 2100, 2700] + durand_altitude = [900, 1500, 1800, 2100, 2700][2:-2] altitudes = durand_altitude study_classes = [CrocusRecentSwe][:] for study in study_iterator_global(study_classes, only_first_one=only_first_one, altitudes=altitudes): study_visualizer = StudyVisualizer(study, save_to_file=save_to_file, verbose=True, multiprocessing=True) - study_visualizer.visualize_summary_of_annual_values_and_stationary_gev_fit() + # study_visualizer.visualize_summary_of_annual_values_and_stationary_gev_fit() + study_visualizer.visualize_all_mean_and_max_graphs() if __name__ == '__main__': diff --git a/experiment/paper1_steps/hard extreme evolution - annual maxima/main3_non_stationary_strength_evolution.py b/experiment/paper1_steps/hard extreme evolution - annual maxima/main3_non_stationary_strength_evolution.py index 5ec783b15fa436167a242d2c644f6bb435c347c1..29713ba1b35b6ada4e64ae01fb2e2f864a3e3ff5 100644 --- a/experiment/paper1_steps/hard extreme evolution - annual maxima/main3_non_stationary_strength_evolution.py +++ b/experiment/paper1_steps/hard extreme evolution - annual maxima/main3_non_stationary_strength_evolution.py @@ -13,7 +13,7 @@ from experiment.paper1_steps.utils import get_full_altitude_visualizer, FULL_ALT def main_fast_spatial_risk_evolution(): - for altitude in FULL_ALTITUDES[-1:]: + for altitude in [1800]: vizualiser = get_full_altitude_visualizer(Altitude_Hypercube_Year_Visualizer, altitude=altitude, exact_starting_year=1958, reduce_strength_array=True, trend_test_class=GevLocationAndScaleTrendTest) @@ -31,8 +31,8 @@ def main_full_spatial_risk_evolution(): def main_run(): - main_full_spatial_risk_evolution() - # main_fast_spatial_risk_evolution() + # main_full_spatial_risk_evolution() + main_fast_spatial_risk_evolution() if __name__ == '__main__': diff --git a/experiment/trend_analysis/univariate_test/abstract_gev_trend_test.py b/experiment/trend_analysis/univariate_test/abstract_gev_trend_test.py index e3584e95a4ee2b92cf8db477b3fccd6bab8038e4..456390e33ffeee82c0db89d5f40fbeafcd9127da 100644 --- a/experiment/trend_analysis/univariate_test/abstract_gev_trend_test.py +++ b/experiment/trend_analysis/univariate_test/abstract_gev_trend_test.py @@ -113,14 +113,18 @@ class AbstractGevTrendTest(AbstractUnivariateTest): @property def non_stationary_constant_gev_params(self) -> GevParams: - return self.non_stationary_estimator.result_from_fit.constant_gev_params + # Constant parameters correspond to the gev params in 1958 + return self.non_stationary_estimator.margin_function_fitted.get_gev_params(coordinate=np.array([1958]), + is_transformed=False) @property def test_trend_slope_strength(self): if self.crashed: return 0.0 else: + # Compute the slope strength slope = self._slope_strength() + # Delta T must in the same unit as were the parameter of slope mu1 and sigma1 slope *= self.nb_years_for_quantile_evolution * self.coordinates.transformed_distance_between_two_successive_years[0] return slope diff --git a/experiment/trend_analysis/univariate_test/abstract_univariate_test.py b/experiment/trend_analysis/univariate_test/abstract_univariate_test.py index 7381e71ca383ac6645ccd34a18ecbd3d11ff9338..7cbbf78e57b2deba5571785eb8db6f2829625dbc 100644 --- a/experiment/trend_analysis/univariate_test/abstract_univariate_test.py +++ b/experiment/trend_analysis/univariate_test/abstract_univariate_test.py @@ -61,8 +61,8 @@ class AbstractUnivariateTest(object): d[cls.ALL_TREND] = 'k-' d[cls.NON_SIGNIFICATIVE_TREND] = 'b-' # d[cls.SIGNIFICATIVE_ALL_TREND] = 'k-' - d[cls.SIGNIFICATIVE_POSITIVE_TREND] = 'g-' - d[cls.SIGNIFICATIVE_NEGATIVE_TREND] = 'r-' + d[cls.SIGNIFICATIVE_POSITIVE_TREND] = 'darkgreen-' + d[cls.SIGNIFICATIVE_NEGATIVE_TREND] = 'darkred-' # d[cls.NO_TREND] = 'k--' return d diff --git a/extreme_estimator/extreme_models/margin_model/temporal_linear_margin_model.py b/extreme_estimator/extreme_models/margin_model/temporal_linear_margin_model.py index 90d95ba18320051cd352888a2c79aa9d4316add9..156558e1396ff8a3319100403e9f70067c5bd3b1 100644 --- a/extreme_estimator/extreme_models/margin_model/temporal_linear_margin_model.py +++ b/extreme_estimator/extreme_models/margin_model/temporal_linear_margin_model.py @@ -37,6 +37,10 @@ class TemporalLinearMarginModel(LinearMarginModel): def shl(self): return get_null() + @property + def siglink(self): + return r('identity') + class StationaryStationModel(TemporalLinearMarginModel): @@ -64,6 +68,16 @@ class NonStationaryScaleStationModel(TemporalLinearMarginModel): return 1 +class NonStationaryLogScaleStationModel(NonStationaryScaleStationModel): + + def load_margin_functions(self, gev_param_name_to_dims=None): + super().load_margin_functions({GevParams.SCALE: [self.coordinates.idx_temporal_coordinates]}) + + @property + def siglink(self): + return r('exp') + + class NonStationaryShapeStationModel(TemporalLinearMarginModel): def load_margin_functions(self, gev_param_name_to_dims=None): diff --git a/extreme_estimator/extreme_models/result_from_fit.py b/extreme_estimator/extreme_models/result_from_fit.py index 78d9d83a18c050836090e3dbae55fb615df40147..c3170e183d625dd17605b9c0fd9882d8996d553a 100644 --- a/extreme_estimator/extreme_models/result_from_fit.py +++ b/extreme_estimator/extreme_models/result_from_fit.py @@ -48,10 +48,6 @@ class ResultFromFit(object): def convergence(self) -> str: raise NotImplementedError - @property - def constant_gev_params(self) -> GevParams: - raise NotImplementedError - class ResultFromIsmev(ResultFromFit): @@ -79,12 +75,6 @@ class ResultFromIsmev(ResultFromFit): i += 1 return coef_dict - @property - def constant_gev_params(self) -> GevParams: - params = {k.split('Coeff1')[0]: v for k, v in self.margin_coef_dict.items() - if 'Coeff1' in k and 'temp' not in k} - return GevParams.from_dict(params) - @property def all_parameters(self): return self.margin_coef_dict diff --git a/test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_temporal.py b/test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_temporal.py index 8ffe351324c74f4df0d402ca2260899fb77a1da6..f0a17fb376c709cb3f4e402a18050ed6e3de6f4d 100644 --- a/test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_temporal.py +++ b/test/test_extreme_estimator/test_margin_fits/test_gev/test_gev_temporal.py @@ -33,8 +33,6 @@ class TestGevTemporal(unittest.TestCase): df2 = pd.DataFrame(data=np.array(r['x_gev']), index=df.index) observations = AbstractSpatioTemporalObservations(df_maxima_gev=df2) self.dataset = AbstractDataset(observations=observations, coordinates=self.coordinates) - # - self.margin_models = load_non_stationary_temporal_margin_models(self.coordinates) def test_gev_temporal_margin_fit_stationary(self): # Create estimator @@ -49,7 +47,8 @@ class TestGevTemporal(unittest.TestCase): def test_gev_temporal_margin_fit_nonstationary(self): # Create estimator - for margin_model in self.margin_models: + margin_models = load_non_stationary_temporal_margin_models(self.coordinates) + for margin_model in margin_models: # margin_model = NonStationaryLocationStationModel(self.coordinates) estimator = LinearMarginEstimator(self.dataset, margin_model) estimator.fit()