diff --git a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb index e32d7f16a3a70de71334812c57c0203edee10cc0..9ffa2487e3afc0c20f3b80548d50be0e0dfe3ba0 100644 --- a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb +++ b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb @@ -238,9 +238,16 @@ "\n", "# Dont apply any corrections if only_offset is requested\n", "if not only_offset:\n", - " corr_bools[\"adjust_mg_baseline\"] = adjust_mg_baseline\n", - " corr_bools[\"cs_corr\"] = cs_corr \n", + " corr_bools[\"cs_corr\"] = cs_corr\n", " corr_bools[\"pc_corr\"] = pc_corr\n", + " if cs_corr:\n", + " corr_bools[\"adjust_mg_baseline\"] = False\n", + " warning(\n", + " \"Currently, `adjust_mg_baseline` correction\"\n", + " \" is not allowed with Current Source gain correction.\"\n", + " \" Skipping `adjust_mg_baseline` correction step.\")\n", + " else:\n", + " corr_bools[\"adjust_mg_baseline\"] = adjust_mg_baseline\n", " corr_bools[\"xray_corr\"] = xray_gain\n", " corr_bools[\"blc_noise\"] = blc_noise\n", " corr_bools[\"blc_stripes\"] = blc_stripes\n", diff --git a/src/cal_tools/agipdlib.py b/src/cal_tools/agipdlib.py index d28b8021b2e84906e83596eebb648c720c1af454..522ee4695d77db204f3d4ed3a0aae0ad5b8dcf24 100644 --- a/src/cal_tools/agipdlib.py +++ b/src/cal_tools/agipdlib.py @@ -1056,12 +1056,6 @@ class AgipdCorrections: # 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"): - if self.corr_bools.get("cs_corr"): - warning( - "Currently, `adjust_mg_baseline` correction" - " is not allowed with Current Source gain correction." - " Skipping `adjust_mg_baseline` correction step.") - else: mgbc = self.md_additional_offset[module_idx][cellid, ...] data[gain == 1] += mgbc[gain == 1] del mgbc @@ -1437,20 +1431,22 @@ class AgipdCorrections: # it is not expected to have SlopesCS and SlopesPC at the sametime. if "SlopesCS" in cons_data: - 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: + # TODO consider updating the SlopesCS shape instead of doing this here. + cons_data["SlopesCS"] = np.transpose(cons_data["SlopesCS"], (2, 3, 1, 0)) + 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: BTW both medium fractions are not the equal after testing! # - 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_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)) + np.median(cons_data["SlopesCS"][..., :self.max_cells, 0]) / + np.median(cons_data["SlopesCS"][..., :self.max_cells, 1])) + # Currently, `adjust_mg_baseline` correction + # is not allowed with Current Source gain correction. + # Skipping `adjust_mg_baseline` correction step." + md_additional_offset = np.zeros((128, 512, self.max_cells), np.float32) elif "SlopesPC" in cons_data: slopesPC = cons_data["SlopesPC"].astype(np.float32, copy=False)