Skip to content

Commit 7584d6e

Browse files
author
Jeff Whitaker
committed
Merge pull request #62 from jswhit/master
fix bug in drawlsmask
2 parents 3e9ae52 + 249fd70 commit 7584d6e

File tree

3 files changed

+57
-38
lines changed

3 files changed

+57
-38
lines changed

Changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
version 1.0.5 (git tag v1.0.5rel)
22
---------------------------------
3+
* fix bug triggered when drawlsmask method called more than once.
34
* fix error in contour method that caused a bogus mask to be applied
45
to the data (issue 58).
56
* fix further corner cases with splitting of parallels that cross

examples/wiki_example.py

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
# set up orthographic map projection with
55
# perspective of satellite looking down at 50N, 100W.
66
# use low resolution coastlines.
7-
map = Basemap(projection='ortho',lat_0=45,lon_0=-100,resolution='l')
7+
bmap = Basemap(projection='ortho',lat_0=45,lon_0=-100,resolution='l')
88
# draw coastlines, country boundaries, fill continents.
9-
map.drawcoastlines(linewidth=0.25)
10-
map.drawcountries(linewidth=0.25)
11-
map.fillcontinents(color='coral',lake_color='aqua')
9+
bmap.drawcoastlines(linewidth=0.25)
10+
bmap.drawcountries(linewidth=0.25)
11+
bmap.fillcontinents(color='coral',lake_color='aqua')
1212
# draw the edge of the map projection region (the projection limb)
13-
map.drawmapboundary(fill_color='aqua')
13+
bmap.drawmapboundary(fill_color='aqua')
1414
# draw lat/lon grid lines every 30 degrees.
15-
map.drawmeridians(np.arange(0,360,30))
16-
map.drawparallels(np.arange(-90,90,30))
15+
bmap.drawmeridians(np.arange(0,360,30))
16+
bmap.drawparallels(np.arange(-90,90,30))
1717
# lat/lon coordinates of five cities.
1818
lats=[40.02,32.73,38.55,48.25,17.29]
1919
lons=[-105.16,-117.16,-77.00,-114.21,-88.10]
2020
cities=['Boulder, CO','San Diego, CA',
2121
'Washington, DC','Whitefish, MT','Belize City, Belize']
2222
# compute the native map projection coordinates for cities.
23-
xc,yc = map(lons,lats)
23+
xc,yc = bmap(lons,lats)
2424
# plot filled circles at the locations of the cities.
25-
map.plot(xc,yc,'bo')
25+
bmap.plot(xc,yc,'bo')
2626
# plot the names of those five cities.
2727
for name,xpt,ypt in zip(cities,xc,yc):
2828
plt.text(xpt+50000,ypt+50000,name,fontsize=9)
@@ -33,69 +33,87 @@
3333
wave = 0.75*(np.sin(2.*lats)**8*np.cos(4.*lons))
3434
mean = 0.5*np.cos(2.*lats)*((np.sin(2.*lats))**2 + 2.)
3535
# compute native map projection coordinates of lat/lon grid.
36-
x, y = map(lons*180./np.pi, lats*180./np.pi)
36+
x, y = bmap(lons*180./np.pi, lats*180./np.pi)
3737
# contour data over the map.
38-
cs = map.contour(x,y,wave+mean,15,linewidths=1.5)
38+
cs = bmap.contour(x,y,wave+mean,15,linewidths=1.5)
3939
plt.title('filled continent background')
4040

4141
# as above, but use land-sea mask image as map background.
4242
fig = plt.figure()
43-
map.drawmapboundary()
44-
map.drawmeridians(np.arange(0,360,30))
45-
map.drawparallels(np.arange(-90,90,30))
43+
bmap.drawmapboundary()
44+
bmap.drawmeridians(np.arange(0,360,30))
45+
bmap.drawparallels(np.arange(-90,90,30))
4646
# plot filled circles at the locations of the cities.
47-
map.plot(xc,yc,'wo')
47+
bmap.plot(xc,yc,'wo')
4848
# plot the names of five cities.
4949
for name,xpt,ypt in zip(cities,xc,yc):
5050
plt.text(xpt+50000,ypt+50000,name,fontsize=9,color='w')
5151
# contour data over the map.
52-
cs = map.contour(x,y,wave+mean,15,linewidths=1.5)
52+
cs = bmap.contour(x,y,wave+mean,15,linewidths=1.5)
5353
plt.title('land-sea mask background')
54-
map.drawlsmask(ocean_color='aqua',land_color='coral')
54+
bmap.drawlsmask(ocean_color='aqua',land_color='coral')
5555

