"""Slide figure: do the models agree with each other more than with GlaMBIE-1 on annual variability? Per region, 2000-2023 calendar years: - mean pairwise correlation between the four independent models (OGGM fixed, Fujita, Rounce, Huss) - mean correlation of each model with the GlaMBIE-1 consensus Usage: python plot_correlation_summary.py Output: plots/correlation_models_vs_glambie1.png and .csv """ import itertools import os import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt import numpy as np import pandas as pd from plot_annual_mb import annual, glambie1 from plot_overview import OUT, REGIONS, INK, MUTED, style_axis MODELS = ['oggm_fix', 'fujita', 'rounce', 'huss'] C_MM, C_MG = '#2a78d6', '#eb6834' def main(): rows = [] for rid in REGIONS: a = pd.DataFrame({k: annual(rid, k)['mwe'] for k in MODELS}).loc[2000:2023] g = glambie1(rid)['mwe'].loc[2000:2023] rows.append(dict(rid=rid, region=REGIONS[rid][1], model_model=np.mean([a[x].corr(a[y]) for x, y in itertools.combinations(MODELS, 2)]), model_g1=np.mean([a[x].corr(g) for x in MODELS]))) t = pd.DataFrame(rows).sort_values('model_g1', ascending=False).reset_index(drop=True) t.to_csv(os.path.join(OUT, 'correlation_models_vs_glambie1.csv'), index=False) fig, ax = plt.subplots(figsize=(12, 7.2)) y = np.arange(len(t)) ax.hlines(y, t.model_g1, t.model_model, color='#d6d5cf', lw=3, zorder=1) ax.plot(t.model_model, y, 'o', ms=10, color=C_MM, zorder=3, mec='white', mew=1.5) ax.plot(t.model_g1, y, 'o', ms=10, color=C_MG, zorder=3, mec='white', mew=1.5) style_axis(ax) ax.lines[-1].remove() # zero line not wanted on a categorical axis ax.set_yticks(y) ax.set_yticklabels([f'{r} {n}' for r, n in zip(t.rid, t.region)], fontsize=11.5, color=INK) ax.invert_yaxis() ax.set_xlim(0.2, 1.0) ax.tick_params(axis='x', labelsize=11) ax.set_xlabel('Correlation of annual mass balance, 2000-2023', fontsize=11.5, color=MUTED) ax.plot([], [], 'o', ms=10, color=C_MM, label='models with each other') ax.plot([], [], 'o', ms=10, color=C_MG, label='models with GlaMBIE-1') ax.legend(loc='upper left', frameon=False, fontsize=11.5, handletextpad=0.3) fig.suptitle('Models agree with each other everywhere, but not with GlaMBIE-1 everywhere', x=0.012, y=0.985, ha='left', fontsize=15, color=INK, fontweight='bold') fig.text(0.012, 0.925, 'Mean pairwise correlation of four models (OGGM, Fujita, Rounce, Huss), and mean correlation of ' 'each model with the GlaMBIE-1 consensus.\nCalendar years. All models share ERA5 forcing.', fontsize=10.5, color=MUTED, ha='left', va='top', linespacing=1.4) fig.tight_layout(rect=(0, 0, 1, 0.86)) fig.savefig(os.path.join(OUT, 'correlation_models_vs_glambie1.png'), dpi=150, facecolor='white') plt.close(fig) print(t.round(2).to_string(index=False)) if __name__ == '__main__': main()