sciapp / gr

GR framework: a graphics library for visualisation applications
Other
329 stars 54 forks source link

scattered data interpolation #38

Closed vermeylen closed 5 years ago

vermeylen commented 7 years ago

Hello GR and Josef Heinen, I am looking for a way to do scattered data interpolation in Julia. Perhaps GR.jl might be helpful. I read your example xd = -2 + 4 rand(100) yd = -2 + 4 rand(100) zd = [Float64(xd[i] * exp(-xd[i]^2 - yd[i]^2)) for i = 1:100] using GR x, y, z = GR.gridit(xd, yd, zd, 200, 200) But is it also possible to return the (interpolated) value of z for a specific inputs (x,y)? So I am looking for a function like the following one: zi = GR.somefunction(xd,yd,zd,xi,yi), where xi and yi are some specific values for x and y. Thank you!

jheinen commented 7 years ago

The current master has an interp2 function (similar to MATLAB's interp2().

using GR

X = Y = linspace(-3, 3, 7)
Z = peaks(7)

Xq = Yq = linspace(-3, 3, 31)
Zq = interp2(X, Y, Z, Xq, Yq, 3)
surface(Xq, Yq, Zq, accelerate=false, xlim=(-4,4), ylim=(-4,4))
vermeylen commented 7 years ago

Thanks for getting back to me! Julia does not see, to know interp2 (even after 'using GR'): I get "ERROR: UndefVarError: interp2 not defined". Also, Matlab has only five arguments for its interp2-function, with a sixth optional one that determines the interpolation method. So I guess your 3 in the example above refers to an interpolation method?

jheinen commented 7 years ago

interp2 is (currently) only available in GR master. So, you have to check it out ...

Pkg.checkout("GR")

... and probably force a rebuld:

ENV["GRDIR"] = ""
Pkg.build("GR")

You're right, the last argument specifies the interpolation method:

  interp2(X, Y, Z, Xq, Yq, method::Int=0, extrapval=0)

    method:
      0 - nearest
      1 - linear
      2 - spline
      3 - cubic
vermeylen commented 7 years ago

Thank you! It works fine after checking out and rebuilding. However, it is not quite what I was looking for. I was looking for an interpolation function for unstructured scattered data, that takes as input a bunch of (x,y) combinations and their corresponding function value z, but where the x- and the y-values are not necessarily on a structured grid. I think you may have defined such an interpolation function somehow to compute the output of GR.gridit.

jheinen commented 7 years ago

Right now, you have to use a combination of delaunay, gridit and interp2. There is no pre-defined function (yet).

vermeylen commented 7 years ago

OK, I'll do that. Thanks a lot!

danielkaiser commented 5 years ago

We are closing this issue due to inactivity. Please reopen the issue and let us know if its cause still persists with the current version of GR.