Commit e04b63d9 authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[projections] comparison of bias in the mean annual maxima.

parent d9e805cd
No related merge requests found
Showing with 34 additions and 19 deletions
+34 -19
......@@ -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
......
......@@ -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
......
......@@ -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)
......
......@@ -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:
......
......@@ -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)
......
......@@ -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__':
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment