#!/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 = 'mx2t'#, 'swvl1'#,'t2m' dsname = '2m_temperature_max'#, 'volumetric_soil_water_layer_1' lons = slice(42, 52) lats = slice(-10, -30) #idir = '/tigress/wenchang/data/era5/raw/monthly/2m_temperature' #idir = f'/tigress/wenchang/data/era5/raw/monthly/{dsname}' idir = f'/tigress/wenchang/data/era5/analysis_wy/{dsname}/daily/' print(f'{idir = }') ifiles = [os.path.join(idir, f'era5.{dsname}.daily.{year}-{month:02d}.nc') for year in range(2000,2021+1) for month in range(1,12+1) ] #ofile = 'era5.2m_temperature.monthly.1979-2020.nc' #ifiles.append(os.path.join(idir, f'era5.{dsname}.monthly.202204.nc')) ifiles2022 = [os.path.join(idir, f'era5.{dsname}.daily.2022-{month:02d}.nc') for month in range(1,3+1)] ifiles = ifiles + ifiles2022 for ifile in ifiles: print(ifile) ofile = f'era5.{daname}.daily.200001-202203.nc' if os.path.exists(ofile): print('[exists]:', ofile) sys.exit() print('loading...') #ds = xr.open_mfdataset(ifiles).load() ds = xr.open_mfdataset(ifiles).sel(longitude=lons, latitude=lats).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()