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

Revert np.nan_to_num usage on rayleigh correction array #159

Merged
merged 2 commits into from
Oct 10, 2022
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
2 changes: 1 addition & 1 deletion pyspectral/rayleigh.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def get_reflectance(self, sun_zenith, sat_zenith, azidiff,
dtype=res.dtype,
chunks=getattr(res, "chunks", None))

res = np.clip(np.nan_to_num(res), 0, 100)
res = np.clip(res, 0, 100)
if compute:
res = res.compute()
return res
Expand Down
30 changes: 14 additions & 16 deletions pyspectral/tests/test_rayleigh.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
TEST_RAYLEIGH_RESULT2 = np.array([9.653559, 8.464997], dtype='float32')
TEST_RAYLEIGH_RESULT3 = np.array([5.488735, 8.533125], dtype='float32')
TEST_RAYLEIGH_RESULT4 = np.array([0.0, 8.64748], dtype='float32')
TEST_RAYLEIGH_RESULT5 = np.array([9.653559, np.nan], dtype='float32')
TEST_RAYLEIGH_RESULT_R1 = np.array([16.66666667, 20.83333333, 25.], dtype='float32')
TEST_RAYLEIGH_RESULT_R2 = np.array([0., 6.25, 12.5], dtype='float32')

Expand Down Expand Up @@ -315,28 +316,25 @@ def test_get_reflectance_redband_outside_clip(self, fake_lut_hdf5):
np.testing.assert_allclose(refl_corr2, refl_corr3)

@patch('pyspectral.rayleigh.da', None)
def test_get_reflectance(self, fake_lut_hdf5):
@pytest.mark.parametrize(
("sun_zenith", "sat_zenith", "azidiff", "redband_refl", "exp_result"),
[
(np.array([67., 32.]), np.array([45., 18.]), np.array([150., 110.]), np.array([14., 5.]),
TEST_RAYLEIGH_RESULT1),
(np.array([60., 20.]), np.array([49., 26.]), np.array([140., 130.]), np.array([12., 8.]),
TEST_RAYLEIGH_RESULT2),
(np.array([60., 20.]), np.array([49., 26.]), np.array([140., 130.]), np.array([12., np.nan]),
TEST_RAYLEIGH_RESULT5),
]
)
def test_get_reflectance(self, fake_lut_hdf5, sun_zenith, sat_zenith, azidiff, redband_refl, exp_result):
"""Test getting the reflectance correction."""
sun_zenith = np.array([67., 32.])
sat_zenith = np.array([45., 18.])
azidiff = np.array([150., 110.])
redband_refl = np.array([14., 5.])
rayl = _create_rayleigh()
with mocked_rsr():
refl_corr = rayl.get_reflectance(
sun_zenith, sat_zenith, azidiff, 'ch3', redband_refl)
np.testing.assert_allclose(refl_corr, TEST_RAYLEIGH_RESULT1)

sun_zenith = np.array([60., 20.])
sat_zenith = np.array([49., 26.])
azidiff = np.array([140., 130.])
redband_refl = np.array([12., 8.])
with mocked_rsr():
refl_corr = rayl.get_reflectance(
sun_zenith, sat_zenith, azidiff, 'ch3', redband_refl)

assert isinstance(refl_corr, np.ndarray)
np.testing.assert_allclose(refl_corr, TEST_RAYLEIGH_RESULT2)
np.testing.assert_allclose(refl_corr, exp_result)

@patch('pyspectral.rayleigh.da', None)
def test_get_reflectance_no_rsr(self, fake_lut_hdf5):
Expand Down