Python - 使用Griddata / Delaunay tri插值2D不规则点

时间:2015-11-18 10:04:55

标签: python numpy datagrid interpolation delaunay

我的目标是插入一些数据。要做到这一点,我想使用griddata因为我可以有很多分数,所以interp2D在这种情况下会失败。

我的初始坐标为InstT[:,1]InstT[:,2],要插值的值为data,新坐标为InstTplus1[:,1]+shiftXInstTplus1[:,2]

使用Griddata,我可以使用np.meshgrid执行meshgrid,如下所示。但是我的结果与interp2D的结果不同(如下所示)。 这似乎是由于我在做网格网时出现数据组织错误?

from scipy.interpolate import griddata
import numpy as np

InstT= np.array([[  2.00000000e+00,   1.74255667e+00,  -8.81166667e-02],
           [  7.00000000e+00,   2.05894667e+00,  -2.56740000e-01],
           [  1.20000000e+01,   1.63387667e+00,   2.36914667e+00],
           [  1.70000000e+01,   2.40539000e+00,   5.91853333e-01],
           [  2.20000000e+01,   2.31335000e+00,  -1.02655333e+00],
           [  2.80000000e+01,   1.85235667e+00,   2.75853333e-01],
           [  3.50000000e+01,   1.02668667e+00,   2.05220000e-01],
           [  4.10000000e+01,   2.15202667e+00,  -4.12653333e-01],
           [  4.60000000e+01,   2.40584667e+00,  -8.79340000e-01],
           [  5.10000000e+01,   2.00418000e+00,  -1.79855667e+00],
           [  5.60000000e+01,   2.05642333e+00,   3.20066667e-02],
           [  6.10000000e+01,   1.15410667e+00,   2.35290000e+00],
           [  6.60000000e+01,   1.48612333e+00,  -1.97530333e+00],
           [  7.10000000e+01,   2.04775333e+00,   3.16490000e-01],
           [  7.60000000e+01,   2.02982333e+00,  -1.18378000e+00],
           [  8.10000000e+01,   2.41636333e+00,   1.77193667e+00],
           [  8.60000000e+01,   1.90254000e+00,   1.99800000e+00],
           [  9.10000000e+01,   1.44889333e+00,   1.95262667e+00],
           [  9.60000000e+01,   1.97192000e+00,   1.21600333e+00],
           [  1.01000000e+02,   1.80270000e+00,  -1.25049000e+00],
           [  1.06000000e+02,   1.70948333e+00,  -1.98784667e+00],
           [  1.11000000e+02,   1.80093667e+00,   8.30646667e-01],
           [  1.16000000e+02,   1.30976333e+00,  -8.02600000e-01],
           [  1.21000000e+02,   3.00946667e-01,   2.98326667e-01],
           [  1.27000000e+02,   5.78493333e-01,  -2.31010667e+00],
           [  1.32000000e+02,   5.11150000e-01,   9.93530000e-01],
           [  1.37000000e+02,   1.23912333e+00,   6.69696667e-01],
           [  1.42000000e+02,   6.80790000e-01,  -1.21987667e+00],
           [  1.47000000e+02,  -4.69450000e-01,   2.07277000e+00],
           [  1.55000000e+02,   6.11773333e-01,   6.21750000e-01],
           [  1.66000000e+02,  -4.59600000e-01,  -2.06928000e+00]])


InstTplus1= np.array([[  1.00000000e+00,  -6.75000000e-01,  -1.37093667e+00],
       [  3.00000000e+01,   2.66313333e-01,   2.12887667e+00],
       [  9.00000000e+01,   5.82246667e-01,   2.32840333e+00],
       [  1.27000000e+02,   5.78493333e-01,  -2.31010667e+00],
       [  1.45000000e+02,  -2.41333333e-03,  -1.50423000e+00],
       [  1.51000000e+02,  -3.85496667e-01,  -1.65609333e+00],
       [  1.57000000e+02,   8.36200000e-02,  -1.12576000e+00],
       [  1.62000000e+02,  -7.54953333e-01,   1.38679667e+00],
       [  1.67000000e+02,  -1.33794667e+00,  -1.49130000e-01],
       [  1.72000000e+02,  -2.25452000e+00,  -1.93793333e-01],
       [  1.77000000e+02,  -2.21772333e+00,  -1.88520667e+00]])



data= np.array([[  2.00000000e+00,  -6.76821461e-05],
       [  7.00000000e+00,  -7.86778619e-05],
       [  1.20000000e+01,  -6.95431069e-05],
       [  1.70000000e+01,  -9.69626174e-05],
       [  2.20000000e+01,  -7.68471315e-05],
       [  2.80000000e+01,  -7.41450228e-05],
       [  3.50000000e+01,  -4.12677958e-05],
       [  4.10000000e+01,  -8.06935132e-05],
       [  4.60000000e+01,  -8.33900849e-05],
       [  5.10000000e+01,  -3.96908987e-05],
       [  5.60000000e+01,  -8.08105809e-05],
       [  6.10000000e+01,  -4.97135382e-05],
       [  6.60000000e+01,  -1.98796779e-05],
       [  7.10000000e+01,  -8.19658308e-05],
       [  7.60000000e+01,  -6.23518269e-05],
       [  8.10000000e+01,  -9.97619742e-05],
       [  8.60000000e+01,  -7.95730205e-05],
       [  9.10000000e+01,  -6.10744925e-05],
       [  9.60000000e+01,  -8.12113819e-05],
       [  1.01000000e+02,  -5.24605251e-05],
       [  1.06000000e+02,  -2.36093623e-05],
       [  1.11000000e+02,  -7.37657756e-05],
       [  1.16000000e+02,  -4.39291265e-05],
       [  1.21000000e+02,  -1.31381378e-05],
       [  1.27000000e+02,  -2.62531466e-06],
       [  1.32000000e+02,  -2.18848005e-05],
       [  1.37000000e+02,  -5.09233626e-05],
       [  1.42000000e+02,  -1.88998207e-05],
       [  1.47000000e+02,   1.89757963e-05],
       [  1.55000000e+02,  -2.56628834e-05],
       [  1.66000000e+02,   4.17862704e-06]])


shiftX = 1.6125

#If i do with interp2D :
from scipy import interpolate
f = interpolate.interp2d(InstT[:,1], InstT[:,2], data[:,1], kind='linear')
znew = f(shiftX + InstTplus1[:,1], InstTplus1[:,2])


#If i do with Griddata:

[Y2,X2]=np.meshgrid(InstTplus1[:,2],InstTplus1[:,1]+shiftX)
grid_z0 = griddata(InstT[:,1:], data[:,1], (X2, Y2), method='linear')

如前所述,使用Griddata获得的结果可能是组织坐标时出错... enter image description here

---编辑以后----

我的坐标是不规则的,如下所示:

enter image description here

0 个答案:

没有答案