#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Mon Sep 27 16:51:22 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 ifile = 'data_precip_AM4urban_amip_5ens_1870-202107.masked.south.nc' da = xr.open_dataarray(ifile).load() da12 = da.sel(time=slice('1870-07', '2021-06')).rolling(time=12).mean().dropna('time') \ .isel(time=slice(0, None, 12)).groupby('time.year').mean('time') \ .pipe(lambda x: x*365).assign_attrs(units='mm') if __name__ == '__main__': from wyconfig import * #my plot settings plt.close('all') fig, ax = plt.subplots() da_ = da12.pipe(lambda x: x - x.sel(year=slice(1981, 2010)).mean('year')).assign_attrs(units='mm') da_.mean('en').plot(marker='o', fillstyle='none', ax=ax) da_.plot(hue='en', add_legend=False, color='C0', alpha=0.2, lw=1, ax=ax) ax.set_title('12-mon (Jul$_{-1}$ $-$ Jun$_{0}$) precip anomaly from AM4') ax.set_xlabel('end year of rainfall period') #savefig if 'savefig' in sys.argv: figname = __file__.replace('.py', f'.png') wysavefig(figname) tt.check(f'**Done**') plt.show()