Skip to content

Commit

Permalink
Fix pr709 (#710)
Browse files Browse the repository at this point in the history
* Per-band unscaling works with indexes

* lint and update changelog

---------

Co-authored-by: Justin Deal <[email protected]>
  • Loading branch information
vincentsarago and Justin Deal authored May 17, 2024
1 parent bef4417 commit b2f678c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 6.6.1 (2024-05-17)

* fix/support `scale/offset` indexes selection (author @jddeal, https://github.com/cogeotiff/rio-tiler/pull/709)

# 6.6.0 (2024-05-16)

* fix type hint for `ImageData.band_names` (author @n8sty, https://github.com/cogeotiff/rio-tiler/pull/704)
Expand Down
8 changes: 6 additions & 2 deletions rio_tiler/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,12 @@ 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")
Expand Down
4 changes: 4 additions & 0 deletions tests/test_io_rasterio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit b2f678c

Please sign in to comment.