#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Thu Apr 16 08:46:47 AM EDT 2026 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 = get_kws_from_argv('ifile', 'precip_HIRAM_amipLMR2019SST0850ic_tigercpu_intelmpi_18_540PE_ens01_0850-1999_selnearest.275.662_29.9253.MulletPond.Rx1day.nc') ofile = ifile.replace('.nc', '.greaterThan85pct20c.nc') func = lambda x: (x > x.sel(year=slice(1900,1999)).quantile(0.85)).astype(int).assign_attrs(units='bool', long_name='Greater than 20c 85 percentile') if os.path.exists(ofile) and 'od' not in sys.argv: da = xr.open_dataarray(ofile) print('[loaded]:', ofile) else: # da = xr.open_dataarray(ifile).pipe(func) da.to_dataset(name='greater').to_netcdf(ofile) print('[saved]:', ofile) if __name__ == '__main__': from wyconfig import * #my plot settings da.plot() #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()