GlacioHack / geoutils

Analysis of georeferenced rasters and vectors
https://geoutils.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
86 stars 19 forks source link

Define consistent nodata propagation for `interp_points` and allow to return interpolator #560

Closed rhugonnet closed 1 month ago

rhugonnet commented 4 months ago

Most of the line changes in this PR are due to re-structuring, moving out functions of the Raster class (see #539, in preparation for #383) into their own module, here only those linked to interp_points.

This PR also adds a nodata propagation scheme (as scipy.interpolate.interpn does not support nodata propagation natively except for methods "nearest" and "linear") and allows to return an interpolator that contains this nodata propagation (to optimize speed of iterative methods calling the same interpolator several times, such as DEM coregistration).

It turned out that interpolation of map_coordinates with splines of order 3/5 does not match "cubic" or "quintic" in interpn, only order 0/1 do match for "nearest" and "linear", so all other are dropped. The nodata propagation and accuracy of results for values near the edge of NaNs is now tested thoroughly! :smile:

Resolves #559 Starts addressing #539 for functions related to interp_points

TO-DO:

rhugonnet commented 2 months ago

This PR is finalized, and ready for review! :smile: @adehecq @erikmannerfelt @atedstone Important: don't lose time looking at changes from functions moved from raster.py to georeferencing.py, etc... This is simply restructuring linked to #539, which was necessary to have functionalities separate from the Raster class (to avoid always re-building a Raster object for performance, for instance in coregistration), and will facilitate building the Xarray accessor as well. All the core changes are in interpolate.py and test_interpolate.py.

We now have a fully consistent point interpolation with all benefits and (normally) none of the limitations of existing implementations:

All the tests allow to check the robustness of the implementation: