viewshed: consistent output name and dtype across backends#2747
Open
brendancol wants to merge 1 commit into
Open
viewshed: consistent output name and dtype across backends#2747brendancol wants to merge 1 commit into
brendancol wants to merge 1 commit into
Conversation
The returned DataArray's .name and dtype depended on which backend ran: numpy left .name None, the RTX path hardcoded "viewshed", and the dask paths leaked the dask graph token. Output dtype was float32 on the GPU/RTX exact path and float64 everywhere else. Add a name= parameter (default 'viewshed') threaded through every backend helper and set on the output, matching slope/curvature/hillshade. Force float64 output on the GPU and dask Tier B paths so the dtype no longer depends on the backend. Add cross-backend tests asserting name and dtype are stable for numpy, dask+numpy, cupy, and dask+cupy, with and without max_distance.
brendancol
commented
May 30, 2026
Contributor
Author
brendancol
left a comment
There was a problem hiding this comment.
PR Review: viewshed consistent output name and dtype across backends
Blockers (must fix before merge)
None.
Suggestions (should fix, not blocking)
None.
Nits (optional improvements)
- The docstring lists the
nametype asstr, but the signature isOptional[str]andNoneis a valid value (it produces an unnamed DataArray). slope.py has the samestrvsOptional[str]docstring wording, so this matches the rest of the codebase. Not worth changing on its own.
What looks good
- The
name=default of'viewshed'is the same string the RTX path used to hardcode, and it follows the sibling-module convention (slope, curvature, hillshade all default to their own function name). name=reaches every backend helper (_viewshed_cpu,_viewshed_windowed,_viewshed_dask,viewshed_gpu,_viewshed_rt) and is set at DataArray construction. Verified live: numpy, cupy/RTX, dask+numpy, and dask+cupy all come back withname='viewshed'(or the custom name). Passingname=at construction does override the dask graph token here, so the dask paths no longer leak it.- The float64 cast widens from float32, so values do not change. The numpy/cupy value differences are the pre-existing algorithm difference already noted in the docstring, not something this PR introduced.
- Tests cover all four backends with and without
max_distance, plus a custom-name case. cupy and dask+cupy are gated onhas_rtx().
Checklist
- Algorithm unchanged (metadata-only change)
- All four backends produce consistent name and dtype
- NaN handling unchanged
- Edge cases: existing suite still passes (37 tests)
- Dask chunk handling unchanged
- No premature materialization introduced
- Benchmark not needed (no perf-critical change)
- README feature matrix not applicable (no new function, no backend change)
- Docstring present for the new parameter
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.
Closes #2743
viewshed()returned a DataArray whose.nameand dtype depended on which backend ran:.name: numpy left itNone, the RTX path hardcoded"viewshed", and the dask paths leaked the internal dask graph token (built without an explicitname=).float32on the GPU/RTX exact path,float64everywhere else.Changes:
name=parameter (default'viewshed'), threaded through every backend helper and set on the output. Matches the convention in slope, curvature, and hillshade.float64output on the GPU and dask Tier B paths so dtype no longer depends on the backend (the RT kernel still works in float32 internally).attrs, coords, and dims were already preserved on every backend; this PR does not change them.
Backend coverage: numpy, cupy (RTX), dask+numpy, dask+cupy. Verified live on a host with CUDA + RTX.
Test plan:
test_viewshed_output_name_and_dtype_consistent— name == 'viewshed' and dtype == float64 across all four backends, with and withoutmax_distancetest_viewshed_custom_name— a user-supplied name is honoured on every backendtest_viewshed.pysuite (37 passed)test_visibility.py,test_min_observable_height.py,test_gpu_rtx_memory.py,test_validation.py(120 passed)