#!/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 tspan = slice('1981','2010') ofile_nc = __file__.replace('.py', '.nc') if os.path.exists(ofile_nc): da = xr.open_dataarray(ofile_nc) print('[loaded]:', ofile_nc) else: ifile = 'data_tmax_AM4urban_amip_5ens_1870-2014.nc' #sel_region = lambda x: x.sel(lon=slice(360-125, 360-117), lat=slice(43, 54)) print('loading...') da = xr.open_dataarray(ifile).sel(time=tspan).load() print('calculating...') da = da.groupby('time.year').max('time').mean('year').mean('en') print('saving...') da.to_dataset(name='TXx').to_netcdf(ofile_nc) 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.pipe(lambda x: x-273.15).assign_attrs(units='$^\circ$C').plot.contourf(ax=ax, levels=np.arange(20,41, 2), cmap='RdBu_r', extend='both') mapplot(ax=ax, xticks=np.arange(360-125, 360-117+1), yticks=np.arange(43, 54+1)) ax.set_title('Mean TXx from GFDL-AM4urban AMIP (1981-2010)') ax.set_xlabel('') ax.set_ylabel('') """ from geoplots.cartopy.api import cartoplot da.pipe(lambda x: x-273.15).assign_attrs(units='$^\circ$C').pipe(cartoplot, proj='cyl', levels=np.arange(20,41), extend='both', figsize=(6,6)) """ #savefig if 'savefig' in sys.argv: figname = __file__.replace('.py', f'.png') wysavefig(figname) tt.check(f'**Done**') plt.show()