Skip to content

Commit 9eb1377

Browse files
author
Jeff Whitaker
committed
Merge pull request #102 from jswhit/master
fix warpimage for projection = 'hammer' (issue 100)
2 parents 41f85c7 + 26cb6e0 commit 9eb1377

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Changelog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
since version 1.0.6
2+
-------------------
3+
* fix warpimage with projection = 'hammer' (issue 100).
4+
15
version 1.0.6 (git tag v1.0.6rel)
26
--------------------------------
37
* fix drawcounties for Python 3.3.

examples/warpimage.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@
3434
plt.title("Blue Marble image warped from 'cyl' to 'mbtfpq' projection",fontsize=12)
3535
print('warp to McBryde-Thomas Flat-Polar Quartic map ...')
3636

37+
# create new figure
38+
fig=plt.figure()
39+
# define projection centered on North America.
40+
m = Basemap(projection='hammer',lon_0=-100,resolution='l')
41+
m.bluemarble(scale=0.5)
42+
# draw coastlines.
43+
m.drawcoastlines(linewidth=0.5,color='0.5')
44+
# draw lat/lon grid lines every 30 degrees.
45+
m.drawmeridians(np.arange(0,360,60),color='0.5')
46+
m.drawparallels(np.arange(-90,90,30),color='0.5')
47+
plt.title("Blue Marble image warped from 'cyl' to 'hammer' projection",fontsize=12)
48+
print('warp to Hammer map ...')
49+
3750
# create new figure
3851
fig=plt.figure()
3952
# define cylindrical equidistant projection.

lib/mpl_toolkits/basemap/__init__.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3982,6 +3982,9 @@ def warpimage(self,image="bluemarble",scale=None,**kwargs):
39823982
except ImportError:
39833983
raise ImportError('warpimage method requires PIL (http://www.pythonware.com/products/pil)')
39843984
from matplotlib.image import pil_to_array
3985+
if self.celestial:
3986+
msg='warpimage does not work in celestial coordinates'
3987+
raise ValueError(msg)
39853988
ax = kwargs.pop('ax', None) or self._check_ax()
39863989
# default image file is blue marble next generation
39873990
# from NASA (http://visibleearth.nasa.gov).
@@ -4089,7 +4092,8 @@ def warpimage(self,image="bluemarble",scale=None,**kwargs):
40894092
# make points outside projection limb transparent.
40904093
self._bm_rgba_warped = self._bm_rgba_warped.filled(0.)
40914094
# treat pseudo-cyl projections such as mollweide, robinson and sinusoidal.
4092-
elif self.projection in _pseudocyl:
4095+
elif self.projection in _pseudocyl and \
4096+
self.projection != 'hammer':
40934097
lonsr,latsr = self(x,y,inverse=True)
40944098
mask = ma.zeros((ny,nx,4),np.int8)
40954099
lon_0 = self.projparams['lon_0']
@@ -4112,6 +4116,12 @@ def warpimage(self,image="bluemarble",scale=None,**kwargs):
41124116
self._bm_rgba_warped = self._bm_rgba_warped.filled(0.)
41134117
# plot warped rgba image.
41144118
im = self.imshow(self._bm_rgba_warped,ax=ax,**kwargs)
4119+
# for hammer projection, use clip path defined by
4120+
# projection limb (patch created in drawmapboundary).
4121+
if self.projection == 'hammer':
4122+
if not self._mapboundarydrawn:
4123+
self.drawmapboundary(color='none',linewidth=None)
4124+
im.set_clip_path(self._mapboundarydrawn)
41154125
else:
41164126
# bmproj True, no interpolation necessary.
41174127
im = self.imshow(self._bm_rgba,ax=ax,**kwargs)

0 commit comments

Comments
 (0)