#!/usr/bin/env python # Wenchang Yang (wenchang@princeton.edu) # Fri May 2 04:35:54 PM EDT 2025 if __name__ == '__main__': import sys,os try: from misc.timer import Timer tt = Timer(f'[{os.getcwd()}] start ' + ' '.join(sys.argv)) except: pass import sys, os.path, os, glob, datetime import xarray as xr, numpy as np, pandas as pd, matplotlib.pyplot as plt #more imports wython = '/tigress/wenchang/wython' if wython not in sys.path: sys.path.append(wython); print('added to python path:', wython) #from misc import get_kws_from_argv import geoxarray # if __name__ == '__main__': try: tt.check('end import') except: pass # #start from here ifile = 'wyplot_map_lintrend__MAM_hist.nc' da = xr.open_dataset(ifile)['slope'] da_hist = da ifile = 'wyplot_map_lintrend__MAM_GHG.nc' da = xr.open_dataset(ifile)['slope'] da_ghg = da da = xr.concat([da_hist, da_ghg], dim=pd.Index(['historical', 'hist-GHG'], name='expname')) da = da.sel(lon=slice(360-93, 360-86), lat=slice(34,39)).geo.fldmean() \ .pipe(lambda da: da*24*3600*100) \ .assign_attrs(units='mm/day/century', long_name='precip linear trend') if __name__ == '__main__': from wyconfig import * #my plot settings da.transpose('model', 'expname').to_pandas().plot.bar() ax = plt.gca() ax.set_ylabel('mm/day/century') ax.set_xlabel('') ax.set_xticklabels(da.model.values, rotation=30, ha='right') ax.set_title('CMIP6 MAM precip linear trend, 1850-2014, 93-86W, 34-39N') #savefig if 'savefig' in sys.argv or 's' in sys.argv: figname = __file__.replace('.py', f'.png') if 'overwritefig' in sys.argv or 'o' in sys.argv: wysavefig(figname, overwritefig=True) else: wysavefig(figname) try: tt.check(f'**Done**') except: pass print() if 'notshowfig' in sys.argv or 'n' in sys.argv: pass else: if 'plt' in globals(): plt.show()