Skip to content

Commit acfea8a

Browse files
author
Jeff Whitaker
committed
don't assume grid is regular in longitude in addcyclic.
This requires a new kwarg 'cyclic_dimension', which is set to a default of 360. Addresses part of issue 139.
1 parent 9dfa89c commit acfea8a

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/mpl_toolkits/basemap/__init__.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,8 +2924,8 @@ def drawgreatcircle(self,lon1,lat1,lon2,lat2,del_s=100.,**kwargs):
29242924

29252925
# create new vertices with a nan inbetween and set those as the path's vertices
29262926
verts = np.concatenate(
2927-
[p.vertices[:cut_point, :],
2928-
[[np.nan, np.nan]],
2927+
[p.vertices[:cut_point, :],
2928+
[[np.nan, np.nan]],
29292929
p.vertices[cut_point+1:, :]]
29302930
)
29312931
p.codes = None
@@ -4087,7 +4087,7 @@ def warpimage(self,image="bluemarble",scale=None,**kwargs):
40874087
from PIL import Image
40884088
except ImportError:
40894089
try:
4090-
import Image
4090+
import Image
40914091
except ImportError:
40924092
raise ImportError('warpimage method requires PIL (http://www.pythonware.com/products/pil)')
40934093

@@ -5087,11 +5087,13 @@ def shiftgrid(lon0,datain,lonsin,start=True,cyclic=360.0):
50875087
dataout[...,i0_shift:] = datain[...,start_idx:i0+start_idx]
50885088
return dataout,lonsout
50895089

5090-
def addcyclic(arrin,lonsin):
5090+
def addcyclic(arrin,lonsin,cyclic_length=360):
50915091
"""
50925092
``arrout, lonsout = addcyclic(arrin, lonsin)``
50935093
adds cyclic (wraparound) point in longitude to ``arrin`` and ``lonsin``,
50945094
assumes longitude is the right-most dimension of ``arrin``.
5095+
If length of cyclic dimension is not 360 (degrees), set with kwarg
5096+
``cyclic_dimension``.
50955097
"""
50965098
nlons = arrin.shape[-1]
50975099
newshape = list(arrin.shape)
@@ -5107,8 +5109,10 @@ def addcyclic(arrin,lonsin):
51075109
else:
51085110
lonsout = np.zeros(nlons+1,lonsin.dtype)
51095111
lonsout[0:nlons] = lonsin[:]
5110-
lonsout[nlons] = lonsin[-1] + lonsin[1]-lonsin[0]
5111-
return arrout,lonsout
5112+
# this assumes a regular grid (in longitude)
5113+
#lonsout[nlons] = lonsin[-1] + lonsin[1]-lonsin[0]
5114+
# the version below is valid for irregular grids.
5115+
lonsout[nlons] = lonsin[-1] + cyclic_length % (lonsin[-1]-lonsin[0])
51125116

51135117
def _choosecorners(width,height,**kwargs):
51145118
"""

0 commit comments

Comments
 (0)