Skip to content

Commit 8862c27

Browse files
author
Jeff Whitaker
committed
Merge pull request #144 from jswhit/master
don't assume longitude grid is regular in addcyclic
2 parents 5e491a2 + f8139ca commit 8862c27

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Changelog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
version 1.0.8 (not yet released)
22
--------------------------------
3+
* don't assume grid is regular with adding cyclic point in addcyclic.
4+
New kwarg 'cyclic_dimension' added, with a default of 360. Partially
5+
addresses issue 139.
36
* fix for coastline drawing glitch (issue 123).
47
* update shapefile.py to version 1.2.0 from pyshp.googlecode.com. Add back
58
in modification clobbered in upgrade to version 1.1.7 (issue 30).

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_length``.
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)