diff --git a/docs/history.rst b/docs/history.rst index 38747916..385b00f9 100644 --- a/docs/history.rst +++ b/docs/history.rst @@ -3,6 +3,9 @@ History Latest ------ +- BUG: Use ``@`` instead of ``*`` for ``Affine`` multiplication to avoid + affine 3.0.1 ``PendingDeprecationWarning`` (issue #937) +- DEP: Add explicit ``affine>=3.0`` dependency (issue #937) 0.23.0 ------ diff --git a/pyproject.toml b/pyproject.toml index 64758495..f12dc256 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ classifiers = [ ] requires-python = ">=3.12" dependencies = [ + "affine>=3.0", "packaging", "rasterio>=1.4.3", # https://github.com/pydata/xarray/issues/11000 diff --git a/rioxarray/_spatial_utils.py b/rioxarray/_spatial_utils.py index c651f012..0557e2b6 100644 --- a/rioxarray/_spatial_utils.py +++ b/rioxarray/_spatial_utils.py @@ -114,16 +114,16 @@ def affine_to_coords( dict: x and y coordinate arrays. """ - transform = affine * affine.translation(0.5, 0.5) + transform = affine @ affine.translation(0.5, 0.5) if affine.is_rectilinear and not _affine_has_rotation(affine): - x_coords, _ = transform * (numpy.arange(width), numpy.zeros(width)) - _, y_coords = transform * (numpy.zeros(height), numpy.arange(height)) + x_coords, _ = transform @ (numpy.arange(width), numpy.zeros(width)) + _, y_coords = transform @ (numpy.zeros(height), numpy.arange(height)) else: - x_coords, y_coords = transform * numpy.meshgrid( + x_coords, y_coords = transform @ numpy.meshgrid( numpy.arange(width), numpy.arange(height), ) - return {y_dim: y_coords, x_dim: x_coords} + return {y_dim: numpy.asarray(y_coords), x_dim: numpy.asarray(x_coords)} def _generate_spatial_coords( diff --git a/rioxarray/rioxarray.py b/rioxarray/rioxarray.py index f3509a43..9145d945 100644 --- a/rioxarray/rioxarray.py +++ b/rioxarray/rioxarray.py @@ -439,7 +439,7 @@ def transform(self, recalc: bool = False) -> Affine: src_resolution_x, src_resolution_y = self.resolution(recalc=recalc) except (DimensionMissingCoordinateError, DimensionError): return Affine.identity() if transform is None else transform - return Affine.translation(src_left, src_top) * Affine.scale( + return Affine.translation(src_left, src_top) @ Affine.scale( src_resolution_x, src_resolution_y ) diff --git a/test/integration/test_integration__io.py b/test/integration/test_integration__io.py index 60fe9a44..33abab1e 100644 --- a/test/integration/test_integration__io.py +++ b/test/integration/test_integration__io.py @@ -1612,3 +1612,32 @@ def test_reading_writing_rpcs(tmp_path): assert ( dst.rpcs is not None ), "Existing RPCs in dst raster (through rpc attribute)" + + +@pytest.mark.parametrize( + "transform", + [Affine(1, 0, 0, 0, -1, 4), Affine(1, 0.5, 0, 0.5, -1, 4)], + ids=["rectilinear", "rotated"], +) +def test_open_rasterio__no_affine_mul_warning(transform): + # https://github.com/corteva/rioxarray/issues/937 + with rasterio.MemoryFile() as memfile: + with memfile.open( + driver="GTiff", + height=4, + width=4, + count=1, + dtype="uint8", + crs="EPSG:4326", + transform=transform, + ) as dataset: + dataset.write(numpy.zeros((1, 4, 4), dtype="uint8")) + with warnings.catch_warnings(): + warnings.filterwarnings( + "error", + message="Use `@` matmul", + category=PendingDeprecationWarning, + ) + with memfile.open() as dataset: + rds = rioxarray.open_rasterio(dataset) + rds.rio.transform(recalc=True)