|
15 | 15 |
|
16 | 16 | from hexrd.rotations import mapAngle |
17 | 17 | from hexrd.utils.decorators import memoize |
18 | | -from hexrd.utils.warnings import ignore_warnings |
19 | | - |
20 | 18 | from hexrd import constants as ct |
21 | 19 | from hexrd.xrdutil import _project_on_detector_plane, _project_on_detector_cylinder |
22 | 20 | from hexrd import instrument |
@@ -521,13 +519,15 @@ def apply_intensity_corrections(self, img: np.ndarray) -> np.ndarray: |
521 | 519 |
|
522 | 520 | stacked = np.ma.stack(output.values()).filled(np.nan) |
523 | 521 |
|
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 |
531 | 531 |
|
532 | 532 | img *= correction_field |
533 | 533 |
|
|
0 commit comments