Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some enhancements producing dask arrays wrapped in dask arrays #2190

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 2 additions & 11 deletions satpy/enhancements/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,6 @@ def _srgb_gamma(arr):
return da.where(arr < 0.0031308, arr * 12.92, 1.055 * arr ** 0.41666 - 0.055)


def _lookup_delayed(luts, band_data):
# can't use luts.__getitem__ for some reason
return luts[band_data]


def lookup(img, **kwargs):
"""Assign values to channels based on a table."""
luts = np.array(kwargs['luts'], dtype=np.float32) / 255.0
Expand All @@ -295,11 +290,7 @@ def _lookup_table(band_data, luts=None, index=-1):
# 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).astype(np.uint8)

new_delay = dask.delayed(_lookup_delayed)(lut, band_data)
new_data = da.from_delayed(new_delay, shape=band_data.shape,
dtype=luts.dtype)
return new_data
return lut[band_data]


def colorize(img, **kwargs):
Expand Down Expand Up @@ -596,6 +587,6 @@ def btemp_threshold(img, min_in, max_in, threshold, threshold_out=None, **kwargs
@using_map_blocks
def _bt_threshold(band_data, threshold, high_coeffs, low_coeffs):
# expects dask array to be passed
return da.where(band_data >= threshold,
return np.where(band_data >= threshold,
high_coeffs.offset - high_coeffs.factor * band_data,
low_coeffs.offset - low_coeffs.factor * band_data)
7 changes: 6 additions & 1 deletion satpy/tests/enhancement_tests/test_enhancements.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ def run_and_check_enhancement(func, data, expected, **kwargs):
new_keys = set(img.data.attrs.keys()) - {"enhancement_history"}
assert old_keys == new_keys

np.testing.assert_allclose(img.data.values, expected, atol=1.e-6, rtol=0)
res_data_arr = img.data
assert isinstance(res_data_arr, xr.DataArray)
assert isinstance(res_data_arr.data, da.Array)
res_data = res_data_arr.data.compute() # mimics what xrimage geotiff writing does
assert not isinstance(res_data, da.Array)
np.testing.assert_allclose(res_data, expected, atol=1.e-6, rtol=0)


def identical_decorator(func):
Expand Down