5656
# as above, but use blue marble image as map background.
5757
fig = plt.figure()
58-
map.drawmapboundary()
59-
map.drawmeridians(np.arange(0,360,30))
60-
map.drawparallels(np.arange(-90,90,30))
58+
bmap.drawmapboundary()
59+
bmap.drawmeridians(np.arange(0,360,30))
60+
bmap.drawparallels(np.arange(-90,90,30))
6161
# plot filled circles at the locations of the cities.
62-
map.plot(xc,yc,'wo')
62+
bmap.plot(xc,yc,'wo')
6363
# plot the names of five cities.
6464
for name,xpt,ypt in zip(cities,xc,yc):
6565
plt.text(xpt+50000,ypt+50000,name,fontsize=9,color='w')
6666
# contour data over the map.
67-
cs = map.contour(x,y,wave+mean,15,linewidths=1.5)
67+
cs = bmap.contour(x,y,wave+mean,15,linewidths=1.5)
6868
plt.title('blue marble background')
69-
map.bluemarble()
69+
bmap.bluemarble()
7070

7171
# as above, but use shaded relief image as map background.
7272
fig = plt.figure()
73-
map.drawmapboundary()
74-
map.drawmeridians(np.arange(0,360,30))
75-
map.drawparallels(np.arange(-90,90,30))
73+
bmap.drawmapboundary()
74+
bmap.drawmeridians(np.arange(0,360,30))
75+
bmap.drawparallels(np.arange(-90,90,30))
7676
# plot filled circles at the locations of the cities.
77-
map.plot(xc,yc,'wo')
77+
bmap.plot(xc,yc,'wo')
7878
# plot the names of five cities.
7979
for name,xpt,ypt in zip(cities,xc,yc):
8080
plt.text(xpt+50000,ypt+50000,name,fontsize=9,color='w')
8181
# contour data over the map.
82-
cs = map.contour(x,y,wave+mean,15,linewidths=1.5)
82+
cs = bmap.contour(x,y,wave+mean,15,linewidths=1.5)
8383
plt.title('shaded relief background')
84-
map.shadedrelief()
84+
bmap.shadedrelief()
8585

8686
# as above, but use etopo image as map background.
8787
fig = plt.figure()
88-
map.drawmapboundary()
89-
map.drawmeridians(np.arange(0,360,30))
90-
map.drawparallels(np.arange(-90,90,30))
88+
bmap.drawmapboundary()
89+
bmap.drawmeridians(np.arange(0,360,30))
90+
bmap.drawparallels(np.arange(-90,90,30))
9191
# plot filled circles at the locations of the cities.
92-
map.plot(xc,yc,'wo')
92+
bmap.plot(xc,yc,'wo')
9393
# plot the names of five cities.
9494
for name,xpt,ypt in zip(cities,xc,yc):
9595
plt.text(xpt+50000,ypt+50000,name,fontsize=9,color='w')
9696
# contour data over the map.
97-
cs = map.contour(x,y,wave+mean,15,linewidths=1.5)
97+
cs = bmap.contour(x,y,wave+mean,15,linewidths=1.5)
9898
plt.title('etopo background')
99-
map.etopo()
99+
bmap.etopo()
100+
101+
# as above, but use etopo image as map background overlaid with
102+
# land-sea mask image where land areas are transparent (so etopo
103+
# image shows through over land).
104+
fig = plt.figure()
105+
bmap.drawmapboundary()
106+
bmap.drawmeridians(np.arange(0,360,30))
107+
bmap.drawparallels(np.arange(-90,90,30))
108+
# plot filled circles at the locations of the cities.
109+
bmap.plot(xc,yc,'wo')
110+
# plot the names of five cities.
111+
for name,xpt,ypt in zip(cities,xc,yc):
112+
plt.text(xpt+50000,ypt+50000,name,fontsize=9,color='w')
113+
# contour data over the map.
114+
cs = bmap.contour(x,y,wave+mean,15,linewidths=1.5)
115+
plt.title('etopo background with oceans masked')
116+
bmap.etopo()
117+
bmap.drawlsmask(ocean_color='DarkBlue',land_color=(255,255,255,1))
100118

101119
plt.show()

lib/mpl_toolkits/basemap/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3679,14 +3679,14 @@ def drawlsmask(self,land_color="0.8",ocean_color="w",lsmask=None,
36793679
mask[j,:]=np.where(np.logical_or(xx<xmin[j],xx>xmax[j]),\
36803680
255,mask[j,:])
36813681
self.lsmask = mask
3682-
ny, nx = mask.shape
3682+
ny, nx = self.lsmask.shape
36833683
rgba = np.ones((ny,nx,4),np.uint8)
36843684
rgba_land = np.array(rgba_land,np.uint8)
36853685
rgba_ocean = np.array(rgba_ocean,np.uint8)
36863686
for k in range(4):
3687-
rgba[:,:,k] = np.where(mask,rgba_land[k],rgba_ocean[k])
3687+
rgba[:,:,k] = np.where(self.lsmask,rgba_land[k],rgba_ocean[k])
36883688
# make points outside projection limb transparent.
3689-
rgba[:,:,3] = np.where(mask==255,0,rgba[:,:,3])
3689+
rgba[:,:,3] = np.where(self.lsmask==255,0,rgba[:,:,3])
36903690
# plot mask as rgba image.
36913691
im = self.imshow(rgba,interpolation='nearest',ax=ax,**kwargs)
36923692
# clip for round polar plots.

0 commit comments

Comments
 (0)