From a1f796e04af592e411550eeec653f0c4660f3d95 Mon Sep 17 00:00:00 2001 From: David Hoese Date: Sat, 2 Apr 2022 21:19:37 -0500 Subject: [PATCH 01/11] Remove marine_clean_aerosol from default AHI rayleigh_corrected modifier --- satpy/etc/composites/ahi.yaml | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/satpy/etc/composites/ahi.yaml b/satpy/etc/composites/ahi.yaml index ef75c4c972..7ab2e2820c 100644 --- a/satpy/etc/composites/ahi.yaml +++ b/satpy/etc/composites/ahi.yaml @@ -2,24 +2,11 @@ sensor_name: visir/ahi modifiers: rayleigh_corrected: - modifier: !!python/name:satpy.modifiers.PSPRayleighReflectance - atmosphere: us-standard - aerosol_type: marine_clean_aerosol - prerequisites: - - wavelength: 0.64 - modifiers: [sunz_corrected] - optional_prerequisites: - - satellite_azimuth_angle - - satellite_zenith_angle - - solar_azimuth_angle - - solar_zenith_angle - - no_aerosol_rayleigh_corrected: modifier: !!python/name:satpy.modifiers.PSPRayleighReflectance atmosphere: us-standard aerosol_type: rayleigh_only prerequisites: - - name: B03 + - wavelength: B03 modifiers: [sunz_corrected] optional_prerequisites: - satellite_azimuth_angle @@ -48,9 +35,9 @@ composites: fractions: [0.6321, 0.2928, 0.0751] prerequisites: - name: B02 - modifiers: [sunz_corrected, no_aerosol_rayleigh_corrected] + modifiers: [sunz_corrected, rayleigh_corrected] - name: B03 - modifiers: [sunz_corrected, no_aerosol_rayleigh_corrected] + modifiers: [sunz_corrected, rayleigh_corrected] - name: B04 modifiers: [sunz_corrected] standard_name: none @@ -247,10 +234,10 @@ composites: compositor: !!python/name:satpy.composites.SelfSharpenedRGB prerequisites: - name: B03 - modifiers: [sunz_corrected, no_aerosol_rayleigh_corrected] + modifiers: [sunz_corrected, rayleigh_corrected] - name: green_true_color_reproduction - name: B01 - modifiers: [sunz_corrected, no_aerosol_rayleigh_corrected] + modifiers: [sunz_corrected, rayleigh_corrected] standard_name: true_color_reproduction # true_color_reducedsize_land: From afd52240b9f406e23bc895b6244afd7c14b5f3e8 Mon Sep 17 00:00:00 2001 From: mherbertson <57386258+mherbertson@users.noreply.github.com> Date: Mon, 4 Apr 2022 05:45:27 +0000 Subject: [PATCH 02/11] Ignore alpha when adding luminance --- satpy/composites/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/satpy/composites/__init__.py b/satpy/composites/__init__.py index 90f4e67aac..f0b4b1922a 100644 --- a/satpy/composites/__init__.py +++ b/satpy/composites/__init__.py @@ -1101,7 +1101,8 @@ def __call__(self, projectables, *args, **kwargs): # Get the enhanced version of the RGB composite to be sharpened rgb_img = enhance2dataset(projectables[1]) - rgb_img *= luminance + # Ignore alpha band when applying luminance + rgb_img = rgb_img.where(rgb_img.bands == 'A', rgb_img * luminance) return super(SandwichCompositor, self).__call__(rgb_img, *args, **kwargs) From 99d2e31c8e702116398c2aecb7104011d242fe73 Mon Sep 17 00:00:00 2001 From: mherbertson <57386258+mherbertson@users.noreply.github.com> Date: Tue, 5 Apr 2022 04:51:31 +0000 Subject: [PATCH 03/11] Update test to compare RGBA and A remains intact --- satpy/tests/test_composites.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/satpy/tests/test_composites.py b/satpy/tests/test_composites.py index 77463872b2..d95b37b449 100644 --- a/satpy/tests/test_composites.py +++ b/satpy/tests/test_composites.py @@ -456,20 +456,26 @@ def test_compositor(self, e2d): """Test luminance sharpening compositor.""" from satpy.composites import SandwichCompositor - rgb_arr = da.from_array(np.random.random((3, 2, 2)), chunks=2) - rgb = xr.DataArray(rgb_arr, dims=['bands', 'y', 'x']) + # Test RGBA + bands = ['R', 'G', 'B', 'A'] + rgba_arr = da.from_array(np.random.random((4, 2, 2)), chunks=2) + rgba = xr.DataArray(rgba_arr, dims=['bands', 'y', 'x'], coords={'bands': bands}) lum_arr = da.from_array(100 * np.random.random((2, 2)), chunks=2) lum = xr.DataArray(lum_arr, dims=['y', 'x']) # Make enhance2dataset return unmodified dataset - e2d.return_value = rgb + e2d.return_value = rgba comp = SandwichCompositor(name='test') - res = comp([lum, rgb]) + res = comp([lum, rgba]) - for i in range(3): - np.testing.assert_allclose(res.data[i, :, :], - rgb_arr[i, :, :] * lum_arr / 100.) + for band in rgba: + if band.bands != 'A': + # Check compositor has modified this band + np.testing.assert_allclose(res.loc[band.bands].to_numpy(), band.to_numpy() * lum_arr / 100.) + else: + # Check Alpha band remains intact + np.testing.assert_allclose(res.loc[band.bands].to_numpy(), band.to_numpy()) # make sure the compositor doesn't modify the input data np.testing.assert_allclose(lum.values, lum_arr.compute()) From fe08bec093cdabcfbbaeb320e4ec0938ddcdbfa4 Mon Sep 17 00:00:00 2001 From: mherbertson <57386258+mherbertson@users.noreply.github.com> Date: Tue, 5 Apr 2022 05:03:20 +0000 Subject: [PATCH 04/11] Updated readability --- satpy/tests/test_composites.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/satpy/tests/test_composites.py b/satpy/tests/test_composites.py index d95b37b449..a84282e53b 100644 --- a/satpy/tests/test_composites.py +++ b/satpy/tests/test_composites.py @@ -459,7 +459,8 @@ def test_compositor(self, e2d): # Test RGBA bands = ['R', 'G', 'B', 'A'] rgba_arr = da.from_array(np.random.random((4, 2, 2)), chunks=2) - rgba = xr.DataArray(rgba_arr, dims=['bands', 'y', 'x'], coords={'bands': bands}) + rgba = xr.DataArray(rgba_arr, dims=['bands', 'y', 'x'], + coords={'bands': bands}) lum_arr = da.from_array(100 * np.random.random((2, 2)), chunks=2) lum = xr.DataArray(lum_arr, dims=['y', 'x']) @@ -472,10 +473,12 @@ def test_compositor(self, e2d): for band in rgba: if band.bands != 'A': # Check compositor has modified this band - np.testing.assert_allclose(res.loc[band.bands].to_numpy(), band.to_numpy() * lum_arr / 100.) + np.testing.assert_allclose(res.loc[band.bands].to_numpy(), + band.to_numpy() * lum_arr / 100.) else: # Check Alpha band remains intact - np.testing.assert_allclose(res.loc[band.bands].to_numpy(), band.to_numpy()) + np.testing.assert_allclose(res.loc[band.bands].to_numpy(), + band.to_numpy()) # make sure the compositor doesn't modify the input data np.testing.assert_allclose(lum.values, lum_arr.compute()) From 2f410170148bf277818ae2c1bcc5fe529a8deb9c Mon Sep 17 00:00:00 2001 From: mherbertson <57386258+mherbertson@users.noreply.github.com> Date: Tue, 5 Apr 2022 05:07:40 +0000 Subject: [PATCH 05/11] Remove trailing whitespace --- satpy/tests/test_composites.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/satpy/tests/test_composites.py b/satpy/tests/test_composites.py index a84282e53b..095b5db0a4 100644 --- a/satpy/tests/test_composites.py +++ b/satpy/tests/test_composites.py @@ -459,7 +459,7 @@ def test_compositor(self, e2d): # Test RGBA bands = ['R', 'G', 'B', 'A'] rgba_arr = da.from_array(np.random.random((4, 2, 2)), chunks=2) - rgba = xr.DataArray(rgba_arr, dims=['bands', 'y', 'x'], + rgba = xr.DataArray(rgba_arr, dims=['bands', 'y', 'x'], coords={'bands': bands}) lum_arr = da.from_array(100 * np.random.random((2, 2)), chunks=2) lum = xr.DataArray(lum_arr, dims=['y', 'x']) @@ -473,11 +473,11 @@ def test_compositor(self, e2d): for band in rgba: if band.bands != 'A': # Check compositor has modified this band - np.testing.assert_allclose(res.loc[band.bands].to_numpy(), + np.testing.assert_allclose(res.loc[band.bands].to_numpy(), band.to_numpy() * lum_arr / 100.) else: # Check Alpha band remains intact - np.testing.assert_allclose(res.loc[band.bands].to_numpy(), + np.testing.assert_allclose(res.loc[band.bands].to_numpy(), band.to_numpy()) # make sure the compositor doesn't modify the input data np.testing.assert_allclose(lum.values, lum_arr.compute()) From d88ff92a19bdbeca7d00043569e9205da1d7b226 Mon Sep 17 00:00:00 2001 From: mherbertson <57386258+mherbertson@users.noreply.github.com> Date: Tue, 5 Apr 2022 05:14:53 +0000 Subject: [PATCH 06/11] Remove over indentation --- satpy/tests/test_composites.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/satpy/tests/test_composites.py b/satpy/tests/test_composites.py index 095b5db0a4..eb1690bb46 100644 --- a/satpy/tests/test_composites.py +++ b/satpy/tests/test_composites.py @@ -474,11 +474,11 @@ def test_compositor(self, e2d): if band.bands != 'A': # Check compositor has modified this band np.testing.assert_allclose(res.loc[band.bands].to_numpy(), - band.to_numpy() * lum_arr / 100.) + band.to_numpy() * lum_arr / 100.) else: # Check Alpha band remains intact np.testing.assert_allclose(res.loc[band.bands].to_numpy(), - band.to_numpy()) + band.to_numpy()) # make sure the compositor doesn't modify the input data np.testing.assert_allclose(lum.values, lum_arr.compute()) From eaeb19cd1b3e53d30465e45540c50f146bbf8f40 Mon Sep 17 00:00:00 2001 From: David Hoese Date: Tue, 5 Apr 2022 06:51:01 -0500 Subject: [PATCH 07/11] Fix typo in satpy/etc/composites/ahi.yaml Co-authored-by: Simon Proud --- satpy/etc/composites/ahi.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/satpy/etc/composites/ahi.yaml b/satpy/etc/composites/ahi.yaml index 7ab2e2820c..f29a36357f 100644 --- a/satpy/etc/composites/ahi.yaml +++ b/satpy/etc/composites/ahi.yaml @@ -6,7 +6,7 @@ modifiers: atmosphere: us-standard aerosol_type: rayleigh_only prerequisites: - - wavelength: B03 + - name: B03 modifiers: [sunz_corrected] optional_prerequisites: - satellite_azimuth_angle From 66b960fd61f8660dd1af8b115dcd5443ad1562a2 Mon Sep 17 00:00:00 2001 From: David Hoese Date: Tue, 5 Apr 2022 14:42:37 -0500 Subject: [PATCH 08/11] Force panel version in CI --- continuous_integration/environment.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/continuous_integration/environment.yaml b/continuous_integration/environment.yaml index 905cfa2f37..d131bad1e0 100644 --- a/continuous_integration/environment.yaml +++ b/continuous_integration/environment.yaml @@ -11,6 +11,7 @@ dependencies: - Cython - sphinx - cartopy + - panel>=0.12.7 - pillow - matplotlib - scipy From 452b2c5a352e37c6a2a3830e9a2504db8055decb Mon Sep 17 00:00:00 2001 From: mherbertson <57386258+mherbertson@users.noreply.github.com> Date: Wed, 6 Apr 2022 00:59:15 +0000 Subject: [PATCH 09/11] Refactor test to include both RGB and RGBA --- satpy/tests/test_composites.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/satpy/tests/test_composites.py b/satpy/tests/test_composites.py index eb1690bb46..01697114f1 100644 --- a/satpy/tests/test_composites.py +++ b/satpy/tests/test_composites.py @@ -448,29 +448,31 @@ def test_compositor(self): np.testing.assert_allclose(res.data, 0.0, atol=1e-9) -class TestSandwichCompositor(unittest.TestCase): +class TestSandwichCompositor: """Test sandwich compositor.""" + # Test RGB and RGBA + @pytest.mark.parametrize("input_shape,bands", + [((3, 2, 2), ['R', 'G', 'B']), + ((4, 2, 2), ['R', 'G', 'B', 'A'])]) @mock.patch('satpy.composites.enhance2dataset') - def test_compositor(self, e2d): + def test_compositor(self, e2d, input_shape, bands): """Test luminance sharpening compositor.""" from satpy.composites import SandwichCompositor - # Test RGBA - bands = ['R', 'G', 'B', 'A'] - rgba_arr = da.from_array(np.random.random((4, 2, 2)), chunks=2) - rgba = xr.DataArray(rgba_arr, dims=['bands', 'y', 'x'], + rgb_arr = da.from_array(np.random.random(input_shape), chunks=2) + rgb = xr.DataArray(rgb_arr, dims=['bands', 'y', 'x'], coords={'bands': bands}) lum_arr = da.from_array(100 * np.random.random((2, 2)), chunks=2) lum = xr.DataArray(lum_arr, dims=['y', 'x']) # Make enhance2dataset return unmodified dataset - e2d.return_value = rgba + e2d.return_value = rgb comp = SandwichCompositor(name='test') - res = comp([lum, rgba]) + res = comp([lum, rgb]) - for band in rgba: + for band in rgb: if band.bands != 'A': # Check compositor has modified this band np.testing.assert_allclose(res.loc[band.bands].to_numpy(), From 8d554e313407ddf921b1db60bc9c4535523c4ceb Mon Sep 17 00:00:00 2001 From: mherbertson <57386258+mherbertson@users.noreply.github.com> Date: Wed, 6 Apr 2022 01:27:46 +0000 Subject: [PATCH 10/11] Remove whitespace and indents --- satpy/tests/test_composites.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/satpy/tests/test_composites.py b/satpy/tests/test_composites.py index 01697114f1..70f13a44b7 100644 --- a/satpy/tests/test_composites.py +++ b/satpy/tests/test_composites.py @@ -452,9 +452,9 @@ class TestSandwichCompositor: """Test sandwich compositor.""" # Test RGB and RGBA - @pytest.mark.parametrize("input_shape,bands", - [((3, 2, 2), ['R', 'G', 'B']), - ((4, 2, 2), ['R', 'G', 'B', 'A'])]) + @pytest.mark.parametrize("input_shape,bands", + [((3, 2, 2), ['R', 'G', 'B']), + ((4, 2, 2), ['R', 'G', 'B', 'A'])]) @mock.patch('satpy.composites.enhance2dataset') def test_compositor(self, e2d, input_shape, bands): """Test luminance sharpening compositor.""" @@ -462,7 +462,7 @@ def test_compositor(self, e2d, input_shape, bands): rgb_arr = da.from_array(np.random.random(input_shape), chunks=2) rgb = xr.DataArray(rgb_arr, dims=['bands', 'y', 'x'], - coords={'bands': bands}) + coords={'bands': bands}) lum_arr = da.from_array(100 * np.random.random((2, 2)), chunks=2) lum = xr.DataArray(lum_arr, dims=['y', 'x']) From b77c4ad87f203863339003abcb3c1cf6aa945e01 Mon Sep 17 00:00:00 2001 From: mherbertson <57386258+mherbertson@users.noreply.github.com> Date: Wed, 6 Apr 2022 02:13:35 +0000 Subject: [PATCH 11/11] Re-indent pytest.mark.parametrize --- satpy/tests/test_composites.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/satpy/tests/test_composites.py b/satpy/tests/test_composites.py index 70f13a44b7..20fbbfdd51 100644 --- a/satpy/tests/test_composites.py +++ b/satpy/tests/test_composites.py @@ -452,9 +452,13 @@ class TestSandwichCompositor: """Test sandwich compositor.""" # Test RGB and RGBA - @pytest.mark.parametrize("input_shape,bands", - [((3, 2, 2), ['R', 'G', 'B']), - ((4, 2, 2), ['R', 'G', 'B', 'A'])]) + @pytest.mark.parametrize( + "input_shape,bands", + [ + ((3, 2, 2), ['R', 'G', 'B']), + ((4, 2, 2), ['R', 'G', 'B', 'A']) + ] + ) @mock.patch('satpy.composites.enhance2dataset') def test_compositor(self, e2d, input_shape, bands): """Test luminance sharpening compositor."""