diff --git a/src/cal_tools/agipdlib.py b/src/cal_tools/agipdlib.py index ecf4766bdc9f3f1243fdc01683386a2adfa4ed62..76bbc1cf84cb3d48a82cf43c71baf71b76d124dc 100644 --- a/src/cal_tools/agipdlib.py +++ b/src/cal_tools/agipdlib.py @@ -28,7 +28,7 @@ from cal_tools.agipdutils import ( ) from cal_tools.enums import AgipdGainMode, BadPixels, SnowResolution from cal_tools.h5_copy_except import h5_copy_except_paths - +from warnings import warn @dataclass class AgipdCtrl: @@ -1048,10 +1048,17 @@ class AgipdCorrections: del rel_corr # Adjust medium gain baseline to match highest high gain value + # This correction is disabled in case CS gain correction is selected. if self.corr_bools.get("adjust_mg_baseline"): - mgbc = self.md_additional_offset[module_idx][cellid, ...] - data[gain == 1] += mgbc[gain == 1] - del mgbc + if self.rel_gain == "CS": + warn( + "`adjust_mg_baseline` correction is not allowed with" + " Current Source correction." + " Skipping `adjust_mg_baseline` correction step") + else: + mgbc = self.md_additional_offset[module_idx][cellid, ...] + data[gain == 1] += mgbc[gain == 1] + del mgbc # Set negative values for medium gain to 0 # TODO: Probably it would be better to add it to badpixel maps, @@ -1422,11 +1429,20 @@ class AgipdCorrections: rel_gain = np.ones((128, 512, self.max_cells, 3), np.float32) if "SlopesCS" in cons_data: # No Chance to have both SlopesPC and SlopesCS used at the same time? - # What to do for SlopesCS - # Switch between SlopesCS and SlopesPC based on rel_gain_mode. rel_gain[..., 1] = rel_gain[..., 0] * cons_data["SlopesCS"][..., self.max_cells, 6] # noqa rel_gain[..., 2] = rel_gain[..., 1] * cons_data["SlopesCS"][..., self.max_cells, 7] # noqa - + # TODO: Decide between: + # - Median of ratio of high gain and medium gain slope + # - Ratio of medians of high gain slope and medium gain slope + frac_high_med_ofratio = np.median( + cons_data["SlopesCS"][..., self.max_cells, 6]) + frac_high_med = ( + np.median(cons_data["SlopesCS"][..., self.max_cells, 0]) / + np.median(cons_data["SlopesCS"][..., self.max_cells, 1])) + # TODO: DECIDE AND REMOVE THIS PRINT AFTER TESTING + print( + "CHECK IF BOTH MEDIAN FRACTIONS ARE THE SAME:", + np.allclose(frac_high_med, frac_high_med_ofratio)) elif "SlopesPC" in cons_data: slopesPC = cons_data["SlopesPC"].astype(np.float32, copy=False)