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

Per-band unscaling works with indexes #709

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rio_tiler/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
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
Loading