#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Fri Sep 8 14:55:21 EDT 2023 if __name__ == '__main__': import sys,os from misc.timer import Timer tt = Timer(f'[{os.getcwd()}] 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 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 # if __name__ == '__main__': tt.check('end import') # #start from here #ifile = 'precip_AM2.5_amipHadISSTlongChancorr_tigercpu_intelmpi_18_540PE_3ens_1871-2021_atmos_daily.interp.256.68_34.39.nc' ifile = 'precip_HIRAM_amipHadISSTlongChancorr_tigercpu_intelmpi_18_540PE_extend2019-2021_5ens_1871-2021_atmos_daily.interp.256.68_34.39.nc' da = xr.open_dataarray(ifile) model = ifile.split('_')[1] if __name__ == '__main__': from wyconfig import * #my plot settings figsize = 8,3 fig,ax = plt.subplots(figsize=figsize) daa = da.groupby('time.year').mean('time') for ii in daa.ens.values: daa.sel(ens=ii).plot(alpha=0.3, color='C0', lw=1, ax=ax) daa.mean('ens').plot(color='C0', ax=ax) #ax = plt.gca() ax.set_title(f'{model} annual mean precip, {daa.ens.size}ens, lon={360-daa.lon.item()}W, lat={daa.lat.item()}N') ax.set_ylabel('mm/day') #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'.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 or 'n' in sys.argv: pass else: if 'plt' in globals(): plt.show()