#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Thu Oct 30 02:50:09 PM EDT 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 daname = 'vmax' years = range(1980,2019+1) #plev or pfull if 'plev' in sys.argv: ifiles = [f'/projects/GEOCLIM/wenchang/MODEL_OUT/AM2.5C360/amipHadISSTlong_chancorr_tigercpu_intelmpi_18_1080PE/en06/analysis_wy/TCIplev/{year}0101.atmos_month.PI.nc' for year in years] ofile = f'PI_{daname}_AM2p5C360_amip_ens06_{years[0]}-{years[-1]}_plev.nc' else: ifiles = [f'/projects/GEOCLIM/wenchang/MODEL_OUT/AM2.5C360/amipHadISSTlong_chancorr_tigercpu_intelmpi_18_1080PE/en06/analysis_wy/TCI/{year}0101.atmos_month.PI.nc' for year in years] ofile = f'PI_{daname}_AM2p5C360_amip_ens06_{years[0]}-{years[-1]}_pfull.nc' if os.path.exists(ofile): print('[exists]:', ofile); sys.exit() #open print('open...') ds = xr.open_mfdataset(ifiles)[[daname]].load() if 'grid_xt' in ds.dims: ds = ds.rename(grid_xt='lon', grid_yt='lat') #save print('save...') encoding = {daname: {'zlib': True, 'complevel': 1}} ds.to_netcdf(ofile, encoding=encoding, unlimited_dims='time') 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()