@@ -325,7 +325,7 @@ def __init__(self):
325325 self ._physics_package = None
326326 self ._detector_coatings = {}
327327 self ._instrument_rigid_body_params = {}
328- self .absorption_corrections_dict = {}
328+ self .intensity_corrections_dict = {}
329329
330330 # Make sure that the matplotlib font size matches the application
331331 self .font_size = self .font_size
@@ -912,75 +912,85 @@ def raw_images_dict(self):
912912 def intensity_corrected_images_dict (self ):
913913 """Performs intensity corrections, if any, before returning"""
914914 images_dict = self .raw_images_dict
915-
916915 if not self .any_intensity_corrections :
917916 # No intensity corrections. Return.
918917 return images_dict
919918
919+ corrections_dict = self .create_intensity_corrections_dict ()
920+ if (
921+ self .image_mode not in
922+ (constants .ViewType .polar , constants .ViewType .stereo )
923+ ):
924+ # If it's not polar or stereo, go ahead and apply the
925+ # corrections
926+ for name , img in images_dict .items ():
927+ images_dict [name ] = img * corrections_dict [name ]
928+
929+ # In the polar view, minimum will be subtracted later
930+ if self .intensity_subtract_minimum :
931+ minimum = min ([np .nanmin (x ) for x in images_dict .values ()])
932+ for name , img in images_dict .items ():
933+ images_dict [name ] = img - minimum
934+
935+ return images_dict
936+
937+ def create_intensity_corrections_dict (self ) -> dict :
938+ # The corrections dict is both stored in `intensity_corrections_dict`
939+ # and returned from this function.
940+ corrections_dict = self .intensity_corrections_dict
941+ corrections_dict .clear ()
942+
920943 # Some methods require an instrument. Go ahead and create one.
921944 from hexrdgui .create_hedm_instrument import create_hedm_instrument
922945 instr = create_hedm_instrument ()
923946
924- if HexrdConfig ().apply_pixel_solid_angle_correction :
925- sangle = dict .fromkeys (images_dict .keys ())
947+ # Initialize the intensity corrections dict as ones
948+ for det_key , panel in instr .detectors .items ():
949+ corrections_dict [det_key ] = np .ones (panel .shape )
950+
951+ if not self .any_intensity_corrections :
952+ return corrections_dict
953+
954+ if self .apply_pixel_solid_angle_correction :
955+ sangle = dict .fromkeys (instr .detectors )
926956 mi = np .finfo (np .float64 ).max # largest floating point number
927957 # normalize by minimum of the entire instrument
928958 # not each detector individually
929- for name , img in images_dict .items ():
930- panel = instr .detectors [name ]
959+ for name , panel in instr .detectors .items ():
931960 sangle [name ] = panel .pixel_solid_angles
932961 mi = np .min ((mi , sangle [name ].min ()))
933- for name , img in images_dict .items ():
934- images_dict [name ] = mi * img / sangle [name ]
935962
936- if HexrdConfig ().apply_polarization_correction :
963+ for name in sangle :
964+ corrections_dict [name ] *= mi / sangle [name ]
965+
966+ if self .apply_polarization_correction :
937967 options = self .config ['image' ]['polarization' ]
938968 kwargs = {
939969 'unpolarized' : options ['unpolarized' ],
940970 'f_hor' : options ['f_hor' ],
941971 'f_vert' : options ['f_vert' ],
942972 }
943973
944- for name , img in images_dict .items ():
945- panel = instr .detectors [name ]
974+ for name , panel in instr .detectors .items ():
946975 factor = panel .polarization_factor (** kwargs )
947- images_dict [name ] = img / factor
976+ corrections_dict [name ] /= factor
948977
949- if HexrdConfig ().apply_lorentz_correction :
950- for name , img in images_dict .items ():
951- panel = instr .detectors [name ]
978+ if self .apply_lorentz_correction :
979+ for name , panel in instr .detectors .items ():
952980 factor = panel .lorentz_factor ()
953- images_dict [name ] = img / factor
954-
955- HexrdConfig ().absorption_corrections_dict .clear ()
956- if HexrdConfig ().apply_absorption_correction :
957- absorption_corrections = HexrdConfig ().absorption_corrections_dict
981+ corrections_dict [name ] /= factor
958982
983+ if self .apply_absorption_correction :
959984 transmissions = instr .calc_transmission ()
960985 max_transmission = max (
961986 [np .nanmax (v ) for v in transmissions .values ()])
962987
963- for name , img in images_dict .items ():
964- transmission = transmissions [name ]
988+ for name , transmission in transmissions .items ():
965989 # normalize by maximum of the entire instrument
966990 transmission /= max_transmission
967- absorption_corrections [name ] = 1 / transmission
968-
969- if (
970- HexrdConfig ().image_mode not in
971- (constants .ViewType .polar , constants .ViewType .stereo )
972- ):
973- # If it's not polar or stereo, go ahead and apply the
974- # corrections
975- for name , img in images_dict .items ():
976- images_dict [name ] = img * absorption_corrections [name ]
991+ corrections_dict [name ] /= transmission
977992
978- if HexrdConfig ().intensity_subtract_minimum :
979- minimum = min ([np .nanmin (x ) for x in images_dict .values ()])
980- for name , img in images_dict .items ():
981- images_dict [name ] = img - minimum
982-
983- return images_dict
993+ return corrections_dict
984994
985995 @property
986996 def images_dict (self ):
0 commit comments