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

Get rid of warnings in compositor tests #2684

Merged
merged 5 commits into from
Dec 14, 2023
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
5 changes: 3 additions & 2 deletions satpy/composites/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015-2023 Satpy developers

Check notice on line 1 in satpy/composites/__init__.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

ℹ Getting worse: Lines of Code in a Single File

The lines of code increases from 1147 to 1148, improve code health by reducing it to 600. The number of Lines of Code in a single file. More Lines of Code lowers the code health.
#
# This file is part of satpy.
#
Expand Down Expand Up @@ -204,7 +204,7 @@
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 _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
@@ -1,4 +1,4 @@
# Copyright (c) 2018 Satpy developers

Check notice on line 1 in satpy/tests/compositor_tests/test_spectral.py

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Code Duplication

reduced similar code in: TestSpectralComposites.test_green_corrector. Avoid duplicated, aka copy-pasted, code inside the module. More duplication lowers the code health.
#
# This file is part of satpy.
#
Expand All @@ -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 @@
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
Loading