Fix dask OOM in visibility and viewshed modules#1167
Merged
brendancol merged 2 commits intomasterfrom Apr 6, 2026
Merged
Conversation
_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.
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.
Summary
_extract_transectwas calling.compute()on the full dask array to read a handful of transect cells. Now usesvindexfancy indexing so only relevant chunks get materialized.cumulative_viewshedallocated a full-sizenp.zeroscount array and called.valueson each viewshed result in a loop, forcing materialization every iteration. Now accumulates lazily withda.zerosand dask array addition when the input is dask-backed.lexsorthits ~360 bytes/pixel (sorted + unsorted event_list coexist) plus 8 bytes/pixel for the computed raster. Updated to 368 bytes/pixel._viewshed_cpucalled.astype(np.float64)unconditionally, copying even when data was already float64. Now passescopy=False.Test plan
test_visibility.pytests pass (includingtest_dask_matches_numpy)test_viewshed.pytests pass (including dask flat, distance sweep, and max distance variants)