Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Make rio.shape order same as rasterio dataset shape (height, width) #121

Merged
merged 2 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)