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 5cd271a392cd43447353698232277b296a296b73..ffd7d5427e0d3003ef9fded6d1b81d264833a87b 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 @@ -123,7 +123,7 @@ class AbstractStudy(object): year_to_wps[year] = self.df_weather_types.loc[days].iloc[:, 0].values return year_to_wps - def df_for_top_annual_maxima(self, nb_top=None, massif_names=None): + def df_for_top_annual_maxima(self, nb_top=None, massif_names=None, limit_for_the_percentage=None): # Replace default arguments if nb_top is None: nb_top = self.nb_years @@ -151,7 +151,10 @@ class AbstractStudy(object): df.drop(columns=drop_columns, inplace=True) df.rename(columns={'50%': 'median'}, inplace=True) df = df.astype(int) - df.index.name = 'Number Top={}'.format(nb_top) + df.index.name = 'Top {} maxima ({} -{})'.format(nb_top, self.year_min, self.year_max) + if limit_for_the_percentage is not None: + ind = df['%'] > limit_for_the_percentage + df = df.loc[ind] return df @cached_property @@ -214,33 +217,6 @@ class AbstractStudy(object): year_to_annual_maxima[year] = time_serie.max(axis=0) return year_to_annual_maxima - @cached_property - def year_to_winter_annual_maxima(self) -> OrderedDict: - # Map each year to an array of size nb_massif - year_to_annual_maxima = OrderedDict() - for year, time_serie in self._year_to_max_daily_time_serie.items(): - year_to_annual_maxima[year] = time_serie[91:-61].max(axis=0) - return year_to_annual_maxima - - @property - def observations_winter_annual_maxima(self) -> AnnualMaxima: - return AnnualMaxima( - df_maxima_gev=pd.DataFrame(self.year_to_winter_annual_maxima, index=self.study_massif_names)) - - @cached_property - def year_to_summer_annual_maxima(self) -> OrderedDict: - # Map each year to an array of size nb_massif - year_to_annual_maxima = OrderedDict() - for year, time_serie in self._year_to_max_daily_time_serie.items(): - annual_maxima = np.concatenate((time_serie[:91], time_serie[-61:]), axis=0).max(axis=0) - year_to_annual_maxima[year] = annual_maxima - return year_to_annual_maxima - - @property - def observations_summer_annual_maxima(self) -> AnnualMaxima: - return AnnualMaxima( - df_maxima_gev=pd.DataFrame(self.year_to_summer_annual_maxima, index=self.study_massif_names)) - @cached_property def year_to_annual_maxima_index(self) -> OrderedDict: # Map each year to an array of size nb_massif diff --git a/extreme_trend/visualizers/utils.py b/extreme_trend/visualizers/utils.py index 43687d4594689d5acb935060ad1e85e65652e9d6..9e2f857ab2c58b142c3424803f97dabd0a8c707b 100644 --- a/extreme_trend/visualizers/utils.py +++ b/extreme_trend/visualizers/utils.py @@ -1,5 +1,6 @@ from collections import OrderedDict +from extreme_data.meteo_france_data.scm_models_data.utils import SeasonForTheMaxima from extreme_fit.model.margin_model.linear_margin_model.abstract_temporal_linear_margin_model import \ TemporalMarginFitMethod from extreme_trend.visualizers.study_visualizer_for_non_stationary_trends import \ @@ -10,11 +11,13 @@ def load_altitude_to_visualizer(altitudes, massif_names, model_subsets_for_uncer uncertainty_methods, study_visualizer_class=StudyVisualizerForNonStationaryTrends, save_to_file=True, - multiprocessing=True): + multiprocessing=True, + season=SeasonForTheMaxima.annual): + print("Season={}".format(season)) fit_method = TemporalMarginFitMethod.extremes_fevd_mle altitude_to_visualizer = OrderedDict() for altitude in altitudes: - study = study_class(altitude=altitude, multiprocessing=multiprocessing) + study = study_class(altitude=altitude, multiprocessing=multiprocessing, season=season) study_visualizer = study_visualizer_class(study=study, multiprocessing=multiprocessing, save_to_file=save_to_file, uncertainty_massif_names=massif_names, uncertainty_methods=uncertainty_methods, diff --git a/projects/contrasting_trends_in_snow_loads/main_result.py b/projects/contrasting_trends_in_snow_loads/main_result.py index 02c5567be8d6f0cb747e54eb9055fb66971aec0c..75b13547e249ae384664642561f0c3e5037a96d5 100644 --- a/projects/contrasting_trends_in_snow_loads/main_result.py +++ b/projects/contrasting_trends_in_snow_loads/main_result.py @@ -2,6 +2,7 @@ from multiprocessing.pool import Pool import matplotlib as mpl +from extreme_data.meteo_france_data.scm_models_data.utils import SeasonForTheMaxima from extreme_trend.visualizers.utils import load_altitude_to_visualizer mpl.use('Agg') @@ -41,7 +42,8 @@ def intermediate_result(altitudes, massif_names=None, """ # Load altitude to visualizer altitude_to_visualizer = load_altitude_to_visualizer(altitudes, massif_names, model_subsets_for_uncertainty, - study_class, uncertainty_methods, save_to_file=save_to_file) + study_class, uncertainty_methods, save_to_file=save_to_file, + season=SeasonForTheMaxima.winter_extended) # Load variable object efficiently for v in altitude_to_visualizer.values(): _ = v.study.year_to_variable_object @@ -65,7 +67,7 @@ def major_result(): model_subsets_for_uncertainty = None # altitudes = paper_altitudes # altitudes = paper_altitudes - altitudes = [900, 1200, 1500, 1800, 2100, 2400, 2700, 3000][:8] + altitudes = [900, 1200, 1500, 1800, 2100, 2400, 2700, 3000][:] snow_load_classes = [CrocusSnowLoad1Day, CrocusSnowLoad3Days, CrocusSnowLoad5Days, CrocusSnowLoad7Days][:] precipitation_classes = [SafranPrecipitation1Day, SafranPrecipitation3Days, SafranPrecipitation5Days, SafranPrecipitation7Days][:] @@ -73,7 +75,7 @@ def major_result(): rainfall_classes = [SafranRainfall1Day, SafranRainfall3Days, SafranRainfall5Days, SafranRainfall7Days] study_classes = precipitation_classes + snow_load_classes # study_classes = snowfall_classes + rainfall_classes - for study_class in study_classes[:1]: + for study_class in study_classes[:]: intermediate_result(altitudes, massif_names, model_subsets_for_uncertainty, uncertainty_methods, study_class, multiprocessing=True) diff --git a/projects/contrasting_trends_in_snow_loads/main_spatial_relative_change_in_maxima_at_fixed_altitude.py b/projects/contrasting_trends_in_snow_loads/main_spatial_relative_change_in_maxima_at_fixed_altitude.py index 5b5a6ea32426c8e07d47306e0cd3106751ebd356..91260c0b93074d2fc48be64ba2cd5db611d4e2e0 100644 --- a/projects/contrasting_trends_in_snow_loads/main_spatial_relative_change_in_maxima_at_fixed_altitude.py +++ b/projects/contrasting_trends_in_snow_loads/main_spatial_relative_change_in_maxima_at_fixed_altitude.py @@ -6,13 +6,6 @@ from extreme_data.meteo_france_data.scm_models_data.visualization.study_visualiz import matplotlib.pyplot as plt -def test(): - study = CrocusSnowLoad3Days(altitude=1200) - study_visualizer = StudyVisualizer(study) - study_visualizer.visualize_max_graphs_poster('Queyras', altitude='noope', snow_abbreviation="ok", color='red') - plt.show() - - def density_wrt_altitude(): save_to_file = True study_class = [SafranPrecipitation, SafranRainfall, SafranSnowfall, CrocusSnowLoad3Days, CrocusSnowLoadTotal][-2] diff --git a/projects/contrasting_trends_in_snow_loads/weather_types_analysis/main_distribution_wps.py b/projects/contrasting_trends_in_snow_loads/weather_types_analysis/main_distribution_wps.py index 9372f13b45771fbe09760ee51d802cb4931a7d5c..52946ba34c073266ab7da920ea13b8851f492420 100644 --- a/projects/contrasting_trends_in_snow_loads/weather_types_analysis/main_distribution_wps.py +++ b/projects/contrasting_trends_in_snow_loads/weather_types_analysis/main_distribution_wps.py @@ -3,76 +3,109 @@ import numpy as np from extreme_data.meteo_france_data.scm_models_data.abstract_extended_study import AbstractExtendedStudy from extreme_data.meteo_france_data.scm_models_data.crocus.crocus import CrocusSnowLoad3Days, CrocusSnowLoad1Day -from extreme_data.meteo_france_data.scm_models_data.safran.safran import SafranPrecipitation1Day +from extreme_data.meteo_france_data.scm_models_data.safran.safran import SafranPrecipitation1Day, \ + SafranPrecipitation3Days +from extreme_data.meteo_france_data.scm_models_data.utils import SeasonForTheMaxima -def main_spatial_distribution_wps(study_class, year_min=1954, year_max=2008): - study = study_class(altitude=1800, year_min=year_min, year_max=year_max) +def main_spatial_distribution_wps(study_class, year_min=1954, year_max=2008, limit_for_the_percentage=None): + study = study_class(altitude=1800, year_min=year_min, year_max=year_max, season=SeasonForTheMaxima.winter_extended) for region_name in AbstractExtendedStudy.region_names: massif_names = AbstractExtendedStudy.region_name_to_massif_names[region_name] print('\n \n', region_name, '\n') - for nb_top in [study.nb_years, 5, 1][1:2]: - print(study.df_for_top_annual_maxima(nb_top=nb_top, massif_names=massif_names), '\n') + for nb_top in [study.nb_years, 10, 1][1:2]: + print(study.df_for_top_annual_maxima(nb_top=nb_top, massif_names=massif_names, limit_for_the_percentage=limit_for_the_percentage), '\n') """ -Some analysis: + Northern Alps + % count mean std min median max +Steady Oceanic 92 65 159 35 121 146 282 + + Central Alps + % count mean std min median max +Steady Oceanic 72 51 136 31 97 130 235 +South Circulation 15 11 128 18 105 126 161 -At altitude 1800m, -for the precipitation in 1 day -between year_min=1954, year_max=2008 + Southern Alps + % count mean min median max +South Circulation 61 37 147 79 147 235 +Steady Oceanic 13 8 121 93 114 187 + + Extreme South Alps + % count mean min median max +South Circulation 80 24 174 101 166 306 -If we look at the 5 biggest maxima for each massif, -and look to which Weather pattern they correspond -then we do some percentage for each climatic region + +Process finished with exit code 0 - Northern Alps - % count mean std min median max -Steady Oceanic 77 27 105 16 80 104 150 -Atlantic Wave 11 4 111 15 95 111 129 - Central Alps - % count mean min median max -Steady Oceanic 57 20 90 70 86 119 -South Circulation 17 6 85 64 88 104 -East Return 14 5 88 74 93 100 - Southern Alps - % count mean min median max -South Circulation 43 13 99 72 106 122 -Central Depression 36 11 98 68 97 136 -East Return 16 5 90 70 83 121 - Extreme South Alps -Central Depression 53.0 8 -South Circulation 47.0 7 """ -def main_temporal_distribution_wps(study_class, year_min=1954, year_max=2008): +def main_temporal_distribution_wps(study_class, year_min=1954, year_max=2008, limit_for_the_percentage=None): altitude = 1800 - study_before = study_class(altitude=altitude, year_min=year_min, year_max=1981) - study_after = study_class(altitude=altitude, year_min=1981, year_max=2008) + study_before = study_class(altitude=altitude, year_min=year_min, year_max=1981, season=SeasonForTheMaxima.winter_extended) + study_after = study_class(altitude=altitude, year_min=1981, year_max=year_max, season=SeasonForTheMaxima.winter_extended) + # todo: same min and max year ? for region_name in AbstractExtendedStudy.region_names: massif_names = AbstractExtendedStudy.region_name_to_massif_names[region_name] - print('\n \n', region_name, '\n') + print('\n \n', '{} ({} massifs)'.format(region_name, len(massif_names)), '\n') for nb_top in [study_before.nb_years, 10][1:]: - print(study_before.df_for_top_annual_maxima(nb_top=nb_top, massif_names=massif_names), '\n') - print(study_after.df_for_top_annual_maxima(nb_top=nb_top, massif_names=massif_names), '\n') + print(study_before.df_for_top_annual_maxima(nb_top=nb_top, massif_names=massif_names, limit_for_the_percentage=limit_for_the_percentage), '\n') + print(study_after.df_for_top_annual_maxima(nb_top=nb_top, massif_names=massif_names, limit_for_the_percentage=limit_for_the_percentage), '\n') """ -There is no real stationarity in the percentage of the kind of storms that are causing extreme. + Northern Alps (7 massifs) + % count mean min median max +Top 10 maxima (1954 -1981) +Steady Oceanic 94 66 130 102 127 202 + +Top 10 maxima (1981 -2008) +Steady Oceanic 82 58 151 104 134 282 + + Central Alps (7 massifs) + % count mean min median max +Top 10 maxima (1954 -1981) +Steady Oceanic 71 50 110 76 107 190 + +Top 10 maxima (1981 -2008) +Steady Oceanic 74 52 125 87 115 235 +South Circulation 14 10 123 100 120 161 + + Southern Alps (6 massifs) + % count mean min median max +Top 10 maxima (1954 -1981) +South Circulation 43 26 113 67 112 197 +Steady Oceanic 16 10 95 82 93 122 +Southwest Circulation 15 9 102 68 95 140 + +Top 10 maxima (1981 -2008) +South Circulation 63 38 134 73 127 235 +Steady Oceanic 21 13 110 80 105 187 + + + Extreme South Alps (3 massifs) + % count mean min median max +Top 10 maxima (1954 -1981) +South Circulation 63 19 136 84 139 194 +Southwest Circulation 13 4 122 95 123 146 + +Top 10 maxima (1981 -2008) +South Circulation 76 23 165 78 159 306 + + -the reparittion of storm before and after (no matter the nb_top consider 10, or all) are the same. -even for the local region it is the same. --> so what is really changing is probably the strength associated to each kind of storm. """ if __name__ == '__main__': - study_class = [CrocusSnowLoad1Day, SafranPrecipitation1Day][-1] - main_spatial_distribution_wps(study_class) - # main_temporal_distribution_wps(study_class) + limit_percentage = 10 + study_class = [CrocusSnowLoad1Day, SafranPrecipitation1Day, SafranPrecipitation3Days][-1] + # main_spatial_distribution_wps(study_class, limit_for_the_percentage=limit_percentage) + main_temporal_distribution_wps(study_class, limit_for_the_percentage=limit_percentage)