Commit 7bd0168c authored by Le Roux Erwan's avatar Le Roux Erwan
Browse files

[projections] fix anomaly of temperatures & check them visually

parent a8b41514
No related merge requests found
Showing with 16 additions and 11 deletions
+16 -11
...@@ -99,7 +99,11 @@ def dat_to_csv(csv_filepath, txt_filepath, mean_annual_column_name, rolling_mean ...@@ -99,7 +99,11 @@ def dat_to_csv(csv_filepath, txt_filepath, mean_annual_column_name, rolling_mean
l = [np.nan] + list(l) l = [np.nan] + list(l)
assert len(l) == len(df.index) assert len(l) == len(df.index)
df[mean_annual_column_name] = l df[mean_annual_column_name] = l
mean_for_reference_period_1850_to_1900 = df.loc[1850:1900, mean_annual_column_name].mean() s_mean_for_reference_period_1850_to_1900 = df.loc[1850:1900, mean_annual_column_name]
# Sometimes some initial global mean temperatures are negative for the first years,
# we remove them for the computation of the mean
ind = s_mean_for_reference_period_1850_to_1900 > 0
mean_for_reference_period_1850_to_1900 = s_mean_for_reference_period_1850_to_1900.loc[ind].mean()
df[anomaly_annual_column_name] = df[mean_annual_column_name] - mean_for_reference_period_1850_to_1900 df[anomaly_annual_column_name] = df[mean_annual_column_name] - mean_for_reference_period_1850_to_1900
# Computing the rolling # Computing the rolling
if rolling is not None: if rolling is not None:
......
...@@ -3,21 +3,21 @@ from matplotlib.lines import Line2D ...@@ -3,21 +3,21 @@ from matplotlib.lines import Line2D
from extreme_data.meteo_france_data.adamont_data.adamont_gcm_rcm_couples import gcm_to_color from extreme_data.meteo_france_data.adamont_data.adamont_gcm_rcm_couples import gcm_to_color
from extreme_data.meteo_france_data.adamont_data.adamont_scenario import get_linestyle_from_scenario, \ from extreme_data.meteo_france_data.adamont_data.adamont_scenario import get_linestyle_from_scenario, \
adamont_scenarios_real, AdamontScenario, scenario_to_str, get_gcm_list adamont_scenarios_real, AdamontScenario, scenario_to_str, get_gcm_list, rcp_scenarios
from extreme_data.meteo_france_data.adamont_data.cmip5.climate_explorer_cimp5 import year_to_global_mean_temp, \ from extreme_data.meteo_france_data.adamont_data.cmip5.climate_explorer_cimp5 import year_to_global_mean_temp, \
years_and_global_mean_temps years_and_global_mean_temps
def main_plot_temperature(): def main_plot_temperature(anomaly=False):
rolling = 30 rolling = 30
ax = plt.gca() ax = plt.gca()
for gcm in get_gcm_list(adamont_version=2)[:]: for gcm in get_gcm_list(adamont_version=2)[:]:
# Plot the historical part in solid line (this part is the same between the different scenarios) # Plot the historical part in solid line (this part is the same between the different scenarios)
linestyle = get_linestyle_from_scenario(AdamontScenario.histo) linestyle = get_linestyle_from_scenario(AdamontScenario.histo)
plot_temperature_for_rcp_gcm(ax, gcm, AdamontScenario.rcp45, year_min=1951, year_max=2005, linestyle=linestyle, plot_temperature_for_rcp_gcm(ax, gcm, AdamontScenario.rcp45, year_min=1951, year_max=2005, linestyle=linestyle,
label=gcm, rolling=rolling) label=gcm, rolling=rolling, anomaly=anomaly)
for scenario in adamont_scenarios_real[1:]: for scenario in rcp_scenarios:
plot_temperature_for_rcp_gcm(ax, gcm, scenario, year_min=2005, year_max=2100, rolling=rolling) plot_temperature_for_rcp_gcm(ax, gcm, scenario, year_min=2005, year_max=2100, rolling=rolling, anomaly=anomaly)
ax2 = ax.twinx() ax2 = ax.twinx()
legend_elements = [ legend_elements = [
...@@ -31,13 +31,14 @@ def main_plot_temperature(): ...@@ -31,13 +31,14 @@ def main_plot_temperature():
ax.legend(loc='upper left') ax.legend(loc='upper left')
ax.set_xlabel('Years') ax.set_xlabel('Years')
add_str = ' averaged on the last {} years'.format(rolling) if rolling is not None else '' add_str = ' averaged on the last {} years'.format(rolling) if rolling is not None else ''
ax.set_ylabel('Global mean Temperature{} (K)\n' add_str1 = 'anomaly of temperature' if anomaly else 'mean Temperature'
'mean is taken on the year centered on the winter'.format(add_str)) ax.set_ylabel('Global {}{} (K)\n'
'mean temperature is taken on the year centered on the winter'.format(add_str1, add_str))
plt.show() plt.show()
def plot_temperature_for_rcp_gcm(ax, gcm, scenario, year_min, year_max, linestyle=None, label=None, rolling=None): def plot_temperature_for_rcp_gcm(ax, gcm, scenario, year_min, year_max, linestyle=None, label=None, rolling=None, anomaly=False):
years, global_mean_temp = years_and_global_mean_temps(gcm, scenario, year_min=year_min, year_max=year_max, rolling=rolling) years, global_mean_temp = years_and_global_mean_temps(gcm, scenario, year_min=year_min, year_max=year_max, rolling=rolling, anomaly=anomaly)
color = gcm_to_color[gcm] color = gcm_to_color[gcm]
if linestyle is None: if linestyle is None:
linestyle = get_linestyle_from_scenario(scenario) linestyle = get_linestyle_from_scenario(scenario)
...@@ -45,4 +46,4 @@ def plot_temperature_for_rcp_gcm(ax, gcm, scenario, year_min, year_max, linestyl ...@@ -45,4 +46,4 @@ def plot_temperature_for_rcp_gcm(ax, gcm, scenario, year_min, year_max, linestyl
if __name__ == '__main__': if __name__ == '__main__':
main_plot_temperature() main_plot_temperature(anomaly=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