Xarray concat does not take into account different CRS data
import rasterio as rxr
da1 = xr.DataArray([[0,1], [1,0]], coords=dict(y=[1,0], x=[0,1]))
da1['time'] = 0
da2 = da1.copy()
da2['time'] = 1
da1 = da1.rio.write_crs(32610)
da2 = da2.rio.write_crs(32611)
xr.concat([da1, da2], dim='time').rio.crs # returns 32610
This snippet shows that when concatenating two DataArrays with different CRS, the result gets the CRS of the first DataArray.
It seems this is due to the fact that the true CRS information is given as attributes of thespatial_ref coordinate, whose numerical value is the same for both CRSs and does not actually mean anything.
Is this a feature or a bug?
xarray is unaware of the spatial information during it's operations. You have to manage it yourself in the current state.
This is something that requires more changes to xarray to have either an error or automagically work.
For more information:
- https://github.com/pydata/xarray/issues/2288#issuecomment-1205793138
- https://github.com/pydata/xarray/issues/3620
For now, I recommend using rio.reproject_match
Related #588