diff --git a/extreme_data/meteo_france_data/adamont_data/abstract_adamont_study.py b/extreme_data/meteo_france_data/adamont_data/abstract_adamont_study.py index 2d2d7c629ffcaa26d9c880275a5e203b1acbdfc3..b2924f9b3cd5fbfbac7e7f9f982809f822d17055 100644 --- a/extreme_data/meteo_france_data/adamont_data/abstract_adamont_study.py +++ b/extreme_data/meteo_france_data/adamont_data/abstract_adamont_study.py @@ -51,7 +51,7 @@ class AbstractAdamontStudy(AbstractStudy): else: if year_min < year_min_scenario: raise WrongYearMinOrYearMax( - 'year min is {} and should be larger than {}'.format(year_min, year_min_scenario)) + 'year min is {} and should be larger than {} for {}'.format(year_min, year_min_scenario, gcm_rcm_couple)) if year_max is None: year_max = year_max_scenario diff --git a/extreme_data/meteo_france_data/adamont_data/adamont_scenario.py b/extreme_data/meteo_france_data/adamont_data/adamont_scenario.py index f7c05d46ef0617252b6ec2d982870bef31f4872b..8f2b78714454c2b9a1d0418a1e6ce45a8f48cb8f 100644 --- a/extreme_data/meteo_france_data/adamont_data/adamont_scenario.py +++ b/extreme_data/meteo_france_data/adamont_data/adamont_scenario.py @@ -52,16 +52,18 @@ def get_year_min(adamont_scenario, gcm_rcm_couple): return year_min -def load_gcm_rcm_couples_for_year_min_and_year_max(year_min, year_max, adamont_scenario=AdamontScenario.histo, - version=2): +def load_gcm_rcm_couples(year_min=None, year_max=None, + adamont_scenario=AdamontScenario.histo, + adamont_version=2): gcm_rcm_couples = [] - gcm_rcm_couple_to_full_name = get_gcm_rcm_couple_adamont_to_full_name(version) + gcm_rcm_couple_to_full_name = get_gcm_rcm_couple_adamont_to_full_name(adamont_version) for gcm_rcm_couple in gcm_rcm_couple_to_full_name.keys(): year_min_couple, year_max_couple = get_year_min_and_year_max_from_scenario( adamont_scenario=adamont_scenario, gcm_rcm_couple=gcm_rcm_couple) - if year_min_couple <= year_min and year_max <= year_max_couple: - gcm_rcm_couples.append(gcm_rcm_couple) + if (year_min is None) or (year_min_couple <= year_min): + if (year_max is None) or (year_max <= year_max_couple): + gcm_rcm_couples.append(gcm_rcm_couple) return gcm_rcm_couples diff --git a/extreme_data/meteo_france_data/scm_models_data/safran/safran_max_snowf.py b/extreme_data/meteo_france_data/scm_models_data/safran/safran_max_snowf.py index 05fd2d9eaa6498e3b2cd66431a1b4fa3593be275..56632129a75f71996630348876614325ced20bb6 100644 --- a/extreme_data/meteo_france_data/scm_models_data/safran/safran_max_snowf.py +++ b/extreme_data/meteo_france_data/scm_models_data/safran/safran_max_snowf.py @@ -13,14 +13,17 @@ class AbstractSafranSnowfallMaxFiles(SafranSnowfall1Day): def __init__(self, safran_year, **kwargs): super().__init__(**kwargs) - self.year_max = max(safran_year, self.year_max) self.nc_filepath = op.join(DATA_PATH, 'SAFRAN_montagne-CROCUS_{}'.format(safran_year), 'max-1day-snowf_SAFRAN.nc') self.safran_year = safran_year @property def ordered_years(self): - return [i for i in list(range(1959, self.safran_year + 1)) if self.year_min <= i <= self.year_max] + return [i for i in self.all_years if self.year_min <= i <= self.year_max] + + @property + def all_years(self): + return list(range(1959, self.safran_year + 1)) @cached_property def year_to_annual_maxima(self) -> OrderedDict: @@ -29,8 +32,9 @@ class AbstractSafranSnowfallMaxFiles(SafranSnowfall1Day): annual_maxima = np.array(dataset.variables['max-1day-snowf']) assert annual_maxima.shape[1] == len(self.column_mask) annual_maxima = annual_maxima[:, self.column_mask] - for year, a in zip(self.ordered_years, annual_maxima): - year_to_annual_maxima[year] = a + for year, maxima in zip(self.all_years, annual_maxima): + if self.year_min <= year <= self.year_max: + year_to_annual_maxima[year] = maxima return year_to_annual_maxima @property @@ -39,8 +43,11 @@ class AbstractSafranSnowfallMaxFiles(SafranSnowfall1Day): class SafranSnowfall2020(AbstractSafranSnowfallMaxFiles): + YEAR_MAX = 2020 def __init__(self, **kwargs): + if ('year_max' not in kwargs) or (kwargs['year_max'] is None): + kwargs['year_max'] = self.YEAR_MAX super().__init__(2020, **kwargs) diff --git a/extreme_data/meteo_france_data/scm_models_data/visualization/study_visualizer.py b/extreme_data/meteo_france_data/scm_models_data/visualization/study_visualizer.py index 8ce26dec5b92ac693605e0a659a1054ae723126b..d7caa81ae9e855799fb2b0140df9ba73dd63823d 100644 --- a/extreme_data/meteo_france_data/scm_models_data/visualization/study_visualizer.py +++ b/extreme_data/meteo_france_data/scm_models_data/visualization/study_visualizer.py @@ -548,9 +548,9 @@ class StudyVisualizer(VisualizationParameters): else: title = self.plot_name if self.only_one_graph: - plt.suptitle(self.plot_name) + plt.suptitle(self.plot_name, y=1.0) elif not no_title: - plt.suptitle(title) + plt.suptitle(title, y=1.0) if self.show: plt.show() if self.save_to_file: diff --git a/projects/projected_snowfall/comparison_with_scm/main_comparison_on_rcp_85_extended.py b/projects/projected_snowfall/comparison_with_scm/main_comparison_on_rcp_85_extended.py index c8998afc2a403931d0a568302225057b2c160fea..fc819ca75bb2f77454d6f08f40dded547b072010 100644 --- a/projects/projected_snowfall/comparison_with_scm/main_comparison_on_rcp_85_extended.py +++ b/projects/projected_snowfall/comparison_with_scm/main_comparison_on_rcp_85_extended.py @@ -9,7 +9,7 @@ mpl.rcParams['text.latex.preamble'] = [r'\usepackage{amsmath}'] from projects.projected_snowfall.comparison_with_scm.comparison_plot import individual_plot, collective_plot from extreme_data.meteo_france_data.adamont_data.adamont.adamont_snowfall import AdamontSnowfall -from extreme_data.meteo_france_data.adamont_data.adamont_scenario import load_gcm_rcm_couples_for_year_min_and_year_max, \ +from extreme_data.meteo_france_data.adamont_data.adamont_scenario import load_gcm_rcm_couples, \ AdamontScenario from extreme_data.meteo_france_data.adamont_data.adamont_studies import AdamontStudies from extreme_data.meteo_france_data.scm_models_data.safran.safran import SafranSnowfall1Day @@ -76,8 +76,8 @@ def load_visualizer(altitude, massif_names, year_min, year_max) -> ComparisonHis # Loading part scm_study = scm_study_class(altitude=altitude, year_min=year_min, year_max=year_max, season=season) - gcm_rcm_couples = load_gcm_rcm_couples_for_year_min_and_year_max(year_min, year_max, - adamont_scenario=adamont_scenario) + gcm_rcm_couples = load_gcm_rcm_couples(year_min, year_max, + adamont_scenario=adamont_scenario) adamont_studies = AdamontStudies(adamont_study_class, gcm_rcm_couples, altitude=altitude, year_min=year_min, year_max=year_max, season=season, scenario=adamont_scenario) diff --git a/projects/projected_snowfall/projected_data/main_projection.py b/projects/projected_snowfall/projected_data/main_projection.py index e27dccd6a442a49ceaf4874ef90d195bffeddf95..52a7d4044c351bb06190e12a172954ff5c1bc695 100644 --- a/projects/projected_snowfall/projected_data/main_projection.py +++ b/projects/projected_snowfall/projected_data/main_projection.py @@ -2,6 +2,8 @@ import matplotlib as mpl +from extreme_data.meteo_france_data.scm_models_data.safran.safran_max_snowf import SafranSnowfall2020 + mpl.use('Agg') mpl.rcParams['text.usetex'] = True mpl.rcParams['text.latex.preamble'] = [r'\usepackage{amsmath}'] @@ -9,7 +11,7 @@ from collections import OrderedDict from extreme_data.meteo_france_data.adamont_data.adamont.adamont_snowfall import AdamontSnowfall from extreme_data.meteo_france_data.adamont_data.adamont_scenario import AdamontScenario, \ - load_gcm_rcm_couples_for_year_min_and_year_max + load_gcm_rcm_couples from extreme_data.meteo_france_data.adamont_data.adamont_studies import AdamontStudies from extreme_data.meteo_france_data.scm_models_data.safran.safran import SafranSnowfall1Day from extreme_data.meteo_france_data.scm_models_data.utils import Season @@ -41,14 +43,18 @@ def main(): for altitude in altitudes: adamont_study_class = AdamontSnowfall season = Season.annual - gcm_rcm_couples = load_gcm_rcm_couples_for_year_min_and_year_max(year_min, year_max, - adamont_scenario=adamont_scenario) + gcm_rcm_couples = load_gcm_rcm_couples(year_min, year_max, + adamont_scenario=adamont_scenario) adamont_studies = AdamontStudies(adamont_study_class, gcm_rcm_couples, altitude=altitude, year_min=year_min, year_max=year_max, season=season, scenario=adamont_scenario, adamont_version=2) - adamont_studies.plot_maxima_time_series_adamont(massif_names) + if year_max <= 2020: + scm_study = SafranSnowfall2020(altitude=altitude, season=season, year_min=year_min, year_max=year_max) + else: + scm_study = None + adamont_studies.plot_maxima_time_series_adamont(massif_names, scm_study=scm_study) if __name__ == '__main__':