lonmin = b*math.floor(min(lon)/b) lonmax = b*math.ceil(max(lon)/b) latmin = b*math.floor(min(lat)/b) latmax = b*math.ceil(max(lat)/b) meridian = (range(lonmin, lonmax+b, b)) parallel = (range(latmin, latmax+b, b)) prj = 'cyl' res = 'i' map = Basemap(projection=prj, llcrnrlon=lonmin, llcrnrlat=latmin, urcrnrlon=lonmax, urcrnrlat=latmax, resolution=res) map.plot(lon, lat, 'r-') map.plot(lon, lat, 'k+') fs = 10 pylab.text(115.9,-31.9, "Perth", fontsize=fs, ha='left', va='top') pylab.text(114.1,-21.9, "Exmouth", fontsize=fs, ha='left', va='top') pylab.text(118.5,-20.4, "Port Hedland", fontsize=fs, ha='left', va='top') pylab.text(130.8,-12.6, "Darwin", fontsize=fs, ha='left', va='top') pylab.text(145.75,-16.9, "Cairns", fontsize=fs, ha='right', va='top') pylab.text(149.2,-21.2, "Mackay", fontsize=fs, ha='right', va='top') pylab.text(153.0,-27.5, "Brisbane", fontsize=fs, ha='right', va='top') pylab.text(153.1,-30.25, "Coffs Harbour", fontsize=fs, ha='right', va='top') pylab.text(151.1,-33.9, "Sydney", fontsize=fs, ha='right', va='top') pylab.text(150.5,-35.3, "Ulladulla", fontsize=fs, ha='right', va='top') map.fillcontinents(color='0.9')
def plot_track(rlon, rlat=None, m=None, **keywords): show_lat = 1 if ('show_lat' in keywords): show_lat = keywords['show_lat'] show_lon = 1 if ('show_lon' in keywords): show_lon = keywords['show_lon'] if (m == None): map_proj = 'cyl' if ('map_proj' in keywords): map_proj = keywords['map_proj'] lat_0 = 0.0 if ('lat_0' in keywords): lat_0 = keywords['lat_0'] minlat = -90.0 maxlat = 90.0 if ('minlat' in keywords): minlat = keywords['minlat'] if ('maxlat' in keywords): maxlat = keywords['maxlat'] minlon = -180 maxlon = 180.0 if ('minlon' in keywords): minlon = keywords['minlon'] if ('maxlon' in keywords): maxlon = keywords['maxlon'] lon_0 = 0 if ('lon_0' in keywords): lon_0 = keywords['lon_0'] boundinglat = 45 if ('boundinglat' in keywords): boundinglat = keywords['boundinglat'] if (map_proj == 'npstere' or map_proj == 'spstere'): m = Basemap(projection=map_proj, lon_0=lon_0, boundinglat=boundinglat) elif (map_proj == 'ortho'): m = Basemap(projection=map_proj, lon_0=lon_0, lat_0=lat_0) else: m=Basemap(llcrnrlon=minlon, llcrnrlat=minlat, \ urcrnrlon=maxlon, urcrnrlat=maxlat,projection=map_proj, lon_0=lon_0, lat_0=lat_0) if (show_lat == 1): m.drawparallels(arange(minlat, maxlat + 30.0, 30.), labels=[1, 0, 0, 0]) if (show_lon == 1): m.drawmeridians(arange(minlon, maxlon + 60, 60.), labels=[0, 0, 0, 1]) sgn = '+' if ('sgn' in keywords): sgn = keywords['sgn'] if ('color' in keywords): lcolor = keywords['color'] if (len(rlon) < 100): m.plot(rlon, rlat, sgn, color=lcolor, markersize=11) else: m.plot(rlon, rlat, sgn, color=lcolor, markersize=6) else: m.plot(rlon, rlat, sgn) m.drawcoastlines(color='w', linewidth=0.5) m.drawmapboundary() # m.drawcountries(color='k', linewidth=0.5) if ('title' in keywords): stitle = keywords['title'] title(stitle) return m
urcrnrlon = llcrnrlon+(array.shape[1]-1)*coords[1] urcrnrlat = coords[3] llcrnrlat = urcrnrlat+(array.shape[0]-1)*coords[5] # create Basemap instance. m = Basemap(llcrnrlon=llcrnrlon,llcrnrlat=llcrnrlat,urcrnrlon=urcrnrlon,urcrnrlat=urcrnrlat,projection='cyl') # create a figure, add an axes # (leaving room for a colorbar). fig = p.figure() ax = fig.add_axes([0.1,0.1,0.75,0.75]) # plot image from DEM over map. im = m.imshow(array,origin='upper') # make a colorbar. cax = p.axes([0.875, 0.1, 0.05, 0.75]) # setup colorbar axes. p.colorbar(cax=cax) # draw colorbar p.axes(ax) # make the original axes current again # draw meridians and parallels. m.drawmeridians(p.linspace(llcrnrlon+0.1,urcrnrlon-0.1,5),labels=[0,0,0,1],fmt='%4.2f') m.drawparallels(p.linspace(llcrnrlat+0.1,urcrnrlat-0.1,5),labels=[1,0,0,0],fmt='%4.2f') # plot county boundaries from # http://edcftp.cr.usgs.gov/pub/data/nationalatlas/countyp020.tar.gz shp_info = m.readshapefile('countyp020','counties',drawbounds=True,linewidth=1.0) # plot some cities. lons = [-105.22,-105.513,-105.316,-105.47]; lats = [39.76,39.801,39.633,39.41] names = ['Golden','Central City','Evergreen','Bailey'] x,y = m(lons,lats) m.plot(x,y,'ko') for name,xx,yy in zip(names,x,y): p.text(xx+0.01,yy+0.01,name) p.title(gd.GetDescription()+' USGS DEM with county boundaries') p.show()
urcrnrlat = coords[3] llcrnrlat = urcrnrlat + (array.shape[0] - 1) * coords[5] # create Basemap instance. m = Basemap(llcrnrlon=llcrnrlon, llcrnrlat=llcrnrlat, urcrnrlon=urcrnrlon, urcrnrlat=urcrnrlat, projection="cyl") # create a figure with the right aspect ratio, add an axes # (leaving room for a colorbar). fig = p.figure(figsize=(8, m.aspect * 8)) ax = fig.add_axes([0.1, 0.1, 0.75, 0.75]) # plot image from DEM over map. im = m.imshow(array, origin="upper") # make a colorbar. cax = p.axes([0.875, 0.1, 0.05, 0.75]) # setup colorbar axes. p.colorbar(tickfmt="%d", cax=cax) # draw colorbar p.axes(ax) # make the original axes current again # draw meridians and parallels. m.drawmeridians(p.linspace(llcrnrlon + 0.1, urcrnrlon - 0.1, 5), labels=[0, 0, 0, 1], fmt="%4.2f") m.drawparallels(p.linspace(llcrnrlat + 0.1, urcrnrlat - 0.1, 5), labels=[1, 0, 0, 0], fmt="%4.2f") # plot county boundaries from # http://edcftp.cr.usgs.gov/pub/data/nationalatlas/countyp020.tar.gz shp_info = m.readshapefile("countyp020", "counties", drawbounds=True, linewidth=1.0) # plot some cities. lons = [-105.22, -105.513, -105.316, -105.47] lats = [39.76, 39.801, 39.633, 39.41] names = ["Golden", "Central City", "Evergreen", "Bailey"] x, y = m(lons, lats) m.plot(x, y, "ko") for name, xx, yy in zip(names, x, y): p.text(xx + 0.01, yy + 0.01, name) p.title(gd.GetDescription() + " USGS DEM with county boundaries") p.show()
# in which direction to depart for other points on earth and how far # it will be to reach that destination. # The specified point shows up as a red dot in the center of the map. # This example shows how to use the width and height keywords # to specify the map projection region (instead of specifying # the lat/lon of the upper right and lower left corners). # user enters the lon/lat of the point, and it's name lon_0 = float(raw_input('input reference lon (degrees):')) lat_0 = float(raw_input('input reference lat (degrees):')) location = raw_input('name of location:') # use these values to setup Basemap instance. width = 28000000 m = Basemap(width=width,height=width,\ resolution='c',projection='aeqd',\ lat_0=lat_0,lon_0=lon_0) # draw coasts and fill continents. m.drawcoastlines(linewidth=0.5) m.fillcontinents() # 20 degree graticule. m.drawparallels(arange(-80, 81, 20)) m.drawmeridians(arange(-180, 180, 20)) # draw a red dot at the center. xpt, ypt = m(lon_0, lat_0) m.plot([xpt], [ypt], 'ro') # draw the title. title('The World According to Garp in ' + location) show()
map.drawcountries(linewidth=0.25) map.fillcontinents(color='coral') # draw the edge of the map projection region (the projection limb) map.drawmapboundary() # draw lat/lon grid lines every 30 degrees. map.drawmeridians(p.arange(0,360,30)) map.drawparallels(p.arange(-90,90,30)) # lat/lon coordinates of five cities. lats=[40.02,32.73,38.55,48.25,17.29] lons=[-105.16,-117.16,-77.00,-114.21,-88.10] cities=['Boulder, CO','San Diego, CA', 'Washington, DC','Whitefish, MT','Belize City, Belize'] # compute the native map projection coordinates for cities. x,y = map(lons,lats) # plot filled circles at the locations of the cities. map.plot(x,y,'bo') # plot the names of those five cities. for name,xpt,ypt in zip(cities,x,y): p.text(xpt+50000,ypt+50000,name,fontsize=9) # make up some data on a regular lat/lon grid. nlats = 73; nlons = 145; delta = 2.*p.pi/(nlons-1) lats = (0.5*p.pi-delta*p.indices((nlats,nlons))[0,:,:]) lons = (delta*p.indices((nlats,nlons))[1,:,:]) wave = 0.75*(p.sin(2.*lats)**8*p.cos(4.*lons)) mean = 0.5*p.cos(2.*lats)*((p.sin(2.*lats))**2 + 2.) # compute native map projection coordinates of lat/lon grid. x, y = map(lons*180./p.pi, lats*180./p.pi) # contour data over the map. cs = map.contour(x,y,wave+mean,15,linewidths=1.5) p.show() #p.savefig('wiki_example.ps')
# in which direction to depart for other points on earth and how far # it will be to reach that destination. # The specified point shows up as a red dot in the center of the map. # This example shows how to use the width and height keywords # to specify the map projection region (instead of specifying # the lat/lon of the upper right and lower left corners). # user enters the lon/lat of the point, and it's name lon_0 = float(raw_input('input reference lon (degrees):')) lat_0 = float(raw_input('input reference lat (degrees):')) location = raw_input('name of location:') # use these values to setup Basemap instance. width = 28000000 m = Basemap(width=width,height=width,\ resolution='c',projection='aeqd',\ lat_0=lat_0,lon_0=lon_0) # draw coasts and fill continents. m.drawcoastlines(linewidth=0.5) m.fillcontinents() # 20 degree graticule. m.drawparallels(arange(-80,81,20)) m.drawmeridians(arange(-180,180,20)) # draw a red dot at the center. xpt, ypt = m(lon_0, lat_0) m.plot([xpt],[ypt],'ro') # draw the title. title('The World According to Garp in '+location) show()
nx = int((m.xmax-m.xmin)/40000.)+1; ny = int((m.ymax-m.ymin)/40000.)+1 topodat,x,y = m.transform_scalar(topoin,lons,lats,nx,ny,returnxy=True) # create the figure. fig=figure(figsize=(8,8)) # add an axes, leaving room for colorbar on the right. ax = fig.add_axes([0.1,0.1,0.7,0.7]) # plot image over map with imshow. im = m.imshow(topodat,cm.jet) # setup colorbar axes instance. l,b,w,h = ax.get_position() cax = axes([l+w+0.075, b, 0.05, h]) colorbar(tickfmt='%d', cax=cax) # draw colorbar axes(ax) # make the original axes current again # plot blue dot on boulder, colorado and label it as such. xpt,ypt = m(-104.237,40.125) m.plot([xpt],[ypt],'bo') text(xpt+100000,ypt+100000,'Boulder') # draw coastlines and political boundaries. m.drawcoastlines() m.drawcountries() m.drawstates() # draw parallels and meridians. # label on left, right and bottom of map. parallels = arange(0.,80,20.) m.drawparallels(parallels,labels=[1,1,0,1]) meridians = arange(10.,360.,30.) m.drawmeridians(meridians,labels=[1,1,0,1]) # set title. title('ETOPO Topography - Lambert Conformal Conic') show()
ax = fig.add_axes([0.1, 0.1, 0.7, 0.7]) # plot image over map with imshow. im = m.imshow(topodat, cm.jet) # use pcolor (looks very similar to imshow, but slower). # p = m.pcolor(x,y,topodat,shading='flat') # plot contour lines over map (colors is a list so neg contours will # not be dashed). # levels, colls = m.contour(x,y,topodat,15,linewidths=0.5,colors=['k','k']) # fill the contours. # levels, colls = m.contourf(x,y,topodat,15,cmap=cm.jet,colors=None) 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 # plot blue dot on boulder, colorado and label it as such. xpt, ypt = m(-104.237, 40.125) m.plot([xpt], [ypt], "bo") text(xpt + 100000, ypt + 100000, "Boulder") # draw coastlines and political boundaries. m.drawcoastlines() m.drawcountries() m.drawstates() # draw parallels and meridians. # label on left, right and bottom of map. parallels = arange(0.0, 80, 20.0) m.drawparallels(parallels, labels=[1, 1, 0, 1]) meridians = arange(10.0, 360.0, 30.0) m.drawmeridians(meridians, labels=[1, 1, 0, 1]) title("ETOPO Topography - Lambert Conformal Conic") show()
# draw the edge of the map projection region (the projection limb) map.drawmapboundary() # draw lat/lon grid lines every 30 degrees. map.drawmeridians(p.arange(0, 360, 30)) map.drawparallels(p.arange(-90, 90, 30)) # lat/lon coordinates of five cities. lats = [40.02, 32.73, 38.55, 48.25, 17.29] lons = [-105.16, -117.16, -77.00, -114.21, -88.10] cities = [ 'Boulder, CO', 'San Diego, CA', 'Washington, DC', 'Whitefish, MT', 'Belize City, Belize' ] # compute the native map projection coordinates for cities. x, y = map(lons, lats) # plot filled circles at the locations of the cities. map.plot(x, y, 'bo') # plot the names of those five cities. for name, xpt, ypt in zip(cities, x, y): p.text(xpt + 50000, ypt + 50000, name, fontsize=9) # make up some data on a regular lat/lon grid. nlats = 73 nlons = 145 delta = 2. * p.pi / (nlons - 1) lats = (0.5 * p.pi - delta * p.indices((nlats, nlons))[0, :, :]) lons = (delta * p.indices((nlats, nlons))[1, :, :]) wave = 0.75 * (p.sin(2. * lats)**8 * p.cos(4. * lons)) mean = 0.5 * p.cos(2. * lats) * ((p.sin(2. * lats))**2 + 2.) # compute native map projection coordinates of lat/lon grid. x, y = map(lons * 180. / p.pi, lats * 180. / p.pi) # contour data over the map. cs = map.contour(x, y, wave + mean, 15, linewidths=1.5)
mapobj= Basemap(projection='merc',lat_0=(box[2]+box[3])/2.0, lon_0=(box[0]+box[1])/2.0,llcrnrlat=box[2], llcrnrlon=box[0], urcrnrlat=box[3] , urcrnrlon=box[1], resolution='l',area_thresh=1., lat_ts=(box[2]+box[3])/2.0) longr, latgr=meshgrid(lons,lats) xx, yy = mapobj(longr, latgr) mapobj.drawmapboundary() mapobj.readshapefile('/flurry/home/scollis/shapes/cstntcd_r','coast',drawbounds=True,linewidth=0.5,color='k',antialiased=1,ax=None) mapobj.contour(xx,yy,angs, levels=[150,30], colors=['r']) mapobj.drawmeridians(array([130.2, 130.4, 130.6, 130.8,131.0,131.2, 131.4]), labels=[1,0,0,1]) mapobj.drawparallels(array([--12.8, -12.6, -12.4, -12.2, -12.0, -11.8, -11.6, -11.4]), labels=[1,0,0,1]) dd_box_xx, dd_box_yy=mapobj(array([dd_box[0], dd_box[1]]),array([dd_box[2], dd_box[3]])) xy=dd_box_xx[0], dd_box_yy[0] width, height= dd_box_xx[1]-dd_box_xx[0], dd_box_yy[1]-dd_box_yy[0] my_patch=matplotlib.patches.Rectangle(xy, width, height, edgecolor='blue', facecolor='white') ax=gca() ax.add_patch(my_patch) radar_xx, radar_yy=mapobj(array([ber_loc[1], gp_loc[1]]), array([ber_loc[0], gp_loc[0]])) mapobj.plot(radar_xx, radar_yy, 'bo') ax.text(radar_xx[0]+1000.0, radar_yy[0]-3000.0, 'Berrimah') ax.text(radar_xx[1]+1000.0, radar_yy[1]-3000.0, 'Gunn Point') savefig('/flurry/home/scollis/results/area_vis.png') close(f) | | ================= ============================================== | Property Description | ================= ============================================== | alpha float | animated [True | False] | antialiased or aa [True | False] | clip_box a matplotlib.transform.Bbox instance
def wrf_grid( # WPS -> map_proj projection, # WPS -> truelat1 lat_1, # WPS -> truelat2 lat_2, # WPS -> stand_lon lon_0, # WPS -> ref_lat grid_centre_lat, # WPS -> ref_lon grid_centre_lon, delta_x, delta_y, # WPS -> e_we nx, # WPS -> e_sn ny, show_mass_grid = False, show_stag_grids = False, ): if lon_0 != grid_centre_lon: print 'not implemented yet -> see the source' print "\tbut let's try it anyways..." #return width = nx * delta_x height = ny * delta_y frame_x = 10 * delta_x frame_y = 10 * delta_y m = Basemap( lat_0 = grid_centre_lat, # this could be a bad assumption... because lon_0 and grid_centre_lon # need not be aligned, but at the same time I need to give this to # basemap for the grid to be centred... I could probably fix it # assigning lon_0 and then imposing a grid shift in native coordinates # if ref_lon and lon_0 were not the same lon_0 = lon_0, lat_1 = lat_1, lat_2 = lat_2, width = width + 2*frame_x, height = height + 2*frame_y, resolution = 'l', area_thresh=1000. ) grid_centre_x, grid_centre_y = m(grid_centre_lon, grid_centre_lat) min_x = grid_centre_x - width/2. min_y = grid_centre_y - height/2. max_x = min_x + width max_y = min_y + height x = n.arange(min_x, max_x + a_small_number, delta_x) y = n.arange(min_y, max_y + a_small_number, delta_y) x = x[1:-1] y = y[1:-1] x_u = n.arange(min_x, max_x + delta_x + a_small_number, delta_x) x_u -= delta_x/2. x_u = x_u[1:-1] y_v = n.arange(min_y, max_y + delta_y + a_small_number, delta_y) y_v -= delta_y/2. y_v = y_v[1:-1] X, Y = p.meshgrid(x,y) lon, lat = m(X, Y, inverse=True) X_u, Y_u = p.meshgrid(x_u,y) lon_u, lat_u = m(X_u, Y_u, inverse=True) X_v, Y_v = p.meshgrid(x,y_v) lon_v, lat_v = m(X_v, Y_v, inverse=True) if show_mass_grid: m.plot(X, Y, 'b+') m.plot([grid_centre_x], [grid_centre_y], 'r+') if show_stag_grids: m.plot(X_u, Y_u, 'g+') m.plot(X_v, Y_v, 'r+') m.drawcoastlines() p.show() output = { 'map' : m, 'mass_stag': { 'lon_2d' : lon, 'lat_2d' : lat, 'x' : x, 'y' : y, 'x_2d' : X, 'y_2d' : Y, }, 'u_stag': { 'lon_2d' : lon_u, 'lat_2d' : lat_u, 'x' : x_u, 'y' : y, 'x_2d' : X_u, 'y_2d' : Y_u, }, 'v_stag': { 'lon_2d' : lon_v, 'lat_2d' : lat_v, 'x' : x, 'y' : y_v, 'x_2d' : X_v, 'y_2d' : Y_v, } } return output