Skip to content

Commit 6eeec95

Browse files
committed
Apply absorption correction after SNIP in polar
Signed-off-by: Patrick Avery <patrick.avery@kitware.com>
1 parent ea32110 commit 6eeec95

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

hexrdgui/calibration/polarview.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ def raw_mask(self):
394394
def apply_image_processing(self):
395395
img = self.raw_img.data
396396
img = self.apply_snip(img)
397+
398+
# Always apply absorption correction after snip
399+
img = self.apply_absorption_correction(img)
400+
397401
# cache this step so we can just re-apply masks if needed
398402
self.snipped_img = img
399403

@@ -440,6 +444,22 @@ def apply_snip(self, img):
440444

441445
return img
442446

447+
def apply_absorption_correction(self, img):
448+
if not HexrdConfig().apply_absorption_correction:
449+
return img
450+
451+
# Warp the absorption correction images to the polar view,
452+
# sum them, and apply.
453+
absorption_corrections = HexrdConfig().absorption_corrections_dict
454+
455+
output = {}
456+
for det_key, panel in self.detectors.items():
457+
corrections = absorption_corrections[det_key]
458+
output[det_key] = self.warp_image(corrections, panel)
459+
460+
correction_field = np.ma.sum(np.ma.stack(output.values()), axis=0)
461+
return img * correction_field.data
462+
443463
def apply_visible_masks(self, img):
444464
# Apply user-specified masks if they are present
445465
from hexrdgui.masking.mask_manager import MaskManager

hexrdgui/hexrd_config.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ def __init__(self):
326326
self._physics_package = None
327327
self._detector_coatings = {}
328328
self._instrument_rigid_body_params = {}
329+
self.absorption_corrections_dict = {}
329330

330331
# Make sure that the matplotlib font size matches the application
331332
self.font_size = self.font_size
@@ -986,7 +987,10 @@ def intensity_corrected_images_dict(self):
986987
factor = panel.lorentz_factor()
987988
images_dict[name] = img / factor
988989

990+
HexrdConfig().absorption_corrections_dict.clear()
989991
if HexrdConfig().apply_absorption_correction:
992+
absorption_corrections = HexrdConfig().absorption_corrections_dict
993+
990994
transmissions = instr.calc_transmission()
991995
max_transmission = max(
992996
[np.nanmax(v) for v in transmissions.values()])
@@ -995,7 +999,16 @@ def intensity_corrected_images_dict(self):
995999
transmission = transmissions[name]
9961000
# normalize by maximum of the entire instrument
9971001
transmission /= max_transmission
998-
images_dict[name] = img * (1 / transmission)
1002+
absorption_corrections[name] = 1 / transmission
1003+
1004+
if (
1005+
HexrdConfig().image_mode not in
1006+
(constants.ViewType.polar, constants.ViewType.stereo)
1007+
):
1008+
# If it's not polar or stereo, go ahead and apply the
1009+
# corrections
1010+
for name, img in images_dict.items():
1011+
images_dict[name] = img * absorption_corrections[name]
9991012

10001013
if HexrdConfig().intensity_subtract_minimum:
10011014
minimum = min([np.nanmin(x) for x in images_dict.values()])

0 commit comments

Comments
 (0)