#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Thu May 27 14:57:22 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 ifile = 'ssttc.histssp585.1850-2100.ens36.nc' ds = xr.open_dataset(ifile) da = ds.HU nwindow = 5 lowpass = lambda x: x.filter.lowpass(1/nwindow, dim='year', padtype='constant') ci = da.pipe(lowpass).quantile([.025, .975], dim='model') ensm = da.pipe(lowpass).mean('model') if __name__ == '__main__': from wyconfig import * #my plot settings fig,ax = plt.subplots() ax.fill_between(ci.year, ci.isel(quantile=0), ci.isel(quantile=-1), alpha=0.5, label='0.025-0.975 quantile') ensm.plot(ax=ax, label=f'ensemble mean ({nwindow}-year LP)') ax.set_title(f'HU # from CMIP6 historical and ssp585: {ds.model.size} models') ax.legend() ax.set_xlim(1850,2100) ax.grid('on') #savefig if 'savefig' in sys.argv: figname = __file__.replace('.py', f'.png') wysavefig(figname) tt.check(f'**Done**') plt.show()