2016-12-16 6 views
1

私は、2次元グリッドに散在する(不均一な)一連のデータポイントを持っています。私はそれらの散らばったデータポイントを均一なグリッド上に補間したいと思います。 Juliaに便利な機能が組み込まれていますか?または、私が追加できる追加パッケージ(Interpolations.jl、Grid.jl、およびGridInterpolations.jlを見てきましたが、この目的のためにそれらをどのように使用するかわかりません)はどうですか?私はMatlabのgriddataに似た何かを探しています。Julia:グリッド上に非一様な間隔の2次元データを補間する方法は?

# x and y position of known data points 
x = [ 1.5 , 8.8 , 2.9 , 7.2 , 7.1 , 3.8 , 8.4 , 2.1 , 0.8 , 5.1 , 7.5 ] 
y = [ 6.1 , 9.3 , 5.2 , 7.7 , 9.8 , 7.7 , 8.5 , 6.4 , 5.8 , 9.0 , 8.7 ] 

# value of known data points 
val = [ 153.9 , 211.8 , 443.6 , 370.8 , 233.8 , 307.2 , 580.3 , 440.9 , 322.2 , 109.3 , 190.8 ] 

# x and y positions to describe the interpolation grid 
x_interp = [ 0.5 , 2.5 , 4.5 , 6.5 , 8.5 , 10.5 ] 
y_interp = [ 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 , 8.0 , 9.0 ] 

# Some function to interpolate the scattered data onto the grid 
val_grid = SomeInterpolationFunction(x,y,val,x_interp,y_interp) 

これを行うことが可能であるジュリア内の関数があります:ここで私は探しています何を実証する(ランダムに選択された値を持つ)の例はありますか?

答えて

1

可能なアプローチが1つ見つかりました。他の人が同様の問題に遭遇した場合に備えて、私はここに掲載します。

using PyCall 
@pyimport scipy.interpolate as si 

# Some 2D function 
f(x,y) = sin(x)*cos(y) 

# Location of random points to sample the function at 
np = 2500 
xmin = 0. 
xmax = 50. 
ymin = 10. 
ymax = 95. 
x = xmin + xmax*rand(np) 
y = ymin + ymax*rand(np) 
points = [x y] 

# Value of the function at the random points 
val = zeros(np) 
for ip = 1:np 
    val[ip] = f(x[ip],y[ip]) 
end 

# Create a uniform grid to interpolate onto 
nx = 50 
ny = 75 
xgrid = collect(linspace(xmin,xmax,nx)) 
ygrid = collect(linspace(ymin,ymax,ny)) 
grid_x = kron(ones(ny),xgrid') 
grid_y = kron(ygrid,ones(1,nx)) 

# Perform the interpolation 
grid_val = si.griddata(points,val,(grid_x,grid_y),method="cubic") 
+0

あなたは 'Dierckx.jl'を試しましたか?あなたのソリューションは 'scipy.interpolate'を使っているので、' Dierckx.jl'は両方とも同じFortranライブラリをラップするので、良い解決策かもしれません。 – sujeet

0

Dierckxは、この機能を提供します。

+1

このリンクは質問に答えるかもしれませんが、ここでは答えの重要な部分を含めて参考にしてください。リンクされたページが変更された場合、リンクのみの回答は無効になります。 – awh112

関連する問題