#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Wed Oct 19 19:06:25 EDT 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 from misc.modelout import get_modelout_data from geoplots import mapplot import geoxarray # if __name__ == '__main__': tt.check('end import') # #start from here daname = 't_surf' model = 'CM2.1p1' years_ctl = range(101,201) years = range(101,121) exps = [('CTL', 'CTL1860_tigercpu_intelmpi_18_80PE'), ('+6% Solar', 'CTL1860_p6pctSolar_tigercpu_intelmpi_18_80PE'), ('-6% Solar', 'CTL1860_m6pctSolar_tigercpu_intelmpi_18_80PE'), ] das = dict() for label,expname in exps: if label=='CTL': das[label] = get_modelout_data(daname=daname, model=model, expname=expname, years=years_ctl) else: das[label] = get_modelout_data(daname=daname, model=model, expname=expname, years=years) def wyplot(label='+6% Solar', transform=None, **kws): title = f'{label} {model} years {years[0]:04d}-{years[-1]:04d}' if transform is not None: title += f' {transform}' daa = das[label].groupby('time.year').mean('time') - das['CTL'].mean('time') if transform is not None: if transform == 'flip': daa = -daa elif transform == 'norm': daa_ref = daa.geo.fldmean() daa = daa/daa_ref levels = np.linspace(-4,4,17) if transform=='norm' else np.linspace(-16,16,33) daa.attrs['units'] = '' if transform == 'norm' else 'K' g = daa.assign_attrs(long_name=title).plot.contourf(col='year', col_wrap=5, levels=levels, extend='both', figsize=(11,6), **kws) for ax in g.axes.flat: plt.sca(ax) mapplot(xticks=range(60,360,120), yticks=range(-60,90,30)) ax.set_xlabel('') ax.set_ylabel('') return title if __name__ == '__main__': from wyconfig import * #my plot settings title = wyplot('+6% Solar') #savefig tag = '_' + title.replace('+6%', 'p6').replace('-6%', 'm6').replace(' ', '_') if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'{tag}.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) title = wyplot('-6% Solar') #savefig tag = '_' + title.replace('+6%', 'p6').replace('-6%', 'm6').replace(' ', '_') if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'{tag}.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) title = wyplot('-6% Solar', transform='flip') #savefig tag = '_' + title.replace('+6%', 'p6').replace('-6%', 'm6').replace(' ', '_') if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'{tag}.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) #fig,ax = plt.subplots() #wyplot('+6% Solar', transform='norm') #fig,ax = plt.subplots() #wyplot('-6% Solar', transform='norm') tt.check(f'**Done**') print() if 'notshowfig' in sys.argv: pass else: plt.show()