def plot_perc_compare_mmm (d, sign, lat, lon, pc, winlen, season, thresh): from matplotlib import pyplot as plt import cartopy.crs as ccrs from matplotlib.colors import BoundaryNorm from matplotlib.ticker import MaxNLocator import numpy as np from grid_tools import fold_grid #Set levels and colormap levels = np.arange(-200,220,20) cmap = plt.get_cmap('Spectral') norm = BoundaryNorm(levels, ncolors=cmap.N, clip=True) #Make the grid circular d, lat, lon = fold_grid(d, lat, lon) lon = lon[0:-1] sign, lat, lon = fold_grid(sign, lat, lon) sign[sign < thresh] = -1.0 sign[sign >= thresh] = 1.0 #Set axes and plot ax = plt.axes(projection=ccrs.PlateCarree()) p=plt.pcolormesh(lon, lat, d, cmap=cmap, norm=norm) cont = plt.contourf(lon, lat, sign, levels=[-1,0,1], transform = ccrs.PlateCarree(),colors='none', hatches=[" ","."]) #Add a colorbar cbar = plt.colorbar(p, extend='both') cbar.ax.set_ylabel('%') ax.coastlines() #Create title for saved plot seasname = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec',\ 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec',\ 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] title = 'MMM_CMIP_'+str(winlen)+'mth_'+seasname[season-1]+seasname[season+winlen-2]+'_'+str(pc)+'th%ile_'+str(thresh)+'modhatch' plt.title(title, fontsize=10) #Save the output savefile = title+'.png' outfile = '/Users/ailieg/Data/drought_model_eval_data/analysis/'+savefile plt.savefig(outfile, dpi=400, format='png',bbox_inches='tight') plt.close()
def plot_mmm_bootstrap(pc, wl, s): import numpy as np from netcdf_tools import ncextractall from matplotlib import pyplot as plt import cartopy.crs as ccrs from matplotlib.colors import BoundaryNorm from matplotlib.ticker import MaxNLocator from grid_tools import fold_grid ofile = '/Users/ailieg/Data/drought_model_eval_data/data/obs/GPCP/precip.mon.mean.nc' cmiptitle = ['ACCESS1-0_historical_r1i1p1',\ 'CanESM2_historical_r1i1p1',\ 'GFDL-CM3_historical_r1i1p1',\ 'HadGEM2-CC_historical_r1i1p1',\ 'MPI-ESM-P_historical_r1i1p1',\ 'CCSM4_historical_r1i1p1',\ 'FGOALS-s2_historical_r1i1p1',\ 'GISS-E2-R_historical_r6i1p1',\ 'NorESM1-M_historical_r1i1p1',\ 'IPSL-CM5B-LR_historical_r1i1p1'] amiptitle = ['FGOALS-s2_amip_r1i1p1',\ 'GFDL-CM3_amip_r1i1p1',\ 'HadGEM2-A_amip_r1i1p1',\ 'NorESM1-M_amip_r1i1p1'] cmipfile = ['CMIP5/ACCESS1-0/r1i1p1/pr/pr_Amon_ACCESS1-0_historical_r1i1p1_185001-200512.nc',\ 'CMIP5/CanESM2/r1i1p1/pr/pr_Amon_CanESM2_historical_r1i1p1_185001-200512.nc',\ 'CMIP5/GFDL-CM3/r1i1p1/pr/pr_Amon_GFDL-CM3_historical_r1i1p1_186001-200512.nc',\ 'CMIP5/HadGEM2-CC/r1i1p1/pr/pr_Amon_HadGEM2-CC_historical_r1i1p1_185912-200511.nc',\ 'CMIP5/MPI-ESM-P/r1i1p1/pr/pr_Amon_MPI-ESM-P_historical_r1i1p1_185001-200512.nc',\ 'CMIP5/CCSM4/r1i1p1/pr/pr_Amon_CCSM4_historical_r1i1p1_185001-200512.nc',\ 'CMIP5/FGOALS-s2/r1i1p1/pr/pr_Amon_FGOALS-s2_historical_r1i1p1_185001-200512.nc',\ 'CMIP5/GISS-E2-R/r6i1p1/pr/pr_Amon_GISS-E2-R_historical_r6i1p1_185001-200512.nc',\ 'CMIP5/NorESM1-M/r1i1p1/pr/pr_Amon_NorESM1-M_historical_r1i1p1_185001-200512.nc',\ 'CMIP5/IPSL-CM5B-LR/r1i1p1/pr/pr_Amon_IPSL-CM5B-LR_historical_r1i1p1_185001-200512.nc'] amipfile = ['AMIP/FGOALS-s2/r1i1p1/pr/pr_Amon_FGOALS-s2_amip_r1i1p1_197901-200812.nc',\ 'AMIP/GFDL-CM3/r1i1p1/pr/pr_Amon_GFDL-CM3_amip_r1i1p1_197901_200812.nc',\ 'AMIP/HadGEM2-A/r1i1p1/pr/pr_Amon_HadGEM2-A_amip_r1i1p1_197809-200811.nc',\ 'AMIP/NorESM1-M/r1i1p1/pr/pr_Amon_NorESM1-M_amip_r1i1p1_197901-200512.nc'] modfile = cmipfile intitle = cmiptitle modpath = '/Users/ailieg/Data/drought_model_eval_data/data/' obsnc = ncextractall(ofile) lon = obsnc['lon'] lat = obsnc['lat'] sigmod = np.zeros((len(modfile), lat.size, lon.size)) for i in range(0,len(modfile)): mfile = modpath+modfile[i] it = intitle[i] d, sig, lat, lon = perc_compare_bsoblen(pc, wl, s, ofile, mfile, it) sig[sig < 0.0] = 0.0 sigmod[i,:,:] = sig sumsig = np.sum(sigmod, axis=0)/len(modfile) #Set levels and colormap levels = np.arange(0,100,10) cmap = plt.get_cmap('Spectral') norm = BoundaryNorm(levels, ncolors=cmap.N, clip=True) #Make the grid circular sumsig, lat, lon = fold_grid(sumsig, lat, lon) #Set axes and plot ax = plt.axes(projection=ccrs.PlateCarree()) p=plt.pcolormesh(lon, lat, d, cmap=cmap, norm=norm) #Add a colorbar cbar = plt.colorbar(p, extend='both') cbar.ax.set_ylabel('%') ax.coastlines() #Create title for saved plot seasname = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec',\ 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec',\ 'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] title = 'PERC_MODELS_CMIP_'+str(wl)+'mth_'+seasname[s-1]+seasname[s+wl-2]+'_'+str(pc)+'th%ile' plt.title(title, fontsize=10) #Save the output savefile = title+'.png' outfile = '/Users/ailieg/Data/drought_model_eval_data/analysis/'+savefile plt.savefig(outfile, dpi=400, format='png',bbox_inches='tight') plt.close()