Skip to content

Commit

Permalink
Merge pull request #2684 from pnuu/compositor-warnings
Browse files Browse the repository at this point in the history
Get rid of warnings in compositor tests
  • Loading branch information
pnuu authored Dec 14, 2023
2 parents 6f0a3ab + 336fc9c commit a78b36f
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 81 deletions.
5 changes: 3 additions & 2 deletions satpy/composites/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def drop_coordinates(self, data_arrays):
if coord not in ds.dims and
any([neglible in coord for neglible in NEGLIGIBLE_COORDS])]
if drop:
new_arrays.append(ds.drop(drop))
new_arrays.append(ds.drop_vars(drop))
else:
new_arrays.append(ds)

Expand Down Expand Up @@ -1180,7 +1180,8 @@ def _combined_sharpened_info(self, info, new_attrs):


def _get_sharpening_ratio(high_res, low_res):
ratio = high_res / low_res
with np.errstate(divide="ignore"):
ratio = high_res / low_res
# make ratio a no-op (multiply by 1) where the ratio is NaN, infinity,
# or it is negative.
ratio[~np.isfinite(ratio) | (ratio < 0)] = 1.0
Expand Down
4 changes: 0 additions & 4 deletions satpy/composites/ahi.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,3 @@
# You should have received a copy of the GNU General Public License along with
# satpy. If not, see <http://www.gnu.org/licenses/>.
"""Composite classes for AHI."""

# The green corrector used to be defined here, but was moved to spectral.py
# in Satpy 0.38 because it also applies to FCI.
from .spectral import GreenCorrector # noqa: F401
21 changes: 0 additions & 21 deletions satpy/composites/spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"""Composite classes for spectral adjustments."""

import logging
import warnings

from satpy.composites import GenericCompositor
from satpy.dataset import combine_metadata
Expand Down Expand Up @@ -199,23 +198,3 @@ def _compute_blend_fraction(self, ndvi):
+ self.limits[0]

return fraction


class GreenCorrector(SpectralBlender):
"""Previous class used to blend channels for green band corrections.
This method has been refactored to make it more generic. The replacement class is 'SpectralBlender' which computes
a weighted average based on N number of channels and N number of corresponding weights/fractions. A new class
called 'HybridGreen' has been created, which performs a correction of green bands centered at 0.51 microns
following Miller et al. (2016, :doi:`10.1175/BAMS-D-15-00154.2`) in order to improve true color imagery.
"""

def __init__(self, *args, fractions=(0.85, 0.15), **kwargs):
"""Set default keyword argument values."""
warnings.warn(
"'GreenCorrector' is deprecated, use 'SpectralBlender' instead, or 'HybridGreen' for hybrid green"
" correction following Miller et al. (2016).",
UserWarning,
stacklevel=2
)
super().__init__(fractions=fractions, *args, **kwargs)
40 changes: 0 additions & 40 deletions satpy/etc/composites/ahi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,46 +15,6 @@ modifiers:
- solar_zenith_angle

composites:
green:
deprecation_warning: "'green' is a deprecated composite. Use the equivalent 'hybrid_green' instead."
compositor: !!python/name:satpy.composites.spectral.HybridGreen
# FUTURE: Set a wavelength...see what happens. Dependency finding
# probably wouldn't work.
prerequisites:
# should we be using the most corrected or least corrected inputs?
# what happens if something requests more modifiers on top of this?
- wavelength: 0.51
modifiers: [sunz_corrected, rayleigh_corrected]
- wavelength: 0.85
modifiers: [sunz_corrected]
standard_name: toa_bidirectional_reflectance

green_true_color_reproduction:
# JMA True Color Reproduction green band
# http://www.jma.go.jp/jma/jma-eng/satellite/introduction/TCR.html
deprecation_warning: "'green_true_color_reproduction' is a deprecated composite. Use the equivalent 'reproduced_green' instead."
compositor: !!python/name:satpy.composites.spectral.SpectralBlender
fractions: [0.6321, 0.2928, 0.0751]
prerequisites:
- name: B02
modifiers: [sunz_corrected, rayleigh_corrected]
- name: B03
modifiers: [sunz_corrected, rayleigh_corrected]
- name: B04
modifiers: [sunz_corrected]
standard_name: none

green_nocorr:
deprecation_warning: "'green_nocorr' is a deprecated composite. Use the equivalent 'hybrid_green_nocorr' instead."
compositor: !!python/name:satpy.composites.spectral.HybridGreen
# FUTURE: Set a wavelength...see what happens. Dependency finding
# probably wouldn't work.
prerequisites:
# should we be using the most corrected or least corrected inputs?
# what happens if something requests more modifiers on top of this?
- wavelength: 0.51
- wavelength: 0.85
standard_name: toa_reflectance

hybrid_green:
compositor: !!python/name:satpy.composites.spectral.HybridGreen
Expand Down
14 changes: 1 addition & 13 deletions satpy/tests/compositor_tests/test_spectral.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import pytest
import xarray as xr

from satpy.composites.spectral import GreenCorrector, HybridGreen, NDVIHybridGreen, SpectralBlender
from satpy.composites.spectral import HybridGreen, NDVIHybridGreen, SpectralBlender
from satpy.tests.utils import CustomScheduler


Expand Down Expand Up @@ -67,18 +67,6 @@ def test_hybrid_green(self):
data = res.compute()
np.testing.assert_allclose(data, 0.23)

def test_green_corrector(self):
"""Test the deprecated class for green corrections."""
comp = GreenCorrector("blended_channel", fractions=(0.85, 0.15), prerequisites=(0.51, 0.85),
standard_name="toa_bidirectional_reflectance")
res = comp((self.c01, self.c03))
assert isinstance(res, xr.DataArray)
assert isinstance(res.data, da.Array)
assert res.attrs["name"] == "blended_channel"
assert res.attrs["standard_name"] == "toa_bidirectional_reflectance"
data = res.compute()
np.testing.assert_allclose(data, 0.23)


class TestNdviHybridGreenCompositor:
"""Test NDVI-weighted hybrid green correction of green band."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from setuptools import find_packages, setup

requires = ["numpy >=1.21", "pillow", "pyresample >=1.24.0", "trollsift",
"trollimage >=1.20", "pykdtree", "pyyaml >=5.1", "xarray >=0.10.1, !=0.13.0",
"trollimage >=1.20", "pykdtree", "pyyaml >=5.1", "xarray >=0.14.1",
"dask[array] >=0.17.1", "pyproj>=2.2", "zarr", "donfig", "appdirs",
"packaging", "pooch", "pyorbital"]

Expand Down

0 comments on commit a78b36f

Please sign in to comment.