QA/QC: align sieve with GDAL and add parity tests#1169
Merged
brendancol merged 5 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.
Cross-validates xrspatial.sieve() against rasterio.features.sieve() (GDAL wrapper) on identical inputs. 30 tests covering thresholds, connectivity modes, nodata, dtypes, and edge cases. Documents one behavioral difference: GDAL runs a single pass while xrspatial iterates. When all regions are below threshold, GDAL leaves the raster unchanged; xrspatial cascades merges to convergence.
GitHub already shows who opened an issue. Removed the field from the feature-proposal template and updated the rockout command to note it should be skipped.
GDAL's sieve only merges a small region into a neighbor whose size is already >= threshold. If no such neighbor exists, the region stays. Previously xrspatial iterated up to 50 passes and merged into any neighbor regardless of its size, causing cascading merges that GDAL does not perform. Changes: - _sieve_numpy: remove iteration loop, filter merge targets to neighbors >= threshold - Remove _MAX_ITERATIONS and convergence warning (single pass always completes) - Update docstrings to document GDAL-matching semantics - Update tests: checkerboard/stripe/all-small-regions cases now correctly leave the raster unchanged - All 30 GDAL parity tests now assert exact equality
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
test_sieve_gdal_parity.pywith 30 tests comparingxrspatial.sieve()againstrasterio.features.sieve()(GDAL wrapper) on identical inputsCloses #1168
Test plan
pytest xrspatial/tests/test_sieve.py-- 45 existing tests updated for single-pass behaviorpytest xrspatial/tests/test_sieve_gdal_parity.py-- 30 new parity tests, all assert exact equality with GDAL (one tie-breaking test allows < 0.5% mismatch)_MAX_ITERATIONSor reference convergence warning