示例#1
0
"""
draw Atlantic Hurricane Tracks for storms that reached Cat 4 or 5.
part of the track for which storm is cat 4 or 5 is shown red.
ESRI shapefile data from http://www.nationalatlas.gov/atlasftp.html
"""
import pylab as p
from matplotlib.toolkits.basemap import Basemap as Basemap
# Lambert Conformal Conic map.
m = Basemap(llcrnrlon=-100.,llcrnrlat=0.,urcrnrlon=-20.,urcrnrlat=57.,
            projection='lcc',lat_1=20.,lat_2=40.,lon_0=-60.)
# make sure map has right aspect ratio.
fig=p.figure(figsize=(8,m.aspect*8))
fig.add_axes([0.1,0.1,0.8,0.8])
# read shapefile.
shp_info = m.readshapefile('huralll020','hurrtracks',drawbounds=False)
print shp_info
# find names of storms that reached Cat 4.
names = []
for shapedict in m.hurrtracks_info:
    cat = shapedict['CATEGORY']
    name = shapedict['NAME']
    if cat in ['H4','H5'] and name not in names:
        if name != 'NOT NAMED':  names.append(name)
print names
print len(names)
# plot tracks of those storms.
for shapedict,shape in zip(m.hurrtracks_info,m.hurrtracks):
    name = shapedict['NAME']
    cat = shapedict['CATEGORY']
    if name in names:
        xx,yy = zip(*shape)
示例#2
0
from matplotlib.toolkits.basemap import Basemap as Basemap
from matplotlib.collections import LineCollection
from matplotlib.colors import rgb2hex
import random

# requires pyshapelib from Thuban (http://thuban.intevation.org/).
# cd to libraries/pyshapelib in Thuban source distribution, run
# 'python setup.py install'.

# Lambert Conformal map of lower 48 states.
m = Basemap(llcrnrlon=-119,llcrnrlat=22,urcrnrlon=-64,urcrnrlat=49,
            projection='lcc',lat_1=33,lat_2=45,lon_0=-95)
fig=p.figure(figsize=(8,m.aspect*8))
fig.add_axes([0.1,0.1,0.8,0.8])
# draw climate division boundaries.
shp_info = m.readshapefile('divisions','climdivs',drawbounds=True)
print shp_info
# make sure the shapefile has polygons (and not just lines).
if shp_info[1] != 5:
    print 'warning: shapefile does not contain polygons'
# choose a color for each climate division (randomly).
colors={}
divnames=[]
print m.climdivs_info[0].keys()
for shapedict in m.climdivs_info:
    divname = shapedict['ST']+repr(shapedict['DIV'])
    colors[divname] = (random.uniform(0,1),random.uniform(0,1),random.uniform(0,1))
    divnames.append(divname)
# cycle through climate divnames, color each one.
for nshape,seg in enumerate(m.climdivs):
    xx,yy = zip(*seg)
示例#3
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')
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()
示例#4
0
from matplotlib.colors import rgb2hex
import random

# Lambert Conformal map of lower 48 states.
m = Basemap(llcrnrlon=-119,
            llcrnrlat=22,
            urcrnrlon=-64,
            urcrnrlat=49,
            projection='lcc',
            lat_1=33,
            lat_2=45,
            lon_0=-95)
fig = p.figure(figsize=(8, m.aspect * 8))
fig.add_axes([0.1, 0.1, 0.8, 0.8])
# draw climate division boundaries.
shp_info = m.readshapefile('divisions', 'climdivs', drawbounds=True)
print shp_info
# make sure the shapefile has polygons (and not just lines).
if shp_info[1] != 5:
    print 'warning: shapefile does not contain polygons'
# choose a color for each climate division (randomly).
colors = {}
divnames = []
print m.climdivs_info[0].keys()
for shapedict in m.climdivs_info:
    divname = shapedict['ST'] + repr(shapedict['DIV'])
    colors[divname] = (random.uniform(0, 1), random.uniform(0, 1),
                       random.uniform(0, 1))
    divnames.append(divname)
