Merged
Conversation
flow_accumulation() only understood D8 integer codes. Passing Dinf angles from flow_direction_dinf() silently produced wrong results (every cell got 1.0) because float angles never matched any D8 code in _code_to_offset. Auto-detect D8 vs Dinf from input values, then run Tarboton's proportional splitting for Dinf. All four backends covered: numpy, cupy, dask+numpy, dask+cupy. 45 tests pass (24 existing D8 unchanged, 15 new Dinf, 6 detection).
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
flow_accumulation()silently returned wrong results for Dinf input (every cell = 1.0) because_code_to_offsettruncated float angles to ints that never matched any D8 codeWhat changed
xrspatial/flow_accumulation.py_classify_flow_block/_detect_flow_type: scan input values to distinguish D8 codes from Dinf angles (handles the 0.0 ambiguity between D8 pit and Dinf east-angle)_angle_to_neighbors: decompose a Dinf angle into two downstream neighbors with proportional weights_flow_accum_dinf_cpu: Kahn's BFS with fractional splitting_init_accum_indegree_dinf,_pull_from_frontier_dinf,_flow_accum_dinf_cupy): frontier-peeling with inlined angle decomposition, reuses_find_ready_and_finalizefrom D8_flow_accum_dinf_tile_kernel,_compute_seeds_dinf, etc.): boundary-propagation with fractional cross-tile seedsflow_accumulation()docstring updated, Tarboton (1997) reference addedxrspatial/tests/test_flow_accumulation.pyflow_direction_dinf(elevation)->flow_accumulation()Test plan
pytest xrspatial/tests/test_flow_accumulation.py)flow_direction_dinf->flow_accumulationon random 20x20 elevation, all values >= 1.0