Skip to content

Commit

Permalink
BUG: Make rio.shape order same as rasterio dataset shape (height, wid…
Browse files Browse the repository at this point in the history
…th) (#121)
  • Loading branch information
snowman2 committed Jun 11, 2020
1 parent 4ce5472 commit 31ee00f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ History

- ENH: Added optional `shape` argument to `rio.reproject` (pull #116)
- Fix ``RasterioDeprecationWarning`` (pull #117)
- BUG: Make rio.shape order same as rasterio dataset shape (height, width) (pull #121)

0.0.26
------
Expand Down
8 changes: 4 additions & 4 deletions rioxarray/rioxarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _make_dst_affine(
):
"""Determine the affine of the new projected `xarray.DataArray`"""
src_bounds = src_data_array.rio.bounds()
src_width, src_height = src_data_array.rio.shape
src_height, src_width = src_data_array.rio.shape
dst_height, dst_width = dst_shape if dst_shape is not None else (None, None)
resolution_or_width_height = {
k: v
Expand Down Expand Up @@ -570,8 +570,8 @@ def height(self):

@property
def shape(self):
"""tuple: Returns the shape (width, height)"""
return (self.width, self.height)
"""tuple(int, int): Returns the shape (height, width)"""
return (self.height, self.width)

def isel_window(self, window):
"""
Expand Down Expand Up @@ -1000,7 +1000,7 @@ def reproject_match(self, match_data_array, resampling=Resampling.nearest):
"""
dst_crs = crs_to_wkt(match_data_array.rio.crs)
dst_affine = match_data_array.rio.transform(recalc=True)
dst_width, dst_height = match_data_array.rio.shape
dst_height, dst_width = match_data_array.rio.shape

return self.reproject(
dst_crs,
Expand Down
5 changes: 5 additions & 0 deletions test/integration/test_integration_rioxarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1616,3 +1616,8 @@ def test_missing_transform_resolution():
xds.attrs.pop("transform")
with pytest.raises(DimensionMissingCoordinateError):
xds.rio.resolution()


def test_shape_order():
rds = rioxarray.open_rasterio(os.path.join(TEST_INPUT_DATA_DIR, "tmmx_20190121.nc"))
assert rds.air_temperature.rio.shape == (585, 1386)

0 comments on commit 31ee00f

Please sign in to comment.