使用scipy.interpolate.griddata时的ZeroDivisionError

时间:2013-06-11 17:42:24

标签: python numpy scipy interpolation

我从以下代码中获得ZeroDivisionError

#stacking the array into a complex array allows np.unique to choose
#truely unique points.  We also keep a handle on the unique indices
#to allow us to index `self` in the same order.
unique_points,index = np.unique(xdata[mask]+1j*ydata[mask],
                         return_index=True)
#Now we break it into the data structure we need.
points = np.column_stack((unique_points.real,unique_points.imag))

xx1,xx2 = self.meta['rcm_xx1'],self.meta['rcm_xx2']
yy1 = self.meta['rcm_yy2']
gx = np.arange(xx1,xx2+dx,dx)
gy = np.arange(-yy1,yy1+dy,dy)
GX,GY = np.meshgrid(gx,gy)

xi = np.column_stack((GX.ravel(),GY.ravel()))
gdata = griddata(points,self[mask][index],xi,method='linear',
                           fill_value=np.nan)

此处,xdataydataself都是具有相同形状和numpy.ndarray的2D dtype=np.float32(或其子类)。 mask是具有相同形状且ndarray的2d dtype=bool。这里是那些想要仔细阅读scipy.interpolate.griddata documentation的人的链接。

最初,xdataydata来自具有4点模板的非均匀圆柱网格 - 我认为错误可能来自同一点被定义的事实多次,所以我根据建议in this question使输入点集合唯一。不幸的是,这似乎没有帮助。完整的追溯是:

Traceback (most recent call last):
  File "/xxxxxxx/rcm.py", line 428, in <module>
    x[...,1].to_pz0()
  File "/xxxxxxx/rcm.py", line 285, in to_pz0
    fill_value=fill_value)
  File "/usr/local/lib/python2.7/site-packages/scipy/interpolate/ndgriddata.py", line 183, in griddata
    ip = LinearNDInterpolator(points, values, fill_value=fill_value)
  File "interpnd.pyx", line 192, in scipy.interpolate.interpnd.LinearNDInterpolator.__init__ (scipy/interpolate/interpnd.c:2935)
  File "qhull.pyx", line 996, in scipy.spatial.qhull.Delaunay.__init__ (scipy/spatial/qhull.c:6607)
  File "qhull.pyx", line 183, in scipy.spatial.qhull._construct_delaunay (scipy/spatial/qhull.c:1919)
ZeroDivisionError: float division

对于它的价值,代码&#34;工作&#34; (没有例外)如果我使用&#34;最近的&#34;方法

0 个答案:

没有答案