diff --git a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb index f091759260a925846c20ef96f18099f7948d70a5..57f57a37802166b5e2a8bca74310a2089b22ccdc 100644 --- a/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb +++ b/notebooks/AGIPD/AGIPD_Correct_and_Verify.ipynb @@ -62,6 +62,7 @@ "noisy_adc_threshold = 0.25 # threshold to mask complete adc\n", "ff_gain = 7.2 # conversion gain for absolute FlatField constants, while applying xray_gain\n", "photon_energy = -1.0 # photon energy in keV, non-positive value for XGM autodetection\n", + "rounding_threshold = 0.5 # the fraction to round to down, 0.5 for standard rounding rule\n", "\n", "# Correction Booleans\n", "only_offset = False # Apply only Offset correction. if False, Offset is applied by Default. if True, Offset is only applied.\n", @@ -527,7 +528,11 @@ " warning('Neither explicit photon energy nor XGM device configured, photon rounding disabled!')\n", " round_photons = False\n", "elif round_photons:\n", - " print(f'Photon energy for rounding: {photon_energy:.3f} keV')" + " print(f'Photon energy for rounding: {photon_energy:.3f} keV')\n", + "\n", + "if round_photons and (rounding_threshold >= .0 or .1 <= rounding_threshold):\n", + " warning('Round threshould is out of (0, 1) range. Use standard 0.5 value.')\n", + " rounding_threshold = 0.5" ] }, { @@ -558,6 +563,7 @@ "agipd_corr.noisy_adc_threshold = noisy_adc_threshold\n", "agipd_corr.ff_gain = ff_gain\n", "agipd_corr.photon_energy = photon_energy\n", + "agipd_corr.rounding_threshold = rounding_threshold\n", "\n", "agipd_corr.compress_fields = compress_fields\n", "if recast_image_data:\n", @@ -565,7 +571,6 @@ ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ diff --git a/src/cal_tools/agipdlib.py b/src/cal_tools/agipdlib.py index d743044f16e7015e7382164d13806b5770d1d171..66127058da88b79ee5d6a6c2368d9fa76aa4cb24 100644 --- a/src/cal_tools/agipdlib.py +++ b/src/cal_tools/agipdlib.py @@ -1068,15 +1068,18 @@ class AgipdCorrections: # Round keV-normalized intensity to photons. if self.corr_bools.get("round_photons"): data_hist_preround, _ = np.histogram(data, bins=self.hist_bins_preround) + + bidx = data < -self.rounding_threshold + data[bidx] = .0 + msk[bidx] |= BadPixels.VALUE_OUT_OF_RANGE - data /= self.photon_energy + # Mask can be used to round only good pixels, + # but the performance difference is negligible. + data = data / self.photon_energy - (self.rounding_threshold - 0.5) np.round(data, out=data) - # This could also be done before and its mask inverted for - # rounding, but the performance difference is negligible. bidx = data < 0 - data[bidx] = 0 - msk[bidx] |= BadPixels.VALUE_OUT_OF_RANGE + data[bidx] = .0 del bidx data_hist_postround, _ = np.histogram(data * self.photon_energy,