# plot vectors in geographical (lat/lon) coordinates. # north polar projection. m = Basemap(lon_0=-135,boundinglat=25, resolution='c',area_thresh=10000.,projection='npstere') # create a figure, add an axes. fig=figure(figsize=(8,8)) ax = fig.add_axes([0.1,0.1,0.7,0.7]) # rotate wind vectors to map projection coordinates. # (also compute native map projections coordinates of lat/lon grid) # only do Northern Hemisphere. urot,vrot,x,y = m.rotate_vector(u[36:,:],v[36:,:],lons[36:,:],lats[36:,:],returnxy=True) # plot filled contours over map. cs = m.contourf(x,y,p[36:,:],15,cmap=cm.jet) # plot wind vectors over map. Q = m.quiver(x,y,urot,vrot) #or specify, e.g., width=0.003, scale=400) qk = quiverkey(Q, 0.95, 1.05, 25, '25 m/s', labelpos='W') cax = axes([0.875, 0.1, 0.05, 0.7]) # setup colorbar axes. colorbar(cax=cax) # draw colorbar axes(ax) # make the original axes current again m.drawcoastlines() m.drawcountries() # draw parallels delat = 20. circles = arange(0.,90.+delat,delat).tolist()+\ arange(-delat,-90.-delat,-delat).tolist() m.drawparallels(circles,labels=[1,1,1,1]) # draw meridians delon = 45. meridians = arange(-180,180,delon) m.drawmeridians(meridians,labels=[1,1,1,1])
projection='npstere') # create a figure, add an axes. fig = figure(figsize=(8, 8)) ax = fig.add_axes([0.1, 0.1, 0.7, 0.7]) # rotate wind vectors to map projection coordinates. # (also compute native map projections coordinates of lat/lon grid) # only do Northern Hemisphere. urot, vrot, x, y = m.rotate_vector(u[36:, :], v[36:, :], lons[36:, :], lats[36:, :], returnxy=True) # plot filled contours over map. cs = m.contourf(x, y, p[36:, :], 15, cmap=cm.jet) # plot wind vectors over map. Q = m.quiver(x, y, urot, vrot) #or specify, e.g., width=0.003, scale=400) qk = quiverkey(Q, 0.95, 1.05, 25, '25 m/s', labelpos='W') cax = axes([0.875, 0.1, 0.05, 0.7]) # setup colorbar axes. colorbar(cax=cax) # draw colorbar axes(ax) # make the original axes current again m.drawcoastlines() m.drawcountries() # draw parallels delat = 20. circles = arange(0.,90.+delat,delat).tolist()+\ arange(-delat,-90.-delat,-delat).tolist() m.drawparallels(circles, labels=[1, 1, 1, 1]) # draw meridians delon = 45. meridians = arange(-180, 180, delon) m.drawmeridians(meridians, labels=[1, 1, 1, 1])
CS = m.contour(x,y,slp[nt,:,:],clevs,linewidths=0.5,colors='k',animated=True) CS = m.contourf(x,y,slp[nt,:,:],clevs,cmap=p.cm.RdBu_r,animated=True) # plot wind vectors on lat/lon grid. # rotate wind vectors to map projection coordinates. #urot,vrot = m.rotate_vector(u[nt,:,:],v[nt,:,:],lons,lats) # plot wind vectors over map. #Q = m.quiver(x,y,urot,vrot,scale=500) # plot wind vectors on projection grid (looks better). # first, shift grid so it goes from -180 to 180 (instead of 0 to 360 # in longitude). Otherwise, interpolation is messed up. ugrid,newlons = shiftgrid(180.,u[nt,:,:],longitudes,start=False) vgrid,newlons = shiftgrid(180.,v[nt,:,:],longitudes,start=False) # transform vectors to projection grid. urot,vrot,xx,yy = m.transform_vector(ugrid,vgrid,newlons,latitudes,51,51,returnxy=True,masked=True) # plot wind vectors over map. Q = m.quiver(xx,yy,urot,vrot,scale=500) # make quiver key. qk = p.quiverkey(Q, 0.1, 0.1, 20, '20 m/s', labelpos='W') # draw coastlines, parallels, meridians, title. m.drawcoastlines(linewidth=1.5) m.drawparallels(parallels) m.drawmeridians(meridians) p.title('SLP and Wind Vectors '+date) if nt == 0: # plot colorbar on a separate axes (only for first frame) cax = p.axes([l+w-0.05, b, 0.03, h]) # setup colorbar axes fig.colorbar(CS,drawedges=True, cax=cax) # draw colorbar cax.text(0.0,-0.05,'mb') p.axes(ax) # reset current axes p.draw() # draw the plot # save first and last frame n1 times # (so gif animation pauses at beginning and end)
# north polar projection. m = Basemap(llcrnrlon=-180.,llcrnrlat=10.,urcrnrlon=0.,urcrnrlat=10.,\ resolution='c',area_thresh=10000.,projection='stere',\ lat_0=90.,lon_0=-135.,lat_ts=90.) # setup figure with same aspect ratio as map. xsize = rcParams['figure.figsize'][0] fig=figure(figsize=(xsize,m.aspect*xsize)) ax = fig.add_axes([0.1,0.1,0.7,0.7]) # rotate wind vectors to map projection coordinates. # (also compute native map projections coordinates of lat/lon grid) # only do Northern Hemisphere. urot,vrot,x,y = m.rotate_vector(u[36:,:],v[36:,:],lons[36:,:],lats[36:,:],returnxy=True) # plot filled contours over map. levels, colls = m.contourf(x,y,p[36:,:],15,cmap=cm.jet,colors=None) # plot wind vectors over map. m.quiver(x,y,urot,vrot) cax = axes([0.875, 0.1, 0.05, 0.7]) # setup colorbar axes. colorbar(tickfmt='%d', cax=cax) # draw colorbar axes(ax) # make the original axes current again m.drawcoastlines() m.drawcountries() # draw parallels delat = 20. circles = arange(0.,90.+delat,delat).tolist()+\ arange(-delat,-90.-delat,-delat).tolist() m.drawparallels(circles,labels=[1,1,1,1]) # draw meridians delon = 45. meridians = arange(-180,180,delon) m.drawmeridians(meridians,labels=[1,1,1,1]) title('Surface Winds Winds and Pressure',y=1.075)
pdat, xp, yp = m.transform_scalar(p,lons,lats,nxp,nyp,returnxy=True) print min(ravel(udat)),max(ravel(udat)) print min(ravel(vdat)),max(ravel(vdat)) print min(ravel(pdat)),max(ravel(pdat)) spd = sqrt(udat**2+vdat**2) print max(ravel(spd)) # setup figure with same aspect ratio as map. xsize = rcParams['figure.figsize'][0] fig=figure(figsize=(xsize,m.aspect*xsize)) ax = fig.add_axes([0.1,0.1,0.7,0.7]) # plot filled contours over map levels, colls = m.contourf(xp,yp,pdat,15,cmap=cm.jet,colors=None) # plot wind vectors over map. m.quiver(xv,yv,udat,vdat) cax = axes([0.875, 0.1, 0.05, 0.7]) # setup colorbar axes. colorbar(tickfmt='%d', cax=cax) # draw colorbar axes(ax) # make the original axes current again m.drawcoastlines() m.drawcountries() # draw parallels delat = 20. circles = arange(0.,90.+delat,delat).tolist()+\ arange(-delat,-90.-delat,-delat).tolist() m.drawparallels(circles,labels=[1,1,1,1]) # draw meridians delon = 45. meridians = arange(-180,180,delon) m.drawmeridians(meridians,labels=[1,1,1,1]) ax.set_xticks([]) # no ticks
# plot wind vectors on projection grid (looks better). # first, shift grid so it goes from -180 to 180 (instead of 0 to 360 # in longitude). Otherwise, interpolation is messed up. ugrid, newlons = shiftgrid(180., u[nt, :, :], longitudes, start=False) vgrid, newlons = shiftgrid(180., v[nt, :, :], longitudes, start=False) # transform vectors to projection grid. urot, vrot, xx, yy = m.transform_vector(ugrid, vgrid, newlons, latitudes, 51, 51, returnxy=True, masked=True) # plot wind vectors over map. Q = m.quiver(xx, yy, urot, vrot, scale=500) # make quiver key. qk = p.quiverkey(Q, 0.1, 0.1, 20, '20 m/s', labelpos='W') # draw coastlines, parallels, meridians, title. m.drawcoastlines(linewidth=1.5) m.drawparallels(parallels) m.drawmeridians(meridians) p.title('SLP and Wind Vectors ' + date) if nt == 0: # plot colorbar on a separate axes (only for first frame) cax = p.axes([l + w - 0.05, b, 0.03, h]) # setup colorbar axes fig.colorbar(CS, drawedges=True, cax=cax) # draw colorbar cax.text(0.0, -0.05, 'mb') p.axes(ax) # reset current axes p.draw() # draw the plot # save first and last frame n1 times # (so gif animation pauses at beginning and end)
nxv, nyv, returnxy=True) pdat, xp, yp = m.transform_scalar(p, lons, lats, nxp, nyp, returnxy=True) print min(ravel(udat)), max(ravel(udat)) print min(ravel(vdat)), max(ravel(vdat)) print min(ravel(pdat)), max(ravel(pdat)) spd = sqrt(udat**2 + vdat**2) print max(ravel(spd)) xsize = rcParams['figure.figsize'][0] fig = figure(figsize=(xsize, m.aspect * xsize)) ax = fig.add_axes([0.1, 0.1, 0.7, 0.7]) levels, colls = m.contourf(xp, yp, pdat, 15, cmap=cm.jet, colors=None) m.quiver(xv, yv, udat, vdat) cax = axes([0.875, 0.1, 0.05, 0.7]) colorbar(tickfmt='%d', cax=cax) # draw colorbar axes(ax) # make the original axes current again m.drawcoastlines() m.drawcountries() # draw parallels delat = 20. circles = arange(0.,90.+delat,delat).tolist()+\ arange(-delat,-90.-delat,-delat).tolist() m.drawparallels(circles, labels=[1, 1, 1, 1]) # draw meridians delon = 45. meridians = arange(-180, 180, delon) m.drawmeridians(meridians, labels=[1, 1, 1, 1]) ax.set_xticks([]) # no ticks