# Delaunay interpolator: support grid whose width or height is 1 #997

Closed
opened this Issue Jul 10, 2012 · 1 comment

None yet

### 3 participants

The current implementation of Delaunay interpolator returns NaN for grids whose x or y has dimension 1 (i.e. when you try to interpolate along a horizontal/vertical line, or in a single point). See example below.

It seems that this can be fixed by simple rearrangement of calculations (pull request underway).
The suggested implementation is almost identical. It might actually perform faster in some cases (there is one less multiplication op in the inner loop). There might be some differences in accuracy, but I believe they should only become observable in cases where the grid size is very large (which would probably cause memory problems anyway).

Example (before suggested patch):

```>>> from matplotlib.delaunay import Triangulation
>>> tri = Triangulation([0,10,10,0],[0,0,10,10])
>>> lin = tri.linear_interpolator([1,10,5,2.0])
>>> # 2x2 grid works fine
>>> lin[3:6:2j,1:4:2j]
array([[ 1.6,  3.1],
[ 1.9,  2.8]])
>>> # but not when 1x2, 2x1, 1x1:
>>> lin[3:6:2j,1:1:1j]
array([[ nan],
[ nan]])
>>> lin[3:3:1j,1:1:1j]
array([[ nan]])
>>>
```

After suggested patch:

```>>> from matplotlib.delaunay import Triangulation
>>> tri = Triangulation([0,10,10,0],[0,0,10,10])
>>> lin = tri.linear_interpolator([1,10,5,2.0])
>>> # 2x2 grid: same same
>>> lin[3:6:2j,1:4:2j]
array([[ 1.6,  3.1],
[ 1.9,  2.8]])
>>> # but these work now
>>> lin[3:6:2j,1:1:1j]
array([[ 1.6],
[ 1.9]])
>>> lin[3:3:1j,1:1:1j]
array([[ 1.6]])
>>>
```
Member

Cross-referencing PR #998

referenced this issue Oct 18, 2012
Closed

#### fix for issue #997 #998

pushed a commit to AmitAronovitch/matplotlib that referenced this issue Nov 10, 2012
 Amit Aronovitch `delaunay: test for 1d and 0d grids (fails upstream) re: issue #997` `49215c2`
pushed a commit to AmitAronovitch/matplotlib that referenced this issue Nov 10, 2012
 Amit Aronovitch `Merge branch 'iss997_test' (test for issue #997)` `1e7e2cc`
referenced this issue Dec 2, 2012
Merged

#### alternate fix for issue #997 #1477

pushed a commit that closed this issue Dec 4, 2012
 Amit Aronovitch `delaunay linear_interpolate_grid: enable grid of height/width 1` `fixes #997` `6065697`
closed this in `6065697` Dec 4, 2012