reproject: support 3-D rasters on dask, cupy, and dask+cupy (#2027)#2034
Merged
Conversation
The 3-D (y, x, band) input contract was only honoured on the eager numpy path. The dask backend built a 2-D template that disagreed with its own 3-D chunks (lazy DataArray claimed 2-D, .compute() crashed). The cupy backend never gained a 3-D branch and tripped a CUDA signature mismatch. merge() advertised 3-D via the validator but crashed at output DataArray construction. - _reproject_chunk_cupy: add per-band loop matching the numpy path - _reproject_dask: build a 3-D template (out_h, out_w, n_bands) for 3-D sources so the lazy metadata matches actual chunk output - _reproject_dask_cupy: route 3-D sources through map_blocks (the fast path's inline window loop is 2-D-only) - _reproject_block_adapter: read 2-D location from a 3-D template; return matching-rank empty chunks - _reproject_chunk_numpy / _cupy: empty-chunk early returns now carry the band axis when the source is 3-D - merge(): tighten _validate_raster to ndim=(2,) so the API surface stops promising 3-D support the implementation cannot deliver - tests: cross-backend 3-D parity on numpy / dask / cupy / dask+cupy plus a merge 3-D rejection test
- _reproject_chunk_cupy: skip the band-data nodata->NaN pre-conversion on the native CUDA path so the 3-D branch matches the 2-D path's contract (the CUDA kernels handle the sentinel internally). - Replace defensive getattr(source_data, 'ndim', 2) shims with direct attribute access; numpy/cupy/dask arrays all expose ndim. - Document why the dask template collapses the band axis to one chunk. - Add cupy uint8 sentinel-nodata round-trip test that exercises the non-NaN nodata branch on the GPU.
Contributor
Author
PR Review (self-review after follow-ups in 2b8c725)Blockers
Suggestions (addressed in 2b8c725)
Nits (addressed in 2b8c725)
What looks good
Checklist
|
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 #2027.
Summary
reproject()accepted 3-D(y, x, band)inputs via_validate_raster(ndim=(2, 3)), but only the eager numpy path actually handled them. The dask path advertised a 2-D template for chunks that returned 3-D arrays (lazy shape disagreed with.compute()output), the cupy path tripped a CUDA signature mismatch, andmerge()crashed at output DataArray construction._reproject_chunk_cupy: per-band loop matching_reproject_chunk_numpy_reproject_dask/_reproject_block_adapter: 3-D template with(out_h, out_w, n_bands)shape so lazy metadata matches actual chunk output_reproject_dask_cupy: route 3-D sources throughmap_blocks(fast path is 2-D-only)merge(): tighten validator tondim=(2,)so callers see a clean error instead of aValueError: different number of dimensions on data and dimscrashBackend coverage
Test plan
TestReproject3DBackends: lazy shape, computed shape, eager-vs-dask parity, integer dtype round-trip, cupy parity, dask+cupy computeTestMerge3DRejection: cleanValueErrorinstead of dim mismatchtest_reproject.pysuite still green (267 tests)