diff --git a/AUTHORS.md b/AUTHORS.md index 577927e3d2..a8da9ec5f5 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -115,3 +115,4 @@ The following people have made contributions to this project: - [Albert Brotzer](https://github.com/albertbrotzer) - [Alexandra Melzer](https://github.com/armelzer) - [Francesc Lucas Carbó (cesclc)](https://github.com/cesclc) +- [Göte Kleringer (Grukank)](https://github.com/Grukank) diff --git a/satpy/enhancements/colormap.py b/satpy/enhancements/colormap.py index 84f60b58de..d41eda3579 100644 --- a/satpy/enhancements/colormap.py +++ b/satpy/enhancements/colormap.py @@ -41,12 +41,16 @@ def lookup(img, **kwargs): @on_separate_bands @using_map_blocks def _lookup_table(band_data, luts=None, index=-1): + # Save positions of NaNs + nans = np.isfinite(band_data) # NaN/null values will become 0 lut = luts[:, index] if len(luts.shape) == 2 else luts band_data = band_data.clip(0, lut.size - 1) # Convert to uint8, with NaN/null values changed into 0 band_data = np.nan_to_num(band_data).astype(np.uint8) - return lut[band_data] + # Lookup data, but with replaced NaNs from saved positions + res = np.where(nans, lut[band_data], np.nan) + return res def colorize(img, **kwargs): # noqa: D417 diff --git a/satpy/tests/enhancement_tests/test_colormap.py b/satpy/tests/enhancement_tests/test_colormap.py index bff59801a3..e3f99eacb1 100644 --- a/satpy/tests/enhancement_tests/test_colormap.py +++ b/satpy/tests/enhancement_tests/test_colormap.py @@ -42,16 +42,16 @@ def test_lookup(self): """Test the lookup enhancement function.""" from satpy.enhancements.colormap import lookup expected = np.array([[ - [0., 0., 0., 0.333333, 0.705882], + [np.nan, 0., 0., 0.333333, 0.705882], [1., 1., 1., 1., 1.]]]) lut = np.arange(256.) run_and_check_enhancement(lookup, self.ch1, expected, luts=lut) - expected = np.array([[[0., 0., 0., 0.333333, 0.705882], + expected = np.array([[[np.nan, 0., 0., 0.333333, 0.705882], [1., 1., 1., 1., 1.]], - [[0., 0., 0., 0.333333, 0.705882], + [[np.nan, 0., 0., 0.333333, 0.705882], [1., 1., 1., 1., 1.]], - [[0., 0., 0., 0.333333, 0.705882], + [[np.nan, 0., 0., 0.333333, 0.705882], [1., 1., 1., 1., 1.]]]) lut = np.arange(256.) lut = np.vstack((lut, lut, lut)).T