#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Tue Jun 29 14:35:53 EDT 2021 if __name__ == '__main__': from misc.timer import Timer tt = Timer(f'start {__file__}') import sys, os.path, os, glob, datetime import xarray as xr, numpy as np, pandas as pd, matplotlib.pyplot as plt #more imports # if __name__ == '__main__': tt.check('end import') # #start from here daname = 't2m' idir = '/tigress/wenchang/data/era5/raw/monthly/2m_temperature' ifiles = [os.path.join(idir, f'era5.2m_temperature.monthly.{year}.nc') for year in range(2000,2021+1)] #ofile = 'era5.2m_temperature.monthly.1979-2020.nc' ifiles.append(os.path.join(idir, 'era5.2m_temperature.monthly.202204.nc')) ofile = 'era5.2m_temperature.monthly.200001-202204.nc' if os.path.exists(ofile): print('[exists]:', ofile) sys.exit() print('loading...') ds = xr.open_mfdataset(ifiles).load() #save data print('saving...') encoding = {daname: {'dtype': 'float32', 'zlib': True, 'complevel': 1}} ds.to_netcdf(ofile, encoding=encoding) print('[saved]:', ofile) if __name__ == '__main__': #from wyconfig import * #my plot settings #savefig if 'savefig' in sys.argv: figname = __file__.replace('.py', f'.png') wysavefig(figname) tt.check(f'**Done**') plt.show()