#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Tue Dec 9 11:00:45 AM EST 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 year = 113 ifile = f'/scratch/gpfs/GEOCLIM/wenchang/tiger3/AM2.5/work/CTL1990_tiger3_intel24ifort_openmpi_1080PE_stpdiagRedo/POSTP/{year:04d}0101.atmos_daily.nc' if os.path.basename(os.getcwd()) == '4xdaily': ifile = ifile.replace('atmos_daily', 'atmos_4xdaily_stp') elif os.path.basename(os.getcwd()) == 'monthly': ifile = ifile.replace('atmos_daily', 'atmos_month_stp') ds = xr.open_dataset(ifile) cape = ds.cape.load() fcape = cape/1500 # ps = ds.ps.load() plcl = ds.pcldb.load() #h850 = ds.h850.load() # if 'srh01' in ds: #if srh01 in ds: srh01 covers 0-1km, srh covers 0-3km; otherwise, srh covers 0-1km srh = ds.srh01.load() else: srh = ds.srh.load() # u500 = ds.u500.load() v500 = ds.v500.load() u200 = ds.u200.load() v200 = ds.u200.load() h500 = ds.h500.load() h200 = ds.h200.load() u0 = ds.u_ref.load() v0 = ds.v_ref.load() # ifile = f'/projects/GEOCLIM/wenchang/MODEL_OUT/AM2.5/tiger3/CTL1990_tiger3_intelmpi_24_1080PE/POSTP/{year:04d}0101.atmos_month.nc' h0 = xr.open_dataset(ifile)['zsurf'].load() #lcl #p850 = 850*100 p500 = 500*100 #sblcl = (h850-h0) * np.log(ps/plcl) / np.log(ps/p850) sblcl = (h500-h0) * np.log(ps/plcl) / np.log(ps/p500) sblcl = sblcl.clip(0) flcl = (2000 - sblcl)/1500 flcl = flcl.clip(0) #srh srh = srh.where(srh.grid_yt>=0, other=-srh) fsrh = srh.clip(0)/150 #shear u = u500 - u0 + (u200 - u500) * (h0 + 6000 - h500) / (h200 - h500) v = v500 - v0 + (v200 - v500) * (h0 + 6000 - h500) / (h200 - h500) bwd = np.sqrt(u**2 + v**2) fbwd = bwd/20 #stp stp = fcape * flcl * fsrh * fbwd # #cin = ds.cin.load() #stp = stp.where(cin<50) if __name__ == '__main__': from wyconfig import * #my plot settings from geoplots import mapplot c = 'lightgray' # '0.9' fig,ax = plt.subplots() cape.max('time', keep_attrs=True).assign_attrs(long_name=f'year{year:04d} annual max cape').plot(robust=True) mapplot(coastlines_color=c) #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__cape.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) fig,ax = plt.subplots() sblcl.median('time').assign_attrs(units='m', long_name=f'year{year:04d} annual median LCL').plot(robust=True) mapplot(coastlines_color=c) #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__lcl.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) fig,ax = plt.subplots() srh.max('time').assign_attrs(units='m/s^2', long_name=f'year{year:04d} annual max storm relative helicity').plot(robust=True) mapplot(coastlines_color=c) #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__srh.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) fig,ax = plt.subplots() bwd.max('time').assign_attrs(units='m/s', long_name=f'year{year:04d} annual max BWD06').plot(robust=True) mapplot(coastlines_color=c) #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__bwd.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) fig,ax = plt.subplots() stp.max('time').assign_attrs(long_name=f'year{year:04d} annual max STP').plot(robust=True) mapplot(coastlines_color=c) #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__stp.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) fig,ax = plt.subplots() stp.mean('time').assign_attrs(long_name=f'year{year:04d} annual mean STP').plot(robust=True) mapplot(coastlines_color=c) #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'__stpAnnualMean.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()