def plot_mask(gridid, Cpos='rho', proj=None, **kwargs): # get grid if type(gridid).__name__ == 'ROMS_Grid': grd = gridid else: grd = pyroms.grid.get_ROMS_grid(gridid) Cpos = str(Cpos) print(Cpos) # get grid information if Cpos == 'rho': lon = grd.hgrid.lon_vert lat = grd.hgrid.lat_vert mask = grd.hgrid.mask_rho elif Cpos == 'u': lon = 0.5 * (grd.hgrid.lon_vert[:,:-1] + grd.hgrid.lon_vert[:,1:]) lat = 0.5 * (grd.hgrid.lat_vert[:,:-1] + grd.hgrid.lat_vert[:,1:]) mask = grd.hgrid.mask_u elif Cpos == 'v': lon = 0.5 * (grd.hgrid.lon_vert[:-1,:] + grd.hgrid.lon_vert[1:,:]) lat = 0.5 * (grd.hgrid.lat_vert[:-1,:] + grd.hgrid.lat_vert[1:,:]) mask = grd.hgrid.mask_v else: raise Warning('Cpos must be rho, u or v') # defined color map land_color = kwargs.pop('land_color', (0.6, 1.0, 0.6)) sea_color = kwargs.pop('sea_color', (0.6, 0.6, 1.0)) cm = plt.matplotlib.colors.ListedColormap([land_color, sea_color], name='land/sea') if proj is None: plt.pcolor(lon, lat, mask, cmap=cm, vmin=0, vmax=1, \ edgecolor='k', **kwargs) pyroms_toolbox.plot_coast_line(grd) else: x, y = proj(lon, lat) Basemap.pcolor(proj, x, y, mask, cmap=cm, vmin=0, vmax=1, \ edgecolor='k', **kwargs) pyroms_toolbox.plot_coast_line(grd, proj=proj) lon_min = lon.min() lon_max = lon.max() lat_min = lat.min() lat_max = lat.max() proj.drawmeridians(np.arange(lon_min,lon_max,(lon_max-lon_min)/5.001), \ labels=[0,0,0,1], fmt='%.1f') proj.drawparallels(np.arange(lat_min,lat_max,(lat_max-lat_min)/5.001), \ labels=[1,0,0,0], fmt='%.1f')
def plot_mask(gridid, Cpos='rho', proj=None, **kwargs): # get grid if type(gridid).__name__ == 'ROMS_Grid': grd = gridid else: grd = pyroms.grid.get_ROMS_grid(gridid) Cpos = str(Cpos) print Cpos # get grid information if Cpos == 'rho': lon = grd.hgrid.lon_vert lat = grd.hgrid.lat_vert mask = grd.hgrid.mask_rho elif Cpos == 'u': lon = 0.5 * (grd.hgrid.lon_vert[:,:-1] + grd.hgrid.lon_vert[:,1:]) lat = 0.5 * (grd.hgrid.lat_vert[:,:-1] + grd.hgrid.lat_vert[:,1:]) mask = grd.hgrid.mask_u elif Cpos == 'v': lon = 0.5 * (grd.hgrid.lon_vert[:-1,:] + grd.hgrid.lon_vert[1:,:]) lat = 0.5 * (grd.hgrid.lat_vert[:-1,:] + grd.hgrid.lat_vert[1:,:]) mask = grd.hgrid.mask_v else: raise Warning, 'Cpos must be rho, u or v' # defined color map land_color = kwargs.pop('land_color', (0.6, 1.0, 0.6)) sea_color = kwargs.pop('sea_color', (0.6, 0.6, 1.0)) cm = plt.matplotlib.colors.ListedColormap([land_color, sea_color], name='land/sea') if proj is None: plt.pcolor(lon, lat, mask, cmap=cm, vmin=0, vmax=1, \ edgecolor='k', **kwargs) pyroms_toolbox.plot_coast_line(grd) else: x, y = proj(lon, lat) Basemap.pcolor(proj, x, y, mask, cmap=cm, vmin=0, vmax=1, \ edgecolor='k', **kwargs) pyroms_toolbox.plot_coast_line(grd, proj=proj) lon_min = lon.min() lon_max = lon.max() lat_min = lat.min() lat_max = lat.max() proj.drawmeridians(np.arange(lon_min,lon_max,(lon_max-lon_min)/5.001), \ labels=[0,0,0,1], fmt='%.1f') proj.drawparallels(np.arange(lat_min,lat_max,(lat_max-lat_min)/5.001), \ labels=[1,0,0,0], fmt='%.1f')
def create_monthly_mean_plot(data_array, plot_date, parameter): grd = pyroms.grid.get_ROMS_grid('NWA') lon = grd.hgrid.lon_rho lat = grd.hgrid.lat_rho plt.figure() # plt.pcolor(lon, lat, daily_o2[0], vmin=bottom_min, vmax=bottom_max) plt.pcolor(lon, lat, data_array, cmap='RdYlGn') plt.colorbar() plt.axis('image') plt.title('{0} for {1}'.format(parameter, plot_date)) # Plot coastline pyroms_toolbox.plot_coast_line(grd) # Save plot outfile = '/Users/jeewantha/Code/images/monthly_means/{0}_bottom_ver_1.png'.format( parameter) plt.savefig(outfile, dpi=300, orientation='portrait') plt.close() return True
def mean_o2(): filepath_1 = '/Volumes/P10/ROMS/NWA/NWA-SZ.HCob05T/1980/NWA-SZ.HCob05T_avg_1980-06-18T01:00:00.nc' filepath_2 = '/Volumes/P10/ROMS/NWA/NWA-SZ.HCob05T/1980/NWA-SZ.HCob05T_avg_1980-06-19T01:00:00.nc' o2_day_i = pyroms.utility.get_nc_var('o2', filepath_1)[0] o2_day_ii = pyroms.utility.get_nc_var('o2', filepath_2)[0] # How to access the layers -> o2_day_i[0] is the bottom, [-1] is the surface # np.mean( np.array([ old_set, new_set ]), axis=0 ) # Remember that these are Masked Arrays o2_mean = np.mean(ma.array([o2_day_i, o2_day_ii]), axis=0) grd = pyroms.grid.get_ROMS_grid('NWA') lon = grd.hgrid.lon_rho lat = grd.hgrid.lat_rho # Plot 2-D view of [O2] at the bottom plt.figure() plt.pcolor(lon, lat, o2_mean[-1]) plt.colorbar() plt.axis('image') # Plot coastline pyroms_toolbox.plot_coast_line(grd) # Save plot outfile = 'o2_mean_surface.png' plt.savefig(outfile, dpi=300, orientation='portrait') # Plot single plt.figure() plt.pcolor(lon, lat, o2_day_ii[-1]) plt.colorbar() plt.axis('image') # Plot coastline pyroms_toolbox.plot_coast_line(grd) # Save plot outfile = 'o2_surface_06_19.png' plt.savefig(outfile, dpi=300, orientation='portrait')
def zview(var, tindex, depth, grid, filename=None, \ cmin=None, cmax=None, clev=None, clb_format='%.2f', \ fill=False, contour=False, d=4, range=None, fts=None, \ title=None, clb=True, pal=None, proj='merc', \ fill_land=False, outfile=None): """ map = zview(var, tindex, depth, grid, {optional switch}) optional switch: - filename if defined, load the variable from file - cmin set color minimum limit - cmax set color maximum limit - clev set the number of color step - fill use contourf instead of pcolor - contour overlay contour (request fill=True) - range set axis limit - fts set font size (default: 12) - title add title to the plot - clb add colorbar (defaul: True) - pal set color map (default: cm.jet) - proj set projection type (default: merc) - fill_land fill land masked area with gray (defaul: True) - outfile if defined, write figure to file plot a constant-z slice of variable var. If filename is provided, var must be a string and the variable will be load from the file. grid can be a grid object or a gridid. In the later case, the grid object correponding to the provided gridid will be loaded. If proj is not None, return a Basemap object to be used with quiver for example. """ # get grid if type(grid).__name__ == 'ROMS_Grid': grd = grid else: grd = pyroms.grid.get_ROMS_grid(grid) # get variable if filename == None: var = var else: data = pyroms.io.Dataset(filename) var = data.variables[var] Np, Mp, Lp = grd.vgrid.z_r[0,:].shape if tindex is not -1: assert len(var.shape) == 4, 'var must be 4D (time plus space).' K, N, M, L = var.shape else: assert len(var.shape) == 3, 'var must be 3D (no time dependency).' N, M, L = var.shape # determine where on the C-grid these variable lies if N == Np and M == Mp and L == Lp: Cpos='rho' mask = grd.hgrid.mask_rho if N == Np and M == Mp and L == Lp-1: Cpos='u' mask = grd.hgrid.mask_u if N == Np and M == Mp-1 and L == Lp: Cpos='v' mask = grd.hgrid.mask_v # get constante-z slice if tindex == -1: var = var[:,:,:] else: var = var[tindex,:,:,:] depth = -abs(depth) if fill == True: zslice, lon, lat = pyroms.tools.zslice(var, depth, grd, \ Cpos=Cpos) else: zslice, lon, lat = pyroms.tools.zslice(var, depth, grd, \ Cpos=Cpos, vert=True) # plot if cmin is None: cmin = zslice.min() else: cmin = float(cmin) if cmax is None: cmax = zslice.max() else: cmax = float(cmax) if clev is None: clev = 100. else: clev = float(clev) dc = (cmax - cmin)/clev ; vc = np.arange(cmin,cmax+dc,dc) if pal is None: pal = cm.jet else: pal = pal if fts is None: fts = 12 else: fts = fts #pal.set_over('w', 1.0) #pal.set_under('w', 1.0) #pal.set_bad('w', 1.0) pal_norm = colors.BoundaryNorm(vc,ncolors=256, clip = False) if range is None: lon_min = lon.min() lon_max = lon.max() lon_0 = (lon_min + lon_max) / 2. lat_min = lat.min() lat_max = lat.max() lat_0 = (lat_min + lat_max) / 2. else: lon_min = range[0] lon_max = range[1] lon_0 = (lon_min + lon_max) / 2. lat_min = range[2] lat_max = range[3] lat_0 = (lat_min + lat_max) / 2. # clear figure #plt.clf() if proj is not None: map = Basemap(projection=proj, llcrnrlon=lon_min, llcrnrlat=lat_min, \ urcrnrlon=lon_max, urcrnrlat=lat_max, lat_0=lat_0, lon_0=lon_0, \ resolution='h', area_thresh=5.) #map = pyroms.utility.get_grid_proj(grd, type=proj) x, y = map(lon,lat) if fill_land is True and proj is not None: # fill land and draw coastlines map.drawcoastlines() map.fillcontinents(color='grey') else: if proj is not None: Basemap.pcolor(map, x, y, mask, vmin=-2, cmap=cm.gray) pyroms_toolbox.plot_coast_line(grd, map) else: plt.pcolor(lon, lat, mask, vmin=-2, cmap=cm.gray) pyroms_toolbox.plot_coast_line(grd) if fill is True: if proj is not None: cf = Basemap.contourf(map, x, y, zslice, vc, cmap = pal, \ norm = pal_norm) else: cf = plt.contourf(lon, lat, zslice, vc, cmap = pal, \ norm = pal_norm) else: if proj is not None: cf = Basemap.pcolor(map, x, y, zslice, cmap = pal, norm = pal_norm) else: cf = plt.pcolor(lon, lat, zslice, cmap = pal, norm = pal_norm) if clb is True: clb = plt.colorbar(cf, fraction=0.075,format=clb_format) for t in clb.ax.get_yticklabels(): t.set_fontsize(fts) if contour is True: if fill is not True: raise Warning, 'Please run again with fill=True to overlay contour.' else: if proj is not None: Basemap.contour(map, x, y, zslice, vc[::d], colors='k', linewidths=0.5, linestyles='solid') else: plt.contour(lon, lat, zslice, vc[::d], colors='k', linewidths=0.5, linestyles='solid') if proj is None and range is not None: plt.axis(range) if title is not None: plt.title(title, fontsize=fts+4) if proj is not None: map.drawmeridians(np.arange(lon_min,lon_max, (lon_max-lon_min)/5.001), \ labels=[0,0,0,1], fmt='%.1f') map.drawparallels(np.arange(lat_min,lat_max, (lat_max-lat_min)/5.001), \ labels=[1,0,0,0], fmt='%.1f') if outfile is not None: if outfile.find('.png') != -1 or outfile.find('.svg') != -1 or \ outfile.find('.eps') != -1: print 'Write figure to file', outfile plt.savefig(outfile, dpi=200, facecolor='w', edgecolor='w', \ orientation='portrait') else: print 'Unrecognized file extension. Please use .png, .svg or .eps file extension.' if proj is None: return else: return map
def isoview(var, prop, tindex, isoval, grid, filename=None, \ cmin=None, cmax=None, clev=None, fill=False, \ contour=False, d=4, range=None, fts=None, \ title=None, clb=True, pal=None, proj='merc', \ fill_land=False, outfile=None): """ map = isoview(var, prop, tindex, isoval, grid, {optional switch}) optional switch: - filename if defined, load the variable from file - cmin set color minimum limit - cmax set color maximum limit - clev set the number of color step - fill use contourf instead of pcolor - contour overlay contour (request fill=True) - d contour density (default d=4) - range set axis limit - fts set font size (default: 12) - title add title to the plot - clb add colorbar (defaul: True) - pal set color map (default: cm.jet) - proj set projection type (default: merc) - fill_land fill land masked area with gray (defaul: True) - outfile if defined, write figure to file plot a projection of variable at property == isoval. If filename is provided, var and prop must be a strings and the variables will be load from the file. grid can be a grid object or a gridid. In the later case, the grid object correponding to the provided gridid will be loaded. If proj is not None, return a Basemap object to be used with quiver for example. """ # get grid if type(grid).__name__ == 'ROMS_Grid': grd = grid else: grd = pyroms.grid.get_ROMS_grid(grid) # get variable if filename == None: var = var prop = prop else: data = pyroms.io.Dataset(filename) var = data.variables[var] prop = data.variables[prop] Np, Mp, Lp = grd.vgrid.z_r[0, :].shape if tindex is not -1: assert len(var.shape) == 4, 'var must be 4D (time plus space).' K, N, M, L = var.shape else: assert len(var.shape) == 3, 'var must be 3D (no time dependency).' N, M, L = var.shape # determine where on the C-grid these variable lies if N == Np and M == Mp and L == Lp: Cpos = 'rho' mask = grd.hgrid.mask_rho if N == Np and M == Mp and L == Lp - 1: Cpos = 'u' mask = grd.hgrid.mask_u if N == Np and M == Mp - 1 and L == Lp: Cpos = 'v' mask = grd.hgrid.mask_v # get constante-iso slice if tindex == -1: var = var[:, :, :] prop = prop[:, :, :] else: var = var[tindex, :, :, :] prop = prop[tindex, :, :, :] if fill == True: isoslice, lon, lat = pyroms.tools.isoslice(var, prop, isoval, \ grd, Cpos=Cpos) else: isoslice, lon, lat = pyroms.tools.isoslice(var, prop, isoval, \ grd, Cpos=Cpos, vert=True) # plot if cmin is None: cmin = isoslice.min() else: cmin = float(cmin) if cmax is None: cmax = isoslice.max() else: cmax = float(cmax) if clev is None: clev = 100. else: clev = float(clev) dc = (cmax - cmin) / clev vc = np.arange(cmin, cmax + dc, dc) if pal is None: pal = cm.jet else: pal = pal if fts is None: fts = 12 else: fts = fts #pal.set_over('w', 1.0) #pal.set_under('w', 1.0) #pal.set_bad('w', 1.0) pal_norm = colors.BoundaryNorm(vc, ncolors=256, clip=False) if range is None: lon_min = lon.min() lon_max = lon.max() lon_0 = (lon_min + lon_max) / 2. lat_min = lat.min() lat_max = lat.max() lat_0 = (lat_min + lat_max) / 2. else: lon_min = range[0] lon_max = range[1] lon_0 = (lon_min + lon_max) / 2. lat_min = range[2] lat_max = range[3] lat_0 = (lat_min + lat_max) / 2. # clear figure #plt.clf() if proj is not None: map = Basemap(projection=proj, llcrnrlon=lon_min, llcrnrlat=lat_min, \ urcrnrlon=lon_max, urcrnrlat=lat_max, lat_0=lat_0, lon_0=lon_0, \ resolution='h', area_thresh=5.) #map = pyroms.utility.get_grid_proj(grd, type=proj) x, y = list(map(lon, lat)) if fill_land is True and proj is not None: # fill land and draw coastlines map.drawcoastlines() map.fillcontinents(color='grey') else: if proj is not None: Basemap.pcolor(map, x, y, mask, vmin=-2, cmap=cm.gray) pyroms_toolbox.plot_coast_line(grd, map) else: plt.pcolor(lon, lat, mask, vmin=-2, cmap=cm.gray) pyroms_toolbox.plot_coast_line(grd) if fill is True: if proj is not None: cf = Basemap.contourf(map, x, y, isoslice, vc, cmap = pal, \ norm = pal_norm) else: cf = plt.contourf(lon, lat, isoslice, vc, cmap = pal, \ norm = pal_norm) else: if proj is not None: cf = Basemap.pcolor(map, x, y, isoslice, cmap=pal, norm=pal_norm) else: cf = plt.pcolor(lon, lat, isoslice, cmap=pal, norm=pal_norm) if clb is True: clb = plt.colorbar(cf, fraction=0.075, format='%.2f') for t in clb.ax.get_yticklabels(): t.set_fontsize(fts) if contour is True: if fill is not True: raise Warning( 'Please run again with fill=True to overlay contour.') else: if proj is not None: Basemap.contour(map, x, y, isoslice, vc[::d], colors='k', linewidths=0.5, linestyles='solid') else: plt.contour(lon, lat, isoslice, vc[::d], colors='k', linewidths=0.5, linestyles='solid') if proj is None and range is not None: plt.axis(range) if title is not None: plt.title(title, fontsize=fts + 4) if proj is not None: map.drawmeridians(np.arange(lon_min,lon_max, (lon_max-lon_min)/5.), \ labels=[0,0,0,1], fmt='%.1f') map.drawparallels(np.arange(lat_min,lat_max, (lat_max-lat_min)/5.), \ labels=[1,0,0,0], fmt='%.1f') if outfile is not None: if outfile.find('.png') != -1 or outfile.find('.svg') != -1 or \ outfile.find('.eps') != -1: print('Write figure to file', outfile) plt.savefig(outfile, dpi=200, facecolor='w', edgecolor='w', \ orientation='portrait') else: print( 'Unrecognized file extension. Please use .png, .svg or .eps file extension.' ) if proj is None: return else: return map
# print(np.max(daily_o2[-1])) surface_min_list.append(np.min(daily_o2[-1])) bottom_max_list.append(np.max(daily_o2[0])) bottom_min_list.append(np.min(daily_o2[0])) print("Surface Max: {0} mol/kg".format(max(surface_max_list))) print("Surface Min: {0} mol/kg".format(min(surface_min_list))) print("Bottom Max: {0} mol/kg".format(max(bottom_max_list))) print("Bottom Min: {0} mol/kg".format(min(bottom_min_list))) surface_max = max(surface_max_list) surface_min = min(surface_min_list) bottom_max = max(bottom_max_list) bottom_min = min(bottom_min_list) # Plot everything i = 1 for daily_file in june_list: daily_o2 = pyroms.utility.get_nc_var('o2', daily_file)[0] plt.figure() # plt.pcolor(lon, lat, daily_o2[0], vmin=bottom_min, vmax=bottom_max) plt.pcolor(lon, lat, daily_o2[-1], vmin=surface_min, vmax=surface_max, cmap='RdYlGn') plt.colorbar() plt.axis('image') plt.title('{0}'.format(i)) # Plot coastline pyroms_toolbox.plot_coast_line(grd) # Save plot outfile = '/Users/jeewantha/Code/images/1982_06/o2_surface_{0:03d}.png'.format(i) plt.savefig(outfile, dpi=300, orientation='portrait') plt.close() i = i + 1
def twoDview( var, tindex, grid, filename=None, cmin=None, cmax=None, clev=None, fill=False, contour=False, d=4, range=None, fts=None, title=None, clb=True, pal=None, proj="merc", fill_land=False, outfile=None, ): """ map = twoDview(var, tindex, grid, {optional switch}) optional switch: - filename if defined, load the variable from file - cmin set color minimum limit - cmax set color maximum limit - clev set the number of color step - fill use contourf instead of pcolor - contour overlay contour (request fill=True) - d contour density (default d=4) - range set axis limit - fts set font size (default: 12) - title add title to the plot - clb add colorbar (defaul: True) - pal set color map (default: cm.jet) - proj set projection type (default: merc) - fill_land fill land masked area with gray (defaul: True) - outfile if defined, write figure to file plot 2-dimensions variable var. If filename is provided, var must be a string and the variable will be load from the file. grid can be a grid object or a gridid. In the later case, the grid object correponding to the provided gridid will be loaded. If proj is not None, return a Basemap object to be used with quiver for example. """ # get grid if type(grid).__name__ == "ROMS_Grid": grd = grid else: grd = pyroms.grid.get_ROMS_grid(grid) # get variable if filename == None: var = var else: data = pyroms.io.Dataset(filename) var = data.variables[var] Np, Mp, Lp = grd.vgrid.z_r[0, :].shape if tindex is not -1: assert len(var.shape) == 3, "var must be 3D (time plus space)." K, M, L = var.shape else: assert len(var.shape) == 2, "var must be 2D (no time dependency)." M, L = var.shape # determine where on the C-grid these variable lies if M == Mp and L == Lp: Cpos = "rho" if fill == True: lon = grd.hgrid.lon_rho lat = grd.hgrid.lat_rho else: lon = grd.hgrid.lon_vert lat = grd.hgrid.lat_vert mask = grd.hgrid.mask_rho if M == Mp and L == Lp - 1: Cpos = "u" if fill == True: lon = grd.hgrid.lon_u lat = grd.hgrid.lat_u else: lon = 0.5 * (grd.hgrid.lon_vert[:, :-1] + grd.hgrid.lon_vert[:, 1:]) lat = 0.5 * (grd.hgrid.lat_vert[:, :-1] + grd.hgrid.lat_vert[:, 1:]) mask = grd.hgrid.mask_u if M == Mp - 1 and L == Lp: Cpos = "v" if fill == True: lon = grd.hgrid.lon_v lat = grd.hgrid.lat_v else: lon = 0.5 * (grd.hgrid.lon_vert[:-1, :] + grd.hgrid.lon_vert[1:, :]) lat = 0.5 * (grd.hgrid.lat_vert[:-1, :] + grd.hgrid.lat_vert[1:, :]) mask = grd.hgrid.mask_v # get 2D var if tindex == -1: var = var[:, :] else: var = var[tindex, :, :] # mask var = np.ma.masked_where(mask == 0, var) # plot if cmin is None: cmin = var.min() else: cmin = float(cmin) if cmax is None: cmax = var.max() else: cmax = float(cmax) if clev is None: clev = 100.0 else: clev = float(clev) dc = (cmax - cmin) / clev vc = np.arange(cmin, cmax + dc, dc) if pal is None: pal = cm.jet else: pal = pal if fts is None: fts = 12 else: fts = fts # pal.set_over('w', 1.0) # pal.set_under('w', 1.0) # pal.set_bad('w', 1.0) pal_norm = colors.BoundaryNorm(vc, ncolors=256, clip=False) if range is None: lon_min = lon.min() lon_max = lon.max() lon_0 = (lon_min + lon_max) / 2.0 lat_min = lat.min() lat_max = lat.max() lat_0 = (lat_min + lat_max) / 2.0 else: lon_min = range[0] lon_max = range[1] lon_0 = (lon_min + lon_max) / 2.0 lat_min = range[2] lat_max = range[3] lat_0 = (lat_min + lat_max) / 2.0 # clear figure # plt.clf() if proj is not None: map = Basemap( projection=proj, llcrnrlon=lon_min, llcrnrlat=lat_min, urcrnrlon=lon_max, urcrnrlat=lat_max, lat_0=lat_0, lon_0=lon_0, resolution="h", area_thresh=5.0, ) x, y = map(lon, lat) if fill_land is True and proj is not None: # fill land and draw coastlines map.drawcoastlines() map.fillcontinents(color="grey") else: if proj is not None: Basemap.pcolor(map, x, y, mask, vmin=-2, cmap=cm.gray) pyroms_toolbox.plot_coast_line(grd, map) else: plt.pcolor(lon, lat, mask, vmin=-2, cmap=cm.gray) pyroms_toolbox.plot_coast_line(grd) if fill is True: if proj is not None: cf = Basemap.contourf(map, x, y, var, vc, cmap=pal, norm=pal_norm) else: cf = plt.contourf(lon, lat, var, vc, cmap=pal, norm=pal_norm) else: if proj is not None: cf = Basemap.pcolor(map, x, y, var, cmap=pal, norm=pal_norm) else: cf = plt.pcolor(lon, lat, var, cmap=pal, norm=pal_norm) if clb is True: clb = plt.colorbar(cf, fraction=0.075, format="%.2f") for t in clb.ax.get_yticklabels(): t.set_fontsize(fts) if contour is True: if fill is not True: raise Warning, "Please run again with fill=True to overlay contour." else: if proj is not None: Basemap.contour(map, x, y, var, vc[::d], colors="k", linewidths=0.5, linestyles="solid") else: plt.contour(lon, lat, var, vc[::d], colors="k", linewidths=0.5, linestyles="solid") if proj is None and range is not None: plt.axis(range) if title is not None: plt.title(title, fontsize=fts + 4) if proj is not None: map.drawmeridians(np.arange(lon_min, lon_max, (lon_max - lon_min) / 5.0), labels=[0, 0, 0, 1], fmt="%.1f") map.drawparallels(np.arange(lat_min, lat_max, (lat_max - lat_min) / 5.0), labels=[1, 0, 0, 0], fmt="%.1f") if outfile is not None: if outfile.find(".png") != -1 or outfile.find(".svg") != -1 or outfile.find(".eps") != -1: print "Write figure to file", outfile plt.savefig(outfile, dpi=200, facecolor="w", edgecolor="w", orientation="portrait") else: print "Unrecognized file extension. Please use .png, .svg or .eps file extension." if proj is None: return else: return map