Fixes #878: extend KDTree path to allocation/direction to prevent OOM#893
Merged
brendancol merged 1 commit intomasterfrom Feb 25, 2026
Merged
Conversation
The memory-safe KDTree path was previously gated to PROXIMITY mode only. This extends it to handle ALLOCATION and DIRECTION modes, since cKDTree.query() returns both distances and nearest-target indices — enough to derive allocation values and direction angles. Changes: - Add _vectorized_calc_direction() for array-based compass directions - Extend _stream_target_counts() to cache target pixel values - Extend _collect_region_targets() to return target values alongside coords - Extend _kdtree_chunk_fn() and _tiled_chunk_query() for all three modes - Thread process_mode and values_cache through the full call chain - Remove process_mode == PROXIMITY restriction from KDTree gate - Add memory guard for non-KDTree fallback (GREAT_CIRCLE, no scipy) - Update memory estimate from 48 to 52 bytes per target
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
max_distance=infon large dask-backed rasterscKDTree.query()returns both distances and nearest-target indices, which is enough to derive allocation values and compass direction anglesMemoryErrorwith actionable guidance instead of silently OOMingKey changes
_vectorized_calc_direction()— new array-based compass direction function matching the scalar_calc_direction()floating-point behaviour_stream_target_counts()— now also caches target pixel values alongside coordinates_collect_region_targets()— returns(coords, vals)tuple_kdtree_chunk_fn()/_tiled_chunk_query()— extended with mode dispatch (PROXIMITY/ALLOCATION/DIRECTION)process_mode == PROXIMITYrestrictionMemoryErrorraised when single-chunk rechunk would exceed 80% available memoryTest plan
test_allocation_dask_kdtree_matches_numpy(EUCLIDEAN + MANHATTAN) — consistency check against proximitytest_direction_dask_kdtree_matches_numpy(EUCLIDEAN + MANHATTAN) — consistency check against allocationtest_allocation_dask_kdtree_with_target_values— target filtering through KDTreetest_direction_dask_kdtree_with_target_values— target filtering through KDTreetest_allocation_dask_kdtree_no_targets/test_direction_dask_kdtree_no_targets— all-NaNtest_allocation_dask_kdtree_max_distance/test_direction_dask_kdtree_max_distance— truncationtest_great_circle_dask_unbounded_memory_guard— MemoryError for GREAT_CIRCLEtest_no_scipy_dask_unbounded_memory_guard— MemoryError when scipy missing