Support 3D rasters, expose nodata, document target_resolution tuple in resample#1474
Merged
brendancol merged 2 commits intomainfrom May 4, 2026
Merged
Support 3D rasters, expose nodata, document target_resolution tuple in resample#1474brendancol merged 2 commits intomainfrom
brendancol merged 2 commits intomainfrom
Conversation
…n resample (#1466) - _validate_raster now allows ndim=(2, 3); 3D inputs are dispatched per band via a recursive call and stacked back along the leading dim. Non-spatial coordinates (e.g. band=[1,2,3]) are preserved. - Add nodata=None keyword. Explicit value wins; otherwise falls back to agg.attrs['_FillValue'] then agg.attrs['nodata']. Sentinels are replaced with NaN before the resample. Output advertises _FillValue=nan when masking was applied. - Document target_resolution as float or (float, float) -- the tuple form was already accepted but undocumented.
Contributor
Author
|
@copilot resolve the merge conflicts in this pull request |
Co-authored-by: brendancol <433221+brendancol@users.noreply.github.com>
Contributor
Merge conflicts resolved in commit |
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.
Closes #1466.
Three small API gaps in
xrspatial.resample.resample(), all touching the same signature/dispatch surface, bundled into one PR.Summary
band, y, x) are now accepted._validate_rasteris called withndim=(2, 3). The 3D dispatch loops over the leading dim, recurses into the 2D path per band, and stacks the results withxr.concatfollowed by atransposeback to the original layout. Non-spatial coordinates (e.g.band=[1, 2, 3]) are preserved.nodata=Nonekeyword. Explicit value wins; otherwise it falls back toagg.attrs['_FillValue'], thenagg.attrs['nodata']. Sentinel pixels are replaced with NaN before the resample usingagg.where(agg != nodata), which dispatches naturally for numpy / cupy / dask backings. The output advertises_FillValue=nanwhen masking was applied.target_resolutiondocstring updated tofloat or (float, float). The tuple form was already accepted at lines 801-803; only the documentation was wrong.Test plan
test_resample.pypass (62 existing + 13 new).bandcoord preserved.nodata=-9999on an int raster produces NaN where the input was -9999, finite floats elsewhere.nodataresolved from_FillValueand fromnodataattrs._FillValueis not added to the output (no behavior change for existing 2D float callers).target_resolution=(2.0, 4.0)on an 8x8 raster gives shape (4, 2).Notes on the 3D dispatch
nodata=float('nan')so the per-band path doesn't try to re-mask attrs that were already masked at the 3D level._apply_nodata_maskshort-circuits on NaN sentinels.xr.concatwas the cleanest way to stack the per-band outputs while keeping the per-band coordinate. Atranspose(*agg.dims)afterwards keeps dim order stable.scale_y == scale_x == 1.0) sits above the 3D branch -- 3D identity copies pass through unchanged.