#!/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 = 'precip' daname = get_kws_from_argv('daname', daname) transform = get_kws_from_argv('transform', None) #model = 'CM2.1p1' #model = 'FLOR' model = 'AM2.5' years_ctl = range(101,151) #years = range(101,121) #years = range(491,511) #years = range(591,611) #years = range(691,711) #years = range(791,811) #years = 'last' years = range(101,151) das = dict() label,expname = 'CTL', 'CTL1990s_tigercpu_intelmpi_18_540PE' das[label] = get_modelout_data(daname=daname, model=model, expname=expname, years=years_ctl) label,expname = '2xCO2', 'CTL1990s_2xCO2_tigercpu_intelmpi_18_540PE' #label,expname = '$+$2%_solar', 'CTL1990s_solar2pctplus_tigercpu_intelmpi_18_540PE' 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='2xCO2', 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) if daname == 'precip': levels = np.linspace(-1.5,1.5,21) daa.attrs['units'] = '' if transform == 'norm' else das['CTL'].attrs['units'] cmap = 'PuOr' if daname in ('ice_mask',) else None if daname in ('precip',): cmap = 'BrBG' 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()