#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Fri Dec 17 14:49:59 EST 2021 if __name__ == '__main__': import sys from misc.timer import Timer s = ' ' tt = Timer(f'start {s.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 from wyconfig import * #my plot settings # if __name__ == '__main__': tt.check('end import') # #start from here ifiles = [f for f in os.listdir() if f.endswith('.nc')] ifiles.sort() N = len(ifiles) for ii,ifile in enumerate(ifiles,start=1): #ifile = 'ts_hist-GHG_NH_ASO_ens110_1982-2017.nc' print(f'{ii:2d} of {N:2d}: {ifile}') figname = ifile.replace('.nc', '.ensmean.png') if os.path.exists(figname): print('[exists]:', figname) continue da = xr.open_dataarray(ifile) fig,ax=plt.subplots() da.groupby(da.model).mean('model_member').assign_attrs(units=da.attrs['units'], long_name=da.attrs['long_name']).plot(hue='model') fig.savefig(figname) print('[saved]:', figname) if __name__ == '__main__': #from wyconfig import * #my plot settings #savefig if len(sys.argv)>1 and 'savefig' in sys.argv[1:]: figname = __file__.replace('.py', f'.png') wysavefig(figname) tt.check(f'**Done**') plt.show()