Skip to content

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

@brendancol

Description

@brendancol

M-6: non-spatial coords dropped by reproject() and merge()

In xrspatial/reproject/__init__.py, the output DataArray is built with only {ydim: y_coords, xdim: x_coords} (plus the band coord on the 3D path). Any other coord on the input is dropped:

  • scalar coords (e.g. a single time timestamp)
  • non-dimension coords (e.g. spatial_ref from rioxarray)
  • any extra dim coord that does not apply to the rebuilt grid

This affects both reproject() (around the result_data.ndim == 3 / 2D branches) and merge() (the final xr.DataArray construction).

Fix: after assigning y/x (and band) coords, copy any remaining coord whose dims do not include the spatial ydim or xdim. Coords aligned to ydim/xdim should still be dropped because their values are stale after the grid is rebuilt.

M-8: y-axis output direction is undocumented

_make_output_coords in xrspatial/reproject/_grid.py always emits y from top - res/2 down to bottom + res/2, so a y-ascending input produces a y-descending output. This is the standard raster convention (top-down, north-up) and is the right behaviour, but it is not stated in the reproject() or merge() docstrings, and the existing test_south_up_matches_north_up only checks .values equality.

Fix: add a sentence to the Returns section of both docstrings.

Plan

  • Update the 2D and 3D branches of reproject() to carry forward non-spatial coords.
  • Update merge() to do the same from the first input raster.
  • Document the y-descending output convention in both docstrings.
  • Add TestCoordsPreservation covering scalar time, non-dim string coord, stale y-aligned coord drop, band coord round-trip, merge scalar coord, and y-descending output for numpy and dask backends.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions