Emit fresh grid metadata and propagate _FillValue through reproject() and merge()#1462
Merged
brendancol merged 1 commit intomainfrom May 4, 2026
Merged
Conversation
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 was referenced May 4, 2026
This was referenced May 5, 2026
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 #1458.
Follow-up to #1446 covering three small metadata items in
xrspatial/reproject/__init__.py.Changes
Fresh
transformandreson output. Bothreproject()andmerge()previously poppedtransformandresbecause the input values described the old grid. The output grid is fully known from_compute_output_grid(returnsres_x,res_y, andbounds), so we now emit:attrs['res'] = (res_x, res_y)attrs['transform'] = (res_x, 0.0, left, 0.0, -res_y, top)— rasterio 6-tuple convention.The geotiff reader in this repo does not emit
transformorresintoattrsitself, so there was no in-repo convention to match. The rasterio form is the standard one external code expects.merge()honours_find_spatial_dims. The helper at line 63 already exists andreproject()uses it.merge()was hardcoded todims[-2]anddims[-1]in two places. Both now call_find_spatial_dims, so inputs withlat/londims (or other non-y/x layouts) work correctly._FillValuepropagation._detect_nodatareads_FillValueas a fallback nodata key, but neither output set_FillValue. When the input has_FillValue, the output now gets the resolved nodata in bothnodataand_FillValue. When the input has no_FillValue, the output stays clean.Tests
Added eight tests in
TestMetadataPreservation:reproject()andmerge()transformandresemitted even when the input had neithermerge()succeeds withlat/londims and preserves them on output_FillValueround-trips through both functions when the input sets it, and stays absent when the input does notTwo existing tests that asserted
transform/reswere dropped have been updated to assert that the new (fresh) values differ from the stale input values.Test plan
pytest xrspatial/tests/test_reproject.py -x(188 passed)