#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Fri Sep 8 15:32:34 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 ifiles = """ precip_AM2.1_amipHadISSTchancorr_ens_tigercpu_intelmpi_18_30PE_5ens_1871-2020_atmos_daily.interp.256.68_34.39.nc precip_AM2.5_amipHadISSTlongChancorr_tigercpu_intelmpi_18_540PE_3ens_1871-2021_atmos_daily.interp.256.68_34.39.nc precip_HIRAM_amipHadISSTlongChancorr_tigercpu_intelmpi_18_540PE_extend2019-2021_5ens_1871-2021_atmos_daily.interp.256.68_34.39.nc precip_AM2.5C360_amipHadISSTlong_chancorr_tigercpu_intelmpi_18_1080PE_10ens_1871-2019_atmos_daily.interp.256.68_34.39.nc """.split() dx = {'AM2.1': '200km', 'AM2.5': '50km', 'HIRAM': '50km', 'AM2.5C360': '25km'} das = [] models = [] for ifile in ifiles: print(ifile) da = xr.open_dataarray(ifile) model = ifile.split('_')[1] das.append(da) models.append(model) if __name__ == '__main__': from wyconfig import * #my plot settings figsize = 8,3 fig,ax = plt.subplots(figsize=figsize) for da,model in zip(das, models): label = f'{model}, {da.ens.size}ens, {dx[model]}' daa = da.groupby('time.year').mean('time').mean('ens') #annual and ens mean daa.plot(ax=ax, label=label) ax = plt.gca() ax.set_ylabel('mm/day') ax.set_title(f'annual and ens mean precip, lon={360-daa.lon.item()}W, lat={daa.lat.item()}N') ax.legend(ncol=2) ax.set_ylim(None, 2) #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()