-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
contours gives “key not found” when n is increased #12
Comments
Both Matplotlib and Matlab were able to create contours for that dataset, so it's definitely a bug in Contour.jl. I probably won't have time to dig deeper into this until I finish my prelim exams though (~ a month). |
Thanks for the bug report! I started looking into this, and it seems there's some odd edge case stuff going on for these parameters - a larger number of levels sometimes works for me (8, 9, 11, 12, 13 and 16 all work, but 10, 14 and 15 don't. I haven't tested higher). I'm not sure I'm familiar enough with the algorithm to be able to pin this down, but I'll take a stab at it - and if I can't fix it, I'll leave my debugging findings here for @darwindarak when you have more time on your hands (good luck with the exams!). |
The problem is our handling of saddle points. I haven't figured out exactly what's wrong yet, but I have been able to produce a simpler example that reproduces the error:
I'll see if I can investigate this further. |
OK, the problem seems to be these lines, which handle the ambiguous cases. There's an implicit assumption in this code that the two contour lines that cross ambiguous cells are parsed in a specific order (for example, case 16 has two contour lines running from top/left to right/bottom, and assumes that the one from left to bottom is processed first). When this is not the case, the lookup tables here will yield incorrect exit faces and tracing directions, which in turn results in the next call to It seems to me that we need to re-think the implementation of these ambiguous cases - fun! ;) |
That's great that you were able to track down the problem! What do you think about using something like an adaptive grid method? I haven't had much time to think about it in detail, but what if we use a bilinear interpolation to find the contour crossing whenever we identify an ambiguous cell? We can then split the cell around the crossing point. We then modify the |
An adaptive grid method is probably a nice idea, but I'm not sure it solves the current problem (I haven't given it a lot of thought either...). A quick fix to solve this would be to keep track of from which edge
That could probably be made more efficient by making use of a lookup table, but you get the general idea. Now, instead of doing this, we can do something like
That will ensure that |
OK, I may have cheered too early on this. After more or less re-implementing the entire algorithm (mostly to increase my own understanding) and verifying that the saddle points are handled correctly, I still get a similar Surprisingly, it only occurs for the unevenly spaced grid; this works fine on my machine:
I've tried to use @darwindarak Is there something in the algorithm that assumes evenly spaced grids? If so, how should we work around it? @dcjones I've overwritten my Julia 0.3 instance with 0.4, under which Gadfly doesn't work. Could you check the result of plotting versus index of I know Darwin still has much to do elsewhere, so I'll keep digging here, but if any of you has any input it is most welcome. |
Thanks for looking into this! If I understand it correctly, I think it only requires Cartesian grids, not necessarily evenly spaced. |
I think I might have a fix for this. I'll aim for a PR by the end of this weekend. |
Not quite fixed yet, the problem still shows up using the dataset provided here |
This is from: GiovineItalia/Gadfly.jl#420. In this example,
contours(x, y, z, n)
will give a “key not found” error ifn >= 7
. Maybe an error is appropriate, I'm not sure, but a descriptive error would be good.Gist to reproduce this: https://gist.github.com/dcjones/c56d09f7934202bca54e
The text was updated successfully, but these errors were encountered: