[SciPy-User] 2D interpolate issues

Mike Toews mwtoews at gmail.com
Tue Mar 22 19:00:50 EDT 2011


Opps, I found a typo:
y = [200, 210, 229, 230]

it should be
y = [200, 210, 220, 230]

which fixes my first question, however I still would like to know
about bounds_error.

Thanks,
-Mike

On 23 March 2011 11:56, Mike Toews <mwtoews at gmail.com> wrote:
> I have a few questions regarding interpolate.interp2d, as I would like
> to do some bilinear interpolation on 2D rasters. I'll illustrate my
> issues with an example:
>
> import numpy
> from scipy import interpolate
> x = [100, 110, 120, 130, 140]
> y = [200, 210, 229, 230]
> z = [[ 1, 2, 3, 4, 5],
>     [12,13,14,15,16],
>     [23,24,25,26,27],
>     [34,35,36,37,38]]
>
> First, why do I get an error with the following?
>>>> f1 = interpolate.interp2d(x, y, z, kind='linear', bounds_error=True)
> Warning:     No more knots can be added because the additional knot
> would coincide
>    with an old one. Probably cause: s too small or too large a weight
>    to an inaccurate data point. (fp>s)
>        kx,ky=1,1 nx,ny=8,4 m=20 fp=263.568959 s=0.000000
>
> I do not get an error if I swap x, y:
>>>> f2 = interpolate.interp2d(y, x, z, kind='linear', bounds_error=True)
> but this is incorrect, as my z list of lists has 5 columns or x-values
> and 4 rows or y-values.
>
> Do I need to transpose my z?
> za = numpy.array(z).T
> f3 = interpolate.interp2d(x, y, za, kind='linear', bounds_error=True)
>
> The example in http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp2d.html
> does not use a transposed array. From the documented example, we can
> see that intuitively len(x) = columns and len(y) = rows in z
>
> Secondly, why does bounds_error do nothing?
>>>> f3(-100,-100)
> array([ 1.])
>>>> f3(1000,1000)
> array([ 38.])
>
> I've supplied x and y values far outside the range, and I do not get
> an error. Similarly, setting bounds_error=True, fill_value is not
> returned when x and y are out of bounds, as documented.
>
> Are these user errors or bugs?
>
> Thanks,
> -Mike
>



More information about the SciPy-User mailing list