Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xarray concat does not take into account different CRS data #568

Open
gcaria opened this issue Aug 30, 2022 · 3 comments
Open

Xarray concat does not take into account different CRS data #568

gcaria opened this issue Aug 30, 2022 · 3 comments
Labels
enhancement New feature or request upstream Issue is related to a dependency (upstream package).

Comments

@gcaria
Copy link

gcaria commented Aug 30, 2022

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?

@gcaria gcaria added the bug Something isn't working label Aug 30, 2022
@snowman2 snowman2 removed the bug Something isn't working label Aug 30, 2022
@snowman2
Copy link
Member

snowman2 commented Aug 30, 2022

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:

@snowman2 snowman2 added the enhancement New feature or request label Aug 30, 2022
@snowman2
Copy link
Member

For now, I recommend using rio.reproject_match

@snowman2 snowman2 added the upstream Issue is related to a dependency (upstream package). label Aug 30, 2022
@snowman2
Copy link
Member

snowman2 commented Nov 7, 2022

Related #588

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request upstream Issue is related to a dependency (upstream package).
Projects
None yet
Development

No branches or pull requests

2 participants