Skip to content

Commit 43c16a8

Browse files
committed
Ensure all nan-slice warnings are caught
Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
1 parent 7ddca04 commit 43c16a8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

hexrdgui/calibration/polarview.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
from hexrd.rotations import mapAngle
1717
from hexrd.utils.decorators import memoize
18-
from hexrd.utils.warnings import ignore_warnings
19-
2018
from hexrd import constants as ct
2119
from hexrd.xrdutil import _project_on_detector_plane, _project_on_detector_cylinder
2220
from hexrd import instrument
@@ -519,13 +517,15 @@ def apply_intensity_corrections(self, img: np.ndarray) -> np.ndarray:
519517

520518
stacked = np.ma.stack(output.values()).filled(np.nan)
521519

522-
# It's okay to have all nan-slices here, but it produces a warning.
523-
# Just ignore the warning.
524-
with ignore_warnings(RuntimeWarning):
525-
# In case there are overlapping detectors, we do nanmean for
526-
# the intensities instead of nansum. This would produce a
527-
# somewhat more reasonable intensity.
528-
correction_field = np.nanmean(stacked, axis=0)
520+
# In case there are overlapping detectors, we do nanmean for
521+
# the intensities instead of nansum. All-NaN slices are expected
522+
# (detector gaps) and should produce NaN in the correction field.
523+
# We compute the mean manually instead of calling np.nanmean()
524+
# because the "Mean of empty slice" RuntimeWarning it emits could
525+
# not be reliably suppressed on all platforms (see PR #1941).
526+
valid_count = np.sum(~np.isnan(stacked), axis=0)
527+
with np.errstate(invalid='ignore', divide='ignore'):
528+
correction_field = np.nansum(stacked, axis=0) / valid_count
529529

530530
img *= correction_field
531531

0 commit comments

Comments
 (0)