Julia 朱莉娅:如何将非均匀间隔的二维数据插值到网格上?

Julia 朱莉娅:如何将非均匀间隔的二维数据插值到网格上?,julia,interpolation,Julia,Interpolation,我有一系列分散(非均匀)在二维网格上的数据点。我想把这些分散的数据点插值到一个统一的网格上。Julia中是否有一个方便的内置函数允许我这样做?或者我可以添加一个额外的包(我一直在看Interpolations.jl、Grid.jl和GridInterpolations.jl,但我不知道如何使用它们来实现这个目的)?我正在寻找类似于Matlab的griddata的东西。下面是一个示例(随机选择的值)来演示我要查找的内容: # x and y position of known data point

我有一系列分散(非均匀)在二维网格上的数据点。我想把这些分散的数据点插值到一个统一的网格上。Julia中是否有一个方便的内置函数允许我这样做?或者我可以添加一个额外的包(我一直在看Interpolations.jl、Grid.jl和GridInterpolations.jl,但我不知道如何使用它们来实现这个目的)?我正在寻找类似于Matlab的
griddata
的东西。下面是一个示例(随机选择的值)来演示我要查找的内容:

# 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)

Julia中是否有一个函数能够做到这一点?

我找到了一种可能的方法。我会把它贴在这里,以防其他人遇到类似的问题

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")

提供此功能

您是否尝试过使用
Dierckx.jl
?由于您的解决方案使用了
scipy.interpolate
,我认为
Dierckx.jl
可能是一个不错的解决方案,因为它们都封装在同一个Fortran库中。虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供链接供参考。如果链接页面发生更改,则仅链接的答案可能无效。