Loc*_*sta 5 python grid interpolation numpy scipy
我有一个大 (2000 x 2000) 像素网格,其值仅在某些 (x,y) 坐标处定义。例如,它的简化版本如下所示:
-5-3--
---0--
-6--4-
-4-5--
---0--
-6--4-
Run Code Online (Sandbox Code Playgroud)
我如何进行线性插值或最近邻插值,以便我可以在网格中的每个位置都有一个定义的值。
这是我的尝试。
import numpy as np
from matplotlib.mlab import griddata
##Generate a random sparse grid
grid = np.random.random((6,6))*10
grid[grid>5] = np.nan
## Create Boolean array of missing values
mask = np.isfinite(grid)
## Get all of the finite values from the grid
values = grid[mask].flatten()
## Find indecies of finite values
index = np.where(mask==True)
x,y = index[0],index[1]
##Create regular grid of points
xi = np.arange(0,len(grid[0,:]),1)
yi = np.arange(0,len(grid[:,0]),1)
## Grid irregular points to regular grid using delaunay triangulation
ivals = griddata(x,y,values,xi,yi,interp='nn')
Run Code Online (Sandbox Code Playgroud)
这就是我将不均匀分布的点插值到规则网格的方法。我没有尝试过任何其他类型的插值方法(即线性)。
| 归档时间: |
|
| 查看次数: |
4605 次 |
| 最近记录: |