#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Fri Jun 21 13:11:28 EDT 2024 if __name__ == '__main__': import sys,os try: from misc.timer import Timer tt = Timer(f'[{os.getcwd()}] start ' + ' '.join(sys.argv)) except: pass 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__': try: tt.check('end import') except: pass # #start from here ifile = 'slp_AM2.5_CTL1990s_tigercpu_intelmpi_18_540PE_0101-0200_atmos_month.nc' da = xr.open_dataarray(ifile) da_ctl = da #nino ifile = 'slp_AM2.5_CTL1990s_plusNino_mclim_tigercpu_intelmpi_18_540PE_0101-0150_atmos_month.nc' da = xr.open_dataarray(ifile) da_nino = da #nina ifile = 'slp_AM2.5_CTL1990s_plusNina_mclim_tigercpu_intelmpi_18_540PE_0101-0150_atmos_month.nc' da = xr.open_dataarray(ifile) da_nina = da #plus2K ifile = 'slp_AM2.5_CTL1990s_plus2K_tigercpu_intelmpi_18_540PE_0101-0150_atmos_month.nc' da = xr.open_dataarray(ifile) da_plus2K = da if __name__ == '__main__': from wyconfig import * #my plot settings from geoplots import mapplot fig,axes = plt.subplots(2, 2, figsize=(11,6)) ax = axes[0, 0] da = da_nino.mean('time') - da_ctl.mean('time') da = da.assign_attrs(units='hPa') da.plot.contourf(levels=21, ax=ax) ax.set_title('Nino experiment') ax = axes[0, 1] da = da_nina.mean('time') - da_ctl.mean('time') da = da.assign_attrs(units='hPa') da.plot.contourf(levels=21, ax=ax) ax.set_title('Nina experiment') ax = axes[1, 0] da = da_plus2K.mean('time') - da_ctl.mean('time') da = (da/2).assign_attrs(units='hPa per K') da.plot.contourf(levels=21, ax=ax) ax.set_title('$+$2K experiment') axes[1,1].set_axis_off() for ax in axes.flat: plt.sca(ax) mapplot(ax=ax) #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) try: tt.check(f'**Done**') except: pass print() if 'notshowfig' in sys.argv or 'n' in sys.argv: pass else: if 'plt' in globals(): plt.show()