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

Copied DataArray loses its set CRS #532

Closed
apiwat-chantawibul opened this issue Jun 2, 2022 · 4 comments
Closed

Copied DataArray loses its set CRS #532

apiwat-chantawibul opened this issue Jun 2, 2022 · 4 comments
Labels
question Further information is requested

Comments

@apiwat-chantawibul
Copy link
Contributor

Code Sample

import xarray as xr
import rioxarray as rxr


da = xr.DataArray(
    [[1,2],[3,4]],
    dims = ('y','x'),
    coords = dict(
        y = [0,1],
        x = [0,1],
    ),
)
da.rio.set_crs('EPSG:4326')
print('CRS before copy:', da.rio.crs)
da_ = da.copy()
print('CRS after copy:', da_.rio.crs)

Problem description

Currently it outputs:

CRS before copy: EPSG:4326
CRS after copy: None

Meaning CRS information is lost by .copy()

Expected Output

CRS before copy: EPSG:4326
CRS after copy: EPSG:4326

Environment Information

Tested on

rioxarray 0.10.3
python 3.10.4
@apiwat-chantawibul apiwat-chantawibul added the bug Something isn't working label Jun 2, 2022
@apiwat-chantawibul
Copy link
Contributor Author

Viewing in another way, maybe the problem has to do with how .set_crs() sets an internal variable instead of something like .attrs which would have been copied automatically.

@apiwat-chantawibul
Copy link
Contributor Author

Okay, I just found rio.write_crs() that explains a lot. So rio.set_crs() has to be followed by rio.write_crs() to make the CRS change portable. And then there is also rio.write_coordinate_system() for some reason. All this seems like a great trap for new users to me. Right now I'm just keeping this issue open in case anyone want to discuss why it has to be this way and how to possibly improve it.

@snowman2
Copy link
Member

snowman2 commented Jun 2, 2022

I recommend reading the Getting Started: Introductory Information references for rioxarray. The Coordinare Reference System Management section is relevant for this issue.

@snowman2 snowman2 added question Further information is requested and removed bug Something isn't working labels Jun 2, 2022
@snowman2
Copy link
Member

snowman2 commented Jun 2, 2022

Related #356

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

No branches or pull requests

2 participants