#!/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 from misc.seasons import sel_season # 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' ifile = sys.argv[1] #e.g. precip_FLOR_HistRCP45_tigercpu_intelmpi_18_576PE_10ens_1860-2100_CSA_masked.nc ofile = ifile.replace('masked.nc', 'index.nc') if os.path.exists(ofile): print('[exists]:', ofile) da = xr.open_dataarray(ofile) else: #make index print('loading...') da = xr.open_dataarray(ifile).load() daname = da.name print('making index...') #OND-mean da = da.geo.fldmean() \ .pipe(sel_season, 'OND').groupby('time.year').mean('time', keep_attrs=True) if daname in ('t_ref',): da = da.pipe(lambda x: x-273.15).assign_attrs(units='degC') #print(da); sys.exit() #save print('saving...') da.to_dataset(name=daname).to_netcdf(ofile) print('[saved]:', ofile) if __name__ == '__main__': from wyconfig import * #my plot settings da.mean('ens').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) tt.check(f'**Done**') print() if 'notshowfig' in sys.argv: pass else: plt.show()