#!/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_AM2.5C360_amip_5ens_1871-202107.masked.south.nc' da = xr.open_dataarray(ifile).load() da14 = da.sel(time=slice('1871-12', '2021-01')).rolling(time=14).mean().dropna('time') \ .isel(time=slice(0, None, 12)).groupby('time.year').mean('time') \ .pipe(lambda x: x*14*30).assign_attrs(units='mm') if __name__ == '__main__': from wyconfig import * #my plot settings plt.close('all') fig, ax = plt.subplots() da_ = da14.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('14-mon (Dec$_{-2}$ $-$ Jan$_{0}$) precip anomaly from AM2.5C360') 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()