def draw_client_density():

    m = Basemap(llcrnrlon=-180.,llcrnrlat=-90,urcrnrlon=180.,urcrnrlat=90.,\
                resolution='c',projection='cyl')

    # plot them as filled circles on the map.
    # first, create a figure.
    dpi=100
    dimx=800/dpi
    dimy=400/dpi
    fig=figure(figsize=(dimx,dimy), dpi=dpi, frameon=False, facecolor='blue')
#    ax=fig.add_axes([0.1,0.1,0.7,0.7],axisbg='g')
    ax=fig.add_axes([0.0,0.0,1.0,1.0],axisbg='g')
    canvas = FigureCanvas(fig)
    results = lookup_client_locations()
    X,Y,Z = find_client_density(m,results)
#    s = random.sample(results, 40000)
#    for t in s:
#        lat=t[2]
#        lon=t[3]
#        # draw a red dot at the center.
#        xpt, ypt = m(lon, lat)
#        m.plot([xpt],[ypt],'ro', zorder=10)
    # draw coasts and fill continents.
    m.drawcoastlines(linewidth=0.5)
    m.drawcountries(linewidth=0.5)
    m.drawlsmask([100,100,100,0],[0,0,255,255])
#    m.fillcontinents(color='green')
    palette = cm.YlOrRd
    m.imshow(Z,palette,extent=(m.xmin,m.xmax,m.ymin,m.ymax),interpolation='gaussian',zorder=0)
#    l,b,w,h = ax.get_position()
#    cax = axes([l+w+0.075, b, 0.05, h])
#    colorbar(cax=cax) # draw colorbar

    canvas.print_figure(outdir+'/clientmap.png', dpi=100)
예제 #2
0
            resolution='l',area_thresh=1000.,projection='lcc',\
            lat_1=50.,lon_0=-107.)
# transform to nx x ny regularly spaced native projection grid
nx = int((m.xmax-m.xmin)/40000.)+1; ny = int((m.ymax-m.ymin)/40000.)+1
topodat,x,y = m.transform_scalar(topoin,lonsin,latsin,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])
# make topodat a masked array, masking values lower than sea level.
topodat = where(topodat < 0.,1.e10,topodat)
topodatm = ma.masked_values(topodat, 1.e10)
palette = cm.YlOrRd
palette.set_bad('aqua', 1.0)
# plot image over map with imshow.
im = m.imshow(topodatm,palette,norm=colors.normalize(vmin=0.0,vmax=3000.0,clip=False))
# setup colorbar axes instance.
l,b,w,h = ax.get_position()
cax = axes([l+w+0.075, b, 0.05, h])
colorbar(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.
예제 #3
0
from matplotlib.toolkits.basemap import Basemap
import cPickle
from pylab import *
# read in topo data from pickle (on a regular lat/lon grid)
topodict = cPickle.load(open('etopo20.pickle', 'rb'))
etopo = topodict['data']
lons = topodict['lons']
lats = topodict['lats']
# create Basemap instance (global cylindrical equidistant is default)
m = Basemap(lons[0], lats[0], lons[-1], lats[-1])
# create figure with same aspect ratio as map.
xsize = rcParams['figure.figsize'][0]
fig = figure(figsize=(xsize, m.aspect * xsize))
fig.add_axes([0.1, 0.1, 0.8, 0.8])
im = m.imshow(etopo)
# draw coastlines and fill continents.
m.drawcoastlines()
m.fillcontinents()
# draw parallels, label on bottom.
circles = arange(-90., 120., 30.)
m.drawparallels(circles, labels=[1, 0, 0, 0])
# draw meridians, label on left.
meridians = arange(0., 390., 60.)
m.drawmeridians(meridians, labels=[0, 0, 0, 1])
title('Cylindrical Equidistant')
show()
예제 #4
0
pylab.axes(ax)  # make the original axes current again
# plot title
pylab.title(plottitle+'- contourf',fontsize=10)

pylab.subplot(212)
ax = pylab.gca()
# draw coastlines, state and country boundaries, edge of map.
m.drawcoastlines()
m.drawstates()
m.drawcountries()
# draw parallels.
m.drawparallels(parallels,labels=[1,0,0,0],fontsize=10)
# draw meridians
m.drawmeridians(meridians,labels=[0,0,0,1],fontsize=10)
# draw image
im = m.imshow(data,cmap=cm.s3pcpn,interpolation='nearest',vmin=0,vmax=750)
# make a copy of the image object, change
# colormap to linear version of the precip colormap.
im2 = copy.copy(im)
im2.set_cmap(cm.s3pcpn_l)
# new axis for colorbar.
l,b,w,h=ax.get_position()
cax = pylab.axes([l+w+0.025, b, 0.025, h]) # setup colorbar axes
# using im2, not im (hack to prevent colors from being
# too compressed at the low end on the colorbar - results
# from highly nonuniform colormap)
pylab.colorbar(im2, cax, format='%d') # draw colorbar
pylab.axes(ax)  # make the original axes current again
# reset colorbar tick labels (hack to get
cax.set_yticks(pylab.linspace(0,1,len(clevs)))
cax.set_yticklabels(['%g' % clev for clev in clevs])
예제 #5
0
lon_0 = 0.0
satellite_height = 35785831.0

fig = figure(figsize=(7, 7))
ax = fig.add_axes((0.1, 0.1, 0.8, 0.8))
# create Basemap instance for a Geostationary projection.
m = Basemap(projection='geos',
            lon_0=lon_0,
            satellite_height=satellite_height,
            resolution='l',
            llcrnrlon=ll_lon,
            llcrnrlat=ll_lat,
            urcrnrlon=ur_lon,
            urcrnrlat=ur_lat)
# add data
m.imshow(data, cmap=cm.gray, interpolation='nearest')
clim(0, 255)
# draw coastlines.
m.drawcoastlines(linewidth=0.5, color=overlay_color)
m.drawcountries(linewidth=0.5, color=overlay_color)
# can't label meridians on bottom, because labels would
# be outside map projection region.
m.drawmeridians(arange(10, 76, 5), labels=[0, 0, 1, 0], color=overlay_color)
m.drawparallels(arange(-90, 90, 5), labels=[1, 0, 0, 0], color=overlay_color)
# add a colobar
#colorbar()
# add timestamp and save
fig = gcf()
fig.text(
    x=0.275,
    y=0.025,
예제 #6
0
nxp = 101
nyp = 101
spd = sqrt(u**2 + v**2)
udat, vdat, xv, yv = m.transform_vector(u,
                                        v,
                                        lons1,
                                        lats1,
                                        nxv,
                                        nyv,
                                        returnxy=True)
pdat, xp, yp = m.transform_scalar(p, lons1, lats1, nxp, nyp, returnxy=True)
# create a figure, add an axes.
fig = figure(figsize=(8, 8))
ax = fig.add_axes([0.1, 0.1, 0.7, 0.7])
# plot image over map
im = m.imshow(pdat, cm.jet)
# plot wind vectors over map.
Q = m.quiver(xv, yv, udat, vdat)  #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.
예제 #7
0
# shift data so lons go from -180 to 180 instead of 20 to 380.
topoin, lons = shiftgrid(180., topoin, lons, start=False)

print 'min/max etopo20 data:'
print min(ravel(topoin)), max(ravel(topoin))

# setup cylindrical equidistant map projection (global domain).
m = Basemap(-180.,-90,180.,90.,\
            resolution='c',area_thresh=10000.,projection='cyl')
# 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.75, 0.75])
# plot image over map.
im = m.imshow(topoin, cm.jet)
cax = axes([0.875, 0.1, 0.05, 0.75])  # setup colorbar axes.
colorbar(tickfmt='%d', cax=cax)  # draw colorbar
axes(ax)  # make the original axes current again
m.drawcoastlines()
#m.drawcountries()
#m.drawstates()
#m.fillcontinents()
# draw parallels
delat = 30.
circles = arange(0.,90.+delat,delat).tolist()+\
          arange(-delat,-90.-delat,-delat).tolist()
m.drawparallels(circles, labels=[1, 0, 0, 1])
# draw meridians
delon = 60.
meridians = arange(-180, 180, delon)
예제 #8
0
# north polar projection.
m = Basemap(lon_0=-135,boundinglat=25,
            resolution='c',area_thresh=10000.,projection='npstere')
# transform from spherical to map projection coordinates (rotation
# and interpolation).
nxv = 41; nyv = 41
nxp = 101; nyp = 101
spd = sqrt(u**2+v**2)
udat, vdat, xv, yv = m.transform_vector(u,v,lons1,lats1,nxv,nyv,returnxy=True)
pdat, xp, yp = m.transform_scalar(p,lons1,lats1,nxp,nyp,returnxy=True)
# create a figure, add an axes.
fig=figure(figsize=(8,8))
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# plot image over map
im = m.imshow(pdat,cm.jet)
# plot wind vectors over map.
Q = m.quiver(xv,yv,udat,vdat) #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.
예제 #9
0
                                   latsin,
                                   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])
