Skip to content

Commit 202b70d

Browse files
authored
Raise a warning if nan in input to mgn (#73)
1 parent 447ad34 commit 202b70d

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

changelog/73.trivial.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
A warning is now raised if the input data to `~sunkit_image.enhance.mgn` contain any NaNs.

sunkit_image/enhance.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
This module contains functions that will enhance the entire image.
33
"""
4+
import warnings
45

56
import numpy as np
67
import scipy.ndimage as ndimage
@@ -79,6 +80,12 @@ def mgn(
7980
arXiv preprint arXiv:1403.6613 (2014).
8081
Ref: Sol Phys (2014) 289: 2945. doi:10.1007/s11207-014-0523-9
8182
"""
83+
if np.isnan(data).any():
84+
warnings.warn(
85+
"One or more entries in the input data are NaN. This implementation does not account "
86+
"for the presence of NaNs in the input data. As such, this may result in undefined "
87+
"behavior."
88+
)
8289

8390
if weights is None:
8491
weights = np.ones(len(sigma))

sunkit_image/tests/test_enhance.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ def test_multiscale_gaussian(map_test):
5656
expect4 = enhance.mgn(map_test)
5757

5858
assert np.allclose(result2, expect4)
59+
60+
61+
def test_nans_raise_warning(map_test):
62+
map_test[0, 0] = np.nan
63+
with pytest.warns(UserWarning, match="One or more entries in the input data are NaN."):
64+
_ = enhance.mgn(map_test)

0 commit comments

Comments
 (0)