#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Thu Oct 30 02:47:03 PM EDT 2025 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 = 'PI_vmax_AM2p5C360_amip_ens06_1980-2019_plev.nc' da = xr.open_dataarray(ifile).load() da_plev = da ifile = 'PI_vmax_AM2p5C360_amip_ens06_1980-2019_pfull.nc' da = xr.open_dataarray(ifile).load() da_pfull = da if __name__ == '__main__': from wyconfig import * #my plot settings from xtc import wherebasin import geoxarray levels = range(0, 101, 10) #plev da_plev.groupby('time.month').mean('time').plot(col='month', col_wrap=4, levels=levels) #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__plev.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) #pfull da_pfull.groupby('time.month').mean('time').plot(col='month', col_wrap=4, levels=levels) #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__pfull.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) #pfull - plev (da_pfull - da_plev).groupby('time.month').mean('time').plot(col='month', col_wrap=4, levels=range(-10,11)) #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__pfull-plev.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) #time series #MDR fig,ax = plt.subplots(figsize=(8,3)) lons = slice(280,340) lats = slice(10,25) basin = 'NA' da_plev.sel(lon=lons, lat=lats).pipe(wherebasin, basin).geo.fldmean().plot(label='plev: pressure levels') da_pfull.sel(lon=lons, lat=lats).pipe(wherebasin, basin).geo.fldmean().plot(label='pfull: model levels', ls='--') ax.legend(ncol=2) ax.set_title('PI over MDR region from AM2.5C360') #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__lines.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()