Preserve input attrs through reproject() and merge()#1446
Merged
brendancol merged 2 commits intomainfrom May 4, 2026
Merged
Conversation
Both public APIs in xrspatial.reproject built `out_attrs` from scratch, dropping units, long_name, scale_factor, add_offset, _FillValue, and any custom metadata the caller had attached. Merge input attrs forward and override only what the operation actually changes. Pop attrs that are stale after the transform (transform, res, crs_wkt) since carrying them through would be actively wrong. merge() now also falls back name to rasters[0].name before 'merged', matching how reproject() falls back to raster.name. Closes #1445
Contributor
Author
|
@copilot resolve the merge conflicts in this pull request |
… tests Co-authored-by: brendancol <433221+brendancol@users.noreply.github.com>
Contributor
Merge conflicts resolved in commit |
This was referenced May 4, 2026
brendancol
added a commit
that referenced
this pull request
May 4, 2026
Three small follow-ups to PR #1446 in `xrspatial/reproject/__init__.py`: - `reproject()` and `merge()` re-emit `attrs['transform']` and `attrs['res']` for the new output grid instead of dropping them. The transform uses the rasterio 6-tuple convention `(res_x, 0.0, left, 0.0, -res_y, top)`. The geotiff reader does not itself write these attrs, so there is no in-repo convention to match and the rasterio form is used as the default. - `merge()` uses `_find_spatial_dims` instead of assuming the last two dims are spatial, both when collecting per-raster shapes and when building the output coords. - Both functions copy the resolved nodata value into `_FillValue` when the input set `_FillValue`. Inputs that did not set `_FillValue` get no `_FillValue` on output. Tests in `TestMetadataPreservation` cover the fresh transform/res values, absence-of-input behaviour, `_find_spatial_dims` use with lat/lon dims, and `_FillValue` round-trip for both functions.
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
reproject()andmerge()now merge inputattrsforward instead of building output attrs from scratch, sounits,long_name,scale_factor,add_offset,_FillValue, and similar metadata survive the transform.transform,res,crs_wkt) are popped before the newcrs/nodataare written, since they describe the old grid and would mislead downstream consumers.merge()falls back its outputnametorasters[0].namebefore'merged', matching the patternreproject()already uses.Test plan
TestMetadataPreservationcoversunits,scale_factor/add_offset,long_name, staletransform, staleres, stalecrs_wkt, and thecrsoverride forreproject().transformdrop, and thenamefallback formerge().pytest xrspatial/tests/test_reproject.py -x-> 146 passed.Closes #1445