# cycle through climate divnames, color each one.
for nshape, seg in enumerate(m.climdivs):
示例#5
0
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()
示例#6
0
import pylab as p
import matplotlib.numerix as nx
from matplotlib.toolkits.basemap import Basemap as Basemap
from matplotlib.colors import rgb2hex
from matplotlib.patches import Polygon

# Lambert Conformal map of lower 48 states.
m = Basemap(llcrnrlon=-119, llcrnrlat=22, urcrnrlon=-64, urcrnrlat=49, projection="lcc", lat_1=33, lat_2=45, lon_0=-95)
# draw state boundaries.
# data from U.S Census Bureau
# http://www.census.gov/geo/www/cob/st2000.html
shp_info = m.readshapefile("st99_d00", "states", drawbounds=True)
# population density by state from
# http://en.wikipedia.org/wiki/List_of_U.S._states_by_population_density
popdensity = {
    "New Jersey": 438.00,
    "Rhode Island": 387.35,
    "Massachusetts": 312.68,
    "Connecticut": 271.40,
    "Maryland": 209.23,
    "New York": 155.18,
    "Delaware": 154.87,
    "Florida": 114.43,
    "Ohio": 107.05,
    "Pennsylvania": 105.80,
    "Illinois": 86.27,
    "California": 83.85,
    "Hawaii": 72.83,
    "Virginia": 69.03,
    "Michigan": 67.55,
    "Indiana": 65.46,
示例#7
0
# Lambert Conformal Conic map.
m = Basemap(llcrnrlon=-100.,
            llcrnrlat=0.,
            urcrnrlon=-20.,
            urcrnrlat=57.,
            projection='lcc',
            lat_1=20.,
            lat_2=40.,
            lon_0=-60.,
            resolution='l',
            area_thresh=1000.)
# create figure, add axes.
fig = p.figure()
fig.add_axes([0.1, 0.1, 0.8, 0.8], axisbg='#99ffff')
# read shapefile.
shp_info = m.readshapefile('huralll020', 'hurrtracks', drawbounds=False)
print shp_info
# find names of storms that reached Cat 4.
names = []
for shapedict in m.hurrtracks_info:
    cat = shapedict['CATEGORY']
    name = shapedict['NAME']
    if cat in ['H4', 'H5'] and name not in names:
        # only use named storms.
        if name != 'NOT NAMED': names.append(name)
print names
print len(names)
# plot tracks of those storms.
for shapedict, shape in zip(m.hurrtracks_info, m.hurrtracks):
    name = shapedict['NAME']
    cat = shapedict['CATEGORY']
示例#8
0
import pylab as p
import matplotlib.numerix as nx
from matplotlib.toolkits.basemap import Basemap as Basemap
from matplotlib.colors import rgb2hex

# Lambert Conformal map of lower 48 states.
m = Basemap(llcrnrlon=-119,llcrnrlat=22,urcrnrlon=-64,urcrnrlat=49,
            projection='lcc',lat_1=33,lat_2=45,lon_0=-95)
fig=m.createfigure()
# draw state boundaries.
# data from U.S Census Bureau
# http://www.census.gov/geo/www/cob/st1990.html
shp_info = m.readshapefile('st99_d90','states',drawbounds=True)
# population density by state from
# http://en.wikipedia.org/wiki/List_of_U.S._states_by_population_density
popdensity = {
'New Jersey':  438.00,
'Rhode Island':   387.35,
'Massachusetts':   312.68,
'Connecticut':	  271.40,
'Maryland':   209.23,
'New York':    155.18,
'Delaware':    154.87,
'Florida':     114.43,
'Ohio':	 107.05,
'Pennsylvania':	 105.80,
'Illinois':    86.27,
'California':  83.85,
'Hawaii':  72.83,
'Virginia':    69.03,
'Michigan':    67.55,
示例#9
0
lon_150=[]
lat_150=[]
for xy in verts:
	lon_150.append(xy[0])
	lat_150.append(xy[1])

close(f)
dd_box=[array(lon_150).min(), array(lon_150).max(), array(lat_150).min(), array(lat_150).max()]
fat=0.05
box=[dd_box[0]-fat, dd_box[1]+fat, dd_box[2]-fat, dd_box[3]+fat]
f=figure()
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)
示例#10
0
from matplotlib.colors import rgb2hex

# Lambert Conformal map of lower 48 states.
m = Basemap(llcrnrlon=-119,
            llcrnrlat=22,
            urcrnrlon=-64,
            urcrnrlat=49,
            projection='lcc',
            lat_1=33,
            lat_2=45,
            lon_0=-95)
fig = m.createfigure()
# draw state boundaries.
# data from U.S Census Bureau
# http://www.census.gov/geo/www/cob/st1990.html
shp_info = m.readshapefile('st99_d90', 'states', drawbounds=True)
# population density by state from
# http://en.wikipedia.org/wiki/List_of_U.S._states_by_population_density
popdensity = {
    'New Jersey': 438.00,
    'Rhode Island': 387.35,
    'Massachusetts': 312.68,
    'Connecticut': 271.40,
    'Maryland': 209.23,
    'New York': 155.18,
    'Delaware': 154.87,
    'Florida': 114.43,
    'Ohio': 107.05,
    'Pennsylvania': 105.80,
    'Illinois': 86.27,
    'California': 83.85,
示例#11
0
# Tissot's Indicatrix (http://en.wikipedia.org/wiki/Tissot's_Indicatrix). 
# These diagrams illustrate the distortion inherent in all map projections.
# In conformal projections, where angles are conserved around every location, 
# the Tissot's indicatrix are all circles, with varying sizes. In equal-area 
# projections, where area proportions between objects are conserved, the 
# Tissot's indicatrix have all unit area, although their shapes and 
# orientations vary with location.

# adapted from http://www.perrygeo.net/wordpress/?p=4

# create new figure
fig=p.figure()
m = Basemap(llcrnrlon=-180,llcrnrlat=-80,urcrnrlon=180,urcrnrlat=80,
            projection='cyl')
shp_info = m.readshapefile('tissot','tissot',drawbounds=True)
ax = p.gca()
for nshape,seg in enumerate(m.tissot):
    poly = Polygon(seg,facecolor='green',zorder=10)
    ax.add_patch(poly)
# draw meridians and parallels.
m.drawparallels(p.arange(-90,91,30),labels=[1,0,0,0])
m.drawmeridians(p.arange(-180,180,60),labels=[0,0,0,1])
m.drawcoastlines()
m.fillcontinents()
p.title('Tissot Diagram - Cylindrical Equal Area')
print 'plot Cylindrical Equidistant Equal Area Tissot diagram ...'

# create new figure
fig=p.figure()
m = Basemap(llcrnrlon=-180,llcrnrlat=-70,urcrnrlon=180,urcrnrlat=70,
示例#12
0
# In conformal projections, where angles are conserved around every location,
# the Tissot's indicatrix are all circles, with varying sizes. In equal-area
# projections, where area proportions between objects are conserved, the
# Tissot's indicatrix have all unit area, although their shapes and
# orientations vary with location.

# adapted from http://www.perrygeo.net/wordpress/?p=4

# create new figure
fig = p.figure()
m = Basemap(llcrnrlon=-180,
            llcrnrlat=-80,
            urcrnrlon=180,
            urcrnrlat=80,
            projection='cyl')
shp_info = m.readshapefile('tissot', 'tissot', drawbounds=True)
ax = p.gca()
for nshape, seg in enumerate(m.tissot):
    poly = Polygon(seg, facecolor='green', zorder=10)
    ax.add_patch(poly)
# draw meridians and parallels.
m.drawparallels(p.arange(-90, 91, 30), labels=[1, 0, 0, 0])
m.drawmeridians(p.arange(-180, 180, 60), labels=[0, 0, 0, 1])
m.drawcoastlines()
m.fillcontinents()
p.title('Tissot Diagram - Cylindrical Equal Area')
print 'plot Cylindrical Equidistant Equal Area Tissot diagram ...'

# create new figure
fig = p.figure()
m = Basemap(llcrnrlon=-180,