If anyone could assist me in understanding what issues result in the error
message below , I would be very grateful.
"Cannot automatically convert masked array to Numeric because data
is masked in one or more locations"
(error raised by Numeric, but within matplotlib core)
I frequently run into this error message when I try to use matplotlib to
produce contour graphs. Does anyone have a more detailed explanation of what
issues prompt this error? What confuses me is that the same script (posted
below, FWIW) may or may not produce this error depending on which datafile I
try to graph? I also get this message if I use the Numeric function where()
to generate any array used by the contour() function.
Thanks,
Kevin Mueller
Univ. Illinois, Dept. Atmospheric Sciences, Urbana/Champaign
···
#######################
traceback:
(python 2.4.1, Numeric 24b, matplotlib 0.80, linux)
#######################
Traceback (most recent call last):
File "/home/manabe/a/kjmuelle/scripts/latlonslice.py", line 39, in ?
badmask=outmask,cmap=cm.jet,colors=None)
File
"/home/manabe/a/kjmuelle/lib/python2.4/site-packages/matplotlib/toolkits/basemap/basemap.py",
line 1030, in contourf
levels, colls = pylab.contourf(*args, **kwargs)
File
"/home/manabe/a/kjmuelle/lib/python2.4/site-packages/matplotlib/pylab.py",
line 1679, in contourf
ret = gca().contourf(*args, **kwargs)
File
"/home/manabe/a/kjmuelle/lib/python2.4/site-packages/matplotlib/axes.py",
line 1248, in contourf
return self._contourHelper.contourf(*args, **kwargs)
File
"/home/manabe/a/kjmuelle/lib/python2.4/site-packages/matplotlib/contour.py",
line 879, in contourf
lev, cmap)
File
"/home/manabe/a/kjmuelle/lib/python2.4/site-packages/matplotlib/contour.py",
line 629, in _process_colors
mappable.autoscale()
File "/home/manabe/a/kjmuelle/lib/python2.4/site-packages/matplotlib/cm.py",
line 456, in autoscale
self.norm.autoscale(self._A)
File
"/home/manabe/a/kjmuelle/lib/python2.4/site-packages/matplotlib/colors.py",
line 580, in autoscale
rval = ravel(A)
File
"/home/manabe/a/kjmuelle/lib/python2.4/site-packages/Numeric/Numeric.py",
line 543, in ravel
return reshape(m, (-1,))
File "/home/manabe/a/kjmuelle/lib/python2.4/site-packages/Numeric/MA/MA.py",
line 632, in __array__
raise MAError, \
MA.MA.MAError: Cannot automatically convert masked array to Numeric because
data
is masked in one or more locations.
############################
WHEN RUNNING THIS SCRIPT:
############################
from Scientific.IO import NetCDF as nc
import Numeric as nm
from pylab import *
import sys,os.path
it=0 # time index
ik=0 # depth index
tracer="DIC" # tracer name
if not len(sys.argv)>1:
print "Error: no datafile arguments given"
else:
datapaths = sys.argv[1:]
for datapath in datapaths:
f = nc.NetCDFFile(datapath)
outdata = f.variables[tracer].getValue()[it,ik,:,:]
outmask = f.variables["TMASK"].getValue()[ik,:,:]
gdepth = f.variables["z_t"].getValue()
f.close()
X,Y,Z = nm.arange(-180,181,4),nm.arange(-90,91,2),gdepth*.01
clf()
levels,colors = contourf(X,Y,outdata,
badmask=outmask,cmap=cm.jet,colors=None)
levels,colors = contour(X,Y,outdata,
badmask=outmask,colors='k')
colorbar(tickfmt="%.1e")
gtitle = "%s: at depth %i, %s" % (os.path.split(datapath[1],-Z[ik],tracer)
title(gtitle)
show()