Skip to content

Commit 16d220c

Browse files
author
Andrew Dawson
committed
Extended addcyclic to arbitrary dimensions.
n-dimensional arrays can be passed to addcyclic, provided that longitude is the last (right-most) dimension.
1 parent e2474fd commit 16d220c

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
@@ -4977,16 +4977,18 @@ def shiftgrid(lon0,datain,lonsin,start=True,cyclic=360.0):
49774977
def addcyclic(arrin,lonsin):
49784978
"""
49794979
``arrout, lonsout = addcyclic(arrin, lonsin)``
4980-
adds cyclic (wraparound) point in longitude to ``arrin`` and ``lonsin``.
4980+
adds cyclic (wraparound) point in longitude to ``arrin`` and ``lonsin``,
4981+
assumes longitude is the right-most dimension of ``arrin``.
49814982
"""
4982-
nlats = arrin.shape[0]
4983-
nlons = arrin.shape[1]
4983+
nlons = arrin.shape[-1]
4984+
newshape = list(arrin.shape)
4985+
newshape[-1] += 1
49844986
if ma.isMA(arrin):
4985-
arrout = ma.zeros((nlats,nlons+1),arrin.dtype)
4987+
arrout = ma.zeros(newshape,arrin.dtype)
49864988
else:
4987-
arrout = np.zeros((nlats,nlons+1),arrin.dtype)
4988-
arrout[:,0:nlons] = arrin[:,:]
4989-
arrout[:,nlons] = arrin[:,0]
4989+
arrout = np.zeros(newshape,arrin.dtype)
4990+
arrout[...,0:nlons] = arrin[:]
4991+
arrout[...,nlons] = arrin[...,0]
49904992
if ma.isMA(lonsin):
49914993
lonsout = ma.zeros(nlons+1,lonsin.dtype)
49924994
else:

0 commit comments

Comments
 (0)