#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Sat May 7 13:16:07 EDT 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 # if __name__ == '__main__': tt.check('end import') # #start from here ifiles = """ t_surf_AM2.5C360_amipHadISSTlong_chancorr_tigercpu_intelmpi_18_1080PE_10ens_1871-2019_glbmean.nc t_surf_AM2.5C360_amipHadISSTlong_chancorr_tigercpu_intelmpi_18_1080PE_extend2020_10ens_2020-2020_glbmean.nc t_surf_AM2.5C360_amipHadISSTlong_chancorr_tigercpu_intelmpi_18_1080PE_extend2021_10ens_2021-2021_glbmean.nc """.split() print(ifiles) ofile = ifiles[0].replace('.nc', '_yearly.nc').replace('1871-2019', '1871-2021') if os.path.exists(ofile): print('[loaded]:', ofile) else: xr.open_mfdataset(ifiles).groupby('time.year').mean('time').to_netcdf(ofile) print('[saved]:', ofile) if __name__ == '__main__': #from wyconfig import * #my plot settings #savefig if len(sys.argv)>1 and 'savefig' in sys.argv[1:]: figname = __file__.replace('.py', f'.png') if 'overwritefig' in sys.argv[1:]: wysavefig(figname, overwritefig=True) else: wysavefig(figname) tt.check(f'**Done**') print() #plt.show()