#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Mon Sep 27 21:44:05 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() \ .sel(time=slice('1991', '2020')).groupby('time.month') da_mclim = da.mean(['time', 'en']).roll(month=6).assign_attrs(units='mm/day') months_roll = da_mclim.month.where(da_mclim.month<7, other=da_mclim.month-12).values#new months: -5, -4, ..., 6 da_mclim = da_mclim.assign_coords(month=months_roll) ci = da.quantile([0.025, 0.975], dim=['time', 'en']).roll(month=6).assign_coords(month=months_roll) mon_names = ['Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'] if __name__ == '__main__': from wyconfig import * #my plot settings plt.close() fig, ax = plt.subplots() ax.fill_between(ci.month, ci.isel(quantile=0), ci.isel(quantile=1), color='C0', alpha=0.2, label='95% range') da_mclim.plot(marker='o', fillstyle='none', label='ens mean mclim') ax.set_xticks(months_roll) ax.set_xticklabels(mon_names) ax.legend() ax.set_title('annual cycle from AM4: 1991-2020, 5ens') #savefig if 'savefig' in sys.argv: figname = __file__.replace('.py', f'.png') wysavefig(figname) tt.check(f'**Done**') plt.show()