Ian,
I'm running into a crash while trying to construct a
tri.LinearTriInterpolator. Here is the short version of the code:
import netCDF4
import matplotlib.tri as tri
var = netCDF4.Dataset('filename.cdf').variables
x = var['x'][:]
y = var['y'][:]
data = var['zeta_max'][:]
elems = var['element'][:, :]-1
triang = tri.Triangulation(x, y, triangles=elems)
# this crashes the python interpreter
interp = tri.LinearTriInterpolator(triang, data)
The data arrays (x, y, data, elems) are fairly large (>1 mio elements),
all
represented as numpy arrays (as returned by netCDF4). The 'data' array is
a
masked array and contains masked values.
If somebody cares, I'd be able to post a link to the netCDF data file
causing this.
All this happens when using matplotlib 1.3.1, Win32, Python 2.7.
Any help would be highly appreciated!
Regards Hartmut
Hartmut,
That is an excellent issue report; all the relevant information and
nothing extraneous. Hence the quick response.
The second argument to TriLinearInterpolator (and other TriInterpolator
classes), i.e. your 'data' array, is expected to be an array of the same
size as the 'x' and 'y' arrays. It is not expecting a masked array. If a
masked array is used the mask will be ignored, and so the values behind
the mask will be used as though they were real values. If my memory of
netCDF is correct, this will be whatever 'FillValue' is defined for the
file, but it may depend on what is used to generate the netCDF file.
I would normally expect the code to work but produce useless output. A
crash is possible though. It would be best if you could post a link to
the netCDF file and I will take a closer look to check there is not
something else going wrong.
Thanks for the quick response!
Here is the data file: http://tinyurl.com/ms7vzxw. I did some more experiments. The picture stays unchanged, even if I fill the masked values in the array with some real numbers (I'm not saying that this would give me any sensible results...):
import netCDF4
import matplotlib.tri as tri
var = netCDF4.Dataset('maxele.63.nc').variables
x = var['x'][:]
y = var['y'][:]
data = var['zeta_max'][:]
elems = var['element'][:, :]-1
triang = tri.Triangulation(x, y, triangles=elems)
data = data.filled(0.0)
# this still crashes the python interpreter
interp = tri.LinearTriInterpolator(triang, data)
Thanks again!
Regards Hartmut
···
---------------
http://stellar.cct.lsu.edu