John,
The attached diff contains a bugfix for the masking problem that Jeff found:
diff -Naur cntr.c_as_sent cntr.c > cntr_bugfix.diff
where cntr.c_as_sent is the old version, cntr.c is the corrected version.
I was simply not transferring the information correctly from the mask to the "reg" array that cntr.c uses; I was setting a value, and then accidentally overwriting it with what should have been an initialization.
With this patch, masked arrays should be handled no better and no worse than before the change from gcntr.c to cntr.c; as far as I know, masking works perfectly for line contours, and it works correctly for filled contours under many but not all circumstances. I tried two workarounds for the latter problem:
1) in line 1359 of cntr.c, change the nchunk variable from 30 to a much smaller value.
long nchunk = 30; /* hardwired for now */
This causes the generation of many small polygons, so it may slow things down quite a bit, and it causes the boundaries to look a little glitchy on the screen (gtkagg); but I haven't done timing tests, and I haven't tried other backends.
2) change the end of ContourSupport._contour_args(), in contour.py:
self.ax.set_xlim((ma.minimum(x), ma.maximum(x)))
self.ax.set_ylim((ma.minimum(y), ma.maximum(y)))
# Workaround for cntr.c bug wrt masked interior regions:
#if filled:
# z = ma.masked_array(z.filled(-1e38))
# It's not clear this is any better than the original bug.
return (x, y, z, lev)
The workaround is to uncomment the "if filled:" block. This method also works, but can leave some artifacts around the boundary of the bad region.
I am not recommending that either of these workarounds be added to CVS, but if some individual runs into major trouble because of the bug, then either of these methods could be used as a stopgap on an individual basis.
Eric
John Hunter wrote:
cntr_bugfix.diff (657 Bytes)
···
"Jeff" == Jeff Whitaker <jswhit@...196...> writes:
> The basemap toolkit relies on the 'badmask' parameter in
> contour/contourf to mask out areas outside the desired map
> projection region in matplotlib 0.80. It works quite
> well. Unfortunately, the new masked array support in CVS
> doesn't (I get all kinds of weird artifacts, especially for
> contourf but also for contour). Can the old badmask
> functionality be added back in for 0.81, at least
> temporarily until the masked array support stabilizes?
I don't have anything to add to this, I'm just replying so I can CC
Eric Firing, who added the masked array support to contour, because I
don't know if he is on the devel list.
JDH