3

I am interpolating data from satellite imagery. My initial data is not on a regular grid. The data e.g. ch1 refers to positions given by longitude and latitude. When I try nearest neighbour interpolation the result I get is good.

from scipy import interpolate

lats = np.arange(latitude.max(), latitude.min(),-.1)
lons = np.arange(longitude.min(),longitude.max(),.1)
all_lon,all_lat = np.meshgrid(lons,lats)

ch1_all = interpolate.griddata((longitude.reshape(-1),latitude.reshape(-1)),ch1.reshape(-1),(all_lon,all_lat),'nearest')    

However when I request bilinear interpolation I raise a Qhull error.

ch1_all = interpolate.griddata((longitude.reshape(-1),latitude.reshape(-1)),ch1.reshape(-1),(all_lon,all_lat),'linear')

The error I get is:

Traceback (most recent call last):
  File "<interactive input>", line 1, in <module>
  File "C:\Python27\lib\site-packages\scipy\interpolate\ndgriddata.py", line 206, in griddata 
    rescale=rescale)
  File "interpnd.pyx", line 239, in scipy.interpolate.interpnd.LinearNDInterpolator.__init__ (scipy\interpolate\interpnd.c:4549)
  File "qhull.pyx", line 1736, in scipy.spatial.qhull.Delaunay.__init__ (scipy\spatial\qhull.c:13719)
  File "qhull.pyx", line 328, in scipy.spatial.qhull._Qhull.__init__ (scipy\spatial\qhull.c:3602)
QhullError: Qhull error

I have read the post at griddata runtime error -- Python / SciPy (Interpolation) but in my case, it interpolates data with one method but not with the other.

What am I doing wrong?

In the image below I have plotted the final point positions (red) and overlaid the initial positions (blue)

enter image description here

Community
  • 1
  • 1
  • Is the error you're getting any more specific? Since you're not showing what the exact error is? –  Jan 16 '15 at 12:48
  • Since the error may depend on your input data, you could try and play around with some of the options, such as `rescale`. –  Jan 16 '15 at 12:49
  • The error means your `longitude` and `latitude` are such that Delaunay triangulation of the data points fails. Possible reason: the points `(longitude[i], latitude[i])`, `i=0...n` fall on a single line. Note also that the interpolation is not bilinear interpolation, but linear interpolation on triangles. Please clarify if your data is on a rectangular grid (the grid spacings in x- and y need not be uniform for the grid be rectangular) --- if yes, then you should use `interpn` or `RectangularGridInterpolator` instead. – pv. Jan 16 '15 at 15:25
  • @pv. : My data is not on a rectangular grid so I think `griddata` is the way to go. The main question is why I get good results when using `nearest` as the interpolation method an a `Qhull error` when using the `linear` method. – Kostas Kammenos Jan 19 '15 at 07:49
  • `nearest` is not Delaunay-based and can tolerate point sets that cannot be triangulated. Please try to do `plot(longitude.reshape(-1), latitude.reshape(-1))` and attach the resulting figure here, so that we can see what your point set is like. – pv. Jan 20 '15 at 17:29

0 Answers0