JuliaGeometry / Contour.jl

Calculating contour curves for 2D scalar fields in Julia
Other
43 stars 13 forks source link

Contours of discntinuous data #75

Closed jamblejoe closed 1 year ago

jamblejoe commented 1 year ago

Consider the following map with discontinuities on the y-axis. The black lines are the contours with value 0. They clearly are wrong at the discontinuity on the y-axis. Expected would be a horizontal line at y=0. Is this a general drawback of the algorithm are is this an edge case, which is not dealt with yet?

xs = range(-6, 6, length=200)
ys = range(-6, 6, length=200)
zs = [angle((x+im*y)^2) for x in xs, y in ys]

heatmap(xs, ys, zs'; cmap=:autumn1)
cl = Contour.contour(xs,ys,zs, 0.)

xs, ys = coordinates(lines(cl)[1])

plot!(xs, ys; color=:black,lw=5)

The first contour: image

The second contour looks like this: image

darwindarak commented 1 year ago

The algorithm doesn't know about the nature of the function you're trying to contour. It sees values changing sign across the y-axis, and without knowing that it's actually a discontinuity it assumes that the function must be zero along the y-axis. I think this will be the case with any contouring algorithm that just takes in a matrix of numbers.

Maybe we can put in an option where the algorithm will treat value jumps larger than some input parameter as a discontinuity? I'd rather handle cases like this by filtering out the contours lines afterwards, but it's not difficult to add this extra parameter in if there's enough people needing this.