#!/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 #cmip5 nwindow = 5 lowpass = lambda x: x.filter.lowpass(1/nwindow, dim='year', padtype='constant') ifile = '/tigress/wenchang/data/cmip5/analysis/ssttc.histrcp85.1850-2100.ens39.nc' ds = xr.open_dataset(ifile) da = ds.HU ci_cmip5 = da.pipe(lowpass).quantile([.025, .975], dim='model') ensm_cmip5 = da.pipe(lowpass).mean('model') ds_cmip5 = ds #cmip6 ifile = 'ssttc.histssp585.1850-2100.ens36.nc' ds = xr.open_dataset(ifile) da = ds.HU ci_cmip6 = da.pipe(lowpass).quantile([.025, .975], dim='model') ensm_cmip6 = da.pipe(lowpass).mean('model') ds_cmip6 = ds if __name__ == '__main__': from wyconfig import * #my plot settings fig,ax = plt.subplots() #cmip5 ci,ensm,ds = ci_cmip5, ensm_cmip5, ds_cmip5 ax.fill_between(ci.year, ci.isel(quantile=0), ci.isel(quantile=-1), alpha=0.3)#, label='0.025-0.975 quantile') ensm.plot(ax=ax, label=f'CMIP5 {ds.model.size} models') #cmip6 ci,ensm,ds = ci_cmip6, ensm_cmip6, ds_cmip6 ax.fill_between(ci.year, ci.isel(quantile=0), ci.isel(quantile=-1), alpha=0.3)#, label='0.025-0.975 quantile') ensm.plot(ax=ax, label=f'CMIP6 {ds.model.size} models') ax.set_title(f'HU # from CMIP5 (historical+RCP85) and CMIP6 (historical+ssp585)') ax.legend(ncol=2,frameon=False) 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()