#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Wed Jul 5 12:03:56 EDT 2023 # run this script after finishing FigS01.py and FigS02.py 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 forcings = ['co2x2', 'co2x4', 'co2xp5', 'co2xp25', 'p2p0solar', 'p6p0solar', 'm2p0solar', 'm6p0solar']#[:4] labels = ['2xCO2', '4xCO2', '0.5xCO2', '0.25xCO2', '$+2$%solar', '$+6$%solar', '$-2$%solar', '$-6$%solar']#[:4] forcingScales = [1, 2, -1, -2, 1, 3, -1, -3]#[:4] #if True: #for forcing,label,scale in zip(forcings,labels,forcingScales): def wyplot(forcing, label, scale, ax=None): if ax is None: fig, ax = plt.subplots() #forcing, label, scale = 'co2x2', '2xCO2', 1 #prediction by gmst ifile = f'fig_lines_precip__FLOR_{forcing}_glbmeanTs.nc' print(ifile) ds = xr.open_dataset(ifile) #adjustment term if 'co2' in forcing: A = ds['A_co2'] else: A = ds['A_solar'] A = A*scale da_actual = ds['pr'].groupby('time.year').mean('time')/ds['pr_ctl_clim'].mean()*100 -100 #% of precip change da_predict = ( ds['Ts'].groupby('time.year').mean('time') - ds['Ts_ctl_clim'].mean() ) * ds['eta'] + A #prediction by tropical mean SST ifile = f'fig_lines_precip__FLOR_{forcing}_tropoceanmeanTs.nc' ds = xr.open_dataset(ifile) da_actual = ds['pr'].groupby('time.year').mean('time')/ds['pr_ctl_clim'].mean()*100 -100 #% of precip change da_predict_to = ( ds['Ts'].groupby('time.year').mean('time') - ds['Ts_ctl_clim'].mean() ) * ds['eta'] + A ax.scatter( da_actual, da_predict, c='none', edgecolor='C0', alpha=0.3, label=f'{label}\n$T_s$:GMST', s=10) ax.scatter(da_actual, da_predict_to, c='none', edgecolor='C1', alpha=0.3, label=f'$T_s$:TMSST', s=10) ax.axline((0,0), slope=1, color='gray', ls='--') ax.legend(loc='upper left', borderpad=0) if __name__ == '__main__': from wyconfig import * #my plot settings figsize = 11, 5 fig, axes = plt.subplots(2, 4, figsize=figsize) for forcing,label,scale,ax in zip(forcings,labels,forcingScales,axes.flat): wyplot(forcing, label, scale, ax) for ax in axes[0,:]: ax.set_xlabel('') for ax in axes[1,:]: ax.set_xlabel('Actual precip change [%]') for ax in axes.flat: ax.set_ylabel('') for ax in axes.flat[0::4]: ax.set_ylabel('Predicted precip change [%]') #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()