#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Tue Jun 29 16:14:32 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 import geoxarray # if __name__ == '__main__': tt.check('end import') # #start from here ofile_nc = __file__.replace('.py', '.nc').replace('get_', 'data_') if os.path.exists(ofile_nc): da = xr.open_dataarray(ofile_nc) print('[loaded]:', ofile_nc) else: daname = 't_ref_max' daname_new = 'tmax' rename_grid = lambda x: x.rename(grid_xt='lon', grid_yt='lat') #sel_region = lambda x: x.sel(lon=slice(360-123, 360-119), lat=slice(47, 52)) sel_region = lambda x: x.sel(lon=slice(360-125, 360-117), lat=slice(43, 54)) years = range(101,1001) idir = '/tigress/wenchang/MODEL_OUT/CTL1860_v201904_tigercpu_intelmpi_18_576PE/POSTP' ifiles = [os.path.join(idir, f'{year:04d}0101.atmos_daily.nc') for year in years] print('openning...') da = xr.open_mfdataset(ifiles)[daname].pipe(rename_grid) print('loading...') da = da.pipe(sel_region).load() print('saving...') encoding = {daname_new: dict(zlib=True, complevel=1)} da.to_dataset(name=daname_new).to_netcdf(ofile_nc, encoding=encoding) print('[saved]:', ofile_nc) if __name__ == '__main__': """ from wyconfig import * #my plot settings from geoplots import mapplot fig, ax = plt.subplots(figsize=(6,6)) da.mean('year').pipe(lambda x: x-273.15).assign_attrs(units='$^\circ$C').plot.contourf(ax=ax, levels=np.arange(20,41), extend='both') mapplot(ax=ax, xticks=np.arange(360-125, 360-117+1), yticks=np.arange(43, 54+1)) """ #savefig if 'savefig' in sys.argv: figname = __file__.replace('.py', f'.png') wysavefig(figname) tt.check(f'**Done**') plt.show()