opendrift icon indicating copy to clipboard operation
opendrift copied to clipboard

perf(reader): replace the scipy.spatial.cKDTree with pygeos.STRtree to find the nearest node and element

Open lyingTree opened this issue 2 years ago • 2 comments

Using pygeos.STRtree method will be more efficient than scipy.spatial.cKDTree when searching for the index of the nearest node and element.

Closes #889

lyingTree avatar Mar 24 '22 14:03 lyingTree

Thank you, have you tried to use strtree from shapely rather than from pygeos? Then we would avoid a new dependency, and pygeos will be deprecated in the future.

gauteh avatar Mar 26 '22 19:03 gauteh

Thank you, have you tried to use strtree from shapely rather than from pygeos? Then we would avoid a new dependency, and pygeos will be deprecated in the future.

I have tried to use shapely to complete this function, but now it's not a good choice. I tried the shapely in 1.7.1, the main release version, and the 1.8.1.post1, the newest release version, but it's all unsatisfactory. The return in the shapely.strtree.STRtree.nearest is a geometry, and it can't return multi-value. Thus we have to reprocess this, which seriously affects the speed.

All in all, it's not a good choice now for here. But for the Shapely 2.0, we should keep paying continuous attention.

lyingTree avatar Mar 30 '22 13:03 lyingTree