Skip to content

Commit 41f85c7

Browse files
author
Jeff Whitaker
committed
Merge pull request #98 from ajdawson/addcyclic-ndim
Extended addcyclic to arbitrary dimensions.
2 parents 60e417c + 16d220c commit 41f85c7

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/mpl_toolkits/basemap/__init__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4970,16 +4970,18 @@ def shiftgrid(lon0,datain,lonsin,start=True,cyclic=360.0):
49704970
def addcyclic(arrin,lonsin):
49714971
"""
49724972
``arrout, lonsout = addcyclic(arrin, lonsin)``
4973-
adds cyclic (wraparound) point in longitude to ``arrin`` and ``lonsin``.
4973+
adds cyclic (wraparound) point in longitude to ``arrin`` and ``lonsin``,
4974+
assumes longitude is the right-most dimension of ``arrin``.
49744975
"""
4975-
nlats = arrin.shape[0]
4976-
nlons = arrin.shape[1]
4976+
nlons = arrin.shape[-1]
4977+
newshape = list(arrin.shape)
4978+
newshape[-1] += 1
49774979
if ma.isMA(arrin):
4978-
arrout = ma.zeros((nlats,nlons+1),arrin.dtype)
4980+
arrout = ma.zeros(newshape,arrin.dtype)
49794981
else:
4980-
arrout = np.zeros((nlats,nlons+1),arrin.dtype)
4981-
arrout[:,0:nlons] = arrin[:,:]
4982-
arrout[:,nlons] = arrin[:,0]
4982+
arrout = np.zeros(newshape,arrin.dtype)
4983+
arrout[...,0:nlons] = arrin[:]
4984+
arrout[...,nlons] = arrin[...,0]
49834985
if ma.isMA(lonsin):
49844986
lonsout = ma.zeros(nlons+1,lonsin.dtype)
49854987
else:

0 commit comments

Comments
 (0)