diff --git a/rio_tiler/reader.py b/rio_tiler/reader.py index 88a65232..e3dc086a 100644 --- a/rio_tiler/reader.py +++ b/rio_tiler/reader.py @@ -263,8 +263,8 @@ def read( data = data.astype("float32", casting="unsafe") # reshaped to match data - scales = numpy.array(dataset.scales).reshape(-1, 1, 1) - offsets = numpy.array(dataset.offsets).reshape(-1, 1, 1) + scales = numpy.array(dataset.scales)[numpy.array(indexes)-1].reshape((-1, 1, 1)) + offsets = numpy.array(dataset.offsets)[numpy.array(indexes)-1].reshape((-1, 1, 1)) numpy.multiply(data, scales, out=data, casting="unsafe") numpy.add(data, offsets, out=data, casting="unsafe") diff --git a/tests/test_io_rasterio.py b/tests/test_io_rasterio.py index de05d2e7..f5c053cb 100644 --- a/tests/test_io_rasterio.py +++ b/tests/test_io_rasterio.py @@ -440,6 +440,10 @@ def test_Reader_Options(): p = src.point(310000, 4100000, coord_crs=src.dataset.crs) numpy.testing.assert_allclose(p.data, [1000.892, 2008.917], atol=1e-03) + # applies correctly when passing indexes=[...] + p = src.point(310000, 4100000, coord_crs=src.dataset.crs, indexes=[2]) + numpy.testing.assert_allclose(p.data, [2008.917], atol=1e-03) + # passing unscale in method should overwrite the defaults p = src.point(310000, 4100000, coord_crs=src.dataset.crs, unscale=False) numpy.testing.assert_equal(p.data, [8917, 8917])