Skip to content

Commit 35b9207

Browse files
author
Henry Hammond
committed
Fixed great circle wrapping issues. Fixed PIL on OSX 10.9 issue.
1 parent 18e789f commit 35b9207

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

lib/mpl_toolkits/basemap/__init__.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,10 +2889,6 @@ def drawgreatcircle(self,lon1,lat1,lon2,lat2,del_s=100.,**kwargs):
28892889
method of Basemap instance.
28902890
============== =======================================================
28912891
2892-
.. note::
2893-
Cannot handle situations in which the great circle intersects
2894-
the edge of the map projection domain, and then re-enters the domain.
2895-
28962892
Returns a matplotlib.lines.Line2D object.
28972893
"""
28982894
# use great circle formula for a perfect sphere.
@@ -2906,7 +2902,34 @@ def drawgreatcircle(self,lon1,lat1,lon2,lat2,del_s=100.,**kwargs):
29062902
lats.append(lat)
29072903
lons.append(lon2); lats.append(lat2)
29082904
x, y = self(lons, lats)
2909-
return self.plot(x,y,**kwargs)
2905+
2906+
# Correct wrap around effect of great circles
2907+
2908+
# get points
2909+
p = self.plot(x,y,**kwargs)[0].get_path()
2910+
2911+
# since we know the difference between any two points, we can use this to find wrap arounds on the plot
2912+
max_dist = 1000*del_s*2
2913+
2914+
# calculate distances and compare with max allowable distance
2915+
dists = np.abs(np.diff(p.vertices[:,0]))
2916+
cuts = np.where( dists > max_dist )[0]
2917+
2918+
# if there are any cut points, cut them and begin again at the next point
2919+
for i,k in enumerate(cuts):
2920+
# vertex to cut at
2921+
cut_point = cuts[i]
2922+
2923+
# create new vertices with a nan inbetween and set those as the path's vertices
2924+
verts = np.concatenate(
2925+
[p.vertices[:cut_point, :],
2926+
[[np.nan, np.nan]],
2927+
p.vertices[cut_point+1:, :]]
2928+
)
2929+
p.codes = None
2930+
p.vertices = verts
2931+
2932+
return p
29102933

29112934
def transform_scalar(self,datin,lons,lats,nx,ny,returnxy=False,checkbounds=False,order=1,masked=False):
29122935
"""
@@ -4056,10 +4079,16 @@ def warpimage(self,image="bluemarble",scale=None,**kwargs):
40564079
40574080
returns a matplotlib.image.AxesImage instance.
40584081
"""
4082+
4083+
# fix PIL import on some versions of OSX and scipy
40594084
try:
40604085
from PIL import Image
40614086
except ImportError:
4062-
raise ImportError('warpimage method requires PIL (http://www.pythonware.com/products/pil)')
4087+
try:
4088+
import Image
4089+
except ImportError:
4090+
raise ImportError('warpimage method requires PIL (http://www.pythonware.com/products/pil)')
4091+
40634092
from matplotlib.image import pil_to_array
40644093
if self.celestial:
40654094
msg='warpimage does not work in celestial coordinates'

0 commit comments

Comments
 (0)