diff --git a/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb b/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb index f79bf83d40ecb0946c9e0447539b55fa67cd23d6..32a4f221cf4e6fcbb67ffdaf8f8b9877000d69b4 100644 --- a/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb +++ b/notebooks/Gotthard2/Characterize_Darks_Gotthard2_NBC.ipynb @@ -52,6 +52,8 @@ "acquisition_rate = -1. # Detector acquisition rate (1.1/4.5), set to -1 to use value in raw file.\n", "single_photon = -1 # Detector single photon mode (High/Low CDS), set to -1 to use value in raw file.\n", "\n", + "# Parameters used for calculating calibration constants\n", + "bpix_noise_nitrs = 5 # number of maximum iterations to actively try to reach correct number of badpixels of NOISE_OUT_OF_THRESHOLD type. Leave -1 to keep iterating until finding maximum number of badpixels.\n", "# Parameters used during selecting raw data trains.\n", "min_trains = 1 # Minimum number of trains that should be available to process dark constants. Default 1.\n", "max_trains = 1000 # Maximum number of trains to use for processing dark constants. Set to 0 to use all available trains.\n", @@ -471,13 +473,28 @@ " badpixels_map[mod][\n", " ~np.isfinite(offset_map[mod])\n", " ] |= BadPixels.OFFSET_NOISE_EVAL_ERROR.value\n", - " badpixels_map[mod][\n", - " eval_bpidx(noise_map[mod])\n", - " ] |= BadPixels.NOISE_OUT_OF_THRESHOLD.value\n", "\n", - " badpixels_map[mod][\n", - " ~np.isfinite(noise_map[mod])\n", - " ] |= BadPixels.OFFSET_NOISE_EVAL_ERROR.value\n", + " # Iteratively identify noisy pixels (OFFSET_NOISE_EVAL_ERROR & NOISE_OUT_OF_THRESHOLD)\n", + " # Due to the low number of strips (1280), outliers can significantly impact\n", + " # the badpixel calculation. We use multiple iterations to gradually refine\n", + " # the sigma threshold, as a single fixed threshold may not be suitable for\n", + " # different Gotthard2 detectors.\n", + " last_nbpix = 0\n", + " nmap = noise_map[mod].copy()\n", + " for itr in range(bpix_noise_nitrs):\n", + " badpixels_map[mod][\n", + " ~np.isfinite(nmap)\n", + " ] |= BadPixels.OFFSET_NOISE_EVAL_ERROR.value\n", + " badpixels_map[mod][\n", + " eval_bpidx(nmap)\n", + " ] |= BadPixels.NOISE_OUT_OF_THRESHOLD.value\n", + " nmap[badpixels_map[mod] > 0] = np.nan\n", + " recent_nbpix = np.count_nonzero(badpixels_map[mod])\n", + "\n", + " if last_nbpix == recent_nbpix:\n", + " # stop iterating if no more badpixels difference\n", + " break\n", + "\n", " if not local_output:\n", " for cell in [0, 1]:\n", " fig, ax = plt.subplots(figsize=(10, 5))\n",