# make topodat a masked array, masking values lower than sea level.
topodat = where(topodat < 0., 1.e10, topodat)
topodatm = ma.masked_values(topodat, 1.e10)
palette = cm.YlOrRd
palette.set_bad('aqua', 1.0)
# plot image over map with imshow.
im = m.imshow(topodatm,
              palette,
              norm=colors.normalize(vmin=0.0, vmax=3000.0, clip=False))
# setup colorbar axes instance.
l, b, w, h = ax.get_position()
cax = axes([l + w + 0.075, b, 0.05, h])
colorbar(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.
예제 #10
0
pylab.axes(ax)  # make the original axes current again
# plot title
pylab.title(plottitle + '- contourf', fontsize=10)

pylab.subplot(212)
ax = pylab.gca()
# draw coastlines, state and country boundaries, edge of map.
m.drawcoastlines()
m.drawstates()
m.drawcountries()
# draw parallels.
m.drawparallels(parallels, labels=[1, 0, 0, 0], fontsize=10)
# draw meridians
m.drawmeridians(meridians, labels=[0, 0, 0, 1], fontsize=10)
# draw image
im = m.imshow(data, cmap=cm.s3pcpn, interpolation='nearest', vmin=0, vmax=750)
# make a copy of the image object, change
# colormap to linear version of the precip colormap.
im2 = copy.copy(im)
im2.set_cmap(cm.s3pcpn_l)
# new axis for colorbar.
l, b, w, h = ax.get_position()
cax = pylab.axes([l + w + 0.025, b, 0.025, h])  # setup colorbar axes
# using im2, not im (hack to prevent colors from being
# too compressed at the low end on the colorbar - results
# from highly nonuniform colormap)
pylab.colorbar(im2, cax, format='%d')  # draw colorbar
pylab.axes(ax)  # make the original axes current again
# reset colorbar tick labels (hack to get
cax.set_yticks(pylab.linspace(0, 1, len(clevs)))
cax.set_yticklabels(['%g' % clev for clev in clevs])
예제 #11
0
fig = figure(figsize=(8,8))

plots = ['contour','pcolor']
#plots = ['contour','imshow']

for np,plot in enumerate(plots):

    fig.add_subplot(1,2,np+1)
    ax = gca()

    # plot data.
    print plot+' plot ...'
    if plot == 'pcolor':
        m.pcolor(x,y,hgt,shading='flat')
    elif plot == 'imshow':
        im = m.imshow(hgt)
    elif plot == 'contour':
        levels, colls = m.contour(x,y,hgt,15,linewidths=0.5,colors='k')
        levels, colls = m.contourf(x,y,hgt,15,cmap=cm.jet,colors=None)

    # set size of plot to match aspect ratio of map.
    l,b,w,h = ax.get_position()
    b = 0.5 - 0.5*w*m.aspect; h = w*m.aspect
    ax.set_position([l,b,w,h])
    
    # draw map.
    m.drawcoastlines()
	
    # draw parallels
    delat = 30.
    delon = 90.
예제 #12
0
fig = figure(figsize=(8, 8))

plots = ['contour', 'pcolor']
#plots = ['contour','imshow']

for np, plot in enumerate(plots):

    fig.add_subplot(1, 2, np + 1)
    ax = gca()

    # plot data.
    print plot + ' plot ...'
    if plot == 'pcolor':
        m.pcolor(x, y, hgt, shading='flat')
    elif plot == 'imshow':
        im = m.imshow(hgt)
    elif plot == 'contour':
        levels, colls = m.contour(x, y, hgt, 15, linewidths=0.5, colors='k')
        levels, colls = m.contourf(x, y, hgt, 15, cmap=cm.jet, colors=None)

    # set size of plot to match aspect ratio of map.
    l, b, w, h = ax.get_position()
    b = 0.5 - 0.5 * w * m.aspect
    h = w * m.aspect
    ax.set_position([l, b, w, h])

    # draw map.
    m.drawcoastlines()

    # draw parallels
    delat = 30.
예제 #13
0
# shift data so lons go from -180 to 180 instead of 20 to 380.
topoin,lons = shiftgrid(180.,topodatin,lonsin,start=False)
lats = latsin

print 'min/max etopo20 data:'
print min(ravel(topoin)),max(ravel(topoin))

# setup cylindrical equidistant map projection (global domain).
m = Basemap(llcrnrlon=-180.,llcrnrlat=-90,urcrnrlon=180.,urcrnrlat=90.,\
            resolution='c',area_thresh=10000.,projection='cyl')
# setup figure with same aspect ratio as map.
fig=figure()
ax = fig.add_axes([0.1,0.1,0.7,0.7])
# plot image over map.
im = m.imshow(topoin,cm.jet)
l,b,w,h = ax.get_position()
cax = axes([l+w+0.05, b, 0.05, h]) # setup colorbar axes.
colorbar(cax=cax) # draw colorbar
axes(ax)  # make the original axes current again
m.drawcoastlines()
#m.drawcountries()
#m.drawstates()
#m.fillcontinents()
# draw parallels
delat = 30.
circles = arange(0.,90.+delat,delat).tolist()+\
          arange(-delat,-90.-delat,-delat).tolist()
m.drawparallels(circles,labels=[1,0,0,1])
# draw meridians
delon = 60.
예제 #14
0
    def makeFigure(self):
        """
        :todo: Uses pylab so may not be threadsafe.
        """

        lon = self.grid.lon0 + N.arrayrange(self.grid.nlon) * self.grid.dlon
        lat = self.grid.lat0 + N.arrayrange(self.grid.nlat) * self.grid.dlat

        ll_lon, ll_lat = lon[0], lat[0]
        ur_lon, ur_lat = lon[-1], lat[-1]

        # Account for variable lat/lon axis ordering
        #!TODO: Could we move this (along with the equivilent in render_imp.py into grid.py?
        if self.grid.ilat < self.grid.ilon:
            latLonOrdering = True
        else:
            latLonOrdering = False

        if latLonOrdering:
            var = self.grid.value
        else:
            var = MA.transpose(self.grid.value)

        fig = p.figure()
        map = Basemap(projection='cyl',
                      llcrnrlon=ll_lon,
                      llcrnrlat=ll_lat,
                      urcrnrlon=ur_lon,
                      urcrnrlat=ur_lat,
                      resolution='l')

        ##         if self.grid.units:
        ##             p.title("%s\n(%s)" % (self.grid.long_name, self.grid.units))
        ##         else:
        ##             p.title(self.grid.long_name)
        p.title(self.grid.long_name)

        if self.type == 'colour':
            # transform_scalar doesn't support masked arrays so we must fill then replace the mask.
            var_dat = map.transform_scalar(var.filled(1.0e20), lon, lat,
                                           len(lon), len(lat))
            var = MA.masked_values(var_dat, 1.0e20)
            map.imshow(var,
                       cmap=self.cmap,
                       vmin=self.vmin,
                       vmax=self.vmax,
                       interpolation='nearest')
            cbar = p.colorbar(orientation='horizontal', format='%.2g')
            if self.grid.units:
                cbar.ax.set_xlabel(self.grid.units)

        else:
            x, y = map(*p.meshgrid(lon, lat))
            c = map.contour(x, y, var, 12, colors='black')
            c.clabel(fontsize=8)
            map.fillcontinents(color='#e0e0e0')

        map.drawcoastlines(color='gray')

        map.drawmeridians(p.arange(-180, 180, 30),
                          labels=[1, 0, 0, 1],
                          color='gray')
        map.drawparallels(p.arange(-90, 90, 15),
                          labels=[1, 0, 0, 1],
                          color='gray')

        # Wrap the caption
        caption = word_wrap(self.caption, 80)

        fig.text(0.1,
                 0.08,
                 caption,
                 fontsize=10,
                 horizontalalignment='left',
                 verticalalignment='top',
                 transform=fig.transFigure)

        return fig
예제 #15
0
from matplotlib.toolkits.basemap import Basemap
import cPickle
from pylab import *
# read in topo data from pickle (on a regular lat/lon grid)
topodict = cPickle.load(open('etopo20.pickle','rb'))
etopo = topodict['data']; lons = topodict['lons']; lats = topodict['lats']
# create Basemap instance (global cylindrical equidistant is default)
m = Basemap(lons[0],lats[0],lons[-1],lats[-1])
# create figure with same aspect ratio as map.
xsize = rcParams['figure.figsize'][0]
fig=figure(figsize=(xsize,m.aspect*xsize))
fig.add_axes([0.1,0.1,0.8,0.8])
im = m.imshow(etopo)
# draw coastlines and fill continents.
m.drawcoastlines()
m.fillcontinents()
# draw parallels, label on bottom.
circles = arange(-90.,120.,30.)
m.drawparallels(circles,labels=[1,0,0,0])
# draw meridians, label on left.
meridians = arange(0.,390.,60.)
m.drawmeridians(meridians,labels=[0,0,0,1])
title('Cylindrical Equidistant')
show()

예제 #16
0
# get data from DEM file
array = gd.ReadAsArray()
# get lat/lon coordinates from DEM file.
coords = gd.GetGeoTransform()
llcrnrlon = coords[0]
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 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)
예제 #17
0
파일: test.py 프로젝트: jtomase/matplotlib
# shift data so lons go from -180 to 180 instead of 20 to 380.
topoin, lons = shiftgrid(180., topodatin, lonsin, start=False)
lats = latsin

