Description
.xrs.preview() downsamples a raster and rebuilds the x/y coordinates for the smaller grid, but copies the input's attrs unchanged. So attrs['res'] keeps describing the original full-resolution grid instead of the downsampled one. Any downstream code that reads res for pixel-size math or georeferencing gets the wrong value.
To Reproduce
study_area.xrs.generate_terrain().xrs.preview()
<xarray.DataArray 'preview' (y: 988, x: 1000)>
Coordinates:
* y (y) float64 8kB 3.37e+06 3.369e+06 ... 3.329e+06 3.329e+06
* x (x) float64 8kB 6.005e+05 6.005e+05 ... 6.414e+05 6.415e+05
Attributes:
res: (0.25, 0.25)
crs: 32614
...
The x coordinates span about 41000 map units across 1000 pixels, so the real resolution is roughly 41 units/pixel. But res still reads (0.25, 0.25) from the source grid.
Expected behavior
res should match the grid that comes back. Recompute it from the output coordinate spacing so it lines up with the returned array's x/y coordinates.
Notes
The stale copy is in xrspatial/preview.py. Every output path rebuilds coords with _interpolate_coords but passes attrs=agg.attrs, and the main preview() re-assigns result.attrs = agg.attrs after the second-pass refinement. The fix recomputes res from the final coordinates. It affects every method (mean, median, max, min, nearest, bilinear) and all backends.
Description
.xrs.preview()downsamples a raster and rebuilds thex/ycoordinates for the smaller grid, but copies the input'sattrsunchanged. Soattrs['res']keeps describing the original full-resolution grid instead of the downsampled one. Any downstream code that readsresfor pixel-size math or georeferencing gets the wrong value.To Reproduce
The
xcoordinates span about 41000 map units across 1000 pixels, so the real resolution is roughly 41 units/pixel. Butresstill reads(0.25, 0.25)from the source grid.Expected behavior
resshould match the grid that comes back. Recompute it from the output coordinate spacing so it lines up with the returned array'sx/ycoordinates.Notes
The stale copy is in
xrspatial/preview.py. Every output path rebuilds coords with_interpolate_coordsbut passesattrs=agg.attrs, and the mainpreview()re-assignsresult.attrs = agg.attrsafter the second-pass refinement. The fix recomputesresfrom the final coordinates. It affects every method (mean, median, max, min, nearest, bilinear) and all backends.