Fix cumulative_viewshed TypeError on cupy rasters (#3194)#3209
Closed
brendancol wants to merge 1 commit into
Closed
Fix cumulative_viewshed TypeError on cupy rasters (#3194)#3209brendancol wants to merge 1 commit into
brendancol wants to merge 1 commit into
Conversation
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.
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. |
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.
Fixes #3194
Problem
cumulative_viewshedandvisibility_frequencyraisedTypeError: Unsupported type <class 'numpy.ndarray'>on a cupy-backed raster.viewshed()returns a cupy-backed DataArray for cupy input, but the accumulatorwas 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()beforeaccumulating into the numpy
count. This matches how_extract_transectalready handles cupy data in the same module.
Test
Added a cupy regression test (gated on
rtxpy) confirming both functions runand 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).