def transport(name, fmod=None, Title=None, dmax=None, N=7, extraname=None, llcrnrlon=-98.5, llcrnrlat=22.5, urcrnrlat=31.0, urcrnrlon=-87.5, colormap='Blues', fig=None, ax=None): ''' Make plot of zoomed-in area near DWH spill of transport of drifters over time. FILL IN Inputs: name U V lon0 lat0 T0 ''' # (name=None, U, V, lon0, lat0, T0, dmax, extraname, Title, N, # llcrnrlon, llcrnrlat, urcrnrlat, urcrnrlon, colormap): # Load in transport information U, V, lon0, lat0, T0 = inout.loadtransport(name, fmod=fmod) # Smaller basemap parameters. loc = 'http://barataria.tamu.edu:8080/thredds/dodsC/NcML/txla_nesting6.nc' grid = inout.readgrid(loc, llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat, urcrnrlat=urcrnrlat, urcrnrlon=urcrnrlon) S = np.sqrt(op.resize(U, 1)**2 + op.resize(V, 0)**2) Splot = (S / T0) * 100 if dmax is None: dmax = Splot.max() else: dmax = dmax # from http://matplotlib.1069221.n5.nabble.com/question-about-contours-and-clim-td21111.html locator = ticker.MaxNLocator(N) # if you want no more than 10 contours locator.create_dummy_axis() locator.set_bounds(0, dmax) #d.min(),d.max()) levs = locator() if fig is None: fig = figure(figsize=(11, 10)) else: fig = fig background(grid=grid) c = contourf(grid['xpsi'], grid['ypsi'], Splot, cmap=colormap, extend='max', levels=levs) title(Title) # # Add initial drifter location (all drifters start at the same location) # lon0 = lon0.mean() # lat0 = lat0.mean() # x0, y0 = grid['basemap'](lon0, lat0) # plot(x0, y0, 'go', markersize=10) if ax is None: ax = gca() else: ax = ax # Want colorbar at the given location relative to axis so this works regardless of # of subplots, # so convert from axis to figure coordinates # To do this, first convert from axis to display coords # transformations: http://matplotlib.org/users/transforms_tutorial.html ax_coords = [0.35, 0.25, 0.6, 0.02] # axis: [x_left, y_bottom, width, height] disp_coords = ax.transAxes.transform([ (ax_coords[0], ax_coords[1]), (ax_coords[0] + ax_coords[2], ax_coords[1] + ax_coords[3]) ]) # display: [x_left,y_bottom,x_right,y_top] inv = fig.transFigure.inverted( ) # inverter object to go from display coords to figure coords fig_coords = inv.transform( disp_coords) # figure: [x_left,y_bottom,x_right,y_top] # actual desired figure coords. figure: [x_left, y_bottom, width, height] fig_coords = [ fig_coords[0, 0], fig_coords[0, 1], fig_coords[1, 0] - fig_coords[0, 0], fig_coords[1, 1] - fig_coords[0, 1] ] # Inlaid colorbar cax = fig.add_axes(fig_coords) # cax = fig.add_axes([0.39, 0.25, 0.49, 0.02]) # cax = fig.add_axes([0.49, 0.25, 0.39, 0.02]) cb = colorbar(cax=cax, orientation='horizontal') cb.set_label('Normalized drifter transport (%)') if extraname is None: savefig('figures/' + name + '/transport', bbox_inches='tight') else: savefig('figures/' + name + '/' + extraname + 'transport', bbox_inches='tight')
def transport(name, fmod=None, Title=None, dmax=None, N=7, extraname=None, llcrnrlon=-98.5, llcrnrlat=22.5, urcrnrlat=31.0, urcrnrlon=-87.5, colormap='Blues'): ''' Make plot of zoomed-in area near DWH spill of transport of drifters over time. FILL IN Inputs: name U V lon0 lat0 T0 ''' # (name=None, U, V, lon0, lat0, T0, dmax, extraname, Title, N, # llcrnrlon, llcrnrlat, urcrnrlat, urcrnrlon, colormap): # Load in transport information U, V, lon0, lat0, T0 = inout.loadtransport(name,fmod=fmod) # Smaller basemap parameters. loc = 'http://barataria.tamu.edu:8080/thredds/dodsC/NcML/txla_nesting6.nc' grid = inout.readgrid(loc, llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat, urcrnrlat=urcrnrlat, urcrnrlon=urcrnrlon) S = np.sqrt(op.resize(U,1)**2+op.resize(V,0)**2) Splot = (S/T0)*100 if dmax is None: dmax = Splot.max() else: dmax = dmax # from http://matplotlib.1069221.n5.nabble.com/question-about-contours-and-clim-td21111.html locator = ticker.MaxNLocator(N) # if you want no more than 10 contours locator.create_dummy_axis() locator.set_bounds(0,dmax)#d.min(),d.max()) levs = locator() fig = figure(figsize=(12,10)) background(grid=grid) c = contourf(grid['xpsi'], grid['ypsi'], Splot, cmap=colormap, extend='max', levels=levs) title(Title) # Add initial drifter location (all drifters start at the same location) lon0 = lon0.mean() lat0 = lat0.mean() x0, y0 = grid['basemap'](lon0, lat0) plot(x0, y0, 'go', markersize=10) # Inlaid colorbar cax = fig.add_axes([0.49, 0.25, 0.39, 0.02]) # cax = fig.add_axes([0.5, 0.2, 0.35, 0.02]) cb = colorbar(cax=cax,orientation='horizontal') cb.set_label('Normalized drifter transport (%)') if extraname is None: savefig('figures/' + name + '/transport', bbox_inches='tight') else: savefig('figures/' + name + '/transport' + extraname, bbox_inches='tight')
def transport( name, fmod=None, Title=None, dmax=None, N=7, extraname=None, llcrnrlon=-98.5, llcrnrlat=22.5, urcrnrlat=31.0, urcrnrlon=-87.5, colormap="Blues", fig=None, ax=None, ): """ Make plot of zoomed-in area near DWH spill of transport of drifters over time. FILL IN Args: name U V lon0 lat0 T0 """ # Load in transport information U, V, lon0, lat0, T0 = inout.loadtransport(name, fmod=fmod) # Smaller basemap parameters. loc = "http://barataria.tamu.edu:8080/thredds/dodsC/NcML/txla_nesting6.nc" grid = inout.readgrid(loc, llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat, urcrnrlat=urcrnrlat, urcrnrlon=urcrnrlon) S = np.sqrt(op.resize(U, 1) ** 2 + op.resize(V, 0) ** 2) Splot = (S / T0) * 100 if dmax is None: dmax = Splot.max() else: dmax = dmax # from http://matplotlib.1069221.n5.nabble.com/question-about-contours-and-clim-td21111.html locator = ticker.MaxNLocator(N) # if you want no more than 10 contours locator.create_dummy_axis() locator.set_bounds(0, dmax) # d.min(),d.max()) levs = locator() if fig is None: fig = plt.figure(figsize=(11, 10)) else: fig = fig background(grid=grid) c = fig.contourf(grid.xpsi, grid.ypsi, Splot, cmap=colormap, extend="max", levels=levs) plt.title(Title) # # Add initial drifter location (all drifters start at the same location) # lon0 = lon0.mean() # lat0 = lat0.mean() # x0, y0 = grid['basemap'](lon0, lat0) # plot(x0, y0, 'go', markersize=10) if ax is None: ax = plt.gca() else: ax = ax # Want colorbar at the given location relative to axis so this works # regardless of # of subplots, # so convert from axis to figure coordinates # To do this, first convert from axis to display coords # transformations: http://matplotlib.org/users/transforms_tutorial.html ax_coords = [0.35, 0.25, 0.6, 0.02] # axis: [x_left, y_bottom, width, height] # display: [x_left,y_bottom,x_right,y_top] disp_coords = ax.transAxes.transform( [(ax_coords[0], ax_coords[1]), (ax_coords[0] + ax_coords[2], ax_coords[1] + ax_coords[3])] ) # inverter object to go from display coords to figure coords inv = fig.transFigure.inverted() # figure: [x_left,y_bottom,x_right,y_top] fig_coords = inv.transform(disp_coords) # actual desired figure coords. figure: [x_left, y_bottom, width, height] fig_coords = [ fig_coords[0, 0], fig_coords[0, 1], fig_coords[1, 0] - fig_coords[0, 0], fig_coords[1, 1] - fig_coords[0, 1], ] # Inlaid colorbar cax = fig.add_axes(fig_coords) # cax = fig.add_axes([0.39, 0.25, 0.49, 0.02]) # cax = fig.add_axes([0.49, 0.25, 0.39, 0.02]) cb = fig.colorbar(cax=cax, orientation="horizontal") cb.set_label("Normalized drifter transport (%)") if extraname is None: fig.savefig("figures/" + name + "/transport", bbox_inches="tight") else: fig.savefig("figures/" + name + "/" + extraname + "transport", bbox_inches="tight")