Skip to content

Honor per-raster nodata sentinels in merge()#1449

Merged
brendancol merged 2 commits intomainfrom
merge-per-raster-nodata
May 4, 2026
Merged

Honor per-raster nodata sentinels in merge()#1449
brendancol merged 2 commits intomainfrom
merge-per-raster-nodata

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1448.

Summary

merge() only detected the first raster's nodata sentinel and reused it for every other input, so rasters with a different sentinel had their invalid pixels passed through reprojection as real data. The mosaic looked fine but contained wrong numerical values.

Fix

  • Detect each raster's own input nodata sentinel in the raster_infos loop, independent of the user-supplied output nodata.
  • Reproject each raster using its own input sentinel, then canonicalize to NaN before the strategy merge so all rasters share one missing-data marker.
  • After the strategy merge, convert NaN back to the user-requested output nodata if that is not NaN.

Applied in both the in-memory path (_merge_inmemory) and the dask path (_merge_block_adapter / _merge_dask).

Test plan

  • pytest xrspatial/tests/test_reproject.py (139 passed)
  • New TestMergeMixedNodata class covers:
    • NaN + -9999 sentinel mix, default output nodata
    • NaN + 0 sentinel mix with mean strategy (verifies zeros are not folded into averages)
    • Mixed sentinels with explicit user-requested nodata=-9999 output

merge() previously detected nodata only from the first raster and reused
that sentinel for every other input. Rasters with a different sentinel
had their invalid pixels passed through reprojection as real data,
producing silently wrong results. Detect each raster's own sentinel,
canonicalize to NaN before the strategy merge, then convert back to the
user-requested output nodata. Affects both _merge_inmemory and the dask
_merge_block_adapter path.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 4, 2026
@brendancol
Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

…ization

Co-authored-by: brendancol <433221+brendancol@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

@copilot resolve the merge conflicts in this pull request

Resolved in 003a7dd. Combined the per-raster raster_nodata_list from this branch with the same_crs_list optimization that landed on main — both now flow through _merge_block_adapter and _merge_dask. 142 tests pass.

@brendancol brendancol merged commit bd35671 into main May 4, 2026
1 check was pending
@brendancol brendancol deleted the merge-per-raster-nodata branch May 5, 2026 03:45
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.

merge() ignores per-raster nodata sentinels, leaks invalid pixels into mosaic

2 participants