print 'min/max etopo20 data:'
print min(ravel(topoin)), max(ravel(topoin))

# create new figure
fig = figure()
# setup cylindrical equidistant map projection (global domain).
m = Basemap(llcrnrlon=-180.,llcrnrlat=-90,urcrnrlon=180.,urcrnrlat=90.,\
            resolution='c',area_thresh=10000.,projection='cyl')
ax = fig.add_axes([0.1, 0.1, 0.7, 0.7])
# plot image over map.
im = m.imshow(topoin, cm.jet)
l, b, w, h = ax.get_position()
cax = axes([l + w + 0.05, b, 0.05, h])  # setup colorbar axes.
colorbar(cax=cax)  # draw colorbar
axes(ax)  # make the original axes current again
m.drawcoastlines()
#m.drawcountries()
#m.drawstates()
#m.fillcontinents()
# draw parallels
delat = 30.
circles = arange(0.,90.+delat,delat).tolist()+\
          arange(-delat,-90.-delat,-delat).tolist()
m.drawparallels(circles, labels=[1, 0, 0, 1])
# draw meridians
delon = 60.
예제 #18
0
# get data from DEM file
array = gd.ReadAsArray()
# get lat/lon coordinates from DEM file.
coords = gd.GetGeoTransform()
llcrnrlon = coords[0]
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')
예제 #19
0
# define lat/lon grid that image spans (projection='cyl').
nlons = rgba.shape[1]
nlats = rgba.shape[0]
delta = 360. / float(nlons)
lons = P.arange(-180. + 0.5 * delta, 180., delta)
lats = P.arange(-90. + 0.5 * delta, 90., delta)

