RocketPy-Team / RocketPy

Next generation High-Power Rocketry 6-DOF Trajectory Simulation
https://docs.rocketpy.org/
MIT License
648 stars 158 forks source link

ENH: Expand Polation Options for ND Functions. #691

Closed phmbressan closed 2 months ago

phmbressan commented 2 months ago

Pull request type

Checklist

Current behavior

Options of ND interpolation and extrapolation of ND Functions are rather limited. Only "shepard" is supported, which might not be adequate for some datasets.

New behavior

This PR introduces the following polation methods for ND Functions:

Interpolation:

Extrapolation:

Note: I could not find an easy / reasonable approach for strictly linear extrapolation, since the dataset dealt by the Function class is generally "unstructed" (check out scipy tools) which prevent the usage of utilities that make use of "structed" data (like interpn). It should be possible to build a Delaunay triangulation with scipy tools to find the nearest points and manually build the linear extrapolation, but the accuracy and applicability of the results will likely vary a lot.

Therefore, due to having more smooth and predictable results, I have decided to apply "rbf" extrapolation to the "linear" option (with a explicit warning). This might be worth of an improvement in the future.

Result Examples

Sample plots comparing interpolation results for the paraboloid $f(x,y) = x^2 + y^2$ :

Lambda Function
Rbf Interpolation
Linear Interpolation
Shepard Interpolation

Breaking change

phmbressan commented 2 months ago

I will update the Documentation regarding the changes shortly, but feature wise the PR should be ready to review.

phmbressan commented 2 months ago

There seems to be a minimum amount of points for the ND linear interpolation to be used. Could this be checked for when initializing the Function object?

I have introduced a check into commit c04d401. Let me know if this solution is enough.

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 92.00000% with 8 lines in your changes missing coverage. Please review.

Project coverage is 75.45%. Comparing base (3c759f7) to head (bae7cae). Report is 17 commits behind head on develop.

Files with missing lines Patch % Lines
rocketpy/mathutils/function.py 92.00% 8 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #691 +/- ## =========================================== + Coverage 75.42% 75.45% +0.03% =========================================== Files 96 96 Lines 10841 10887 +46 =========================================== + Hits 8177 8215 +38 - Misses 2664 2672 +8 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

MateusStano commented 2 months ago

I have introduced a check into commit c04d401. Let me know if this solution is enough.

Seems good enough to me