Skip to content

Commit ff27fdd

Browse files
authored
Merge pull request #1941 from HEXRD/catch-nan-slice-warnings
Ensure all nan-slice warnings are caught
2 parents 2689877 + 43c16a8 commit ff27fdd

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
@@ -521,13 +519,15 @@ def apply_intensity_corrections(self, img: np.ndarray) -> np.ndarray:
521519

522520
stacked = np.ma.stack(output.values()).filled(np.nan)
523521

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

532532
img *= correction_field
533533

0 commit comments

Comments
 (0)