ZeroDivisionError when using scipy.interpolate.griddata

I get ZeroDivisionError from the following code:

 #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) 

Here xdata , ydata and self are all 2D numpy.ndarray (or their subclasses) with the same form and dtype=np.float32 . mask is a 2d ndarray with the same shape and dtype=bool . Here is a link for those who want to view the scipy.interpolate.griddata documentation .

Initially, xdata and ydata were obtained from an uneven cylindrical grid that has a 4-point stencil - I thought the error could come from the fact that the same point was determined several times, so I made the set of input points unique, as suggested in this question . Unfortunately, this did not seem to help. Full trace:

 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 

For what it's worth, the code "works" (without exception) if I use the "closest" method.

+4
source share

Source: https://habr.com/ru/post/1485661/


All Articles