#!/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_atmos_daily_selnearest.275.662_29.9253.MulletPond.nc') ifile_Rx1day = ifile.replace('.nc', '.Rx1day.nc').replace('_atmos_daily', '') ofile = ifile_Rx1day.replace('.nc', '.greaterRainfallDays.nc') Rx1day_threshold = xr.open_dataarray(ifile_Rx1day).sel(year=slice(1900, 1999)).quantile(0.85).item() #print(threshold); sys.exit() func = lambda x: (x > Rx1day_threshold).groupby('time.year').sum('time') 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) if da.ens.size == 1: da = da.squeeze('ens', drop=True) da.to_dataset(name='greaterRaifallDays').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()