Skip to content

Commit 4b459b0

Browse files
author
Jeff Whitaker
committed
Merge pull request #138 from j08lue/master
improvement of basemap.addcyclic
2 parents a68aeb3 + 0ad978a commit 4b459b0

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

Changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ version 1.0.8 (not yet released)
66
ability to fill counties with specified matplotlib color argument.
77
* fix drawgreatcircle bug so that lines exiting and reentering a projection
88
region don't draw horizontally across the map.
9+
* change addcyclic so that it works for ND-arrays with an optional 'axis' parameter.
910

1011
version 1.0.7 (git tag v1.0.7rel)
1112
---------------------------------

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ Jeff Whitaker <[email protected]>
108108

109109
##Thanks
110110

111-
Special thanks to John Hunter, Andrew Straw, Eric Firing, Rob Hetland, Scott Sinclair, Ivan Lima, Erik Andersen, Michael Hearne, Jesper Larsen, Ryan May, David Huard, Mauro Cavalcanti, Chris Murphy, Pierre Gerard-Marchant, Christoph Gohlke, Eric Bruning, Stephane Raynaud, Tom Loredo, Patrick Marsh, Phil Elson, and Henry Hammond for valuable contributions.
111+
Special thanks to John Hunter, Andrew Straw, Eric Firing, Rob Hetland, Scott Sinclair, Ivan Lima, Erik Andersen, Michael Hearne, Jesper Larsen, Ryan May, David Huard, Mauro Cavalcanti, Chris Murphy, Pierre Gerard-Marchant, Christoph Gohlke, Eric Bruning, Stephane Raynaud, Tom Loredo, Patrick Marsh, Jonas Bluethgen, Phil Elson, and Henry Hammond for valuable contributions.

lib/mpl_toolkits/basemap/__init__.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5087,28 +5087,25 @@ 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(*arr,**axiskwarg):
50915091
"""
5092-
``arrout, lonsout = addcyclic(arrin, lonsin)``
5093-
adds cyclic (wraparound) point in longitude to ``arrin`` and ``lonsin``,
5094-
assumes longitude is the right-most dimension of ``arrin``.
5092+
``arrout, lonsout = addcyclic(arrin,lonsin,axis=-1)``
5093+
adds cyclic (wraparound) points in longitude to one or several arrays,
5094+
(e.g. ``arrin`` and ``lonsin``),
5095+
where ``axis`` sets the dimension longitude is in (optional, default: right-most).
50955096
"""
5096-
nlons = arrin.shape[-1]
5097-
newshape = list(arrin.shape)
5098-
newshape[-1] += 1
5099-
if ma.isMA(arrin):
5100-
arrout = ma.zeros(newshape,arrin.dtype)
5097+
# get axis keyword argument (default: -1)
5098+
axis = axiskwarg.get('axis',-1)
5099+
# define function for a single grid array
5100+
def _addcyclic(a):
5101+
aT = np.swapaxes(a,0,axis)
5102+
idx = np.append(np.arange(aT.shape[0]),0)
5103+
return np.swapaxes(aT[idx],axis,0)
5104+
# process array(s)
5105+
if len(arr) == 1:
5106+
return _addcyclic(arr[0])
51015107
else:
5102-
arrout = np.zeros(newshape,arrin.dtype)
5103-
arrout[...,0:nlons] = arrin[:]
5104-
arrout[...,nlons] = arrin[...,0]
5105-
if ma.isMA(lonsin):
5106-
lonsout = ma.zeros(nlons+1,lonsin.dtype)
5107-
else:
5108-
lonsout = np.zeros(nlons+1,lonsin.dtype)
5109-
lonsout[0:nlons] = lonsin[:]
5110-
lonsout[nlons] = lonsin[-1] + lonsin[1]-lonsin[0]
5111-
return arrout,lonsout
5108+
return map(_addcyclic,arr)
51125109

51135110
def _choosecorners(width,height,**kwargs):
51145111
"""

0 commit comments

Comments
 (0)