Skip to content
Merged
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
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 5 additions & 1 deletion satpy/enhancements/colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions satpy/tests/enhancement_tests/test_colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading