Propagate input dims/coords through true_color() (#3429)#3434
Merged
Conversation
true_color() hardcoded output dims to ['y','x','band'] and rebuilt coords via r['y']/r['x'], so it raised KeyError on lat/lon (or row/col) rasters and dropped non-spatial coords like spatial_ref. Derive the two spatial dims and coords from the input instead, then append the band dim, matching how the other indices in the module preserve metadata. Verified on numpy, cupy, dask+numpy, dask+cupy.
brendancol
commented
Jun 20, 2026
brendancol
left a comment
Contributor
Author
There was a problem hiding this comment.
PR Review: Propagate input dims/coords through true_color() (#3429)
Blockers (must fix before merge)
None.
Suggestions (should fix, not blocking)
None.
Nits (optional improvements)
- multispectral.py:1828 — if an input raster carried a coord literally named
band, the'band': [0, 1, 2, 3]entry would overwrite it. Far-fetched (a 2D raster with a non-dim coord calledband), and the old code had the same collision, so it's not a regression. Not worth guarding against unless it ever comes up.
What looks good
- The fix mirrors how every other index in the module preserves metadata, so true_color is no longer the odd one out.
- Metadata is built in the public function after dispatch, so all four backends share one code path. The parametrized test runs numpy, cupy, dask+numpy, and dask+cupy with lat/lon input.
[*r.dims, 'band']lines up with the(H, W, 4)output cube:ris validated 2D and the stack axis is appended last on every backend.- Tests assert on dims, coord values, and attrs, not just that the call returns. The spatial_ref test covers the dropped-coord half of the bug.
Checklist
- Algorithm matches reference/paper (N/A, metadata-only change, pixel math untouched)
- All implemented backends produce consistent results
- NaN handling is correct (unchanged)
- Edge cases are covered by tests (lat/lon dims, extra coord)
- Dask chunk boundaries handled correctly (metadata built post-dispatch, no chunk interaction)
- No premature materialization or unnecessary copies
- Benchmark exists or is not needed (not needed, no perf change)
- README feature matrix updated (N/A, no new function or backend change)
- Docstrings present and accurate
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 #3429.
true_color()hardcoded its output dims to['y','x','band']and rebuilt coords viar['y']/r['x']. That raisedKeyError: 'y'on rasters withlat/lon(orrow/col) dims and silently dropped non-spatial coords likespatial_ref. The other indices in the module already passdims/coords/attrsstraight through; this bringstrue_color()in line.banddim.Backend coverage: numpy, cupy, dask+numpy, dask+cupy (all verified locally on a GPU host).
Test plan:
test_true_color_preserves_non_yx_dimsruns on all four backends withlat/loninput.test_true_color_preserves_extra_coordschecks aspatial_refcoord survives.test_multispectral.pypasses (159 tests).