diff --git a/rio_tiler/reader.py b/rio_tiler/reader.py index 006e04b5..f87d7974 100644 --- a/rio_tiler/reader.py +++ b/rio_tiler/reader.py @@ -261,8 +261,13 @@ def read( if unscale: data = data.astype("float32", casting="unsafe") - numpy.multiply(data, dataset.scales[0], out=data, casting="unsafe") - numpy.add(data, dataset.offsets[0], out=data, casting="unsafe") + + # reshaped to match data + scales = numpy.array(dataset.scales).reshape((-1,) + (1,) * (len(data.shape[1:]))) + offsets = numpy.array(dataset.offsets).reshape((-1,) + (1,) * (len(data.shape[1:]))) + + numpy.multiply(data, scales, out=data, casting="unsafe") + numpy.add(data, offsets, out=data, casting="unsafe") if post_process: data = post_process(data) diff --git a/tests/fixtures/cog_scale.tif b/tests/fixtures/cog_scale.tif index f0408030..b59b9dc3 100644 Binary files a/tests/fixtures/cog_scale.tif and b/tests/fixtures/cog_scale.tif differ diff --git a/tests/test_io_rasterio.py b/tests/test_io_rasterio.py index 017bc12c..eeb610a6 100644 --- a/tests/test_io_rasterio.py +++ b/tests/test_io_rasterio.py @@ -439,11 +439,11 @@ def test_Reader_Options(): with Reader(COG_SCALE, options={"unscale": True}) as src: p = src.point(310000, 4100000, coord_crs=src.dataset.crs) - assert round(float(p.data[0]), 3) == 1000.892 + numpy.testing.assert_allclose(p.data, [1000.892, 1001], atol=1e-03) # passing unscale in method should overwrite the defaults p = src.point(310000, 4100000, coord_crs=src.dataset.crs, unscale=False) - assert p.data[0] == 8917 + numpy.testing.assert_equal(p.data, [8917, 1001]) cutline = "POLYGON ((13 1685, 1010 6, 2650 967, 1630 2655, 13 1685))" with Reader(COGEO, options={"vrt_options": {"cutline": cutline}}) as src: diff --git a/tests/test_reader.py b/tests/test_reader.py index 6af3e8fa..7ac172e0 100644 --- a/tests/test_reader.py +++ b/tests/test_reader.py @@ -429,8 +429,8 @@ def test_point(): assert pt.band_names == ["b1"] pt = reader.point(src_dst, [310000, 4100000], coord_crs=src_dst.crs) - assert pt.data == numpy.array([8917]) - assert pt.band_names == ["b1"] + numpy.testing.assert_equal(pt.data, [8917, 1001]) + assert pt.band_names == ["b1", "b2"] with pytest.raises(PointOutsideBounds): reader.point(src_dst, [810000, 4100000], coord_crs=src_dst.crs)