从scipy interpole/gridata检索数据点



我使用Scipy的Griddata来填充这个网格数据,使用绘制的点(显示为空)。有没有一种方法可以根据(x,y)坐标获得插值(z)?这是绘图的代码,x、y、z值都是系列。

    xi = np.linspace(min(lats),max(lats),360)
    yi = np.linspace(min(lons),max(lons),360)
    # grid the data.
    zi = griddata((lats, lons), nuits, (xi[None,:], yi[:,None]), method='cubic')
    # contour the gridded data.
    plt.contourf(xi,yi,zi,15,cmap=cMap)
    plt.colorbar()
    # plot data points.
    #plt.scatter(lats,lons,c=nuits,marker='o',s=26,cmap=cMap)
    plt.scatter(lats,lons,facecolors='none', edgecolors='k',s=26)
    plt.show()

这将起作用:

xi_coords = {value: index for index, value in enumerate(xi)}
yi_coords = {value: index for index, value in enumerate(yi)}
xic = <your coordinate>
yic = <your coordinate>
zi[xi_coords[xic], yi_coords[yic]]

您可以通过以下方法从(xi,yi)坐标中获取插值的zi坐标:

# (xi,yi) coords to get the interpolated zi coords
# where len(xic) = len(yic)  
xic = <your coordinate>
yic = <your coordinate>
# sort these coordinates in an increasing order
s_xic = np.sort(xic)
s_yic = np.sort(yic)
# indices belonging to xic, yic, that would sort the array
ind_s_xic = np.argsort(xic)
ind_s_yic = np.argsort(yic)
 
dict_xic = dict(zip(ind_s_xic, np.array(range(len(xic))))
dict_yic = dict(zip(ind_s_yic, np.array(range(len(yic))))

xi,yi = np.meshgrid(s_xic, s_yic)
# zi_grid has dimensions ( len(yic), len(xic) )
zi_grid = griddata((lats, lons), nuits, (xi, yi), method='cubic')
# zic is the interpolated z-coordinate data with an arrangement order,
# corresponding to the x and y-coordinate data in xic and yic
zic =  [ zi_grid[dict_yic[i], dict_xic[i]] for i in range(len(xic)) ]

访问如何使用numpy';s具有随机间隔而不是等距间隔的网格函数?了解meshgrid是如何工作的。

网格可以根据不均匀间隔的(xi,yi)坐标创建,然后,网格可以使用网格从基于点=(lats,lons),值=nuits创建的插值曲面中插值z坐标。

最新更新