"""LMR v2.1 vs LMR Seasonal vs Berkeley Earth, annual anomalies vs 1961-1990. Top: the whole LMR Seasonal period (800-2024), with a long running mean. Bottom: zoom from 1700, with a shorter one. Thin lines: annual values; thick lines: centered running mean, full windows only. Reads ``series/tas_annual_anom_1961-1990.csv`` (run regional.py first). Usage: python plot_lmr_be.py [long_window] [short_window] (defaults: 31 11) """ import os import sys import matplotlib.pyplot as plt import pandas as pd HERE = os.path.dirname(os.path.abspath(__file__)) LABELS = {'lmr_v2.1': 'LMR v2.1', 'lmr_seas': 'LMR Seasonal', 'berkeley-earth': 'Berkeley Earth'} COLORS = {'lmr_v2.1': '#2a78d6', 'lmr_seas': '#4a3aa7', 'berkeley-earth': '#eb6834'} long_window = int(sys.argv[1]) if len(sys.argv) > 1 else 31 short_window = int(sys.argv[2]) if len(sys.argv) > 2 else 11 df = pd.read_csv(os.path.join(HERE, 'series', 'tas_annual_anom_1961-1990.csv'), index_col=0)[list(LABELS)] fig, axs = plt.subplots(2, 1, figsize=(11, 9)) for ax, start, window in [(axs[0], 800, long_window), (axs[1], 1700, short_window)]: ax.axhline(0, color='#52514e', lw=0.8) ax.axvspan(1961, 1990, color='#d0cfc8', alpha=0.35, lw=0) ax.axvline(1850, color='k', lw=1) for name in LABELS: s = df[name].dropna() s = s.reindex(range(s.index[0], s.index[-1] + 1)) # single missing years (BE 1752) are interpolated for the running # mean only, and it is computed before cutting at the start year sm = s.interpolate(limit=1, limit_area='inside').rolling( window, center=True, min_periods=window).mean().loc[start:] s = s.loc[start:] ax.plot(s.index, s, color=COLORS[name], lw=0.5, alpha=0.35) ax.plot(sm.index, sm, color=COLORS[name], lw=2, label=f'{LABELS[name]} ({s.dropna().index[0]}–' f'{s.dropna().index[-1]})') ax.set_xlim(start, df.index[-1] + 2) ax.set_ylabel('Anomaly vs 1961–1990 (K)') ax.set_title(f'From {start}. Thin: yearly, thick: {window}-yr running ' 'mean', loc='left', fontsize=10) ax.grid(axis='y', color='#e6e5e0', lw=0.6) for sp in ['top', 'right']: ax.spines[sp].set_visible(False) axs[0].legend(frameon=False, loc='upper left', fontsize=9) fig.suptitle('Annual temperature, glacier-area weighted over the Alps ' '(RGI6.2 11-01)', x=0.01, ha='left', fontsize=11) fig.tight_layout() f = os.path.join(HERE, 'figs', 'lmr_be_annual_anom.png') fig.savefig(f, dpi=150) print(f)