#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Fri Dec 5 03:47:58 PM 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 ifile = '/projects/GEOCLIM/wenchang/MODEL_OUT/AM2.5/tiger3/CTL1990_tiger3_intelmpi_24_1080PE/POSTP/03000101.atmos_daily.nc' ds = xr.open_dataset(ifile) da_h500 = ds.h500.isel(time=0).load() ifile = '/projects/GEOCLIM/wenchang/MODEL_OUT/AM2.5/tiger3/CTL1990_tiger3_intelmpi_24_1080PE/POSTP/03000101.atmos_month.nc' da_zsurf = xr.open_dataset(ifile).zsurf.load() #estimate R = 287 g = 9.8 T = ( ds.t_ref.isel(time=0).load() + ds.t500.isel(time=0).load())/2 ps = ds.ps.isel(time=0).load() da_h500e = (R*T/g)*np.log(ps/50000) + da_zsurf # h = (RT)/g * log(ps/p) + h0 da_h500e = da_h500e.assign_attrs(long_name='estimated 500-mb hght', units='m') if __name__ == '__main__': from wyconfig import * #my plot settings from geoplots import mapplot fig,axes = plt.subplots(2, 1, figsize=(6,6)) levels = range(0, 6100, 300) ax = axes[0] da_h500.plot(ax=ax, levels=levels) ax.set_title('h500 from modelout', loc='right') ax = axes[1] da_h500e.plot(ax=ax, levels=levels) ax.set_title('h500 estimated', loc='right') for ax in axes: plt.sca(ax) mapplot() ax.set_xlabel('') ax.set_ylabel('') #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()