# define cylindrical equidistant projection.
m = Basemap(projection='cyl',
            llcrnrlon=-180,
            llcrnrlat=-90,
            urcrnrlon=180,
            urcrnrlat=90,
            resolution='l')
# plot (unwarped) rgba image.
im = m.imshow(rgba)
# draw coastlines.
m.drawcoastlines(linewidth=0.5, color='0.5')
# draw lat/lon grid lines.
m.drawmeridians(P.arange(-180, 180, 60), labels=[0, 0, 0, 1], color='0.5')
m.drawparallels(P.arange(-90, 90, 30), labels=[1, 0, 0, 0], color='0.5')
P.title("Blue Marble image - native 'cyl' projection", fontsize=12)
P.show()

# define orthographic projection centered on North America.
m = Basemap(projection='ortho', lat_0=40, lon_0=40, resolution='l')
# transform to nx x ny regularly spaced native projection grid
# nx and ny chosen to have roughly the same horizontal res as original image.
dx = 2. * P.pi * m.rmajor / float(nlons)
nx = int((m.xmax - m.xmin) / dx) + 1
ny = int((m.ymax - m.ymin) / dx) + 1
예제 #20
0
# shift data so lons go from -180 to 180 instead of 20 to 380.
topoin,lons = shiftgrid(180.,topoin,lons,start=False)

print 'min/max etopo20 data:'
print min(ravel(topoin)),max(ravel(topoin))

# setup cylindrical equidistant map projection (global domain).
m = Basemap(-180.,-90,180.,90.,\
            resolution='c',area_thresh=10000.,projection='cyl')
# 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.75,0.75])
# plot image over map.
im = m.imshow(topoin,cm.jet)
cax = axes([0.875, 0.1, 0.05, 0.75]) # setup colorbar axes.
colorbar(tickfmt='%d', cax=cax) # draw colorbar
axes(ax)  # make the original axes current again
m.drawcoastlines()
#m.drawcountries()
#m.drawstates()
#m.fillcontinents()
# draw parallels
delat = 30.
circles = arange(0.,90.+delat,delat).tolist()+\
          arange(-delat,-90.-delat,-delat).tolist()
