Eric Firing wrote:
I have applied your patch and modified contourf_demo slightly to illustrate
interior masking. Thanks very much for the beautiful work! These contour
bugs that you fixed were major mpl problems--general embarrassments, and
specific impediments to my own applications, since the data sets I work with
often have masked interior regions. (And, I also use line contours on top
of filled contours, so the saddle-point decision fix helps as well.)
I'm glad my contribution passes the quality control checks!
It occurs to me that there might be a nice refinement: when following a
masked boundary, how hard would it be to cross the single-cell gap
diagonally instead of proceeding step-wise along the boundary? In the case
of the circular masked region that I added to the contourf_demo, this would
simply smooth out the boundary of that region.
I think it would be fairly easy to do half a solution to this, but
difficult to do it properly. It would be easy to change the
edge_walker function to miss out a grid point when, for example,
moving clockwise around a masked region from an i-edge to a j-edge.
But what should happen in the situations when a contour level
intersects one of those two edges: either (a) do nothing, or (b) still
do the diagonal cut-off. The do nothing option (a) is easy (!) but
means that there will be a mixture of diagonal cut-offs and stepwise
changes, which won't look particularly elegant, whereas (b) will mean
some pretty serious rewriting as the contouring code will have to deal
with these diagonal edges for both contour lines and filled contours,
and there will have to be some slightly arbitrary interpolation from
the grid z-values to these diagonal edges. So the answer to your
question is "difficult but doable".
My preference is to leave it as it is, as the current blocky solution
is what I expect to see. But I am happy to take a look at it if
you/others think it is a good idea.
On the subject of contouring masked grids, I sometimes want to specify
which grid squares are masked rather than which grid points, i.e. for
a grid of nx by ny points I want to specify a mask of (nx-1) by (ny-1)
squares. I've discovered that cntr.c uses such a square mask,
creating it from the incoming point mask. It would therefore be easy
to add support for such a grid by changing the python front end to
pass it in. Is this a good idea and would this be useful to others,
or am I being overly simplistic?
P.S. Eric, I see that you work with Kelvin Richards - he was my PhD
supervisor many years ago. Small world!