#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Sun Apr 7 23:06:56 EDT 2024 # calculate relative humidity (RH) from vp and TS: https://www.pnas.org/doi/10.1073/pnas.2302480120 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 ofile = 'merra2.vpd.1980-2020.westUS.nc' if os.path.exists(ofile): print('[exists]:', ofile) sys.exit() #vp ifile = 'merra2.VP.1980-2020.westUS.nc' vp = xr.open_dataarray(ifile) #units hPa #t2m and vps ifile = 'merra2.T2M.1980-2020.westUS.nc' t2m = xr.open_dataarray(ifile) #units K #vpd t2m_c = t2m - 273.15 # K -> C vps = 6.112*np.exp(17.67*t2m_c/(t2m_c + 243.5)) #units hPa vpd = (vps - vp).clip(0) #units hPa vpd = vpd.assign_attrs(units='hPa', long_name='vapor pressure deficit at 2m') #save vpd.to_dataset(name='vpd').to_netcdf(ofile) print('[saved]:', ofile) if __name__ == '__main__': #from wyconfig import * #my plot settings #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()