@@ -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,88 @@ 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+ # Create this corrections dict, even if we don't use it, because
920+ # it updates the `intensity_corrections_dict` that may be used
921+ # elsewhere.
922+ corrections_dict = self .create_intensity_corrections_dict ()
923+ if (
924+ self .image_mode not in
925+ (constants .ViewType .polar , constants .ViewType .stereo )
926+ ):
927+ # If it's not polar or stereo, go ahead and apply the
928+ # corrections
929+ for name in images_dict :
930+ images_dict [name ] *= corrections_dict [name ]
931+
932+ # In the polar view, minimum will be subtracted later
933+ if self .intensity_subtract_minimum :
934+ minimum = min ([np .nanmin (x ) for x in images_dict .values ()])
935+ for name in images_dict :
936+ images_dict [name ] -= minimum
937+
938+ return images_dict
939+
940+ def create_intensity_corrections_dict (self ) -> dict :
941+ # The corrections dict is both stored in `intensity_corrections_dict`
942+ # and returned from this function.
943+ corrections_dict = self .intensity_corrections_dict
944+ corrections_dict .clear ()
945+
920946 # Some methods require an instrument. Go ahead and create one.
921947 from hexrdgui .create_hedm_instrument import create_hedm_instrument
922948 instr = create_hedm_instrument ()
923949
924- if HexrdConfig ().apply_pixel_solid_angle_correction :
925- sangle = dict .fromkeys (images_dict .keys ())
950+ # Initialize the intensity corrections dict as ones
951+ for det_key , panel in instr .detectors .items ():
952+ corrections_dict [det_key ] = np .ones (panel .shape )
953+
954+ if not self .any_intensity_corrections :
955+ return corrections_dict
956+
957+ if self .apply_pixel_solid_angle_correction :
958+ sangle = dict .fromkeys (instr .detectors )
926959 mi = np .finfo (np .float64 ).max # largest floating point number
927960 # normalize by minimum of the entire instrument
928961 # not each detector individually
929- for name , img in images_dict .items ():
930- panel = instr .detectors [name ]
962+ for name , panel in instr .detectors .items ():
931963 sangle [name ] = panel .pixel_solid_angles
932964 mi = np .min ((mi , sangle [name ].min ()))
933- for name , img in images_dict .items ():
934- images_dict [name ] = mi * img / sangle [name ]
935965
936- if HexrdConfig ().apply_polarization_correction :
966+ for name in sangle :
967+ corrections_dict [name ] *= mi / sangle [name ]
968+
969+ if self .apply_polarization_correction :
937970 options = self .config ['image' ]['polarization' ]
938971 kwargs = {
939972 'unpolarized' : options ['unpolarized' ],
940973 'f_hor' : options ['f_hor' ],
941974 'f_vert' : options ['f_vert' ],
942975 }
943976
944- for name , img in images_dict .items ():
945- panel = instr .detectors [name ]
977+ for name , panel in instr .detectors .items ():
946978 factor = panel .polarization_factor (** kwargs )
947- images_dict [name ] = img / factor
979+ corrections_dict [name ] /= factor
948980
949- if HexrdConfig ().apply_lorentz_correction :
950- for name , img in images_dict .items ():
951- panel = instr .detectors [name ]
981+ if self .apply_lorentz_correction :
982+ for name , panel in instr .detectors .items ():
952983 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
984+ corrections_dict [name ] /= factor
958985
986+ if self .apply_absorption_correction :
959987 transmissions = instr .calc_transmission ()
960988 max_transmission = max (
961989 [np .nanmax (v ) for v in transmissions .values ()])
962990
963- for name , img in images_dict .items ():
964- transmission = transmissions [name ]
991+ for name , transmission in transmissions .items ():
965992 # normalize by maximum of the entire instrument
966993 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 ]
977-
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
994+ corrections_dict [name ] /= transmission
982995
983- return images_dict
996+ return corrections_dict
984997
985998 @property
986999 def images_dict (self ):
0 commit comments