Skip to content

Fix dask OOM in visibility and viewshed modules#1167

Merged
brendancol merged 2 commits into
masterfrom
fix/visibility-viewshed-dask-oom
Apr 6, 2026
Merged

Fix dask OOM in visibility and viewshed modules#1167
brendancol merged 2 commits into
masterfrom
fix/visibility-viewshed-dask-oom

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Summary

  • _extract_transect was calling .compute() on the full dask array to read a handful of transect cells. Now uses vindex fancy indexing so only relevant chunks get materialized.
  • cumulative_viewshed allocated a full-size np.zeros count array and called .values on each viewshed result in a loop, forcing materialization every iteration. Now accumulates lazily with da.zeros and dask array addition when the input is dask-backed.
  • Viewshed Tier B memory guard underestimated peak usage at 280 bytes/pixel. Actual peak during lexsort hits ~360 bytes/pixel (sorted + unsorted event_list coexist) plus 8 bytes/pixel for the computed raster. Updated to 368 bytes/pixel.
  • _viewshed_cpu called .astype(np.float64) unconditionally, copying even when data was already float64. Now passes copy=False.

Test plan

  • All 25 test_visibility.py tests pass (including test_dask_matches_numpy)
  • All 23 test_viewshed.py tests pass (including dask flat, distance sweep, and max distance variants)
  • No deprecation warnings from chunk tuple handling

_extract_transect was calling .compute() on the full dask array just to
read a handful of transect cells. Now uses vindex fancy indexing so only
the relevant chunks are materialized.

cumulative_viewshed was allocating a full-size np.zeros count array and
calling .values on each viewshed result, forcing materialization every
iteration. Now accumulates lazily with da.zeros and dask array addition
when the input is dask-backed.
The dask Tier B memory guard underestimated peak usage at 280 bytes/pixel.
Actual peak during lexsort reaches ~360 bytes/pixel (sorted + unsorted
event_list coexist) plus 8 bytes/pixel for the computed raster. Updated
estimate to 368 bytes/pixel to prevent borderline OOM.

Also use astype(copy=False) to skip the float64 copy when data is already
float64.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label Apr 6, 2026
@brendancol brendancol merged commit 26bde73 into master Apr 6, 2026
11 checks passed
@brendancol brendancol deleted the fix/visibility-viewshed-dask-oom branch May 4, 2026 13:05
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.

1 participant