Skip to content

viewshed: consistent output name and dtype across backends#2747

Open
brendancol wants to merge 1 commit into
mainfrom
deep-sweep-metadata-viewshed-2026-05-29
Open

viewshed: consistent output name and dtype across backends#2747
brendancol wants to merge 1 commit into
mainfrom
deep-sweep-metadata-viewshed-2026-05-29

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #2743

viewshed() returned a DataArray whose .name and dtype depended on which backend ran:

  • .name: numpy left it None, the RTX path hardcoded "viewshed", and the dask paths leaked the internal dask graph token (built without an explicit name=).
  • dtype: float32 on the GPU/RTX exact path, float64 everywhere else.

Changes:

  • Add a name= parameter (default 'viewshed'), threaded through every backend helper and set on the output. Matches the convention in slope, curvature, and hillshade.
  • Force float64 output 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 without max_distance
  • test_viewshed_custom_name — a user-supplied name is honoured on every backend
  • Full test_viewshed.py suite (37 passed)
  • test_visibility.py, test_min_observable_height.py, test_gpu_rtx_memory.py, test_validation.py (120 passed)

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.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 30, 2026
Copy link
Copy Markdown
Contributor Author

@brendancol brendancol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 name type as str, but the signature is Optional[str] and None is a valid value (it produces an unnamed DataArray). slope.py has the same str vs Optional[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 with name='viewshed' (or the custom name). Passing name= 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 on has_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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

viewshed() output .name and dtype differ across backends

1 participant