#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Wed Nov 30 22:49:56 EST 2022 if __name__ == '__main__': import sys from misc.timer import Timer tt = Timer('start ' + ' '.join(sys.argv)) import sys, os.path, os, glob, datetime import xarray as xr, numpy as np, pandas as pd, matplotlib.pyplot as plt #more imports # if __name__ == '__main__': tt.check('end import') # #start from here dss = [] cases = [] #AM2.5C360 ifile = '/tigress/wenchang/analysis/TC/AM2.5C360/amipHadISSTrcp45_tigercpu_intelmpi_18_1080PE/netcdf/tc_counts.TS17.ens16.1871-2100.yearly.nc' ds = xr.open_dataset(ifile) dss.append(ds.mean('en')) cases.append('AM2.5C360') #HIRAM ifile = '/tigress/wenchang/analysis/TC/HIRAM/amipHadISSTrcp45_tigercpu_intelmpi_18_540PE/netcdf/tc_counts.TS17.ens01.1871-2100.yearly.nc' ds = xr.open_dataset(ifile) dss.append(ds.mean('en')) cases.append('HiRAM') #FLOR ifile = '/tigress/wenchang/analysis/TC/HistRCP45_tigercpu_intelmpi_18_576PE/netcdf/tc_counts.TS17.10nens.1860-2100.yearly.nc' ds = xr.open_dataset(ifile) dss.append(ds.sel(en=[1,]).mean('en')) cases.append('FLOR') ds = xr.concat(dss, dim=pd.Index(cases, name='case')) if __name__ == '__main__': from wyconfig import * #my plot settings basin = 'global' #basin = 'NA' #years_ref = slice(1986,2005) years_ref = slice(1980,2010) years_ref = slice(2020,2050) ds_ = ds/ds.sel(year=years_ref).mean('year') lowpass = lambda x: x.rolling(year=31, center=True).mean() ds_[basin].pipe(lowpass).plot(hue='case') ax = plt.gca() ax.axvline((years_ref.start + years_ref.stop)/2, color='gray', lw=1) ax.set_ylabel(f'{years_ref.start}-{years_ref.stop} {basin} TC frequency clim') #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'_{basin}_base{years_ref.start}-{years_ref.stop}.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) tt.check(f'**Done**') print() if 'notshowfig' in sys.argv: pass else: plt.show()