Skip to content

reproject_match renames dims #751

Open

Description

@mwtoews

Code Sample

from pathlib import Path
import xarray as xr

REPO_DIR = Path("/data/mtoews/src/rioxarray")
TEST_INPUT_DATA_DIR = REPO_DIR / "test" / "test_data" / "input"
ds = xr.open_dataset(TEST_INPUT_DATA_DIR / "nonstandard_dim.nc")
da = ds.analysed_sst
da2 = da.rio.reproject_match(da)

print(da.dims)
# ('time', 'lat', 'lon')

print(da2.dims)
# ('time', 'y', 'x')

# workaround
if da.dims != da2.dims:
    da2 = da2.rename(dict(zip(da2.dims, da.dims)))
print(da2.dims)
# ('time', 'lat', 'lon')

Problem description

It is expected that reproject_match with a DataArray would keep the original x_dim and y_dim names, but they appear to always go to y and x.

Environment Information

rioxarray (0.15.0) deps:
  rasterio: 1.3.6
    xarray: 2023.11.0
      GDAL: 3.6.2
      GEOS: 3.11.1
      PROJ: 9.1.1
 PROJ DATA: C:\Users\mtoews\AppData\Local\miniforge3\envs\pyforge\Library\share\proj
 GDAL DATA: C:\Users\mtoews\AppData\Local\miniforge3\envs\pyforge\Library\share\gdal

Other python deps:
     scipy: 1.11.3
    pyproj: 3.5.0

System:
    python: 3.10.13 | packaged by conda-forge | (main, Oct 26 2023, 18:01:37) [MSC v.1935 64 bit (AMD64)]
executable: C:\Users\mtoews\AppData\Local\miniforge3\envs\pyforge\python.exe
   machine: Windows-10-10.0.19045-SP0

But also on linux with current master branch.

Installation method

  • conda, but also pip

Activity

  1. mwtoews commented on Feb 27, 2024

    @mwtoews
    ContributorAuthor

    I should note that there are relevant cases where the dimensions should be renamed from (e.g.) lat to y, for instance when projecting from a geographic CRS with distance units in degrees to a projected coordinate system like a UTM zone with distance units in meters. Not sure if keeping/renaming dims should be user-controlled or not, but I've noted a workaround above. So these new dim names and units are expected:

    da3 = da.rio.reproject("EPSG:2193")
    print(da3.x.attrs)
    # {'axis': 'X', 'long_name': 'x coordinate of projection', 'standard_name': 'projection_x_coordinate', 'units': 'metre'}
    print(da.lon.attrs)
    # {'long_name': 'longitude', 'standard_name': 'longitude', 'axis': 'X', 'units': 'degrees_east', 'valid_min': -180.0, 'valid_max': 180.0, 'comment': 'geolocations inherited from the input data without correction'}

    it's just this dimension name that's inconsistent:

    print(da2.x.attrs)
    # {'axis': 'X', 'long_name': 'longitude', 'standard_name': 'longitude', 'units': 'degrees_east'}
  2. snowman2 commented on Feb 27, 2024

    @snowman2
    Member

    This was by design to keep the logic simple. As you demonstrated, there are cases where you would transform from geographic to projected coordinate systems or the other way around. Attempting to preserve coordinate names in some instances and not others would make the behavior somewhat unpredictable. With the current design, you always know what your dimensions will be in the output.

  3. removed
    bugSomething isn't working
    on Jul 8, 2024
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

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions