Pierre Haessig | 25 Jun 2012 17:14
Favicon
Gravatar

interp2d bounds checking

Hi,

I just have a small question about scipy.interpolate.interp2d

I noticed that bounds checking when calling the interpolation instance
seems to be ineffective.
I found a ticket about this issue, but not much activity around it.
http://projects.scipy.org/scipy/ticket/1072

I looked at the code and at the documentation
 (
http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp2d.html#scipy.interpolate.interp2d

https://raw.github.com/scipy/scipy/master/scipy/interpolate/interpolate.py )

and it seems that the `bounds_error` argument is never used in the
initialization of the interp2d object (unlike inter1d).
I'm not at all a specialist of 2D interpolation but I guess that bounds
checking in 2D is not as easy as in 1D...

Maybe, if there is no easy way to check bounds in interp2d, we should
just add a "big warning" in the docstring stating that `bounds_error` is
not currently used (and therefore `fill_value` as well).
What do you think ?

Best,
Pierre

about docstring editing, I didn't find the "Edit page" link on interp2d
page. Did I miss something ?
(Continue reading)

Ralf Gommers | 1 Jul 2012 11:21
Gravatar

Re: interp2d bounds checking



On Mon, Jun 25, 2012 at 5:14 PM, Pierre Haessig <pierre.haessig <at> crans.org> wrote:
Hi,

I just have a small question about scipy.interpolate.interp2d

I noticed that bounds checking when calling the interpolation instance
seems to be ineffective.
I found a ticket about this issue, but not much activity around it.
http://projects.scipy.org/scipy/ticket/1072

I looked at the code and at the documentation
 (
http://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp2d.html#scipy.interpolate.interp2d

https://raw.github.com/scipy/scipy/master/scipy/interpolate/interpolate.py )

and it seems that the `bounds_error` argument is never used in the
initialization of the interp2d object (unlike inter1d).
I'm not at all a specialist of 2D interpolation but I guess that bounds
checking in 2D is not as easy as in 1D...

Maybe, if there is no easy way to check bounds in interp2d, we should
just add a "big warning" in the docstring stating that `bounds_error` is
not currently used (and therefore `fill_value` as well).
What do you think ?

Bounds checking on a 2-D grid isn't really more difficult than on a 1-D grid. It looks like someone just copied the interp1d interface and then ran out of time or energy to fully implement it.

Would be good if someone feels like implementing the missing bits, and otherwise we should at least document that right now out-of-bounds input simply raises an error (I didn't check which one).


Best,
Pierre

about docstring editing, I didn't find the "Edit page" link on interp2d
page. Did I miss something ?

I see an edit button at http://docs.scipy.org/scipy/docs/scipy.interpolate.interpolate.interp2d/. Were you trying to find it there, or on the link you gave above (=built docs).

Ralf
 

_______________________________________________
SciPy-Dev mailing list
SciPy-Dev <at> scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-dev


_______________________________________________
SciPy-Dev mailing list
SciPy-Dev <at> scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-dev
Pauli Virtanen | 1 Jul 2012 20:40
Picon
Picon
Favicon

Re: interp2d bounds checking

01.07.2012 11:21, Ralf Gommers kirjoitti:
[clip]
> Bounds checking on a 2-D grid isn't really more difficult than on a 1-D
> grid. It looks like someone just copied the interp1d interface and then
> ran out of time or energy to fully implement it.
> 
> Would be good if someone feels like implementing the missing bits, and
> otherwise we should at least document that right now out-of-bounds input
> simply raises an error (I didn't check which one).

IMO, interp2d should be deprecated.

It is equivalent to SmoothBivariateSpline with s=0.

It's sort of a almost-name-alias for a Matlab function, but it works
differently --- scattered data interpolation vs. grid interpolation.
However, as FITPACK's 2-D scattered data splines not so rarely explode
with real data, I don't think this "replacement function" does its work
properly, so it should be deprecated. If the users want these 2-D
splines, it's better to make them ask for them explicitly...

We can maybe think about adding a deprecation category "deprecated and
removed from documentation, but we'll keep it around indefinitely for
backwards compatibility". Move to e.g. to a new file '_deprecated.py' to
keep the moldy code separate.

   ***

What's needed is a proper grid-base interpolation. It would be rather
easy to write a simple wrapper around ndimage.map_coordinates to get
general spline interpolation. Such interpolants are also easy to
construct up from the polynomial interpolants in Scipy.

If someone is looking for something to do: *here* would be a nice, a
relatively easy, and very likely a very useful project to work on.

    ***

Also, where interp2d works, griddata should work better in most use cases.

I've also been thinking about enlarging the griddata syntax from the
possibly somewhat unfriendly

	griddata((x, y), z, (xi, yi), **kw)
	griddata((x, y, z), u, (xi, yi, zi), **kw)

to the variable argument one

	griddata(x, y, z, xi, yi, **kw)
	griddata(x, y, z, u, xi, yi, zi, **kw)

which may be more familiar to users. Thoughts?

	Pauli
Ralf Gommers | 6 Jul 2012 18:19
Gravatar

Re: interp2d bounds checking



On Sun, Jul 1, 2012 at 8:40 PM, Pauli Virtanen <pav <at> iki.fi> wrote:
01.07.2012 11:21, Ralf Gommers kirjoitti:
[clip]
> Bounds checking on a 2-D grid isn't really more difficult than on a 1-D
> grid. It looks like someone just copied the interp1d interface and then
> ran out of time or energy to fully implement it.
>
> Would be good if someone feels like implementing the missing bits, and
> otherwise we should at least document that right now out-of-bounds input
> simply raises an error (I didn't check which one).

IMO, interp2d should be deprecated.

It is equivalent to SmoothBivariateSpline with s=0.

It's sort of a almost-name-alias for a Matlab function, but it works
differently --- scattered data interpolation vs. grid interpolation.
However, as FITPACK's 2-D scattered data splines not so rarely explode
with real data, I don't think this "replacement function" does its work
properly, so it should be deprecated. If the users want these 2-D
splines, it's better to make them ask for them explicitly...

We can maybe think about adding a deprecation category "deprecated and
removed from documentation, but we'll keep it around indefinitely for
backwards compatibility". Move to e.g. to a new file '_deprecated.py' to
keep the moldy code separate.

This sounds like a good idea. interp2d is widely used I think, and we don't usually deprecate functions like that.
 
   ***

What's needed is a proper grid-base interpolation. It would be rather
easy to write a simple wrapper around ndimage.map_coordinates to get
general spline interpolation. Such interpolants are also easy to
construct up from the polynomial interpolants in Scipy.

If someone is looking for something to do: *here* would be a nice, a
relatively easy, and very likely a very useful project to work on.

    ***

Also, where interp2d works, griddata should work better in most use cases.

I've also been thinking about enlarging the griddata syntax from the
possibly somewhat unfriendly

        griddata((x, y), z, (xi, yi), **kw)
        griddata((x, y, z), u, (xi, yi, zi), **kw)

to the variable argument one

        griddata(x, y, z, xi, yi, **kw)
        griddata(x, y, z, u, xi, yi, zi, **kw)

which may be more familiar to users. Thoughts?

That does look easier to use, but having two interfaces will be confusing. And deprecating the old one will be painful. What exactly do you have in mind to do here?

Ralf

_______________________________________________
SciPy-Dev mailing list
SciPy-Dev <at> scipy.org
http://mail.scipy.org/mailman/listinfo/scipy-dev
Pauli Virtanen | 6 Jul 2012 20:51
Picon
Picon
Favicon

Re: interp2d bounds checking

06.07.2012 18:19, Ralf Gommers kirjoitti:
> On Sun, Jul 1, 2012 at 8:40 PM, Pauli Virtanen wrote:
[clip]
>     I've also been thinking about enlarging the griddata syntax from the
>     possibly somewhat unfriendly
> 
>             griddata((x, y), z, (xi, yi), **kw)
>             griddata((x, y, z), u, (xi, yi, zi), **kw)
> 
>     to the variable argument one
> 
>             griddata(x, y, z, xi, yi, **kw)
>             griddata(x, y, z, u, xi, yi, zi, **kw)
> 
>     which may be more familiar to users. Thoughts?
> 
> That does look easier to use, but having two interfaces will be
> confusing. And deprecating the old one will be painful. What exactly do
> you have in mind to do here?

I was thinking about making the latter syntax an alias for the former,
keeping both around. But perhaps it's confusing.

Another issue is that variable arguments don't play too well with
function signatures. This is BTW one thing that is better in Python 3,
which has keyword-only arguments.

	Pauli
Nathaniel Smith | 6 Jul 2012 21:28
Picon
Favicon

Re: interp2d bounds checking

On Fri, Jul 6, 2012 at 7:51 PM, Pauli Virtanen <pav <at> iki.fi> wrote:
> 06.07.2012 18:19, Ralf Gommers kirjoitti:
>> On Sun, Jul 1, 2012 at 8:40 PM, Pauli Virtanen wrote:
> [clip]
>>     I've also been thinking about enlarging the griddata syntax from the
>>     possibly somewhat unfriendly
>>
>>             griddata((x, y), z, (xi, yi), **kw)
>>             griddata((x, y, z), u, (xi, yi, zi), **kw)
>>
>>     to the variable argument one
>>
>>             griddata(x, y, z, xi, yi, **kw)
>>             griddata(x, y, z, u, xi, yi, zi, **kw)
>>
>>     which may be more familiar to users. Thoughts?
>>
>> That does look easier to use, but having two interfaces will be
>> confusing. And deprecating the old one will be painful. What exactly do
>> you have in mind to do here?
>
> I was thinking about making the latter syntax an alias for the former,
> keeping both around. But perhaps it's confusing.

If I had the option I'd use the former ("old") syntax, but then, I'm weird.

-N

Gmane