From ba8551010336d8bd3b75e16add22327471956e61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dion=20H=C3=A4fner?= Date: Thu, 14 Dec 2023 15:30:27 +0100 Subject: [PATCH] avoid warning when converting images with nans --- terracotta/image.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/terracotta/image.py b/terracotta/image.py index 229f2c2a..ca62032c 100755 --- a/terracotta/image.py +++ b/terracotta/image.py @@ -156,6 +156,8 @@ def to_uint8(data: Array, lower_bound: Number, upper_bound: Number) -> Array: """Re-scale an array to [1, 255] and cast to uint8 (0 is used for transparency)""" rescaled = contrast_stretch(data, (lower_bound, upper_bound), (1, 255), clip=True) rescaled = np.rint(rescaled) + # explicitly set NaNs to 0 to avoid warnings + rescaled[~np.isfinite(rescaled)] = 0 return rescaled.astype(np.uint8)