Problem
Both reproject() and merge() in xrspatial/reproject/__init__.py build their output attrs from scratch instead of carrying the input attrs forward.
reproject() at lines ~672-697:
out_attrs = {
'crs': tgt_wkt,
'nodata': nd,
}
merge() at lines ~1473-1477:
attrs={
'crs': tgt_wkt,
'nodata': nd,
},
Anything attached to the input — units, long_name, description, scale_factor, add_offset, _FillValue, custom GeoTIFF tags, history, provenance — is dropped on the floor.
Impact
- Downstream code that reads
units (e.g. unit-aware plots, validators) sees nothing.
- Packed datasets relying on
scale_factor / add_offset lose the unpacking metadata. Any subsequent math is wrong.
_FillValue / nodata overrides set by users disappear.
- Provenance text (
history, description, long_name) is gone.
This is the same bug class as #1407 (sky_view_factor cellsize loss). Operations that transform a raster shouldn't strip every attr the user attached.
Fix
Merge input attrs first, then override the ones the operation legitimately changes:
out_attrs = {**raster.attrs}
out_attrs['crs'] = tgt_wkt
out_attrs['nodata'] = nd
A few input attrs become stale after reprojection and should be popped explicitly:
transform: the affine transform changed; the old one is wrong.
crs_wkt: we re-emit canonical crs, drop the duplicate.
res: refers to the old grid resolution.
For merge(), use rasters[0].attrs as the base (consistent with the default strategy='first'), and fall back name to rasters[0].name before 'merged'.
Tests
xrspatial/tests/test_reproject.py doesn't currently assert any attr survives the round-trip — only 'crs' in result.attrs. Add coverage so the next regression in this area gets caught.
Problem
Both
reproject()andmerge()inxrspatial/reproject/__init__.pybuild their outputattrsfrom scratch instead of carrying the input attrs forward.reproject()at lines ~672-697:merge()at lines ~1473-1477:Anything attached to the input —
units,long_name,description,scale_factor,add_offset,_FillValue, custom GeoTIFF tags, history, provenance — is dropped on the floor.Impact
units(e.g. unit-aware plots, validators) sees nothing.scale_factor/add_offsetlose the unpacking metadata. Any subsequent math is wrong._FillValue/nodataoverrides set by users disappear.history,description,long_name) is gone.This is the same bug class as #1407 (
sky_view_factorcellsize loss). Operations that transform a raster shouldn't strip every attr the user attached.Fix
Merge input attrs first, then override the ones the operation legitimately changes:
A few input attrs become stale after reprojection and should be popped explicitly:
transform: the affine transform changed; the old one is wrong.crs_wkt: we re-emit canonicalcrs, drop the duplicate.res: refers to the old grid resolution.For
merge(), userasters[0].attrsas the base (consistent with the defaultstrategy='first'), and fall backnametorasters[0].namebefore'merged'.Tests
xrspatial/tests/test_reproject.pydoesn't currently assert any attr survives the round-trip — only'crs' in result.attrs. Add coverage so the next regression in this area gets caught.