#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Thu Apr 15 09:56:26 EDT 2021 if __name__ == '__main__': from misc.timer import Timer tt = Timer(f'start {__file__}') import sys, os.path, os, glob, datetime import xarray as xr, numpy as np, pandas as pd, matplotlib.pyplot as plt #more imports import xfilter # if __name__ == '__main__': tt.check('end import') # #start from here thisdir = os.path.dirname(__file__) ibasename = 't_surf.glbmean.volcs.nens30.nc' ifile = os.path.join(thisdir, 'data', ibasename) da = xr.open_dataarray(ifile).load() #time_new = xr.cftime_range('1001-01-01', periods=12*15, freq='MS')#, calendar='noleap') #da = da.assign_coords(time=time_new) if __name__ == '__main__': from wyconfig import * #my plot settings from cycler import cycler colors = ['k'] + [x['color'] for x in plt.rcParams['axes.prop_cycle']] cycle = cycler(color=colors) fig, ax = plt.subplots() ax.set_prop_cycle(cycle) n_window = 12 # 12 months in the filter window da.mean('en') \ .pipe(lambda x: x.groupby('time.month') - x.sel(volc='CTL').groupby('time.month').mean('time') ) \ .filter.lowpass(1/n_window, dim='time', padtype='even') \ .plot(hue='volc') ax.set_ylabel('global mean t_surf anomaly [K]') #ax.spines['right'].set_visible(False) #ax.spines['top'].set_visible(False) times = da.time[0::12] ax.set_xlim(da.time[0], da.time[-1]) ax.set_xticks(times) ax.set_xticklabels([f'{yr-2001:02d}' for yr in times.dt.year.values])#da.time.dt.year.values[0::24]]) ax.set_xlabel('year') ax.set_title('') #savefig if len(sys.argv) > 1 and sys.argv[1] == 'savefig': figname = __file__.replace('.py', f'.png') wysavefig(figname) tt.check(f'**Done**') plt.show()