From 6d06707e1e0456108764e3afd9f13f79b0720e78 Mon Sep 17 00:00:00 2001 From: David Hammer <dhammer@mailbox.org> Date: Tue, 2 Mar 2021 10:02:12 +0100 Subject: [PATCH] Skipping thresholds, gain separation bp for fixed gain mode --- .../Characterize_AGIPD_Gain_Darks_NBC.ipynb | 76 +++++++++++-------- 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb index dfbeb5b60..58aaf3e52 100644 --- a/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb +++ b/notebooks/AGIPD/Characterize_AGIPD_Gain_Darks_NBC.ipynb @@ -462,11 +462,12 @@ "outputs": [], "source": [ "# Add a badpixel due to bad gain separation\n", - "for g in range(2):\n", - " # Bad pixels during bad gain separation.\n", - " # Fraction of pixels in the module with separation lower than \"thresholds_gain_sigma\".\n", - " bad_sep = (gain_g[qm][..., g+1] - gain_g[qm][..., g]) / np.sqrt(gainstd_g[qm][..., g+1]**2 + gainstd_g[qm][..., g]**2)\n", - " badpix_g[qm][...,g+1][(bad_sep)<thresholds_gain_sigma]|= BadPixels.GAIN_THRESHOLDING_ERROR.value" + "if not fixed_gain_mode:\n", + " for g in range(2):\n", + " # Bad pixels during bad gain separation.\n", + " # Fraction of pixels in the module with separation lower than \"thresholds_gain_sigma\".\n", + " bad_sep = (gain_g[qm][..., g+1] - gain_g[qm][..., g]) / np.sqrt(gainstd_g[qm][..., g+1]**2 + gainstd_g[qm][..., g]**2)\n", + " badpix_g[qm][...,g+1][(bad_sep)<thresholds_gain_sigma]|= BadPixels.GAIN_THRESHOLDING_ERROR.value" ] }, { @@ -482,13 +483,14 @@ "metadata": {}, "outputs": [], "source": [ - "thresholds_g = {}\n", - "for qm in gain_g.keys():\n", - " thresholds_g[qm] = np.zeros((gain_g[qm].shape[0], gain_g[qm].shape[1], gain_g[qm].shape[2], 5))\n", - " thresholds_g[qm][...,0] = (gain_g[qm][...,1]+gain_g[qm][...,0])/2\n", - " thresholds_g[qm][...,1] = (gain_g[qm][...,2]+gain_g[qm][...,1])/2\n", - " for i in range(3):\n", - " thresholds_g[qm][...,2+i] = gain_g[qm][...,i]" + "if not fixed_gain_mode:\n", + " thresholds_g = {}\n", + " for qm in gain_g.keys():\n", + " thresholds_g[qm] = np.zeros((gain_g[qm].shape[0], gain_g[qm].shape[1], gain_g[qm].shape[2], 5))\n", + " thresholds_g[qm][...,0] = (gain_g[qm][...,1]+gain_g[qm][...,0])/2\n", + " thresholds_g[qm][...,1] = (gain_g[qm][...,2]+gain_g[qm][...,1])/2\n", + " for i in range(3):\n", + " thresholds_g[qm][...,2+i] = gain_g[qm][...,i]" ] }, { @@ -503,9 +505,10 @@ " res[qm] = {\n", " 'Offset': offset_g[qm],\n", " 'Noise': noise_g[qm],\n", - " 'ThresholdsDark': thresholds_g[qm],\n", " 'BadPixelsDark': badpix_g[qm]\n", - " }" + " }\n", + " if not fixed_gain_mode:\n", + " res[qm]['ThresholdsDark'] = thresholds_g[qm]" ] }, { @@ -545,7 +548,10 @@ "outputs": [], "source": [ "# Retrieve existing constants for comparison\n", - "clist = [\"Offset\", \"Noise\", \"ThresholdsDark\", \"BadPixelsDark\"]\n", + "if fixed_gain_mode:\n", + " clist = [\"Offset\", \"Noise\", \"BadPixelsDark\"]\n", + "else:\n", + " clist = [\"Offset\", \"Noise\", \"ThresholdsDark\", \"BadPixelsDark\"]\n", "old_const = {}\n", "old_mdata = {}\n", "detinst = getattr(Detectors, dinstance)\n", @@ -776,19 +782,20 @@ "metadata": {}, "outputs": [], "source": [ - "# Plot only three gain threshold maps.\n", - "bp_thresh = OrderedDict()\n", - "for mod, con in badpix_g.items():\n", - " bp_thresh[mod] = np.zeros((con.shape[0], con.shape[1], con.shape[2], 5), dtype=con.dtype)\n", - " bp_thresh[mod][...,:2] = con[...,:2]\n", - " bp_thresh[mod][...,2:] = con\n", + "if not fixed_gain_mode:\n", + " # Plot only three gain threshold maps.\n", + " bp_thresh = OrderedDict()\n", + " for mod, con in badpix_g.items():\n", + " bp_thresh[mod] = np.zeros((con.shape[0], con.shape[1], con.shape[2], 5), dtype=con.dtype)\n", + " bp_thresh[mod][...,:2] = con[...,:2]\n", + " bp_thresh[mod][...,2:] = con\n", "\n", "\n", - "create_constant_overview(thresholds_g, \"Threshold (ADU)\", max_cells, 4000, 10000, 5,\n", - " badpixels=[bp_thresh, np.nan],\n", - " gmap=['HG-MG Threshold', 'MG-LG Threshold', 'High gain', 'Medium gain', 'low gain'],\n", - " marker=['d','d','','','']\n", - " )" + " create_constant_overview(thresholds_g, \"Threshold (ADU)\", max_cells, 4000, 10000, 5,\n", + " badpixels=[bp_thresh, np.nan],\n", + " gmap=['HG-MG Threshold', 'MG-LG Threshold', 'High gain', 'Medium gain', 'low gain'],\n", + " marker=['d','d','','','']\n", + " )" ] }, { @@ -883,14 +890,21 @@ " \"New constant\", \"Old constant \",\n", " \"New constant\", \"Old constant \"]\n", "\n", - "for const in ['Offset', 'Noise', 'ThresholdsDark']:\n", - " if const != 'ThresholdsDark':\n", - " table = [['','High gain', 'High gain', 'Medium gain', 'Medium gain', 'Low gain', 'Low gain']]\n", - " else:\n", + "if fixed_gain_mode:\n", + " constants = ['Offset', 'Noise']\n", + "else:\n", + " ['Offset', 'Noise', 'ThresholdsDark']\n", + "\n", + "for const in constants:\n", + " \n", + " if const == 'ThresholdsDark':\n", " table = [['','HG-MG threshold', 'HG-MG threshold', 'MG-LG threshold', 'MG-LG threshold']]\n", - " for qm in res.keys():\n", + " else: \n", + " table = [['','High gain', 'High gain', 'Medium gain', 'Medium gain', 'Low gain', 'Low gain']]\n", "\n", + " for qm in res.keys():\n", " data = np.copy(res[qm][const])\n", + " \n", " if const == 'ThresholdsDark':\n", " data[...,0][res[qm]['BadPixelsDark'][...,0]>0] = np.nan\n", " data[...,1][res[qm]['BadPixelsDark'][...,1]>0] = np.nan\n", -- GitLab