Fix metadata propagation in reproject (#1572, #1573)#1575
Open
brendancol wants to merge 1 commit intomainfrom
Open
Fix metadata propagation in reproject (#1572, #1573)#1575brendancol wants to merge 1 commit intomainfrom
brendancol wants to merge 1 commit intomainfrom
Conversation
geoid_height_raster previously dropped all input attrs and used
raster.dims[-2:] as the output dims. The latter produced garbage for
3D (y, x, band) rasters: the output came out shaped (4, 3) with dims
('x', 'band') instead of (4, 4) with dims ('y', 'x'). Use
_find_spatial_dims so the y/x axes are resolved regardless of layout,
and carry input attrs forward so crs / res / transform survive.
reproject and merge previously ignored attrs['nodatavals'] (rasterio's
plural convention) unless rioxarray happened to be installed and its
accessor picked it up. Without rioxarray, a raster carrying only
nodatavals was treated as if nodata was NaN, so the sentinel pixels
silently survived resampling. _detect_nodata now consults nodatavals
after _FillValue / nodata / missing_value, and the output keeps the
nodatavals tuple consistent with the resolved nodata.
Tests cover both bugs across 2D and 3D inputs and verify attrs
survive on numpy, dask, cupy, and dask+cupy backends.
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
geoid_height_rasternow carries input attrs forward and resolves the y/x dims via_find_spatial_dims, so 3D (y, x, band) rasters reduce to a correct 2D output (closes geoid_height_raster drops input attrs and mishandles 3D rasters #1572)._detect_nodataconsultsattrs['nodatavals'](rasterio plural convention) after the singular keys, andreproject/mergerefresh thenodatavalstuple to match the resolved nodata so the two attrs no longer disagree (closes reproject ignores attrs['nodatavals'] when rioxarray is not installed #1573).Before this change, a
(y, x, band)-shaped raster passed togeoid_height_rasterproduced a 2D output labelled('x', 'band')with the wrong shape and the wrong coords (becauseraster.dims[-2:]for a(y, x, band)input is('x', 'band')). Input attrs likecrs,res,transform,_FillValue,long_namewere also dropped.Without rioxarray installed, a raster carrying only
attrs['nodatavals'] = (-9999,)would be treated by reproject as if nodata was NaN, so the -9999 pixels survived resampling unmasked while the output still carried a stalenodatavals=(-9999,)attr alongside a freshnodata=NaN.xrspatial.resamplealready handlesnodatavals, so the inconsistency was local to reproject.Test plan
pytest xrspatial/tests/test_reproject.py-- 200 passing including 9 new metadata testsattrs['nodata']andattrs['nodatavals']agree on output for all four paths(y, x, band)input togeoid_height_rasterreturns a 2D(y, x)array with inputcrspreservedpytest xrspatial/tests/test_resample.py-- 169 passing (no regressions from the shared_detect_nodatachange)Found during deep-sweep / metadata pass on the reproject module.