Skip to content

Commit

Permalink
BUG:reproject_match: Remove setting spatial dims on output resampled …
Browse files Browse the repository at this point in the history
…dataset (#769)
  • Loading branch information
snowman2 authored Apr 16, 2024
1 parent 9b9401f commit 6ec9bbc
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ History

Latest
------
- BUG:reproject_match: Remove setting spatial dims on output resampled dataset (issue #768)

0.15.3
------
Expand Down
4 changes: 1 addition & 3 deletions rioxarray/raster_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,7 @@ def reproject_match(
):
raise
resampled_dataset[var] = self._obj[var].copy()
return resampled_dataset.rio.set_spatial_dims(
x_dim=self.x_dim, y_dim=self.y_dim, inplace=True
)
return resampled_dataset

def pad_box(
self,
Expand Down
22 changes: 22 additions & 0 deletions test/integration/test_integration_rioxarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,28 @@ def test_reproject_match__non_geospatial(dummy_dataset_non_geospatial):
assert "non_geo_stuff" in ds_reproject.data_vars


def test_reproject_match__geographic_dataset():
lat = [0.1, 0.15, 0.2]
lon = [0.1, 0.15, 0.2]
data = numpy.arange(1, 10).reshape(3, 3)
ds = xarray.Dataset(
data_vars={
"foo": (["lat", "lon"], data),
"bar": (["lat", "lon"], data),
},
coords={"lat": lat, "lon": lon},
)

ds = (
ds.rio.write_crs(4326, inplace=True)
.rio.set_spatial_dims(x_dim="lon", y_dim="lat", inplace=True)
.rio.write_coordinate_system(inplace=True)
)
ds_match = ds.rio.reproject_match(ds)
assert_almost_equal(ds_match.x.values, ds.lon.values)
assert_almost_equal(ds_match.y.values, ds.lat.values)


def test_interpolate_na__non_geospatial(dummy_dataset_non_geospatial):
pytest.importorskip("scipy")
ds = dummy_dataset_non_geospatial
Expand Down

0 comments on commit 6ec9bbc

Please sign in to comment.