BUG: N-D Function with linear interpolation sometimes returns NaN or raises errors for valid-looking queries
Describe the bug
When using Function(..., interpolation="linear") with N-D input data, nan values or error can be raised depending on the data set:
- One query returns
nansilently. - Another query raises an exception.
This happens in in this example:
from rocketpy import Function
data = [
[0.0, 0.0, 0.000],
[0.0, 0.1, 0.1],
[0.0, 0.4, 0.4],
[0.3, 0.2, 0.15],
]
f = Function(data, interpolation="linear")
print(f(0.3, 0.3)) # returns nan
aa = Function([[1, 1, 10], [2, 2, 20], [3, 3, 30]], interpolation="linear")
print(aa(4, 4)) # raises error
- bb(0.3, 0.3) returns nan without explicit warning/error.
- aa(4, 4) raises an exception.
This appears to happen only with very specific point configurations/datasets. Please investigate the underlying cause and clarify intended behavior for these edge cases.
My two cents:
- The ND Interpolator from scipy returns nan for points outside the convex hull (i.e. the boundary of the domain triangulation). Therefore likely there is an issue with the
Functionlogic that identify if it should extrapolate or not (in theget_value_nd). - For the second case, your set of points is colinear. It is a degenerate domain whence no triagulation can be made. I would expect that the scipy library would raise an exception that is detailed enough for us not to have to implement this manual check.
Agent run 41735ddc07b34ef38ac32a720181980a started.
Agent run 41735ddc07b34ef38ac32a720181980a finished without PR: Baseline pytest failed; aborting run
My two cents:
- The ND Interpolator from scipy returns nan for points outside the convex hull (i.e. the boundary of the domain triangulation). Therefore likely there is an issue with the
Functionlogic that identify if it should extrapolate or not (in theget_value_nd).- For the second case, your set of points is colinear. It is a degenerate domain whence no triagulation can be made. I would expect that the scipy library would raise an exception that is detailed enough for us not to have to implement this manual check.
@phmbressan would you say we should open an issue on scipy's repo instead of making the comparison ourselves?
@phmbressan would you say we should open an issue on scipy's repo instead of making the comparison ourselves?
I don't think so. The behavior we are seeing is what is expected/documented from scipy. It is the Function that is incorrectly using the Interpolator for points outside the domain (this is an educated guess, I haven't investigated the issue myself).
Now, if the scipy interpolator should support native extrapolation, I believe there is already an issue in their repository about this. I can find the link later.
@MateusStano does #927 solve this issue?
Nope, it does not fix it