#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Fri Nov 17 17:15:29 EST 2023 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 from misc.landmask import whereland import geoxarray # if __name__ == '__main__': tt.check('end import') # #start from here ifile = 'data_AM2.5C360_amipHadISSTrcp45_tigercpu_intelmpi_18_1080PE_3ens_1871-2100_atmos_daily.region.199_206_18_23.hdwi.nc' da = xr.open_dataarray(ifile) ofile = ifile.replace('data', 'index') if os.path.exists(ofile): print('[exists]:', ofile); sys.exit() da = da.pipe(whereland).sel(lon=slice(203.2, 204), lat=slice(20.3,21)).geo.fldmean() da.to_dataset(name='hdwi').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()