Skip to content

CRS set on Dataset does not persist for DataArrays obtained by selecting data variable  #356

Closed

Description

@vidurmithal

Code Sample

da1 = xr.DataArray(np.arange(10*10).reshape(10, 10), [("x", np.linspace(70,80,10)), ("y", np.linspace(20,30,10))], name='var_1')
da2 = xr.DataArray(np.arange(10*10).reshape(10, 10), [("x", np.linspace(70,80,10)), ("y", np.linspace(20,30,10))], name='var_2')

ds = xr.merge([da1,da2])

ds = ds.rio.set_crs('epsg:4326')

print('Dataset CRS: {}'.format(ds.rio.crs))
print('DataArray 1 CRS: {}'.format(ds['var_1'].rio.crs))
print('DataArray 2 CRS: {}'.format(ds['var_2'].rio.crs))

Problem description

The CRS set on a Dataset using .rio.set_crs() does not persist to a DataArray obtained by selecting individual variables from the Dataset. Printing the CRS of the Dataset gives the previously set CRS, but printing the CRS of the DataArray gives None.

Expected Output

The CRS set on a Dataset should also apply to DataArrays of individual variables. Printing DataArray.rio.crs should give the set CRS, EPSG:4326 in this case.

Environment Information

rioxarray (0.1.1) deps:
  rasterio: 1.1.0
    xarray: 0.16.2
      GDAL: 3.0.2

Other python deps:
     scipy: 1.4.1
    pyproj: 2.6.0

System:
   python: 3.7.7 (default, Mar 23 2020, 22:36:06)  [GCC 7.3.0]
   machine: Linux-5.4.89+-x86_64-with-debian-bullseye-sid

Installation method

PyPi

Activity

  1. snowman2 commented on Jun 14, 2021

    @snowman2
    Member

    We recommend using rio.write_crs as it persists better.

  2. snowman2 commented on Jun 14, 2021

    @snowman2
    Member

    Related #252

  3. snowman2 commented on Jun 2, 2022

    @snowman2
    Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions