Skip to content

Preserve non-spatial coords through reproject() and merge()#1455

Merged
brendancol merged 2 commits intomainfrom
preserve-non-spatial-coords-reproject-merge
May 4, 2026
Merged

Preserve non-spatial coords through reproject() and merge()#1455
brendancol merged 2 commits intomainfrom
preserve-non-spatial-coords-reproject-merge

Conversation

@brendancol
Copy link
Copy Markdown
Contributor

Closes #1454.

Summary

  • reproject() and merge() rebuilt the output DataArray with only the y/x (and band) coords. Scalar coords like a single time timestamp, non-dimension coords like rioxarray's spatial_ref, and unrelated extra-dim coords were silently dropped.
  • Both functions now copy any coord whose dims do not include the rebuilt spatial dims. Coords aligned to ydim or xdim are still dropped because their values are stale after the grid is rebuilt.
  • Documents in the Returns section of both docstrings that the output y coordinate is always emitted in descending order (top-down, north-up) regardless of the input direction. This matches the standard raster convention.

Test plan

  • pytest xrspatial/tests/test_reproject.py -x (155 passed)
  • New TestCoordsPreservation class covers:
    • scalar time coord round-trip through reproject()
    • non-dim string coord round-trip
    • stale y-aligned coord is dropped
    • band coord round-trip on 3D input
    • first-raster scalar coord round-trip through merge()
    • y-descending output for ascending input on numpy and dask backends

Closes #1454.

reproject() and merge() rebuilt the output DataArray with only the y/x
coords (and band coord on the 3D path). Other coords on the input were
silently dropped: scalar coords like a single 'time' timestamp,
non-dimension coords such as rioxarray's 'spatial_ref', and any extra
dim coord unrelated to the spatial grid.

Both functions now copy any coord whose dims do not include the
rebuilt spatial dims. Coords aligned to ydim or xdim are still
dropped because their values are stale after the grid is rebuilt.

Also document in the reproject() and merge() Returns section that
the output y coordinate is always emitted in descending order
(top-down, north-up) regardless of the input direction.

Adds TestCoordsPreservation covering scalar time coord, non-dim
string coord, stale y-aligned coord drop, band coord round-trip,
merge scalar coord, and y-descending output for numpy and dask.
@github-actions github-actions Bot added the performance PR touches performance-sensitive code label May 4, 2026
@brendancol
Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

…coords-reproject-merge

# Conflicts:
#	xrspatial/reproject/__init__.py

Co-authored-by: brendancol <433221+brendancol@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

@copilot resolve the merge conflicts in this pull request

Resolved in c1f9dca. The conflict in xrspatial/reproject/__init__.py combined both the non-spatial coords preservation from this branch and the attrs preservation logic from main. All 165 tests pass.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.proj.org
    • Triggering command: /home/REDACTED/.local/bin/pytest pytest xrspatial/tests/test_reproject.py -x -q (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@brendancol brendancol merged commit 29b6241 into main May 4, 2026
1 check was pending
@brendancol brendancol deleted the preserve-non-spatial-coords-reproject-merge branch May 5, 2026 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance PR touches performance-sensitive code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reproject() and merge() drop non-spatial coords; y-axis convention undocumented

2 participants