# SciTools/iris

Closed
opened this Issue Sep 21, 2012 · 3 comments

### 2 participants

SciTools member

The problem seems to require all of: the data to not be square; the latitude coordinate to be monotonically decreasing; the longitude coordinate to be circular; and `cube.data.sharedmask` to be False!

The problem was originally triggered by a netCDF4 file with the all the characteristics listed above.

```import iris
import iris.tests.stock as stock

cube = stock.realistic_4d_w_missing_data()
# Workaround - slicing a cube removes the mask!
data = cube.data
cube = cube[0, 2, 18::-1]
data = data[0, 2, 18::-1]
cube.data = data
cube.coord('grid_longitude').circular = True

print 'Before'
print cube.data.data.shape
s = str(cube.data)

sample = [('grid_longitude',0), ('grid_latitude',0)]
inter = iris.analysis.interpolate.linear(cube, sample)

print 'After'
print cube.data.data.shape
s = str(cube.data)```

gives (with NumPy 1.6.1):

``````Before
(19, 20)
(19, 20)
After
(19, 20)
(20, 19)
Traceback (most recent call last):
File "foo", line 26, in <module>
s = str(cube.data)
File ".../python2.7/site-packages/numpy/ma/core.py", line 3531, in __str__
res[m] = f
IndexError: index (19) out of range (0<=index<18) in dimension 0
``````
commented Oct 2, 2012

Isolated

```import numpy
import numpy.ma

def simple_ma():
data = numpy.arange(20).reshape(4,5)
data[:2, :2] = -1
return data

# Create a simple masked array
data = simple_ma()
print "Before\n------"
print "data", data.shape, "\n", data, "\n"

# Create a new array from the masked array
result = numpy.append(data, data[:, :1], axis=1)
print "After\n-----"
print "data", data.shape, "\n", data, "\n"

# Workaround
data = simple_ma()
new_data = numpy.append(data.data, data.data[:, :1], axis=1)
print "Workaround\n----------"
print "data", data.shape, "\n", data, "\n"

prints

``````Before
------
data (4, 5)
[[-- -- 2 3 4]
[-- -- 7 8 9]
[10 11 12 13 14]
[15 16 17 18 19]]

[[ True  True False False False]
[ True  True False False False]
[False False False False False]
[False False False False False]]

After
-----
data (4, 5)
[[-- -- 2 3 4]
[-1 -- -- 8 9]
[10 11 12 13 14]
[15 16 17 18 19]]

[[ True  True False False]
[False  True  True False]
[False False False False]
[False False False False]
[False False False False]]

Workaround
----------
data (4, 6)
[[-- -- 2 3 4 --]
[-- -- 7 8 9 --]
[10 11 12 13 14 10]
[15 16 17 18 19 15]]

[[ True  True False False False  True]
[ True  True False False False  True]
[False False False False False False]
[False False False False False False]]
``````
commented Oct 2, 2012

Related to http://projects.scipy.org/numpy/ticket/1623
Raised a new numpy issue on guthub: numpy/numpy#478

was assigned Oct 2, 2012
referenced this issue Oct 2, 2012
Closed

### linear: numpy masked append workaround #123

commented Oct 16, 2012

merged

closed this Oct 16, 2012