From 2137081dd57134ddf8b379daf174e26535af4e54 Mon Sep 17 00:00:00 2001 From: Panu Lahtinen Date: Fri, 24 Nov 2023 10:12:58 +0200 Subject: [PATCH] Add a test for stretching uint8 data --- trollimage/tests/test_image.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/trollimage/tests/test_image.py b/trollimage/tests/test_image.py index 3421efe..f211e4d 100644 --- a/trollimage/tests/test_image.py +++ b/trollimage/tests/test_image.py @@ -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."""