#!/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 from misc import get_kws_from_argv # if __name__ == '__main__': tt.check('end import') # #start from here #daname = 't_surf' daname = 'ice_mask' daname = get_kws_from_argv('daname', daname) transform = get_kws_from_argv('transform', None) model = 'CM2.1p1' #model = 'FLOR' years_ctl = range(101,201) #years = range(101,121) #years = range(491,511) #years = range(591,611) #years = range(691,711) #years = range(791,811) years = 'last' if model == 'CM2.1p1': exps = [('CTL', 'CTL1860_tigercpu_intelmpi_18_80PE'), ('+6% Solar', 'CTL1860_p6pctSolar_tigercpu_intelmpi_18_80PE'), ('-6% Solar', 'CTL1860_m6pctSolar_tigercpu_intelmpi_18_80PE'), ] elif model == 'FLOR': exps = [('CTL', 'CTL1860_newdiag_tigercpu_intelmpi_18_576PE'), ('+6% Solar', 'p6p0sol_CTL1860_tigercpu_intelmpi_18_576PE'), ('-6% Solar', 'm6p0sol_CTL1860_tigercpu_intelmpi_18_576PE'), ] das = dict() for label,expname in exps[0:1]: 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) label,expname = '$-$6% Solar', 'CTL1860_m6pctSolar_tigercpu_intelmpi_18_80PE' #label,expname = '$-$6% Solar', 'm6p0sol_CTL1860_tigercpu_intelmpi_18_576PE' das[label] = get_modelout_data(daname=daname, model=model, expname=expname, years=years) years = das[label].time.dt.year.values #actual years selected def wyplot(label='$-$6% Solar', transform=None, **kws): ax = kws.pop('ax', plt.gca()) daa = das[label].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 21 # np.linspace(-16,16,33) daa.attrs['units'] = '' if transform == 'norm' else das['CTL'].attrs['units'] cmap = 'PuOr' if daname in ('ice_mask',) else None daa.plot.contourf(levels=levels, extend='both', center=0, cmap=cmap, **kws) mapplot() title = f'{label} {model} {daname} years {years[0]:04d}-{years[-1]:04d}' if transform is not None: title += f' {transform}' ax.set_title(title) return title if __name__ == '__main__': from wyconfig import * #my plot settings fig,ax = plt.subplots() title = wyplot(label, transform=transform) #savefig tag = '__' + title.replace('$+$', 'p').replace('$-$', 'm').replace('%','').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() 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) fig,ax = plt.subplots() 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()