def orog_dif_plot(): '''Plot spatial differences between MetUM model output using default and updated orography and coastline files during foehn and non-foehn conditions. Thesis Figure 4.8. ''' # Load necessary files old_orog = iris.load_cube('/data/clivarm/wip/ellgil82/new_ancils/km1p5/orog/orog_original.nc', 'OROGRAPHY (/STRAT LOWER BC)')[0,0,:,:] new_orog = iris.load_cube('/data/clivarm/wip/ellgil82/new_ancils/km1p5/orog/new_orog_smoothed.nc', 'Height')[0, 0,:, :] old_lsm = iris.load_cube('/data/clivarm/wip/ellgil82/new_ancils/km1p5/lsm/lsm_original.nc', 'LAND MASK (No halo) (LAND=TRUE)')[0, 0, :, :] new_lsm = iris.load_cube('/data/clivarm/wip/ellgil82/new_ancils/km1p5/lsm/new_mask.nc', 'LAND MASK (No halo) (LAND=TRUE)')[0,0,:,:] # Set up figure fig, ax = plt.subplots(1, 1, figsize=(10,11.5)) ax.spines['right'].set_visible(False) ax.spines['left'].set_visible(False) ax.spines['top'].set_visible(False) ax.spines['bottom'].set_visible(False) ax.tick_params(axis='both', which='both', length=0, labelbottom='off', labelleft='off') # Plot Cabinet Inlet AWS cube = iris.load_cube('/data/clivarm/wip/ellgil82/May_2016/Re-runs/CS2/20160522T1200Z_Peninsula_km1p5_ctrl_pa000.pp','surface_altitude') real_lon, real_lat = rotate_data(cube, 0, 1) ax.plot(-63.37105, -66.48272, markersize=15, marker='o', color='#f68080', zorder=10) # Calculate differences orog_dif = new_orog.data - old_orog.data lsm_dif = new_lsm.data - old_lsm.data # Mask data where no difference is seen orog_dif = ma.masked_where((lsm_dif == 0) & (new_lsm.data == 0), orog_dif) lsm_dif = ma.masked_where(lsm_dif == 0, lsm_dif) # Truncate colormap to minimise visual impact of one or two extreme values squished_bwr = shiftedColorMap(cmap=matplotlib.cm.bwr, min_val=-800, max_val=800, name='squished_bwr', var=orog_dif, start = .15, stop = .85) # Plot differences between old and new orography and LSM c = ax.pcolormesh(real_lon, real_lat, orog_dif, cmap='squished_bwr', vmin=-800, vmax=800, zorder = 1) lsm = ax.contourf(real_lon, real_lat, lsm_dif, cmap = 'bwr', vmax = 1, vmin = -1, zorder = 2) # Add new LSM and 25 m orography contour ax.contour(real_lon, real_lat, new_lsm.data, lw=3, colors='dimgrey', zorder = 3) ax.contour(real_lon, real_lat, new_orog.data, lw = 2, levels = [100], colors = 'dimgrey', zorder = 4) # Set up colour bar cbaxes = fig.add_axes([0.22, 0.12, 0.56, 0.03]) cbticks = np.linspace(-800, 800, 4) cbticklabs = [-800, 0, 800] cb = plt.colorbar(c, cax=cbaxes, orientation='horizontal', ticks=cbticks) cb.set_ticks(cbticks, cbticklabs) cb.ax.set_xlabel('Surface elevation difference (m)', fontsize=30, labelpad=20, color='dimgrey') cb.ax.text(-0.3, 2.2, 'Area removed \nfrom new LSM', fontsize = 30, color = 'dimgrey') cb.ax.text(0.78, 2.2, 'Area added \nto new LSM', fontsize = 30, color = 'dimgrey') cb.outline.set_edgecolor('dimgrey') cb.outline.set_linewidth(2) cb.solids.set_edgecolor('face') cb.ax.tick_params(labelsize=30, tick1On=False, tick2On=False, labelcolor='dimgrey', pad=10) [l.set_visible(False) for (w, l) in enumerate(cb.ax.xaxis.get_ticklabels()) if w % 3 != 0] plt.subplots_adjust(bottom=0.27, left=0.11, right=0.89, top=0.95, hspace=0.05) plt.savefig('/users/ellgil82/figures/new_ancils/orog_difs_km1p5.png', transparent = True) plt.savefig('/users/ellgil82/figures/new_ancils/orog_difs_km1p5.eps', transparent = True) plt.savefig('/users/ellgil82/figures/new_ancils/orog_difs_km1p5.pdf', transparent=True) plt.show()
def mask_difs(): difs = glm_SIC.data-ERA_SIC.data difs[glm_SIC==0] = 0 difs_m = np.ma.masked_equal(difs, 0) difs_m = np.ma.masked_greater_equal(difs, -0.001) fig, ax = plt.subplots(1,1, figsize = (12,9)) ax.spines['right'].set_visible(False) ax.spines['left'].set_visible(False) ax.spines['top'].set_visible(False) ax.spines['bottom'].set_visible(False) ax.tick_params(which = 'both', tick1On = 'False', tick2On = 'False') ax.axis('off') plt.setp(ax.get_yticklabels(), visible=False) plt.setp(ax.get_xticklabels(), visible = False) bwr_zero = shiftedColorMap(cmap=matplotlib.cm.bwr, min_val=-2.5, max_val=3.5, name='bwr_zero', var='s', start=0., stop=1.) GLM = ax.contourf(glm_SST.data, cmap=bwr_zero, vmin=-2.5, vmax=3.5) difs = ax.contourf(difs_m, cmap = 'viridis') lsm1 = ax.contour(glm_LSM.data, colors='dimgrey', linewidths=3, levels=[0]) thresh1 = ax.contour(glm_SIC.data, levels =[0.1], linewidths=5, colors = 'r', zorder = 9, ) thresh2 = ax.contour(ERA_SIC.data, levels= [0] , linewidths=5,colors = 'green') CBarXTicks = [-2, 0, 2] SST_axes = fig.add_axes([0.1, 0.1, 0.03, 0.7]) #left, bottom, width, height dif_axes = fig.add_axes([0.82, 0.1, 0.03, 0.7]) CBar1 = plt.colorbar(GLM, cax=SST_axes, orientation='vertical', ticks=CBarXTicks) # ax.text(-0.25, 1.1, s = 'SST ($^{\circ}$C)', transform = ax.transAxes, rotation = 0, color = 'dimgrey', fontsize = '34') CBar2 = plt.colorbar(difs, cax = dif_axes, orientation='vertical', ticks = [0, -0.05, -0.1]) ax.text(0.98, 1.1, s = 'glm SIC - \nERA SIC', transform = ax.transAxes, rotation = 0, color = 'dimgrey', fontsize = '34') for CBar in [CBar1, CBar2]: CBar.solids.set_edgecolor("face") CBar.outline.set_edgecolor('dimgrey') CBar.ax.tick_params(which='both', axis='both', labelsize=34, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False) CBar.outline.set_linewidth(2) lns = [Line2D([0], [0], color='red', linewidth=5), Line2D([0], [0], color='green', linewidth=5)] labs = ['glm SIC = 0.1','ERA SIC edge']# ' ',' ' lgd = plt.legend(lns, labs, ncol=1, bbox_to_anchor=(-6,1.2), borderaxespad=0., prop={'size': 24}) for ln in lgd.get_texts(): plt.setp(ln, color='dimgrey') lgd.get_frame().set_linewidth(0.0) plt.subplots_adjust(left = 0.2, bottom = 0.1, right = 0.78, top = 0.8) plt.show()
def plot_SMB(SMBvar, comp_dict, region, mean_or_SD, calc): range_dict = { 'pr': (0, 1000), 'sbl': (0, 300), 'snm': (0, 10), 'mrro': (0, 10), 'SMB': (-200, 1000), 'evap': (0, 300) } fig = plt.figure(figsize=[10, 6]) ax = plt.subplot(1, 1, 1, projection=ccrs.SouthPolarStereo()) fig.subplots_adjust(bottom=0.05, top=0.9, left=0.04, right=0.85, wspace=0.02) # Limit the map to -60 degrees latitude and below. ax.set_extent([-180, 180, -90, -59.5], ccrs.PlateCarree()) lsm_full = iris.load_cube(filepath + 'sftlf.nc') if region == 'AIS': lsm = lsm_full else: lsm = iris.load_cube(filepath + 'sftlf.nc', region) gridlons = lsm.coord('longitude').contiguous_bounds() gridlats = lsm.coord('latitude').contiguous_bounds() ax.spines['geo'].set_visible(False) if calc == 'yes': if mean_or_SD == 'mean': mean_data = comp_dict[SMBvar].collapsed('time', iris.analysis.MEAN).data elif mean_or_SD == 'SD': mean_data = comp_dict[SMBvar].collapsed('time', iris.analysis.STD_DEV).data else: mean_data = comp_dict[SMBvar] squished_cmap = shiftedColorMap(cmap=matplotlib.cm.coolwarm_r, min_val=range_dict[SMBvar][0], max_val=range_dict[SMBvar][1], name='squished_cmap', var=mean_data, start=0.3, stop=0.7) f = ax.pcolormesh(gridlons, gridlats, np.ma.masked_where(lsm.data == 0, mean_data), transform=ccrs.PlateCarree(), cmap=squished_cmap, vmin=range_dict[SMBvar][0], vmax=range_dict[SMBvar][1]) ax.contour(lsm_full.coord('longitude').points, lsm_full.coord('latitude').points, lsm_full.data > 0, levels=[0], linewidths=2, colors='k', transform=ccrs.PlateCarree()) CbAx = fig.add_axes([0.85, 0.15, 0.02, 0.6]) cb = plt.colorbar(f, orientation='vertical', cax=CbAx, extend='both', ticks=[ range_dict[SMBvar][0], 0, range_dict[SMBvar][1] / 2, range_dict[SMBvar][1] ]) #shrink = 0.8, cb.solids.set_edgecolor("face") cb.outline.set_edgecolor('dimgrey') cb.ax.tick_params(which='both', axis='both', labelsize=20, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False) cb.outline.set_linewidth(2) cb.ax.set_title('Annual mean\n' + SMBvar + ' (kg m$^{-2}$ yr$^{-1}$)', fontname='Helvetica', color='dimgrey', fontsize=20, pad=20) gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, y_inline=True, linewidth=2, color='gray', alpha=0.5, linestyle=':') gl.xlabel_style = { 'color': 'dimgrey', 'size': 20, } gl.ylabel_style = { 'color': 'dimgrey', 'size': 20, } plt.savefig(filepath + 'ERA-Interim_historical_' + mean_or_SD + SMBvar + string_dict[region] + '.png') plt.show()
def plot_SMB_components(region, mean_or_SD, components): orog_full = iris.load_cube(filepath + 'orog.nc') lsm_full = iris.load_cube(filepath + 'sftlf.nc') if region == 'AIS': lsm = lsm_full else: lsm = iris.load_cube(filepath + 'sftlf.nc', region) lsm.coord('latitude').guess_bounds() lsm.coord('longitude').guess_bounds() # turn the iris Cube data structure into numpy arrays gridlons = lsm.coord('longitude').contiguous_bounds() gridlats = lsm.coord('latitude').contiguous_bounds() projection = ccrs.SouthPolarStereo() axes_class = (GeoAxes, dict(map_projection=projection)) fig = plt.figure(figsize=(20, 14)) axgr = AxesGrid( fig, 111, axes_class=axes_class, nrows_ncols=(2, 3), axes_pad=2, #cbar_location='right', #cbar_mode='single', #cbar_pad=0.4, #cbar_size='2.5%', label_mode='') titles = ['pr', 'evapsbl', 'sbl', 'mrro', 'snm', 'SMB', 'SD of SMB'] # Will miss SD SMB out if sbl inc. maxvals = [3000, 100, 100, 100, 10, 3000, 300] minvals = [-100, -100, -100, -100, -10, -100, -10] for i, ax in enumerate(axgr): ax.set_extent([-180, 180, -90, -59.5], ccrs.PlateCarree()) squished_cmap = shiftedColorMap(cmap=matplotlib.cm.coolwarm_r, min_val=-200., max_val=2000., name='squished_cmap', var=components[i], start=0.3, stop=0.7) ax.contour(lsm_full.coord('longitude').points, lsm_full.coord('latitude').points, lsm_full.data > 0, levels=[0], linewidths=2, colors='k', transform=ccrs.PlateCarree()) f = ax.pcolormesh(gridlons, gridlats, np.ma.masked_where(lsm.data == 0, components[i]), norm=colors.SymLogNorm(linthresh=0.1, linscale=0.1, vmin=minvals[i], vmax=maxvals[i]), cmap='coolwarm_r', transform=ccrs.PlateCarree()) ax.spines['geo'].set_visible(False) gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, y_inline=True, linewidth=2, color='gray', alpha=0.5, linestyle=':') gl.xlabel_style = { 'color': 'dimgrey', 'size': 20, } gl.ylabel_style = { 'color': 'dimgrey', 'size': 20, } ax.set_title(titles[i], fontsize=24, fontweight='bold', color='dimgrey', pad=20) cb = plt.colorbar(f, extend='both', orientation='vertical', ax=ax) cb.solids.set_edgecolor("face") cb.outline.set_edgecolor('dimgrey') cb.ax.tick_params(which='both', axis='both', labelsize=20, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False) cb.outline.set_linewidth(2) #cb = axgr.cbar_axes[0].colorbar(f, extend='both')#, shrink = 0.8), orientation='vertical', #CbAx = fig.add_axes([0.9, 0.15, 0.015, 0.6]) #cb = fig.colorbar(f, extend = 'both', orientation = 'vertical', cax = CbAx) #cb.solids.set_edgecolor("face") #cb.outline.set_edgecolor('dimgrey') #cb.ax.tick_params(which='both', axis='both', labelsize=20, labelcolor='dimgrey', pad=10, size=0, tick1On=False, # tick2On=False) #cb.outline.set_linewidth(2) #cb.ax.set_title('Annual mean\n (kg m$^{-2}$ yr$^{-1}$)', fontname='Helvetica', color='dimgrey', fontsize=20, # pad=20) fig.subplots_adjust(bottom=0.05, top=0.9, left=0.05, right=0.85, wspace=0.18, hspace=0.18) plt.savefig(filepath + 'ERA-Interim_historical_SMB_components_' + mean_or_SD + '_' + string_dict[region] + '.png') plt.show()
def plot_synop_composite(cf_var, c_var, u_var, v_var): fig = plt.figure(frameon=False, figsize=( 9, 10)) # !!change figure dimensions when you have a larger model domain fig.patch.set_visible(False) ax = fig.add_subplot(111) #, projection=ccrs.PlateCarree()) plt.axis = 'off' PlotLonMin = np.min(var_dict['lon'][120:170]) PlotLonMax = np.max(var_dict['lon'][120:170]) PlotLatMin = np.min(var_dict['lat'][130:175]) PlotLatMax = np.max(var_dict['lat'][130:175]) XTicks = np.linspace(PlotLonMin, PlotLonMax, 3) XTickLabels = [None] * len(XTicks) for i, XTick in enumerate(XTicks): if XTick < 0: XTickLabels[i] = '{:.0f}{:s}'.format(np.abs(XTick), '$^{\circ}$W') else: XTickLabels[i] = '{:.0f}{:s}'.format(np.abs(XTick), '$^{\circ}$E') # plt.xticks(XTicks, XTickLabels) ax.set_xlim(PlotLonMin, PlotLonMax) ax.tick_params(which='both', pad=10, labelsize=34, color='dimgrey') YTicks = np.linspace(PlotLatMin, PlotLatMax, 3) YTickLabels = [None] * len(YTicks) for i, YTick in enumerate(YTicks): if YTick < 0: YTickLabels[i] = '{:.0f}{:s}'.format(np.abs(YTick), '$^{\circ}$S') else: YTickLabels[i] = '{:.0f}{:s}'.format(np.abs(YTick), '$^{\circ}$N') plt.yticks(YTicks, YTickLabels) ax.set_ylim(PlotLatMin, PlotLatMax) ax.tick_params(which='both', axis='both', labelsize=34, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False) bwr_zero = shiftedColorMap(cmap=matplotlib.cm.bwr, min_val=-15., max_val=2., name='bwr_zero', var=cf_var.data, start=0.15, stop=0.85) #-6, 3 xlon, ylat = np.meshgrid(var_dict['lon'][120:170], var_dict['lat'][130:175]) c = ax.pcolormesh(xlon, ylat, cf_var, cmap=bwr_zero, vmin=-15., vmax=2., zorder=1) # latlon=True, transform=ccrs.PlateCarree(), cs = ax.contour(xlon, ylat, np.ma.masked_where( var_dict['lsm'].data[130:175, 120:170] == 1, c_var), latlon=True, colors='k', zorder=4) ax.clabel(cs, inline=True, fontsize=24, inline_spacing=30, fmt='%1.0f') coast = ax.contour(xlon, ylat, var_dict['lsm'].data[130:175, 120:170], levels=[0], colors='#222222', lw=2, latlon=True, zorder=2) topog = ax.contour(xlon, ylat, var_dict['orog'].data[130:175, 120:170], levels=[50], colors='#222222', linewidth=1.5, latlon=True, zorder=3) CBarXTicks = [ -15, 0, 2 ] # CLevs[np.arange(0,len(CLevs),int(np.ceil(len(CLevs)/5.)))] CBAxes = fig.add_axes([0.22, 0.2, 0.6, 0.025]) CBar = plt.colorbar(c, cax=CBAxes, orientation='horizontal', ticks=CBarXTicks, extend='both') # CBar.set_label('Mean daily maximum 1.5 m \nair temperature ($^{\circ}$C)', fontsize=34, labelpad=10, color='dimgrey') CBar.solids.set_edgecolor("face") CBar.outline.set_edgecolor('dimgrey') CBar.ax.tick_params(which='both', axis='both', labelsize=34, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False) CBar.outline.set_linewidth(2) x, y = np.meshgrid(var_dict['lon'], var_dict['lat']) q = ax.quiver(x[::8, ::8], y[::8, ::8], u_var[::8, ::8], v_var[::8, ::8], pivot='middle', scale=50, zorder=5, width=0.006) plt.quiverkey( q, 0.25, 0.9, 5, r'$5$ $m$ $s^{-1}$', labelpos='N', color='dimgrey', labelcolor='dimgrey', fontproperties={ 'size': '32', 'weight': 'bold' }, coordinates='figure', ) plt.subplots_adjust(left=0.2, bottom=0.33, right=0.85) plt.savefig( '/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/synoptic_cond_Tair_max_LarsenB_melt_period_zoomed.png' ) plt.savefig( '/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/synoptic_cond_Tair_max_LarsenB_melt_period_zoomed.eps' ) plt.show()
def subplots_simple(var, clim, savefig): fig, ax = plt.subplots(1,3, figsize = (22,8)) ax.flatten() if clim == 'True' or clim == 'yes': case_list = ['Climatology', 'GLM', 'LAM'] else: case_list = ['ERA-Interim', 'GLM', 'LAM'] lab_dict = {0: 'a', 1: 'b', 2: 'c'} for a in [0, 1, 2]: ax[a].spines['right'].set_visible(False) ax[a].spines['left'].set_visible(False) ax[a].spines['top'].set_visible(False) ax[a].spines['bottom'].set_visible(False) ax[a].tick_params(which = 'both', tick1On = 'False', tick2On = 'False') ax[a].axis('off') plt.setp(ax[a].get_yticklabels(), visible=False) plt.setp(ax[a].get_xticklabels(), visible = False) lab = ax[a].text(0.1, 0.85, transform = ax[a].transAxes, zorder=100, s=lab_dict[a], fontsize=32, fontweight='bold', color='dimgrey') ax[a].set_title(case_list[a], fontsize=40, color='dimgrey') if var == 'SST': bwr_zero = shiftedColorMap(cmap=matplotlib.cm.bwr, min_val=-2.5, max_val=3.5, name='bwr_zero', var='s', start=0., stop=1.) if clim == 'True' or clim == 'yes': if date == '20080101' or date == '20080130': clim = ax[0].pcolormesh(Jan_SST.data, cmap=bwr_zero, vmin= -2.5, vmax = 3.5) elif date == '20080207': clim = ax[0].pcolormesh(Feb_SST.data, cmap=bwr_zero, vmin= -2.5, vmax = 3.5) else: ERA = ax[0].pcolormesh(ERA_SST.data, cmap=bwr_zero,vmin= -2.5, vmax = 3.5) lsm0 = ax[0].contour(glm_LSM.data, colors='dimgrey', linewidths=3, levels=[0]) GLM = ax[1].pcolormesh(glm_SST.data, cmap = bwr_zero, vmin= -2.5, vmax = 3.5) lsm1 = ax[1].contour(glm_LSM.data, colors='dimgrey', linewidths = 3, levels = [0]) LAM = ax[2].pcolormesh(LAM_SST.data, cmap =bwr_zero, vmin= -2.5, vmax = 3.5) lsm2 = ax[2].contour(LAM_LSM.data, colors='dimgrey', linewidths = 3, levels = [0]) CBarXTicks = [-2, 0, 2] elif var == 'SIC': if clim == 'True' or clim == 'yes': if date == '20080101' or date == '20080130': clim = ax[0].pcolormesh(Jan_SIC.data, cmap='Blues_r', vmin= 0., vmax = 1.) elif date == '20080207': clim = ax[0].pcolormesh(Feb_SIC.data, cmap='Blues_r', vmin= 0., vmax = 1.) else: ERA = ax[0].pcolormesh(ERA_SIC.data, cmap = 'Blues_r', vmin = 0., vmax = 1.) lsm0 = ax[0].contour(glm_LSM.data, colors='dimgrey', linewidths=3, levels=[0]) GLM = ax[1].pcolormesh(glm_SIC.data, cmap = 'Blues_r', vmin = -0., vmax = 1.) lsm1 = ax[1].contour(glm_LSM.data, colors = 'dimgrey', linewidths = 3, levels = [0]) LAM = ax[2].pcolormesh(LAM_SIC.data, cmap = 'Blues_r', vmin = 0., vmax = 1.) lsm2 = ax[2].contour(LAM_LSM.data, colors = 'dimgrey', linewidths = 3, levels = [0]) CBarXTicks = [ 0., 0.5, 1.] # CLevs[np.arange(0,len(CLevs),int(np.ceil(len(CLevs)/5.)))] ax[2].yaxis.tick_right() CBAxes = fig.add_axes([0.4, 0.15, 0.2, 0.03]) CBar = plt.colorbar(LAM, cax=CBAxes, orientation='horizontal', ticks=CBarXTicks) # CBar.solids.set_edgecolor("face") CBar.outline.set_edgecolor('dimgrey') CBar.ax.tick_params(which='both', axis='both', labelsize=34, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False) CBar.outline.set_linewidth(2) plt.subplots_adjust(left = 0.08, right = 0.92, top = 0.9, bottom = 0.28, wspace = 0.23, hspace = 0.18) if savefig == 'yes' or savefig == True: if var == 'SIC': CBar.set_label('Sea ice fraction', fontsize=34, labelpad=10, color='dimgrey') if clim == 'yes': plt.savefig(filepath + date + '_clim_SIC_inheritance_glm_ERA_native.png') plt.savefig(filepath + date + '_clim_SIC_inheritance_glm_ERA_native.eps') else: plt.savefig(filepath + date + '_SIC_inheritance_glm_ERA_native.png') plt.savefig(filepath + date + '_SIC_inheritance_glm_ERA_native.eps') elif var == 'SST': CBar.set_label('SST ($^{\circ}$C)', fontsize=34, labelpad=10, color='dimgrey') if clim == 'yes': plt.savefig(filepath+date+'_clim_SST_inheritance_glm_ERA_native.png') plt.savefig(filepath+date+'_clim_SST_inheritance_glm_ERA_native.eps') else: plt.savefig(filepath + date + '_SST_inheritance_glm_ERA_native.png') plt.savefig(filepath + date + '_SST_inheritance_glm_ERA_native.eps') plt.show()
def plot_ERA(): 'Plot ERA-5 reanalysis data at the onset of foehn conditions during both cases. Thesis Figure 4.1.' fig, axs = plt.subplots(1,2, figsize=(20, 12), frameon=False) lab_dict = {0: 'a', 1: 'b'} #ax = fig.add_axes([0.18, 0.25, 0.75, 0.63], frameon=False) # , projection=ccrs.PlateCarree())# case_list = ['CS1', 'CS2'] for a in [0,1]: axs[a].spines['right'].set_visible(False) axs[a].spines['left'].set_visible(False) axs[a].spines['top'].set_visible(False) axs[a].spines['bottom'].set_visible(False) ERA_dict = load_ERA(case=case_list[a]) MetUM_dict = load_files(case=case_list[a], period='onset',res='km4p0') # Regrid ERA data onto MetUM 4 km domain grid regridded_P = P_ERA.regrid(MetUM_dict['P'], iris.analysis.Linear()) regridded_P = np.ma.masked_where(lsm.data == 1, regridded_P.data) regridded_Tair = T_ERA.regrid(MetUM_dict['T_air'], iris.analysis.Linear()) regridded_u = u_ERA.regrid(MetUM_dict['u_wind'], iris.analysis.Linear()) regridded_v = v_ERA.regrid(MetUM_dict['v_wind'], iris.analysis.Linear()) axs[a].contour(MetUM_dict['lsm'].coord('longitude').points, MetUM_dict['lsm'].coord('latitude').points, MetUM_dict['lsm'].data, colors='#535454', linewidths=2.5, zorder=2) # , transform=RH.coord('grid_longitude').coord_system.as_cartopy_projection()) axs[a].contour(MetUM_dict['orog'].coord('longitude').points, MetUM_dict['orog'].coord('latitude').points, MetUM_dict['orog'].data, colors='#535454', levels=[15], linewidths=2.5, zorder=3) P_lev = axs[a].contour(MetUM_dict['lsm'].coord('longitude').points, MetUM_dict['lsm'].coord('latitude').points, regridded_P, colors='#222222', linewidths=3, levels=range(960, 1040, 8), zorder=4) axs[a].clabel(P_lev, v=[960, 968, 976, 982, 990], inline=True, inline_spacing=3, fontsize=28, fmt='%1.0f') bwr_zero = shiftedColorMap(cmap=matplotlib.cm.bwr, min_val=-20., max_val=10., name='bwr_zero', var=regridded_Tair.data, start = 0., stop = 1.) c = axs[a].pcolormesh(MetUM_dict['real_lon'], MetUM_dict['real_lat'], regridded_Tair.data, cmap=bwr_zero, vmin=-20., vmax=10., zorder=1) # x, y = np.meshgrid(MetUM_dict['real_lon'], MetUM_dict['real_lat']) q = axs[a].quiver(x[::40, ::40], y[::40, ::40], regridded_u.data[::40, ::40], regridded_v.data[::40, ::40], color='#414345', pivot='middle', scale=150, zorder=5) axs[a].tick_params(which='both', axis='both', labelsize=34, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False) PlotLonMin = np.min(MetUM_dict['real_lon']) PlotLonMax = np.max(MetUM_dict['real_lon']) PlotLatMin = np.min(MetUM_dict['real_lat']) PlotLatMax = np.max(MetUM_dict['real_lat']) XTicks = np.linspace(PlotLonMin, PlotLonMax, 3) XTickLabels = [None] * len(XTicks) for i, XTick in enumerate(XTicks): if XTick < 0: XTickLabels[i] = '{:.0f}{:s}'.format(np.abs(XTick), '$^{\circ}$W') else: XTickLabels[i] = '{:.0f}{:s}'.format(np.abs(XTick), '$^{\circ}$E') plt.sca(axs[a]) plt.xticks(XTicks, XTickLabels) axs[a].set_xlim(PlotLonMin, PlotLonMax) axs[a].tick_params(which='both', pad=10, labelsize=34, color='dimgrey') YTicks = np.linspace(PlotLatMin, PlotLatMax, 4) YTickLabels = [None] * len(YTicks) for i, YTick in enumerate(YTicks): if YTick < 0: YTickLabels[i] = '{:.0f}{:s}'.format(np.abs(YTick), '$^{\circ}$S') else: YTickLabels[i] = '{:.0f}{:s}'.format(np.abs(YTick), '$^{\circ}$N') plt.sca(axs[a]) plt.yticks(YTicks, YTickLabels) axs[a].set_ylim(PlotLatMin, PlotLatMax) lab = axs[a].text(-80, -61.5, zorder=100, s=lab_dict[a], fontsize=32, fontweight='bold', color='dimgrey') axs[a].set_title(case_list[a], fontsize=34, color='dimgrey') CBarXTicks = [-20, -10, 0, 10] # CLevs[np.arange(0,len(CLevs),int(np.ceil(len(CLevs)/5.)))] CBAxes = fig.add_axes([0.35, 0.15, 0.3, 0.03]) CBar = plt.colorbar(c, cax=CBAxes, orientation='horizontal', ticks=CBarXTicks) # CBar.set_label('2 m air temperature ($^{\circ}$C)', fontsize=34, labelpad=10, color='dimgrey') CBar.solids.set_edgecolor("face") CBar.outline.set_edgecolor('dimgrey') CBar.ax.tick_params(which='both', axis='both', labelsize=34, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False) CBar.outline.set_linewidth(2) plt.sca(axs[1]) plt.tick_params(axis = 'y', which= 'both', labelleft = 'off', labelright = 'on') #yaxis.set_label_coords(1.27, 0.5) plt.quiverkey(q, 0.51, 0.9, 20, r'$20$ $m$ $s^{-1}$', labelpos='N', color='#414345', labelcolor='#414345', fontproperties={'size': '32', 'weight': 'bold'}, coordinates='figure', ) plt.draw() plt.subplots_adjust(bottom = 0.25, top = 0.85) plt.savefig('/users/ellgil82/figures/Wintertime melt/Re-runs/ERA_foehn_onset_both_cases.png', transparent=True) plt.savefig('/users/ellgil82/figures/Wintertime melt/Re-runs/ERA_foehn_onset_both_cases.eps', transparent=True) plt.show()
def plot_both(period, res): ''' Plot spatial maps of synoptic conditions during both cases from MetUM model output, either before or during the onset of foehn conditions. Thesis Figure 4.4. Inputs: - period: string indicating either pre-foehn onset or during foehn onset, either 'pre' or 'onset' - res: string indicating resolution of model output loaded, either 'km1p5' or 'km4p0' Outputs: - image files in .png and .eps format ''' fig, axs = plt.subplots(1,2, figsize=(20, 12), frameon=False) lab_dict = {0: 'c', 1: 'd'} #ax = fig.add_axes([0.18, 0.25, 0.75, 0.63], frameon=False) # , projection=ccrs.PlateCarree())# case_list = ['CS1', 'CS2'] for a in [0,1]: axs[a].spines['right'].set_visible(False) axs[a].spines['left'].set_visible(False) axs[a].spines['top'].set_visible(False) axs[a].spines['bottom'].set_visible(False) MetUM_dict = load_files(case = case_list[a], period = period, res = res) axs[a].contour(MetUM_dict['lsm'].coord('longitude').points, MetUM_dict['lsm'].coord('latitude').points, MetUM_dict['lsm'].data, colors='#535454', linewidths=2.5, zorder=2) # , transform=RH.coord('grid_longitude').coord_system.as_cartopy_projection()) axs[a].contour(MetUM_dict['orog'].coord('longitude').points, MetUM_dict['orog'].coord('latitude').points, MetUM_dict['orog'].data, colors='#535454', levels=[50], linewidths=2.5, zorder=3) # Plot orography at approx. height of grounding line P_lev = axs[a].contour(MetUM_dict['lsm'].coord('longitude').points, MetUM_dict['lsm'].coord('latitude').points, MetUM_dict['P'], colors='#222222', linewidths=3, levels=range(960, 1020, 4), zorder=4) # Plot MSLP contours axs[a].clabel(P_lev, v=[960, 968, 976, 982, 990], inline=True, inline_spacing=3, fontsize=28, fmt='%1.0f') bwr_zero = shiftedColorMap(cmap=matplotlib.cm.bwr, min_val=-30., max_val=10., name='bwr_zero', var=T_air.data, start = 0., stop = 1.) c = axs[a].pcolormesh(MetUM_dict['real_lon'], MetUM_dict['real_lat'], MetUM_dict['T_air'].data, cmap=bwr_zero, vmin=-30., vmax=10., zorder=1) # Plot temperatures x, y = np.meshgrid(MetUM_dict['real_lon'], MetUM_dict['real_lat']) q = axs[a].quiver(x[::25, ::25], y[::25, ::25], MetUM_dict['u'].data[::25, ::25], MetUM_dict['v'].data[::25, ::25], color='#414345', pivot='middle', scale=100, zorder=5) # Plot 10 m wind vectors axs[a].tick_params(which='both', axis='both', labelsize=34, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False) # Set up plot ticks and labels PlotLonMin = np.min(real_lon) PlotLonMax = np.max(real_lon) PlotLatMin = np.min(real_lat) PlotLatMax = np.max(real_lat) XTicks = np.linspace(PlotLonMin, PlotLonMax, 3) XTickLabels = [None] * len(XTicks) for i, XTick in enumerate(XTicks): if XTick < 0: XTickLabels[i] = '{:.0f}{:s}'.format(np.abs(XTick), '$^{\circ}$W') else: XTickLabels[i] = '{:.0f}{:s}'.format(np.abs(XTick), '$^{\circ}$E') plt.sca(axs[a]) plt.xticks(XTicks, XTickLabels) axs[a].set_xlim(PlotLonMin, PlotLonMax) axs[a].tick_params(which='both', pad=10, labelsize=34, color='dimgrey') YTicks = np.linspace(PlotLatMin, PlotLatMax, 4) YTickLabels = [None] * len(YTicks) for i, YTick in enumerate(YTicks): if YTick < 0: YTickLabels[i] = '{:.0f}{:s}'.format(np.abs(YTick), '$^{\circ}$S') else: YTickLabels[i] = '{:.0f}{:s}'.format(np.abs(YTick), '$^{\circ}$N') plt.sca(axs[a]) plt.yticks(YTicks, YTickLabels) axs[a].set_ylim(PlotLatMin, PlotLatMax) lab = axs[a].text(-80, -61.5, zorder=100, s=lab_dict[a], fontsize=32, fontweight='bold', color='dimgrey') axs[a].set_title(case_list[a], fontsize=34, color='dimgrey') CBarXTicks = [-30, -10, 10] # CLevs[np.arange(0,len(CLevs),int(np.ceil(len(CLevs)/5.)))] CBAxes = fig.add_axes([0.35, 0.15, 0.3, 0.03]) CBar = plt.colorbar(c, cax=CBAxes, orientation='horizontal', ticks=CBarXTicks) # CBar.set_label('1.5 m air temperature ($^{\circ}$C)', fontsize=34, labelpad=10, color='dimgrey') CBar.solids.set_edgecolor("face") CBar.outline.set_edgecolor('dimgrey') CBar.ax.tick_params(which='both', axis='both', labelsize=34, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False) CBar.outline.set_linewidth(2) plt.sca(axs[1]) plt.tick_params(axis = 'y', which= 'both', labelleft = 'off', labelright = 'on') #yaxis.set_label_coords(1.27, 0.5) plt.quiverkey(q, 0.51, 0.9, 10, r'$10$ $m$ $s^{-1}$', labelpos='N', color='#414345', labelcolor='#414345', fontproperties={'size': '32', 'weight': 'bold'}, coordinates='figure', ) plt.draw() plt.subplots_adjust(bottom = 0.25, top = 0.85) plt.savefig('/users/ellgil82/figures/Wintertime melt/Re-runs/synop_cond_both_cases_'+ period + res + '.png') plt.savefig('/users/ellgil82/figures/Wintertime melt/Re-runs/synop_cond_both_cases_'+ period + res + '.eps') plt.show()
def plot_transect(res): ''''Plot transect through mountains during foehn conditions. Thesis Figure 4.7. Inputs: - res: string indicating resolution of MetUM model output. Outputs: - image files in .eps or .png format ''' fig, ax = plt.subplots(1,1, figsize = (12,10)) ax.set_facecolor('#222222') bwr_zero = shiftedColorMap(cmap=matplotlib.cm.bwr, min_val=-10., max_val=40., name='bwr_zero', var=res['theta'].data, start=0., stop=1.) if res == surf_4p0: slice_idx = 163 res_str = '4km' elif res == surf_1p5: slice_idx = 235 res_str = '1p5km' cf = iplt.contourf(res['theta'][12, :, slice_idx, :], cmap=bwr_zero, vmin=-10.1, vmax=40., levels=[-10, -8, -6, -4, -2, 0, 2, 4, 6, 8, 10, 13, 16, 19, 21, 25, 30, 35, 40]) #np.linspace(-10., 40., 21)) c = iplt.contour(res['zonal'][:,slice_idx,:], levels = [0,8,16,24,32,40], colors = 'k') if case_study == 'CS1': plt.clabel(c, [8,16,24,32], rotation = 0, fontsize = 28, color = 'k', inline = True, fmt = '%.0f') elif case_study == 'CS2': plt.clabel(c, [8, 24, 32], rotation=0, fontsize=28, color='k', inline=True, fmt='%.0f') plt.setp(ax.spines.values(), linewidth=2, color='dimgrey') ax.spines['right'].set_visible(False) ax.spines['top'].set_visible(False) PlotLonMin, PlotLonMax = -68, -60 ax.set_ylim(0,5000) ax.set_yticks([0, 2500, 5000]) ax.tick_params(axis='both', which='both', labelsize=32, tick1On=False, tick2On=False, labelcolor='dimgrey', pad=10) ax.set_ylabel('Altitude\n(m)', rotation=0, fontsize=32, labelpad=70, color='dimgrey') [l.set_visible(False) for (w, l) in enumerate(ax.yaxis.get_ticklabels()) if w % 2 != 0] XTicks = np.linspace(PlotLonMin, PlotLonMax, 3) XTickLabels = [None] * len(XTicks) for i, XTick in enumerate(XTicks): if XTick < 0: XTickLabels[i] = '{:.0f}{:s}'.format(np.abs(XTick), '$^{\circ}$W') else: XTickLabels[i] = '{:.0f}{:s}'.format(np.abs(XTick), '$^{\circ}$E') plt.sca(ax) plt.xticks(XTicks, XTickLabels) ax.set_xlim(PlotLonMin, PlotLonMax) CBarXTicks = [-10, 0, 10, 20, 30, 40] # CLevs[np.arange(0,len(CLevs),int(np.ceil(len(CLevs)/5.)))] CBAxes = fig.add_axes([0.4, 0.15, 0.45, 0.03]) CBar = plt.colorbar(cf, cax=CBAxes, orientation='horizontal', ticks=CBarXTicks) # CBar.set_label('Air potential temperature ($^{\circ}$C)', fontsize=34, labelpad=10, color='dimgrey') CBar.solids.set_edgecolor("face") CBar.outline.set_edgecolor('dimgrey') CBar.ax.tick_params(which='both', axis='both', labelsize=32, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False) CBar.outline.set_linewidth(2) plt.subplots_adjust(left = 0.3, right = 0.95, bottom = 0.27, top = 0.97) plt.savefig('/users/ellgil82/figures/Wintertime melt/Re-runs/transects_theta_u_wind_'+case_study+'_'+res_str+'.png') plt.savefig('/users/ellgil82/figures/Wintertime melt/Re-runs/transects_theta_u_wind_'+case_study+'_'+res_str+'.eps') plt.show()
def correlation_maps(year_list, xvar, yvar): if len(year_list) > 1: fig, ax = plt.subplots(7, 3, figsize=(8, 18)) CbAx = fig.add_axes([0.25, 0.1, 0.5, 0.02]) ax = ax.flatten() comp_r = np.zeros((220, 220)) plot = 0 for year in year_list: vars_yr = load_vars(year) ax[plot].axis('off') r, r2, p, err, xmasked, y_masked, Larsen_mask = run_corr(vars_yr, xvar = xvar, yvar = yvar[:58444]) if np.mean(r) < 0: squished_cmap = shiftedColorMap(cmap=matplotlib.cm.bone_r, min_val=-1., max_val=0., name='squished_cmap', var=r, start=0.25, stop=0.75) c = ax[plot].pcolormesh(r, cmap=matplotlib.cm.Spectral, vmin=-1., vmax=0.) elif np.mean(r) > 0: squished_cmap = shiftedColorMap(cmap = matplotlib.cm.gist_heat_r, min_val = 0, max_val = 1, name = 'squished_cmap', var = r, start = 0.25, stop = 0.75) c = ax[plot].pcolormesh(r, cmap = matplotlib.cm.Spectral, vmin = 0., vmax = 1.) ax[plot].contour(vars_yr['lsm'].data, colors='#222222', lw=2) ax[plot].contour(vars_yr['orog'].data, colors='#222222', levels=[100]) comp_r = comp_r + r ax[plot].text(0.4, 1.1, s=year_list[plot], fontsize=24, color='dimgrey', transform=ax[plot].transAxes) unmasked_idx = np.where(y_masked.mask[0,:,:] == 0) sig = np.ma.masked_array(p, mask = y_masked[0,:,:].mask) sig = np.ma.masked_greater(sig, 0.01) ax[plot].contourf(sig, hatches = '...') plot = plot + 1 mean_r_composite = comp_r / len(year_list) ax[-1].contour(vars_yr['lsm'].data, colors='#222222', lw=2) if np.mean(mean_r_composite) < 0: squished_cmap = shiftedColorMap(cmap=matplotlib.cm.bone_r, min_val=-1., max_val=0., name='squished_cmap', var=mean_r_composite, start=0.25, stop=0.75) c = ax[-1].pcolormesh(mean_r_composite, cmap=squished_cmap, vmin=-1., vmax=0.) elif np.mean(r) > 0: squished_cmap = shiftedColorMap(cmap=matplotlib.cm.gist_heat_r, min_val=0, max_val=1, name='squished_cmap', var=mean_r_composite, start=0.25, stop=0.75) c = ax[-1].pcolormesh(r, cmap=squished_cmap, vmin=0., vmax=1.) ax[-1].contour(vars_yr['orog'].data, colors='#222222', levels=[100]) ax[-1].text(0., 1.1, s='Composite', fontsize=24, color='dimgrey', transform=ax[-1].transAxes) cb = plt.colorbar(c, orientation='horizontal', cax=CbAx, ticks=[0, 0.5, 1]) cb.solids.set_edgecolor("face") cb.outline.set_edgecolor('dimgrey') cb.ax.tick_params(which='both', axis='both', labelsize=24, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False) cb.outline.set_linewidth(2) cb.ax.xaxis.set_ticks_position('bottom') # cb.ax.set_xticks([0,4,8]) cb.set_label('Correlation coefficient', fontsize=24, color='dimgrey', labelpad=30) plt.subplots_adjust(left=0.05, right=0.95, top=0.95, bottom=0.15, hspace=0.3, wspace=0.05) if host == 'bsl': plt.savefig('/users/ellgil82/figures/Hindcast/SMB/'+ xvar + '_v_' + yvar + '_all_years.png', transparent=True) plt.savefig('/users/ellgil82/figures/Hindcast/SMB/'+ xvar + '_v_' + yvar + '_all_years.eps', transparent=True) elif host == 'jasmin': plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/Drivers/'+ xvar + '_v_' + yvar + '_all_years.png', transparent=True) plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/Drivers/'+ xvar + '_v_' + yvar + '_all_years.eps', transparent=True) # Save composite separately elif len(year_list) == 1: r, r2, p, err, xmasked, y_masked, Larsen_mask = run_corr(surf, xvar=xvar, yvar=yvar) unmasked_idx = np.where(y_masked.mask[0, :, :] == 0) sig = np.ma.masked_array(p, mask=y_masked[0, :, :].mask) sig = np.ma.masked_greater(sig, 0.01) mean_r_composite = r fig, ax = plt.subplots(figsize=(8, 8)) ax.axis('off') # Make masked areas white, instead of colour used for zero in colour map ax.contourf(y_masked.mask[0, :, :], cmap='Greys_r') # Plot coastline ax.contour(surf['lsm'].data, colors='#222222', lw=2) # Plot correlations c = ax.pcolormesh(np.ma.masked_where((y_masked.mask[0, :, :] == 1.), mean_r_composite), cmap=matplotlib.cm.Spectral_r)#, vmin=-1, vmax=1) # Plot 50 m orography contour on top ax.contour(surf['orog'].data, colors='#222222', levels=[100]) # Overlay stippling to indicate signficance ax.contourf(sig, hatches='...', alpha = 0.0) # Set up colourbar cb = plt.colorbar(c, orientation='horizontal')#, ticks=[-1, 0, 1]) cb.solids.set_edgecolor("face") cb.outline.set_edgecolor('dimgrey') cb.ax.tick_params(which='both', axis='both', labelsize=24, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False) cb.outline.set_linewidth(2) cb.ax.xaxis.set_ticks_position('bottom') cb.set_label('Correlation coefficient', fontsize=24, color='dimgrey', labelpad=30) # Save figure if host == 'bsl': plt.savefig('/users/ellgil82/figures/Hindcast/SMB/' + xvar + '_v_' + yvar + '_composite.png', transparent=True) plt.savefig('/users/ellgil82/figures/Hindcast/SMB/' + xvar + '_v_' + yvar + '_composite.eps', transparent=True) elif host == 'jasmin': plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/Drivers/' + xvar + '_v_' + yvar + '_composite.png',transparent=True) plt.savefig('/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/Drivers/' + xvar + '_v_' + yvar + '_composite.eps',transparent=True)
def plot_foehn_index(subplot): Larsen_box = np.zeros((220, 220)) Larsen_box[40:135, 90:155] = 1. if subplot == False or subplot == 'no': fig = plt.figure(frameon=False, figsize=( 8, 8 )) # !!change figure dimensions when you have a larger model domain fig.patch.set_visible(False) ax = fig.add_subplot(111) #, projection=ccrs.PlateCarree()) plt.axis = 'off' #cf_var = np.nanmean(surf['foehn_idx'].data, axis = 0) ax.text(0., 1.1, zorder=6, transform=ax.transAxes, s='e', fontsize=36, fontweight='bold', color='dimgrey') ax.text(0.4, 1.1, transform=ax.transAxes, s='ANN', fontsize=30, fontweight='bold', color='dimgrey') cf_var = mn_foehn plt.setp(ax.spines.values(), linewidth=0, color='dimgrey') PlotLonMin = np.min(real_lon) PlotLonMax = np.max(real_lon) PlotLatMin = np.min(real_lat) PlotLatMax = np.max(real_lat) XTicks = np.linspace(PlotLonMin, PlotLonMax, 3) XTickLabels = [None] * len(XTicks) for i, XTick in enumerate(XTicks): if XTick < 0: XTickLabels[i] = '{:.0f}{:s}'.format(np.abs(XTick), '$^{\circ}$W') else: XTickLabels[i] = '{:.0f}{:s}'.format(np.abs(XTick), '$^{\circ}$E') # plt.xticks(XTicks, XTickLabels) ax.set_xlim(PlotLonMin, PlotLonMax) ax.tick_params(which='both', pad=10, labelsize=34, color='dimgrey') YTicks = np.linspace(PlotLatMin, PlotLatMax, 3) YTickLabels = [None] * len(YTicks) for i, YTick in enumerate(YTicks): if YTick < 0: YTickLabels[i] = '{:.0f}{:s}'.format(np.abs(YTick), '$^{\circ}$S') else: YTickLabels[i] = '{:.0f}{:s}'.format(np.abs(YTick), '$^{\circ}$N') plt.yticks(YTicks, YTickLabels) ax.set_ylim(PlotLatMin, PlotLatMax) ax.tick_params(which='both', axis='both', labelsize=34, labelcolor='dimgrey', pad=30, size=0, tick1On=False, tick2On=False) bwr_zero = shiftedColorMap(cmap=matplotlib.cm.bwr, min_val=-0.25, max_val=0.25, name='bwr_zero', var=cf_var.data, start=0.15, stop=0.85) #-6, 3 xlon, ylat = np.meshgrid(real_lon, real_lat) c = ax.pcolormesh(xlon, ylat, np.ma.masked_where((Larsen_box == 0.), cf_var), cmap='Spectral_r', vmin=-.25, vmax=.25) #ax.contour(xlon, ylat, shaded, levels= [1.], colors='dimgrey', linewidths = 4, latlon=True) #ax.text(0., 1.1, zorder=6, transform=ax.transAxes, s='b', fontsize=32, fontweight='bold', color='dimgrey') coast = ax.contour(xlon, ylat, surf['lsm'].data, levels=[0], colors='#222222', lw=2, latlon=True, zorder=2) topog = ax.contour(xlon, ylat, surf['orog'].data, levels=[50], colors='#222222', linewidth=1.5, latlon=True, zorder=3) elif subplot == True or subplot == 'yes': fig, axs = plt.subplots(2, 2, frameon=False, figsize=( 15, 17 )) # !!change figure dimensions when you have a larger model domain fig.patch.set_visible(False) axs = axs.flatten() lab_dict = { 0: ('a', 'DJF'), 1: ('b', 'MAM'), 2: ('c', 'JJA'), 3: ('d', 'SON') } plot = 0 vars = [ np.nanmean(DJF_FI.data, axis=0), np.nanmean(MAM_FI.data, axis=0), np.nanmean(JJA_FI.data, axis=0), np.nanmean(SON_FI.data, axis=0) ] for ax in axs: plt.sca(ax) cf_var = vars[plot] plt.axis = 'off' plt.setp(ax.spines.values(), linewidth=0, color='dimgrey') PlotLonMin = np.min(real_lon) PlotLonMax = np.max(real_lon) PlotLatMin = np.min(real_lat) PlotLatMax = np.max(real_lat) XTicks = np.linspace(PlotLonMin, PlotLonMax, 3) XTickLabels = [None] * len(XTicks) for i, XTick in enumerate(XTicks): if XTick < 0: XTickLabels[i] = '{:.0f}{:s}'.format( np.abs(XTick), '$^{\circ}$W') else: XTickLabels[i] = '{:.0f}{:s}'.format( np.abs(XTick), '$^{\circ}$E') # plt.xticks(XTicks, XTickLabels) ax.set_xlim(PlotLonMin, PlotLonMax) ax.tick_params(which='both', pad=10, labelsize=34, color='dimgrey') YTicks = np.linspace(PlotLatMin, PlotLatMax, 3) YTickLabels = [None] * len(YTicks) for i, YTick in enumerate(YTicks): if YTick < 0: YTickLabels[i] = '{:.0f}{:s}'.format( np.abs(YTick), '$^{\circ}$S') else: YTickLabels[i] = '{:.0f}{:s}'.format( np.abs(YTick), '$^{\circ}$N') plt.yticks(YTicks, YTickLabels) ax.set_ylim(PlotLatMin, PlotLatMax) ax.tick_params(which='both', axis='both', labelsize=34, labelcolor='dimgrey', pad=30, size=0, tick1On=False, tick2On=False) bwr_zero = shiftedColorMap(cmap=matplotlib.cm.bwr, min_val=-.25, max_val=.25, name='bwr_zero', var=cf_var.data, start=0.15, stop=0.85) #-6, 3 xlon, ylat = np.meshgrid(real_lon, real_lat) c = ax.pcolormesh(xlon, ylat, np.ma.masked_where((Larsen_box == 0.), cf_var), cmap='Spectral_r', vmin=-.25, vmax=.25) #ax.contour(xlon, ylat, shaded, levels= [1.], colors='dimgrey', linewidths = 4, latlon=True) ax.text(0., 1.1, zorder=6, transform=ax.transAxes, s=lab_dict[plot][0], fontsize=32, fontweight='bold', color='dimgrey') ax.text(0.4, 1.1, transform=ax.transAxes, s=lab_dict[plot][1], fontsize=28, fontweight='bold', color='dimgrey') coast = ax.contour(xlon, ylat, surf['lsm'].data, levels=[0], colors='#222222', lw=2, latlon=True, zorder=2) topog = ax.contour(xlon, ylat, surf['orog'].data, levels=[50], colors='#222222', linewidth=1.5, latlon=True, zorder=3) plot = plot + 1 CBarXTicks = [ -.25, 0, .25 ] # CLevs[np.arange(0,len(CLevs),int(np.ceil(len(CLevs)/5.)))] CBAxes = fig.add_axes([0.35, 0.18, 0.4, 0.02]) CBar = plt.colorbar(c, cax=CBAxes, orientation='horizontal', ticks=CBarXTicks, extend='both') # CBar.set_label('Mean foehn index \n(dimensionless)', fontsize=34, labelpad=10, color='dimgrey') CBar.solids.set_edgecolor("face") CBar.outline.set_edgecolor('dimgrey') CBar.ax.tick_params(which='both', axis='both', labelsize=34, labelcolor='dimgrey', pad=10, size=0, tick1On=False, tick2On=False) CBar.outline.set_linewidth(2) plt.subplots_adjust(left=0.2, bottom=0.3, wspace=0.35, hspace=0.35, right=0.85) if subplot == True or subplot == 'yes': plt.savefig( '/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/Mean_foehn_index_seas.png', transparent=True) plt.savefig( '/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/Mean_foehn_index_seas.eps', transparent=True) else: plt.savefig( '/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/Mean_foehn_index.png', transparent=True) plt.savefig( '/gws/nopw/j04/bas_climate/users/ellgil82/hindcast/figures/Mean_foehn_index.eps', transparent=True) plt.show()