m.drawparallels(circles,labels=[1,0,0,1])
# draw meridians
delon = 60.
meridians = arange(-180,180,delon)
예제 #21
0
# use major and minor sphere radii from WGS84 ellipsoid.
m = Basemap(llcrnrlon=-145.5,llcrnrlat=1.,urcrnrlon=-2.566,urcrnrlat=46.352,\
            rsphere=(6378137.00,6356752.3142),\
            resolution='l',area_thresh=1000.,projection='lcc',\
            lat_1=50.,lon_0=-107.)
# transform to nx x ny regularly spaced native projection grid
nx = int((m.xmax-m.xmin)/40000.)+1; ny = int((m.ymax-m.ymin)/40000.)+1
topodat,x,y = m.transform_scalar(topoin,lonsin,latsin,nx,ny,returnxy=True)
# set up figure with same aspect ratio as map.
fig=m.createfigure()
ax = fig.add_axes([0.1,0.1,0.7,0.7],axisbg='aqua')
# make topodat a masked array, masking values lower than sea level.
topodat = where(topodat < 0.,1.e10,topodat)
topodat = ma.masked_values(topodat, 1.e10)
# plot image over map with imshow.
im = m.imshow(topodat,cm.jet,norm=colors.normalize(vmin=-4000.0,vmax=3000.0,clip=False))
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.,80,20.)
m.drawparallels(parallels,labels=[1,1,0,1])
예제 #22
0
pilImage = Image.open('land_shallow_topo_2048.jpg')
rgba = pil_to_array(pilImage)
rgba = rgba.astype(P.Float32)/255. # convert to normalized floats.

# define lat/lon grid that image spans (projection='cyl').
nlons = rgba.shape[1]; nlats = rgba.shape[0]
delta = 360./float(nlons)
lons = P.arange(-180.+0.5*delta,180.,delta)
lats = P.arange(-90.+0.5*delta,90.,delta)

# create new figure
fig=P.figure()
# define cylindrical equidistant projection.
m = Basemap(projection='cyl',llcrnrlon=-180,llcrnrlat=-90,urcrnrlon=180,urcrnrlat=90,resolution='l')
# plot (unwarped) rgba image.
im = m.imshow(rgba)
# draw coastlines.
m.drawcoastlines(linewidth=0.5,color='0.5')
# draw lat/lon grid lines.
m.drawmeridians(P.arange(-180,180,60),labels=[0,0,0,1],color='0.5')
m.drawparallels(P.arange(-90,90,30),labels=[1,0,0,0],color='0.5')
P.title("Blue Marble image - native 'cyl' projection",fontsize=12)
print 'plot cylindrical map (no warping needed) ...'

# create new figure
fig=P.figure()
# define orthographic projection centered on North America.
m = Basemap(projection='ortho',lat_0=40,lon_0=40,resolution='l')
# transform to nx x ny regularly spaced native projection grid
# nx and ny chosen to have roughly the same horizontal res as original image.
dx = 2.*P.pi*m.rmajor/float(nlons)
예제 #23
0
# define data region and projection parameters
ll_lon = 9.74
ll_lat = -35.55
ur_lon = 48.45
ur_lat = 0.2
lon_0 = 0.0
satellite_height = 35785831.0

fig = figure(figsize=(7,7))
ax = fig.add_axes((0.1,0.1,0.8,0.8))
# create Basemap instance for a Geostationary projection.
m = Basemap(projection='geos', lon_0=lon_0, satellite_height=satellite_height,
            resolution='l', llcrnrlon=ll_lon, llcrnrlat=ll_lat, urcrnrlon=ur_lon, urcrnrlat=ur_lat)
# add data
m.imshow(data, cmap=cm.gray, interpolation='nearest')
clim(0, 255)
# draw coastlines.
m.drawcoastlines(linewidth=0.5, color=overlay_color)
m.drawcountries(linewidth=0.5, color=overlay_color)
# can't label meridians on bottom, because labels would
# be outside map projection region.
m.drawmeridians(arange(10,76,5), labels=[0,0,1,0], color=overlay_color)
m.drawparallels(arange(-90,90,5), labels=[1,0,0,0], color=overlay_color)
# add a colobar
#colorbar()
# add timestamp and save
fig = gcf()
fig.text(x=0.275, y=0.025, s=u'Meteosat-9 VIS 0.6 channel - 12:00 UTC 04/06/2007\n    \N{COPYRIGHT SIGN} EUMETSAT 2007',
            horizontalalignment='left',
            verticalalignment='bottom',