#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Fri Sep 27 13:41:27 EDT 2024 if __name__ == '__main__': import sys,os try: from misc.timer import Timer tt = Timer(f'[{os.getcwd()}] start ' + ' '.join(sys.argv)) except: pass import sys, os.path, os, glob, datetime import xarray as xr, numpy as np, pandas as pd, matplotlib.pyplot as plt #more imports wython = '/tigress/wenchang/wython' if wython not in sys.path: sys.path.append(wython); print('added to python path:', wython) #from misc import get_kws_from_argv import xlinregress from wyplot_index_NS_EW import wyplot from misc.landmask import whereocean # if __name__ == '__main__': try: tt.check('end import') except: pass # #start from here #nonFA ifile = 't_surf_FLOR_HistRCP45_tigercpu_intelmpi_18_576PE_10ens_1970-2020_annualmean.nc' da = xr.open_dataarray(ifile).load() da = da.mean('time') da0 = da #FA ifiles = [f't_surf_FLOR_HistRCP45_FA_tigercpu_intelmpi_18_576PE_e{ii}_1970-2020_annualmean.nc' for ii in range(1,3+1)] das = [xr.open_dataset(ifile)['t_surf'].load() for ifile in ifiles] da = xr.concat(das, dim=pd.Index(range(1,3+1), name='ens')) da = da.mean('time') daFA = da if __name__ == '__main__': from wyconfig import * #my plot settings from geoplots import mapplot figsize = 8,3 levels = np.arange(12, 30+1, 1) sst0 = 27 #HadISST fig,ax = plt.subplots(figsize=figsize) func = lambda x: (x.pipe(whereocean).sel(lat=slice(-40,40)) -273.15).assign_attrs(units='degC') ifile = '/projects2/w/wenchang/modelInput/HadISST/HadISST_sst.187001-202403.wy.nc' da = xr.open_dataarray(ifile).sel(time=slice('1970', '2020')).mean('time') da = da.pipe(func) da.plot.contourf(levels=levels, robust=True, extend='both', ax=ax) cs = da.plot.contour(levels=[sst0,], colors='k', linewidths=0.5) ax.clabel(cs) wyplot(ax=ax) mapplot(fill_continents=True) ax.set_title(f'HadISST sst annual mean clim: 1970-2020') #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__HadISST.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) #nonFA fig,ax = plt.subplots(figsize=figsize) func = lambda x: (x.pipe(whereocean).sel(lat=slice(-40,40)) -273.15).assign_attrs(units='degC') da = da0.mean('ens').pipe(func) da.plot.contourf(levels=levels, robust=True, extend='both', ax=ax) cs = da.plot.contour(levels=[sst0,], colors='k', linewidths=0.5) ax.clabel(cs) wyplot(ax=ax) mapplot(fill_continents=True) ax.set_title(f'FLOR Hist t_surf annual mean clim: 1970-2020, {da0.ens.size}ens') #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__nonFA.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) #FA fig,ax = plt.subplots(figsize=figsize) func = lambda x: (x.pipe(whereocean).sel(lat=slice(-40,40)) - 273.15).assign_attrs(units='degC') da = daFA.mean('ens').pipe(func) da.plot.contourf(levels=levels, robust=True, extend='both', ax=ax) cs = da.plot.contour(levels=[sst0,], colors='k', linewidths=0.5) ax.clabel(cs) wyplot(ax=ax) mapplot(fill_continents=True) ax.set_title(f'FLOR_FA Hist t_surf annual mean clim: 1970-2020, {daFA.ens.size}ens') #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__FA.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) #FA-nonFA levels = 21 fig,ax = plt.subplots(figsize=figsize) func = lambda x: (x.pipe(whereocean).sel(lat=slice(-40,40))).assign_attrs(units='degC') da = (daFA.mean('ens') - da0.mean('ens')).pipe(func) da.plot.contourf(levels=levels, center=0, robust=True, extend='both', ax=ax) #cs = da.plot.contour(levels=[1,], colors='k', linewidths=0.5) #ax.clabel(cs) wyplot(ax=ax) mapplot(fill_continents=True) ax.set_title(f'Hist t_surf annual mean clim (1970-2020) diff: FA $-$ nonFA') #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__FA-nonFA.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) try: tt.check(f'**Done**') except: pass print() if 'notshowfig' in sys.argv or 'n' in sys.argv: pass else: if 'plt' in globals(): plt.show()