Switch cell_xy checks over to using a STRtree query#1348
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1348 +/- ##
========================================
Coverage 94.95% 94.96%
========================================
Files 71 71
Lines 7379 7382 +3
========================================
+ Hits 7007 7010 +3
Misses 372 372 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
dalonsoa
left a comment
There was a problem hiding this comment.
Looks good to me. When the time comes (hopefully from next week, or maybe March), we can use pytest-benchmark to get some performance information out of the existing testsuite with minimum changes. We will look into it when the time comes.
|
Actually, if you want to give it a try, just update the existing virtual_ecosystem/tests/core/test_grid.py Lines 436 to 437 in 01128a3 by these: cell_map = benchmark(
fixture_square_grid.map_xy_to_cell_id
np.array(x_coord)
np.array(y_coord)And you will have the performance information for free. Then, the new custom test won't be needed, as the performance data will be readily available. |
|
Interesting - hadn't seen It does work - but I won't put it in this PR because it's only really useful once you have a database of previous profiling that you can use to compare runs to. I agree the current test is a hack, but I'd rather leave as is until we have a profiling plan and an initial DB setup. |
Description
This PR replaces the incredibly slow check that incoming cell coordinate data maps 1-to-1 onto the grid with a SRTtree spatial search structure (https://shapely.readthedocs.io/en/latest/strtree.html#).
I've added a test that is purely there to run speed checks for three pairs of (nx, ny) grid sizes. There might be a better place for it, but maybe that will emerge from the upcoming performance review.
Using
pytest tests/core/test_grid.py::test_map_xy_to_cell_ids_performance --durations=0 -n 0to run this test gives the following runtimes for the old code vs this PR.Before:
After:
Fixes #1347
Type of change
Key checklist
pre-commitchecks:$ pre-commit run -a$ poetry run pytestFurther checks