2017-04-22 114 views
0

我有一些相當有間隔的測量數據,我使用numpy的Griddata製作等值線圖。 Griddata與實際測量的部分相關性很好。我期望將網格數據外推到測量點之外。我已經看過使用RBF和interp2D,但是,這兩種方法從根本上改變了輪廓輪廓。使用RBF外推GridData

有沒有辦法提取griddata(x,y,z)座標並將它們饋送到RBF函數中,以便輪廓能夠擴展並在一定程度上保持griddata插值?或者有更好的方法嗎?

我已經嘗試了不同的方法來獲取griddata,主要從這個答案,但沒有成功。 HTTP:// stackoverflow.com/questions/34489039/檢索數據點從 - SciPy的-插值-的GridData

這裏是我的代碼(Python的3.4.3):

from matplotlib.mlab import griddata 
import matplotlib.pyplot as plt 
import numpy as np 
import scipy.interpolate as interp 

#data points 
x=[20,20,20,20,20,20,0,0,0,0,0,0,-20,-20,-20,-20,-20,-20] 
y=[59,27,16,-16,-27,-59,59,27,16,-16,-27,-59,59,27,16,-16,-27,-59] 
z=[0.212,0.2099,0.2097,0.2099,0.21,0.213,0.2117,0.209,0.2084,0.2085,0.2086,0.2113,0.2128,0.21,0.2098,0.2094,0.21,0.2114] 

# define grid. 
xi = np.linspace(-25, 25, 100) 
yi = np.linspace(-65, 65, 100) 
# grid the data. 
zi = griddata(x, y, z, xi, yi, interp='linear') 

#RBF Method 
##xi,yi=np.meshgrid(xi, yi) 
##RBFi = interp.Rbf(x, y, z, function='linear', smooth=0) 
### grid the data. 
##zi = RBFi(xi, yi) 

#interp2D 
#xi,yi=np.meshgrid(xi, yi) 
##zfun_smooth_interp2d = interp.interp2d(x, y, z, kind='cubic') 
##xvec = xi[0,:] 
##yvec = yi[:,0] 
##zi = zfun_smooth_interp2d(xvec,yvec) 


plt.figure(num=None, figsize=(9.95, 16.712), dpi=80, facecolor='w', edgecolor='k') 
# contour the gridded data, plotting dots at the nonuniform data points. 
CS = plt.contour(xi, yi, zi, 30, linewidths=0.5, colors='k') 
CS = plt.contourf(xi, yi, zi, 50, cmap=plt.cm.rainbow) 
plt.colorbar() # draw colorbar 
# plot data points. 
plt.scatter(x, y, marker='o', c='b', s=5, zorder=10) 
plt.xlim(-25, 25) 
plt.ylim(-65, 65) 

plt.show() 

下面是得到的Griddata和RBF圖。 Griddata RBF

回答

0

很多修修補補之後,我能弄明白(使用原始鏈接我張貼)。這可能不是最好的,但它完成了。我仍然必須確保我的新高度陣列中沒有任何「蒙面」數據。這裏是我的新代碼:

from matplotlib.mlab import griddata 
import matplotlib.pyplot as plt 
import numpy as np 
import scipy.interpolate as interp 

#data points 
x=[20,20,20,20,20,20,0,0,0,0,0,0,-20,-20,-20,-20,-20,-20] 
y=[59,27,16,-16,-27,-59,59,27,16,-16,-27,-59,59,27,16,-16,-27,-59] 
z=[0.212,0.2099,0.2097,0.2099,0.21,0.213,0.2117,0.209,0.2084,0.2085,0.2086,0.2113,0.2128,0.21,0.2098,0.2094,0.21,0.2114] 

# define grid. 
xi = np.linspace(-20, 20, 21) 
yi = np.linspace(-59, 59, 21) 
# grid the data. 
zi = griddata(x, y, z, xi, yi, interp='linear') 

#from http:// stackoverflow.com/questions/34489039/ retrieving-data-points-from-scipy-interpolate-griddata 
xi_coords = {value: index for index, value in enumerate(xi)} 
yi_coords = {value: index for index, value in enumerate(yi)} 


#iterate to find all the griddata z-height values 
zii = [] 

for index, value in enumerate(xi): 
    for index, value2 in enumerate(yi): 
     zii.append(zi[xi_coords[value],yi_coords[value2]]) 

#RBF Method 
xi,yi=np.meshgrid(xi, yi) 
RBFi = interp.Rbf(xi, yi, zii, function='quintic', smooth=0) 
# re-grid the data to fit the entire graph 
xi = np.linspace(-25, 25, 151) 
yi = np.linspace(-65, 65, 151) 
xi,yi=np.meshgrid(xi, yi) 
zi = RBFi(xi, yi) 



plt.figure(num=None, figsize=(9.95, 16.712), dpi=80, facecolor='w', edgecolor='k') 
# contour the gridded data, plotting dots at the nonuniform data points. 
CS = plt.contour(xi, yi, zi, 30, linewidths=0.5, colors='k') 
CS = plt.contourf(xi, yi, zi, 50, cmap=plt.cm.rainbow) 
plt.colorbar() # draw colorbar 
# plot data points. 
plt.scatter(x, y, marker='o', c='b', s=5, zorder=10) 
plt.xlim(-25, 25) 
plt.ylim(-65, 65) 

plt.show()