#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Fri Jul 5 14:29:29 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 ifiles = """ tau_x_correction.nc tau_y_correction.nc """.split() da_x = xr.open_dataarray(ifiles[0]) da_y = xr.open_dataarray(ifiles[1]) units = da_x.attrs['units'] ds = xr.Dataset(dict(tau_x=da_x, tau_y=da_y)) #heat FA ifile = 'temp_sfc_correction.nc' da = xr.open_dataarray(ifile) if __name__ == '__main__': from wyconfig import * #my plot settings da.mean('time', keep_attrs=True).plot.contourf(robust=True, levels=21) quiver = ds.mean('time').isel(xu_ocean=slice(None, None, 10), yu_ocean=slice(None, None, 10)) \ .plot.quiver(x='xu_ocean', y='yu_ocean', u='tau_x', v='tau_y', add_guide=False, scale=0.5) ax = plt.gca() U = 0.05 ax.quiverkey(quiver, 0.9, 1.03, U, f'{U} {units}', labelpos='E') ax.set_title('temp_sfc_correction and tau_x_correction') #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'.png') figname = figname.replace('.png', f'__{ifile[:-3]}.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()