#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Wed Jun 19 10:49:22 EDT 2024 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 model = 'CM2.1' daname = 'tau_y' years = range(1980,2016+1) #ifile_template = '/home/wenchang/scratch/FLOR/work/nudgeAllTrop_e2_newdiag_tigercpu_intelmpi_18_576PE/POSTP/yyyy0101.ocean.nc' #FLOR experiment #ifile_template = '/tiger/scratch/gpfs/wenchang/CM2.1p1/work/nudgeAllTrop_e1_tigercpu_intelmpi_18_80PE/POSTP/yyyy0101.ocean_month.nc' ifile_template = '/tiger/scratch/gpfs/wenchang/CM2.1p1/work/nudgeAllTrop_FAtauTrop_e1_tigercpu_intelmpi_18_80PE/POSTP/yyyy0101.ocean_month.nc' ofile = f'{model}.ocean.{daname}.mclim.{years[0]:04d}-{years[-1]:04d}.e1.nc' if '_e2_' in ifile_template: ofile = ofile.replace('.e1.nc', '.e2.nc') if os.path.exists(ofile): print('[exists]:', ofile) sys.exit() ifiles = [ifile_template.replace('yyyy', f'{year:04d}') for year in years] print('openning...') print(ifiles[0]) print(' to') print(ifiles[-1]) print(len(ifiles), 'files') ds = xr.open_mfdataset(ifiles)[[daname]] ds = ds.groupby('time.month').mean('time', keep_attrs=True) #mclim print('saving...') 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()