#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Tue Nov 5 13:29:48 EST 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 danames = ['ucomp', 'vcomp', 'temp', 'z_full', 'sphum'] model = 'HIRAM' #expname = 'CTL1990s_v201910_tigercpu_intelmpi_18_540PE' expname = 'CTL1990s_v201910_plusColdBlob_tigercpu_intelmpi_18_540PE' levels = (1000, 850, 500, 200) for daname in danames: ifiles = glob.glob(f'/tigress/wenchang/MODEL_OUT/{model}/{expname}/analysis_wy/plev/????0101.atmos_month.plev.{daname}.nc') ifiles.sort() years = [int(os.path.basename(ifile)[0:4]) for ifile in ifiles] ofile = f'{daname}_{model}_{expname}_{years[0]:04d}-{years[-1]:04d}_atmos_month_plev.nc' print('ofile:', ofile) if os.path.exists(ofile): print('[exists]:', ofile) continue print('openning...') print(ifiles[0]) print(' -->') print(ifiles[-1]) ds = xr.open_mfdataset(ifiles).sel(level=levels).rename(grid_xt='lon', grid_yt='lat').load() 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()