Skip to content

Commit

Permalink
Add a test for stretching uint8 data
Browse files Browse the repository at this point in the history
  • Loading branch information
pnuu committed Nov 24, 2023
1 parent dd16cdf commit 2137081
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions trollimage/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,18 @@ def test_linear_stretch_does_not_affect_alpha(self, dtype):

np.testing.assert_allclose(img.data.values, res, atol=1.e-6)

def test_linear_stretch_uint8(self):
"""Test linear stretch with uint8 data."""
arr = np.arange(75, dtype=np.uint8).reshape(5, 5, 3)
arr[4, 4, :] = 255
data = xr.DataArray(arr.copy(), dims=['y', 'x', 'bands'],
coords={'bands': ['R', 'G', 'B']})
img = xrimage.XRImage(data)
img.stretch_linear()

assert img.data.values.min() == pytest.approx(0.0)
assert img.data.values.max() == pytest.approx(1.0960743801652901)

@pytest.mark.parametrize("dtype", (np.float32, np.float64, float))
def test_histogram_stretch(self, dtype):
"""Test histogram stretching."""
Expand Down

0 comments on commit 2137081

Please sign in to comment.