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

[projections] fix test_existing_gcm_rcm_couple_and_rcp

parent a3dd9ba5
No related merge requests found
Showing with 17 additions and 11 deletions
+17 -11
......@@ -90,10 +90,14 @@ class AbstractAdamontStudy(AbstractStudy):
year_min, year_max = get_year_min_and_year_max_from_scenario(self.scenario, self.gcm_rcm_couple)
years = list(range(year_min, year_max + 1))
if self.scenario in adamont_scenarios_real:
time = dataset.variables['time']
time = np.array(dataset.variables['time'])
msg = 'len_years={} while len_time={},' \
'check year_min and year_max, ' \
'check in debug mode the time field of the daatset to see the starting date'.format(years, time)
# # Some print to check which year are in the data
# start = datetime(year=2005, month=8, day=1, hour=6, minute=0, second=0)
# dates = [start + timedelta(hours=int(h)) for h in time]
# print(["{}-{}".format(date.year-1, date.year) for date in dates])
assert len(years) == len(time), msg
for year, maxima in zip(years, annual_maxima):
if self.year_min <= year <= self.year_max:
......
......@@ -73,7 +73,7 @@ def get_gcm_rcm_couple_adamont_version_2(scenario):
('CNRM-CM5', 'CCLM4-8-17'), ('IPSL-CM5A-MR', 'WRF381P'), ('NorESM1-M', 'HIRHAM5'),
('IPSL-CM5A-MR', 'WRF331F'), ('HadGEM2-ES', 'RCA4')],
AdamontScenario.rcp45: [('NorESM1-M', 'REMO2015'), ('HadGEM2-ES', 'RegCM4-6')],
AdamontScenario.rcp85: [],
AdamontScenario.rcp85: [('HadGEM2-ES', 'RACMO22E')],
}
for couple_to_remove in scenario_to_list_to_remove[scenario]:
s.remove(couple_to_remove)
......
......@@ -45,7 +45,8 @@ class PointwiseGevStudyVisualizer(AltitudesStudies):
for i in range(8):
for massif_name in massif_names[i::8]:
linear_coef, _, r2 = self._plot_gev_params_against_altitude_one_massif(ax, massif_name, param_name,
elevation_as_xaxis, legend=legend)
elevation_as_xaxis,
legend=legend)
massif_name_to_linear_coef[massif_name] = 100 * linear_coef[0]
massif_name_to_r2_score[massif_name] = str(round(r2, 2))
print(param_name, np.mean([c for c in massif_name_to_linear_coef.values()]))
......@@ -135,7 +136,6 @@ class PointwiseGevStudyVisualizer(AltitudesStudies):
# labels = np.array(handles).reshape((3, 8)).transpose().flatten()
# ax.legend(handles, labels)
plt.gcf().subplots_adjust(right=0.15)
ax.set_yticks([])
ax.set_ylabel('')
......@@ -173,7 +173,8 @@ class PointwiseGevStudyVisualizer(AltitudesStudies):
)
plt.close()
def _plot_gev_params_against_altitude_one_massif(self, ax, massif_name, param_name, elevation_as_xaxis, legend=False):
def _plot_gev_params_against_altitude_one_massif(self, ax, massif_name, param_name, elevation_as_xaxis,
legend=False):
altitudes = []
params = []
# confidence_intervals = []
......@@ -189,7 +190,8 @@ class PointwiseGevStudyVisualizer(AltitudesStudies):
params.append(param)
# confidence_intervals.append(gev_params.param_name_to_confidence_interval[param_name])
massif_id = self.study.all_massif_names().index(massif_name)
plot_against_altitude(altitudes, ax, massif_id, massif_name, params, fill=False, elevation_as_xaxis=elevation_as_xaxis,
plot_against_altitude(altitudes, ax, massif_id, massif_name, params, fill=False,
elevation_as_xaxis=elevation_as_xaxis,
legend=legend)
return fit_linear_regression(altitudes, params)
......@@ -313,6 +315,7 @@ class PointwiseGevStudyVisualizer(AltitudesStudies):
# a_list.append(a)
# return np.mean(np.array(a_list))
def main_paper2():
altitudes = list(chain.from_iterable(altitudes_for_groups))
......@@ -328,12 +331,13 @@ def main_paper2():
def main_paper3():
altitudes = list(chain.from_iterable(altitudes_for_groups))
altitudes = [1200, 1500, 1800]
for scenario in rcp_scenarios[:2]:
# altitudes = [1200, 1500, 1800]
for scenario in rcp_scenarios[:]:
for gcm_rcm_couple in get_gcm_rcm_couple_adamont_version_2(scenario):
visualizer = PointwiseGevStudyVisualizer(AdamontSnowfall, altitudes=altitudes, scenario=scenario,
gcm_rcm_couple=gcm_rcm_couple)
visualizer.plot_gev_params_against_altitude()
if __name__ == '__main__':
main_paper3()
......@@ -41,7 +41,7 @@ class TestAdamontStudy(unittest.TestCase):
def test_existing_gcm_rcm_couple_and_rcp(self):
altitude = 1800
for scenario in rcp_scenarios[:2]:
for scenario in rcp_scenarios[:]:
l = []
for gcm_rcm_couple in get_gcm_rcm_couple_adamont_version_2(scenario):
adamont_study = AdamontSnowfall(altitude=altitude, adamont_version=2,
......@@ -51,8 +51,6 @@ class TestAdamontStudy(unittest.TestCase):
_ = adamont_study.year_to_annual_maxima[2098]
except FileNotFoundError:
l.append(gcm_rcm_couple)
print(scenario, l)
self.assertTrue(True)
......
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