From d8bd3febac4913ea839ce9655a9c928270390403 Mon Sep 17 00:00:00 2001 From: Le Roux Erwan <erwan.le-roux@irstea.fr> Date: Tue, 30 Mar 2021 09:32:35 +0200 Subject: [PATCH] [projection snowfall] fix temperature for HadGem. rely on the merge visualizer. --- .../adamont_data/cmip5/climate_explorer_cimp5.py | 4 +++- .../adamont_data/cmip5/plot_temperatures.py | 2 +- .../independent_ensemble_fit/one_fold_fit_merge.py | 4 ++++ .../ensemble_fit/visualizer_for_projection_ensemble.py | 2 +- .../section_data_and_results/preliminary_analysis.py | 4 ++-- projects/projected_extreme_snowfall/data/main_data.py | 5 ++--- .../results/main_projections_ensemble.py | 6 +++--- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/extreme_data/meteo_france_data/adamont_data/cmip5/climate_explorer_cimp5.py b/extreme_data/meteo_france_data/adamont_data/cmip5/climate_explorer_cimp5.py index 87166420..3117c25d 100644 --- a/extreme_data/meteo_france_data/adamont_data/cmip5/climate_explorer_cimp5.py +++ b/extreme_data/meteo_france_data/adamont_data/cmip5/climate_explorer_cimp5.py @@ -93,14 +93,16 @@ def dat_to_csv(csv_filepath, txt_filepath, gcm): l = df_temp_until_july.sum(axis=1).values + df_temp_after_august.sum(axis=1).values l /= 12 l = [np.nan] + list(l) + l = np.array(l) assert len(l) == len(df.index) + l[l < 280] = np.nan # First we compute the standard column df = set_anomaly(df, mean_data=l, spline=False) # Then we regress some cubic spline on the temperature columns noisy_data = df[get_column_name(anomaly=False, spline=False)] - ind = noisy_data > -50 + ind = ~noisy_data.isna() spline_data = noisy_data.copy() spline_data.loc[ind] = apply_cubic_spline(noisy_data.loc[ind].index.values, noisy_data.loc[ind].values, gcm) df = set_anomaly(df, mean_data=spline_data, spline=True) diff --git a/extreme_data/meteo_france_data/adamont_data/cmip5/plot_temperatures.py b/extreme_data/meteo_france_data/adamont_data/cmip5/plot_temperatures.py index 2c68e0c8..f7e07827 100644 --- a/extreme_data/meteo_france_data/adamont_data/cmip5/plot_temperatures.py +++ b/extreme_data/meteo_france_data/adamont_data/cmip5/plot_temperatures.py @@ -32,7 +32,7 @@ def main_plot_temperature_with_spline_on_top(anomaly=True): scenarios = rcp_scenarios for scenario in scenarios: label = gcm if scenario == scenarios[0] else None - plot_temperature_for_rcp_gcm(ax, gcm, scenario, year_min=1951, year_max=2005, linestyle=linestyle, + plot_temperature_for_rcp_gcm(ax, gcm, scenario, year_min=1850, year_max=2005, linestyle=linestyle, label=label, spline=spline, anomaly=anomaly) plot_temperature_for_rcp_gcm(ax, gcm, scenario, year_min=2005, year_max=2100, spline=spline, anomaly=anomaly) diff --git a/extreme_trend/ensemble_fit/independent_ensemble_fit/one_fold_fit_merge.py b/extreme_trend/ensemble_fit/independent_ensemble_fit/one_fold_fit_merge.py index 2345fca5..d749c081 100644 --- a/extreme_trend/ensemble_fit/independent_ensemble_fit/one_fold_fit_merge.py +++ b/extreme_trend/ensemble_fit/independent_ensemble_fit/one_fold_fit_merge.py @@ -32,3 +32,7 @@ class OneFoldFitMerge(OneFoldFit): merged_relative_changes = list(self.merge_function(np.array(all_relative_changes), axis=0)) assert len(all_relative_changes[0]) == len(merged_relative_changes) return merged_relative_changes + + @property + def best_shape(self): + return self.merge_function([o.best_shape for o in self.one_fold_fit_list]) diff --git a/extreme_trend/ensemble_fit/visualizer_for_projection_ensemble.py b/extreme_trend/ensemble_fit/visualizer_for_projection_ensemble.py index 70ba3371..096e5e9e 100644 --- a/extreme_trend/ensemble_fit/visualizer_for_projection_ensemble.py +++ b/extreme_trend/ensemble_fit/visualizer_for_projection_ensemble.py @@ -112,7 +112,7 @@ class VisualizerForProjectionEnsemble(object): merge_keys = [AbstractEnsembleFit.Median_merge, AbstractEnsembleFit.Mean_merge] keys = self.gcm_rcm_couples + merge_keys # Only plot Mean for speed - keys = [AbstractEnsembleFit.Mean_merge] + # keys = [AbstractEnsembleFit.Mean_merge] for key in keys: visualizer_list = [independent_ensemble_fit.gcm_rcm_couple_to_visualizer[key] if key in self.gcm_rcm_couples diff --git a/projects/past_extreme_snowfall/section_data_and_results/preliminary_analysis.py b/projects/past_extreme_snowfall/section_data_and_results/preliminary_analysis.py index ff04a43d..0b9ee6d3 100644 --- a/projects/past_extreme_snowfall/section_data_and_results/preliminary_analysis.py +++ b/projects/past_extreme_snowfall/section_data_and_results/preliminary_analysis.py @@ -206,9 +206,9 @@ def main_paper2(): def main_paper3(): altitudes = list(chain.from_iterable(altitudes_for_groups)) # altitudes = [1200, 1500, 1800] - for scenario in rcp_scenarios[2:]: + for scenario in rcp_scenarios[:]: gcm_rcm_couples = get_gcm_rcm_couples(scenario) - gcm_rcm_couples =[('CNRM-CM5', 'CCLM4-8-17')] + # gcm_rcm_couples =[('CNRM-CM5', 'CCLM4-8-17')] for gcm_rcm_couple in gcm_rcm_couples: visualizer = PointwiseGevStudyVisualizer(AdamontSnowfall, altitudes=altitudes, scenario=scenario, gcm_rcm_couple=gcm_rcm_couple) diff --git a/projects/projected_extreme_snowfall/data/main_data.py b/projects/projected_extreme_snowfall/data/main_data.py index f20e2858..898b8eba 100644 --- a/projects/projected_extreme_snowfall/data/main_data.py +++ b/projects/projected_extreme_snowfall/data/main_data.py @@ -20,12 +20,11 @@ from extreme_data.meteo_france_data.scm_models_data.utils import Season def main(): scm_study_class = SafranSnowfall1Day adamont_study_class = AdamontSnowfall - year_min = 2006 + year_min = 1950 year_max = 2100 massif_names = ['Vanoise'] season = Season.annual scenarios = rcm_scenarios_extended - scenarios = rcp_scenarios altitudes = [600, 2100, 3600] for altitude, adamont_scenario in list(zip(altitudes, scenarios))[:]: plt.figure(figsize=(10, 5)) @@ -38,7 +37,7 @@ def main(): season=season, scenario=adamont_scenario) print(altitude, adamont_scenario) adamont_studies.plot_maxima_time_series_adamont(massif_names=massif_names, - scm_study=scm_study, legend_and_labels=True) + scm_study=scm_study, legend_and_labels=False) if __name__ == '__main__': diff --git a/projects/projected_extreme_snowfall/results/main_projections_ensemble.py b/projects/projected_extreme_snowfall/results/main_projections_ensemble.py index 49ea7796..864f6f95 100644 --- a/projects/projected_extreme_snowfall/results/main_projections_ensemble.py +++ b/projects/projected_extreme_snowfall/results/main_projections_ensemble.py @@ -39,7 +39,7 @@ from extreme_data.meteo_france_data.scm_models_data.utils import Season def main(): start = time.time() study_class = AdamontSnowfall - ensemble_fit_classes = [IndependentEnsembleFit, TogetherEnsembleFit][1:] + ensemble_fit_classes = [IndependentEnsembleFit, TogetherEnsembleFit][:1] temporal_covariate_for_fit = [TimeTemporalCovariate, AnomalyTemperatureWithSplineTemporalCovariate][0] set_seed_for_test() @@ -58,12 +58,12 @@ def main(): gcm_rcm_couples = get_gcm_rcm_couples(scenario) if fast is None: massif_names = None - gcm_rcm_couples = gcm_rcm_couples + gcm_rcm_couples = gcm_rcm_couples[:2] AbstractExtractEurocodeReturnLevel.NB_BOOTSTRAP = 10 altitudes_list = altitudes_for_groups[3:] elif fast: massif_names = ['Vanoise', 'Haute-Maurienne'] - gcm_rcm_couples = gcm_rcm_couples[:] + gcm_rcm_couples = gcm_rcm_couples[:2] AbstractExtractEurocodeReturnLevel.NB_BOOTSTRAP = 10 altitudes_list = altitudes_for_groups[:1] else: -- GitLab