#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Wed Dec 14 09:50:06 EST 2022 if __name__ == '__main__': import sys from misc.timer import Timer tt = Timer('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 import geoxarray # if __name__ == '__main__': tt.check('end import') # #start from here ifile = 't_ref_max_FLOR_HistRCP45_tigercpu_intelmpi_18_576PE_10ens_1860-2100_Argentina_masked.nc' ofile = ifile.replace('masked.nc', 'index.nc') if os.path.exists(ofile): print('[exists]:', ofile) sys.exit() #make index print('loading...') da = xr.open_dataarray(ifile).load() daname = da.name print('making index...') #the year is defined over Jul-Jun da = da.geo.fldmean() \ .rolling(time=7, center=True).mean() \ .resample(time='AS-JUL').max().sel(time=slice('1860', '2100')) \ .groupby('time.year').max('time') \ .pipe(lambda x: x-273.15).assign_attrs(units='degC') #save print('saving...') da.to_dataset(name=daname).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: pass else: plt.show()