#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Mon Mar 2 17:15:22 EST 2020 if __name__ == '__main__': from misc.timer import Timer tt = Timer(f'start {__file__}') import sys, os.path, os, datetime import xarray as xr, numpy as np, pandas as pd #import matplotlib.pyplot as plt #print() if __name__ == '__main__': tt.check('end import') model = 'AM2.5C360' expname = 'amipHadISST_tigercpu_intelmpi_18_1080PE' data_name = 'VI' ens = range(1, 4) years = range(1971, 2019) ofile = f'data.{data_name}.nc' ifiles = [[f'/tigress/wenchang/MODEL_OUT/{model}/{expname}/en{en:02d}/analysis_wy/TCI/{year:04d}0101.atmos_month.VI.nc' for year in years] for en in ens] if __name__ == '__main__': ds = xr.open_mfdataset(ifiles, concat_dim=['en', 'time'], combine='nested') ds = ds.rename({'grid_xt': 'lon', 'grid_yt': 'lat'}) ds.attrs['model'] = model ds.attrs['expname'] = expname encoding = {data_name: {'dtype': 'float32', 'zlib': True, 'complevel': 1}} ds.to_netcdf(ofile, encoding=encoding) print('[saved]:', ofile) tt.check('**Done**') print()