Skip to content

Fix cumulative_viewshed TypeError on cupy rasters (#3194)#3209

Closed
brendancol wants to merge 1 commit into
mainfrom
deep-sweep-accuracy-visibility-2026-06-10
Closed

Fix cumulative_viewshed TypeError on cupy rasters (#3194)#3209
brendancol wants to merge 1 commit into
mainfrom
deep-sweep-accuracy-visibility-2026-06-10

Conversation

@brendancol

Copy link
Copy Markdown
Contributor

Fixes #3194

Problem

cumulative_viewshed and visibility_frequency raised
TypeError: Unsupported type <class 'numpy.ndarray'> on a cupy-backed raster.
viewshed() returns a cupy-backed DataArray for cupy input, but the accumulator
was a numpy array (count = np.zeros(...)), and cupy refuses a numpy+cupy add.
The cupy path had no test coverage, so this went unnoticed.

Fix

Pull each per-observer viewshed result to numpy with .get() before
accumulating into the numpy count. This matches how _extract_transect
already handles cupy data in the same module.

Test

Added a cupy regression test (gated on rtxpy) confirming both functions run
and return valid int32 counts. It does not assert cell-for-cell parity with
numpy: the GPU viewshed uses RTX ray tracing and the numpy backend uses the
GRASS sweep, a divergence already documented on viewshed.

Verified on an RTX A6000: both functions run, return int32 / float64 with
valid ranges, 26 visibility tests pass.

Found by the accuracy sweep (Cat 5: backend inconsistency).

cumulative_viewshed and visibility_frequency raised
TypeError: Unsupported type <class 'numpy.ndarray'> on a cupy-backed
raster. viewshed() returns a cupy-backed result for cupy input, and the
numpy `count` accumulator could not be added to it.

Pull each per-observer viewshed result to numpy with .get() before
accumulating, matching how _extract_transect already handles cupy data.

Add a cupy regression test (gated on rtxpy) that checks both functions
run and return valid int32 counts. The test does not require cell-for-cell
parity with numpy because the GPU viewshed uses RTX ray tracing and the
numpy backend uses the GRASS sweep, a divergence documented on viewshed.

Update sweep-accuracy state for visibility.
@brendancol

Copy link
Copy Markdown
Contributor Author

Closing in favor of #3205, which fixes the same cumulative_viewshed cupy crash but keeps the accumulator on-device, so cupy input yields a cupy-backed result (consistent with the cross-backend parity convention). This PR's .get() approach returns numpy output for cupy input, and the two test suites assert contradictory result types, so they can't both land. #3205 also covers visibility_frequency and metadata preservation.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cumulative_viewshed and visibility_frequency raise TypeError on cupy-backed rasters

1 participant