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

Checking non-dimensional coordinates for equality #2996

Open
djhoese opened this issue May 29, 2019 · 3 comments
Open

Checking non-dimensional coordinates for equality #2996

djhoese opened this issue May 29, 2019 · 3 comments

Comments

@djhoese
Copy link
Contributor

djhoese commented May 29, 2019

Code Sample, a copy-pastable example if possible

I'm working on a proof-of-concept for the geoxarray project where I'd like to store coordinate reference system (CRS) information in the coordinates of a DataArray or Dataset object. I'd like to avoid subclassing objects and instead depend completely on xarray accessors to implement any utilities I need.

I'm having trouble deciding what the best place is for this CRS information so that it benefits the user; .coords made the most sense. My hope was that adding two DataArrays together with two different crs coordinates would cause an error, but found out that since crs is not a dimension it doesn't get treated the same way; even when changing join method to 'exact'.

from pyproj import CRS
import xarray as xr
import dask.array as da

crs1 = CRS.from_string('+proj=lcc +datum=WGS84 +lon_0=-95 +lat_0=25 +lat_1=25')
crs2 = CRS.from_string('+proj=lcc +datum=WGS84 +lon_0=-95 +lat_0=35 +lat_1=35')


a = xr.DataArray(da.zeros((5, 5), chunks=2), dims=('y', 'x'), coords={'y': da.arange(1, 6, chunks=3), 'x': da.arange(2, 7, chunks=3), 'crs': crs1, 'test': 1, 'test2': 2})      

b = xr.DataArray(da.zeros((5, 5), chunks=2), dims=('y', 'x'), coords={'y': da.arange(1, 6, chunks=3), 'x': da.arange(2, 7, chunks=3), 'crs': crs2, 'test': 2, 'test2': 2})            

a + b                                                                                                                                                                              
# Results in:
# <xarray.DataArray 'zeros-e5723e7f9121b7ac546f61c19dabe786' (y: 5, x: 5)>
# dask.array<shape=(5, 5), dtype=float64, chunksize=(2, 2)>
# Coordinates:
#   * y        (y) int64 1 2 3 4 5
#   * x        (x) int64 2 3 4 5 6
#     test2    int64 2

In the above code I was hoping that because the crs coordinates are different (lat_0 and lat_1 are different and crs1 != crs2) that I could get it to raise an exception.

Any ideas for how I might be able to accomplish something like this? I'm not an expert on xarray/pandas indexes, but could this be another possible solution?

Edit: xr.merge with compat='no_conflicts' does detect this difference.

@dcherian
Copy link
Contributor

dcherian commented Aug 7, 2019

It seems like we need an arithmetic_compat option similar to arithmetic_join

@shoyer
Copy link
Member

shoyer commented Aug 8, 2019

I think the ideal solution to this would be to make CRS coordinates a virtual "index" of sorts associated with the x/y coordinates that gets checked for equality (and maybe that supports alignment).

@dcherian
Copy link
Contributor

dcherian commented Aug 8, 2019

An index attribute with compat='identical' by default?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants