#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Tue Feb 18 04:26:56 PM EST 2025 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 dsname = get_kws_from_argv('dsname', 'u850') timeslice = slice('1979', '2020') print(dsname, '...') ifiles = f'/projects/w/wenchang/data/era5/analysis_wy/plevels/{dsname}/daily/era5.{dsname}.daily.*.nc' ds = xr.open_mfdataset(ifiles).sel(time=timeslice) #r7dclim ofile = f'era5.{dsname}.daily.{timeslice.start}-{timeslice.stop}.r7dclim.nc' if os.path.exists(ofile): print('[exists]:', ofile) else: print(dsname, '...') ds = ds.rolling(time=7, center=True).mean(keep_attrs=True) #rolling mean print('daily climatology ...') ds = ds.groupby('time.dayofyear').mean('time', keep_attrs=True) #daily climatology print('save...') ds.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) 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()