From 99202f8191d738ca5886339a2dc61aeaa44ad069 Mon Sep 17 00:00:00 2001
From: Kiana Setoodehnia <kiana.setoodehnia@xfel.eu>
Date: Fri, 9 Aug 2019 09:09:19 +0200
Subject: [PATCH] Dark notebook issues are fixed

---
 ...s_NewDAQ_FastCCD_NBC_New_Common_Mode.ipynb | 410 ++++++++++++------
 1 file changed, 275 insertions(+), 135 deletions(-)

diff --git a/notebooks/FastCCD/Characterize_Darks_NewDAQ_FastCCD_NBC_New_Common_Mode.ipynb b/notebooks/FastCCD/Characterize_Darks_NewDAQ_FastCCD_NBC_New_Common_Mode.ipynb
index 100155b07..f139d016b 100644
--- a/notebooks/FastCCD/Characterize_Darks_NewDAQ_FastCCD_NBC_New_Common_Mode.ipynb
+++ b/notebooks/FastCCD/Characterize_Darks_NewDAQ_FastCCD_NBC_New_Common_Mode.ipynb
@@ -6,7 +6,7 @@
    "source": [
     "# FastCCD Dark Characterization\n",
     "\n",
-    "Author: I. Klačková, S. Hauf, K. Setoodehnia and M. Cascella (Version 1.0)\n",
+    "Author: K. Setoodehnia, S. Hauf, M. Cascella and I. Klačková\n",
     "\n",
     "The following notebook provides dark image analysis of the FastCCD detector.\n",
     "\n",
@@ -55,10 +55,11 @@
     "temperature_k = 233 # This is only used in the case of a fixed temperature for the calibration database\n",
     "chunkSize = 100 # Number of images to read per chunk\n",
     "cpuCores = 40 # Specifies the number of running cpu cores\n",
-    "memoryCells = 1 # FastCCD has 1 memory cell\n",
     "commonModeAxis = 1 # Axis along which common mode will be calculated (0: along rows, 1: along columns)\n",
+    "ADU_to_electron = 6.1 # According to Table 6.1 of Ivana Klačková's master's thesis, for upper hemisphere: conversion gain\n",
+    "                      # is 1 ADU = 6.1e-, and for lower hemisphere: 1 ADU = 6.2e-\n",
     "run_parallel = True # For parallel computation \n",
-    "db_output = True # Output constants to the calibration database"
+    "db_output = False # Output constants to the calibration database"
    ]
   },
   {
@@ -91,6 +92,8 @@
     "import matplotlib.pyplot as plt\n",
     "%matplotlib inline\n",
     "import numpy as np\n",
+    "from lmfit.models import GaussianModel\n",
+    "from prettytable import PrettyTable\n",
     "\n",
     "from iCalibrationDB import ConstantMetaData, Constants, Conditions, Detectors, Versions\n",
     "from iCalibrationDB.detectors import DetectorTypes\n",
@@ -194,6 +197,7 @@
    },
    "outputs": [],
    "source": [
+    "memoryCells = 1 # FastCCD has 1 memory cell\n",
     "sensorSize = [x, y]\n",
     "blockSize = [sensorSize[0]//2, sensorSize[1]] # Sensor area will be analysed according to blocksize\n",
     "xcal.defaultBlockSize = blockSize\n",
@@ -339,7 +343,42 @@
    "source": [
     "### Plotting the Offset and Noise Maps prior to Common Mode Correction:\n",
     "\n",
-    "In the following cell, the histogram of the FastCCD offset, FastCCD offset map, as well as the initial uncorrected noise map are plotted:"
+    "In the following two cells, the histogram of the FastCCD offset, FastCCD offset map, as well as the initial uncorrected noise map are plotted. We are also fitting the offset histogram using a Gaussian function to derive the offset (in ADU) as the centroid of the histogram."
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "ExecuteTime": {
+     "end_time": "2018-12-06T10:56:20.686534Z",
+     "start_time": "2018-12-06T10:56:11.721829Z"
+    }
+   },
+   "outputs": [],
+   "source": [
+    "#**************OFFSET MAP HISTOGRAM***********#\n",
+    "ho,co = np.histogram(offsetMap.flatten(), bins=700) # ho = offset histogram; co = offset bin centers\n",
+    "\n",
+    "# Fitting the offset histogram using a Gaussian function:\n",
+    "# Fitting model and its initial parameters:\n",
+    "model = GaussianModel()\n",
+    "params = model.make_params(amplitude=100000, center=3706, sigma=107) \n",
+    "# Best fit result with chi^2-minimization method given as the least-squares method:\n",
+    "result = model.fit(ho, params, x=co[:-1], method='leastsq')\n",
+    "# Resulting plot:\n",
+    "plt.errorbar(co[:-1], ho, yerr=np.sqrt(ho[:]), color='navy', drawstyle = 'steps', label='Uncorrected Signal') \n",
+    "plt.plot(co[:-1], result.best_fit, color='red', label='Best Fit') \n",
+    "plt.rcParams[\"figure.figsize\"] = (20,10)\n",
+    "plt.ylabel('Counts')\n",
+    "plt.xlabel('Raw Signal (ADU)')\n",
+    "plt.title('Offset Histogram')\n",
+    "plt.xlim(3300,4100)\n",
+    "plt.legend(loc='upper right')\n",
+    "plt.show()\n",
+    "print('Center is the offset in ADU:')\n",
+    "result.params\n",
+    "#fig.savefig('RawOffset_Hist.svg', format='svg', dpi=1200, bbox_inches='tight')"
    ]
   },
   {
@@ -354,21 +393,7 @@
    },
    "outputs": [],
    "source": [
-    "#**************OFFSET MAP HISTOGRAM***********#\n",
-    "ho,co = np.histogram(offsetMap.flatten(), bins=700)\n",
-    "\n",
-    "do = {'x': co[:-1],\n",
-    "     'y': ho,\n",
-    "     'y_err': np.sqrt(ho[:]),\n",
-    "     'drawstyle': 'bars',\n",
-    "     'color': 'cornflowerblue',\n",
-    "     }\n",
-    "\n",
-    "fig = xana.simplePlot(do, figsize='1col', aspect=1, x_label = 'Raw Signal (ADU)', y_label=\"Counts\", y_log=False, \n",
-    "                      x_range=(3400, 4000), y_range=(0,105000), title = 'Offset Histogram')\n",
-    "#fig.savefig('RawOffset_Hist.svg', format='svg', dpi=1200, bbox_inches='tight')\n",
-    "\n",
-    "#**************HEAT MAPS*******************#\n",
+    "#**************OffsetMAP*******************#\n",
     "fig = xana.heatmapPlot(offsetMap[:,:,0], x_label='Column Number', y_label='Row Number',  aspect=1,\n",
     "                       x_range=(0,y), y_range=(0,x), vmin=3000, vmax=4300, lut_label='Offset (ADU)', \n",
     "                       panel_x_label='Columns Stat (ADU)', panel_y_label='Rows Stat (ADU)', \n",
@@ -376,6 +401,7 @@
     "                       panel_side_high_lim = 5000, title = 'OffsetMap')\n",
     "#fig.savefig('RawOffsetMap.pdf', format='pdf', dpi=400, bbox_inches='tight')\n",
     "\n",
+    "#**************Raw NoiseMAP*******************#\n",
     "fig = xana.heatmapPlot(noiseMap[:,:,0], x_label='Column Number', y_label='Row Number', aspect=1,\n",
     "                       lut_label='Uncorrected Noise (ADU)', x_range=(0,y),\n",
     "                       y_range=(0,x), vmax=2*np.mean(noiseMap), panel_x_label='Columns Stat (ADU)', \n",
@@ -435,13 +461,8 @@
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "### Second Iteration"
-   ]
-  },
-  {
-   "cell_type": "markdown",
-   "metadata": {},
-   "source": [
+    "### Second Iteration:\n",
+    "\n",
     "During the second iteration, the data are offset corrected and then common mode corrected to produced a common mode corrected noise map. The common mode correction is calculated by subtracting out the median of all pixels that are read out at the same time along a row."
    ]
   },
@@ -469,13 +490,87 @@
     "print(\"Offset and common mode corrections are applied.\")"
    ]
   },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# I am copying these so that I can replot them later after the calculators are reset:\n",
+    "\n",
+    "ho_second_trial = copy.copy(ho)\n",
+    "co_second_trial = copy.copy(co)\n",
+    "hCM_second_trial = copy.copy(hCM)\n",
+    "cCM_second_trial = copy.copy(cCM)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "### Signal after Offset and Common Mode Corrections:\n",
+    "\n",
+    "The cells below compares the offset corrected signal with the common-mode corrected signal (in the form of binned histograms). Both data are fitted using Gaussian functions and the fit results are shown in tabular format: "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Fitting the histogram of corrected signal using a Gaussian function:\n",
+    "# Fitting individual models:\n",
+    "gauss_mod_1 = GaussianModel(prefix='offset_corr_') # Offset corrected data\n",
+    "gauss_mod_2 = GaussianModel(prefix='cm_corr_') # Common mode corrected data\n",
+    "\n",
+    "# Initial parameters:\n",
+    "params_1 = gauss_mod_1.make_params(offset_corr_amplitude=3.7e7, offset_corr_center=0, offset_corr_sigma=3) \n",
+    "params_2 = gauss_mod_2.make_params(cm_corr_amplitude=4.5e7, cm_corr_center=0, cm_corr_sigma=3)\n",
+    "# Best fit result with chi^2-minimization method given as the least-squares method:\n",
+    "result = gauss_mod_1.fit(ho, params_1, x=co, method='leastsq')\n",
+    "result_cm = gauss_mod_2.fit(hCM, params_2, x=cCM, method='leastsq')\n",
+    "# Resulting plot:\n",
+    "plt.errorbar(co, ho, yerr=np.sqrt(ho[:]), drawstyle = 'steps', label='Offset Corrected Signal') \n",
+    "plt.plot(co, result.best_fit, label='Best Fit for Offset Corrected Signal') \n",
+    "plt.errorbar(cCM, hCM, yerr=np.sqrt(hCM[:]), drawstyle = 'steps', label='Common Mode Corrected Signal') \n",
+    "plt.plot(co, result_cm.best_fit, label='Best Fit for Common Mode Corrected Signal') \n",
+    "plt.rcParams[\"figure.figsize\"] = (20,10)\n",
+    "plt.ylabel('Counts')\n",
+    "plt.xlabel('Corrected Signal (ADU)')\n",
+    "plt.title('Signal (and Fits) after Corrections')\n",
+    "plt.xlim(-15,15)\n",
+    "plt.legend(loc='upper right')\n",
+    "plt.show()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "display(Markdown('#### Offset Corrected Signal Fit Results:'))\n",
+    "result.params"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "display(Markdown('#### Common Mode Corrected Signal Fit Results:'))\n",
+    "result_cm.params"
+   ]
+  },
   {
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "### Plotting the Noise Map after Common Mode Correction:\n",
+    "### The Noise Map after Common Mode Correction:\n",
     "\n",
-    "In the following cell, the offset and common mode corrected signal from FastCCD is shown in the form of binned histogram. Also shown is the effect of common mode correction on the noise. Finally common mode corrected noise map (noiseMapCM) is displayed and compared to the initial uncorrected noise map:"
+    "In the following cell, the effect of common mode correction on the noise is shown. Finally common mode corrected noise map (noiseMapCM) is displayed and compared to the initial uncorrected noise map:"
    ]
   },
   {
@@ -486,32 +581,8 @@
    },
    "outputs": [],
    "source": [
-    "d = [{'x': co,\n",
-    "     'y': ho,\n",
-    "     'y_err': np.sqrt(ho[:]),\n",
-    "     'drawstyle': 'steps-mid',\n",
-    "     'color': 'blue',#'cornflowerblue',\n",
-    "     'errorstyle': 'bars',\n",
-    "     'label': 'After Offset Correction' \n",
-    "     },\n",
-    "    {'x': cCM,\n",
-    "     'y': hCM,\n",
-    "     'y_err': np.sqrt(hCM[:]),\n",
-    "     'drawstyle': 'steps-mid',\n",
-    "     'color': 'crimson',\n",
-    "     'errorstyle': 'bars',\n",
-    "     'ecolor': 'crimson',\n",
-    "     'label': 'After Common Mode Correction'\n",
-    "     }]\n",
-    "\n",
-    "fig = xana.simplePlot(d, figsize='2col', aspect=1, x_label = 'Corrected Signal (ADU)', y_label=\"Counts\", \n",
-    "                      x_range=(-20,20), y_range=(0,5e7), y_log=False, legend='top-center-frame-1col', \n",
-    "                      title = 'Signal after Corrections')\n",
-    "                      \n",
-    "#fig.savefig('FirstTrialCorrections.svg', format='svg', dpi=1200, bbox_inches='tight') \n",
-    "\n",
     "#*****NOISE MAP HISTOGRAM FROM THE COMMON MODE CORRECTED DATA*******#\n",
-    "hn,cn = np.histogram(noiseMap.flatten(), bins=200, range=(2,40))\n",
+    "hn,cn = np.histogram(noiseMap.flatten(), bins=200, range=(2,40)) # hn: histogram of noise, cn: bin centers for noise\n",
     "hn_CM,cn_CM = np.histogram(noiseMapCM.flatten(), bins=200, range=(2,40))\n",
     "\n",
     "dn = [{'x': cn[:-1],\n",
@@ -561,7 +632,7 @@
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "## BadPixelMap:\n",
+    "### BadPixelMap:\n",
     "This is generated based on the offset and CM corrected noise maps:"
    ]
   },
@@ -715,41 +786,132 @@
    "source": [
     "### Plotting the Final Results:\n",
     "\n",
-    "In the following cell, the offset and common mode corrected signal after exclusion of bad pixels from the data is shown in the form of binned histogram. Also shown is the effect of exclusion of bad pixels on common mode corrected noise. Finally common mode corrected noise map with bad pixels excluded (noiseMapCM_2nd) is displayed:"
+    "The following plot compares the offset and common mode corrected signal with and without the bad pixels:"
    ]
   },
   {
    "cell_type": "code",
    "execution_count": null,
-   "metadata": {
-    "scrolled": false
-   },
+   "metadata": {},
    "outputs": [],
    "source": [
-    "d2 = [{'x': co2,\n",
+    "do_Final = [{'x': co_second_trial,\n",
+    "     'y': ho_second_trial,\n",
+    "     'y_err': np.sqrt(ho_second_trial[:]),\n",
+    "     'drawstyle': 'steps-mid',\n",
+    "     'color': 'blue',#'cornflowerblue',\n",
+    "     'errorstyle': 'bars',\n",
+    "     'label': 'Offset Corrected Signal, Bad Pixels Included - 2nd Trial'\n",
+    "     },\n",
+    "    {'x': cCM_second_trial,\n",
+    "     'y': hCM_second_trial,\n",
+    "     'y_err': np.sqrt(hCM_second_trial[:]),\n",
+    "     'drawstyle': 'steps-mid',\n",
+    "     'color': 'red',\n",
+    "     'errorstyle': 'bars',\n",
+    "     'ecolor': 'crimson',\n",
+    "     'label': 'Common Mode Corrected Signal, Bad Pixels Included - 2nd Trial' \n",
+    "     },\n",
+    "    {'x': co2,\n",
     "     'y': ho2,\n",
     "     'y_err': np.sqrt(ho2[:]),\n",
     "     'drawstyle': 'steps-mid',\n",
-    "     'color': 'blue',#'cornflowerblue',\n",
+    "     'color': 'black', #'cornflowerblue',\n",
     "     'errorstyle': 'bars',\n",
-    "     'label': 'After Offset Correction' \n",
+    "     'label': 'Offset Corrected Signal, Bad Pixels Excluded - 3rd Trial'\n",
     "     },\n",
-    "     {'x': cCM2,\n",
+    "    {'x': cCM2,\n",
     "     'y': hCM2,\n",
     "     'y_err': np.sqrt(hCM2[:]),\n",
     "     'drawstyle': 'steps-mid',\n",
-    "     'color': 'red',\n",
+    "     'color': 'green', #'cornflowerblue',\n",
     "     'errorstyle': 'bars',\n",
-    "     'ecolor': 'crimson',\n",
-    "     'label': 'After Common Mode Correction'\n",
+    "     'label': 'Common Mode Corrected Signal, Bad Pixels Excluded - 3rd Trial'\n",
     "     }]\n",
     "\n",
-    "fig = xana.simplePlot(d2, figsize='2col', aspect=1, x_label = 'Final Corrected Signal (ADU)', \n",
-    "                      y_label=\"Counts\", x_range=(-20,20), y_range=(0,5e7), y_log=False, \n",
-    "                      legend='top-right-frame-1col', title = 'Corrected Signal after Exclusion of Bad Pixels')\n",
-    "                    \n",
-    "#fig.savefig('Correction_2.svg', format='svg', dpi=1200, bbox_inches='tight') \n",
+    "fig = xana.simplePlot(do_Final, figsize='2col', aspect=1, x_label = 'Corrected Signal (ADU)', \n",
+    "                      y_label=\"Counts (Logarithmic Scale)\", y_log=True, x_range=(-40,40), legend='bottom-left-frame-1col',\n",
+    "                      title = 'Comparison of Corrected Signal')"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "In the following few cells, the offset and common mode corrected signal after exclusion of bad pixels from the data is shown in the form of binned histogram. These data are fitted using Gaussian functions and the fit results are displayed in tabular format:"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Fitting the histogram of corrected data using a Gaussian function:\n",
+    "# Fitting individual models:\n",
+    "gauss_mod_1 = GaussianModel(prefix='offset_corr_')\n",
+    "gauss_mod_2 = GaussianModel(prefix='cm_corr_')\n",
+    "\n",
+    "# Initial parameters:\n",
+    "params_1 = gauss_mod_1.make_params(offset_corr_amplitude=3.7e7, offset_corr_center=0, offset_corr_sigma=3) \n",
+    "params_2 = gauss_mod_2.make_params(cm_corr_amplitude=4.5e7, cm_corr_center=0, cm_corr_sigma=3)\n",
+    "\n",
+    "\n",
+    "# Best fit result with chi^2-minimization method given as the least-squares method:\n",
+    "result = gauss_mod_1.fit(ho2, params_1, x=co2, method='leastsq')\n",
+    "result_cm = gauss_mod_2.fit(hCM2, params_2, x=cCM2, method='leastsq')\n",
+    "\n",
+    "# Resulting plot:\n",
+    "plt.errorbar(co2, ho2, yerr=np.sqrt(ho2[:]), drawstyle = 'steps', label='Offset Corrected Signal - 3rd Trial') \n",
+    "plt.plot(co, result.best_fit, label='Best Fit for Offset Corrected Signal - 3rd Trial') \n",
+    "plt.errorbar(cCM2, hCM2, yerr=np.sqrt(hCM2[:]), drawstyle = 'steps', label='Common Mode Corrected Signal - 3rd Trial') \n",
+    "plt.plot(co, result_cm.best_fit, label='Best Fit for Common Mode Corrected Signal - 3rd Trial')\n",
+    "plt.rcParams[\"figure.figsize\"] = (20,10)\n",
+    "plt.ylabel('Counts')\n",
+    "plt.xlabel('Final Corrected Signal (ADU)')\n",
+    "plt.title('Corrected Signal (ADU) and Fits after Exclusion of Bad Pixels')\n",
+    "plt.xlim(-15,15)\n",
+    "plt.legend(loc='upper right')\n",
+    "plt.show()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "display(Markdown('#### Offset Corrected Signal Final Fit Results:'))\n",
+    "result.params"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "display(Markdown('#### Common Mode Corrected Signal Final Fit Results:'))\n",
+    "result_cm.params"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "### Plotting the Final NoiseMap:\n",
     "\n",
+    "The effect of exclusion of bad pixels on common mode corrected noise is shown below. Finally common mode corrected noise map with bad pixels excluded (noiseMapCM_2nd) is displayed:"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {
+    "scrolled": false
+   },
+   "outputs": [],
+   "source": [
     "#*****NOISE MAP HISTOGRAM FROM THE COMMON MODE CORRECTED DATA*******#\n",
     "hn_CM2,cn_CM2 = np.histogram(noiseMapCM_2nd.flatten(), bins=200, range=(2,40))\n",
     "\n",
@@ -776,10 +938,8 @@
     "     'label': 'Common Mode Corrected Noise after Bad Pixels Exclusion'\n",
     "     }]\n",
     "\n",
-    "fig = xana.simplePlot(dn2, figsize='2col', \n",
-    "                      x_label = 'Noise (ADU)', \n",
-    "                      y_label=\"Counts\", y_log=True, x_range=(0,40), y_range=(0,1e6), legend='top-right-frame-1col',\n",
-    "                      title = 'Final Noise Comparison')\n",
+    "fig = xana.simplePlot(dn2, figsize='2col', aspect = 1, x_label = 'Noise (ADU)', y_label=\"Counts\", y_log=True, \n",
+    "                      x_range=(0,40), y_range=(0,1e6), legend='top-right-frame-1col', title = 'Final Noise Comparison')\n",
     "\n",
     "#fig.savefig('Noise_Hist_2.svg', format='svg', dpi=1200, bbox_inches='tight') \n",
     "\n",
@@ -838,71 +998,41 @@
    ]
   },
   {
-   "cell_type": "code",
-   "execution_count": null,
+   "cell_type": "markdown",
    "metadata": {},
-   "outputs": [],
    "source": [
-    "#**************RMS CALCULATION*******************#\n",
-    "\n",
-    "display(Markdown('## Noise (ADU) Comparison:'))\n",
-    "display(Markdown('### Initial non-corrected noise:'))\n",
-    "rms = np.mean(noiseMap)*6.1\n",
-    "stdRms = np.std(noiseMap)*6.1\n",
-    "print(\"RMS noise for entire detector = {:0.2f} ADU\".format(rms/6.1), \"= {:0.2f} e\".format(rms))\n",
-    "print('standard deviation of rms (entire detector) = {:0.2f} e'.format(stdRms))\n",
-    "\n",
-    "# lower hemisphere:\n",
-    "rms = np.mean(noiseMap[:x//2,:])*6.1\n",
-    "stdRms = np.std(noiseMap[:x//2,:])*6.1\n",
-    "print(\"RMS noise for lower hemisphere = {:0.2f} ADU\".format(rms/6.1), \"= {:0.2f} e\".format(rms))\n",
-    "print('standard deviation of rms (LH) = {:0.2f} e'.format(stdRms))\n",
-    "\n",
-    "# upper hemishere:\n",
-    "rms = np.mean(noiseMap[x//2:,:])*6.1\n",
-    "stdRms = np.std(noiseMap[x//2:,:])*6.1\n",
-    "print(\"RMS noise for upper hemisphere = {:0.2f} ADU\".format(rms/6.1), \"= {:0.2f} e\".format(rms))\n",
-    "print('standard deviation of rms (UH) = {:0.2f} e'.format(stdRms))\n",
+    "### Electronic Noise:\n",
     "\n",
-    "display(Markdown('### Common mode corrected noise without exlusion of bad pixels:'))\n",
+    "According to Ivana Klačková's master's thesis: \"The electronic noise is determined by the Root Mean Square (RMS) value of system noise in electrons, and the FWHM of noise is defined as: FWHM_Noise = 2.355 x *epsilon* x RMS, where *epsilon* is the mean energy needed to create an electron-hole pair.\"\n",
     "\n",
-    "# all:\n",
-    "rms = np.mean(noiseMapCM)*6.1\n",
-    "stdRms = np.std(noiseMapCM)*6.1\n",
-    "print(\"RMS noise for entire detector = {:0.2f} ADU\".format(rms/6.1), \"= {:0.2f} e\".format(rms))\n",
-    "print('standard deviation of rms (entire detector) = {:0.2f} e'.format(stdRms))\n",
+    "She also mentions in her thesis (Table 6.1, page 80) that: \"Conversion gain for lower hemisphere = 6.2e-/ADU and for upper hemisphere, the conversion gain = 6.1e-/ADU.\"\n",
     "\n",
-    "# lower hemisphere:\n",
-    "rms = np.mean(noiseMapCM[:x//2,:])*6.1\n",
-    "stdRms = np.std(noiseMapCM[:x//2,:])*6.1\n",
-    "print(\"RMS noise for lower hemisphere = {:0.2f} ADU\".format(rms/6.1), \"= {:0.2f} e\".format(rms))\n",
-    "print('standard deviation of rms (LH) = {:0.2f} e'.format(stdRms))\n",
-    "\n",
-    "# upper hemishere:\n",
-    "rms = np.mean(noiseMapCM[x//2:,:])*6.1\n",
-    "stdRms = np.std(noiseMapCM[x//2:,:])*6.1\n",
-    "print(\"RMS noise for upper hemisphere  = {:0.2f} ADU\".format(rms/6.1), \"= {:0.2f} e\".format(rms))\n",
-    "print('standard deviation of rms (UH) = {:0.2f} e'.format(stdRms))\n",
-    "\n",
-    "display(Markdown('### Common mode corrected noise with exlusion of bad pixels:'))\n",
-    "\n",
-    "# all:\n",
-    "rms = np.mean(noiseMapCM_2nd)*6.1\n",
-    "stdRms = np.std(noiseMapCM_2nd)*6.1\n",
-    "print(\"RMS noise for entire detector = {:0.2f} ADU\".format(rms/6.1), \"= {:0.2f} e\".format(rms))\n",
-    "print('standard deviation of rms (entire detector) = {:0.2f} e'.format(stdRms))\n",
-    "\n",
-    "# lower hemisphere:\n",
-    "rms = np.mean(noiseMapCM_2nd[:x//2,:])*6.1\n",
-    "stdRms = np.std(noiseMapCM_2nd[:x//2,:])*6.1\n",
-    "print(\"RMS noise for lower hemisphere = {:0.2f} ADU\".format(rms/6.1), \"= {:0.2f} e\".format(rms))\n",
-    "print('standard deviation of rms (LH) = {:0.2f} e'.format(stdRms))\n",
-    "\n",
-    "# upper hemishere:\n",
-    "rms = np.mean(noiseMapCM_2nd[x//2:,:])*6.1\n",
-    "stdRms = np.std(noiseMapCM_2nd[x//2:,:])*6.1\n",
-    "print(\"RMS noise for upper hemisphere = {:0.2f} ADU\".format(rms/6.1), \"= {:0.2f} e\".format(rms))\n",
-    "print('standard deviation of rms (UH) = {:0.2f} e'.format(stdRms))"
+    "The following cell presents the noise at different steps along lower hemisphere, upper hemisphere, and the entire FastCCD detector. Here, the values in ADU are the mean of noise per pixel, and the values in e- (electrons) are the standard deviation of noise per pixel. Also, noiseMap refers to the initial uncorrected noise, noiseMapCM  refers to common mode corrected noise with inclusion of bad pixels, and noiseMapCM_2nd refers to common mode corrected noise without inclusion of bad pixels:"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "t0 = PrettyTable()\n",
+    "t0.title = \"Comparison of Means of Noise per Pixel\"\n",
+    "t0.field_names = [\"Initial Uncorrected Noise\",\"CM Corrected Noise, Bad Pixels Incl.\", \"CM Corrected Noise, No Bad Pixels\"]\n",
+    "t0.add_row([\"Entire Detector: {:0.2f} ADU = {:0.2f} e-\".format(np.mean(noiseMap),np.mean(noiseMap)*ADU_to_electron), \"Entire Detector: {:0.2f} ADU = {:0.2f} e-\".format(np.mean(noiseMapCM), np.mean(noiseMapCM)*ADU_to_electron), \"Entire Detector: {:0.2f} ADU = {:0.2f} e-\".format(np.mean(noiseMapCM_2nd), np.mean(noiseMapCM_2nd)*ADU_to_electron)])\n",
+    "t0.add_row([\"Lower Hemisphere: {:0.2f} ADU = {:0.2f} e-\".format(np.mean(noiseMap[:x//2,:]), np.mean(noiseMap[:x//2,:])*ADU_to_electron), \"Lower Hemisphere: {:0.2f} ADU = {:0.2f} e-\".format(np.mean(noiseMapCM[:x//2,:]), np.mean(noiseMapCM[:x//2,:])*ADU_to_electron), \"Lower Hemisphere: {:0.2f} ADU = {:0.2f} e-\".format(np.mean(noiseMapCM_2nd[:x//2,:]), np.mean(noiseMapCM_2nd[:x//2\n",
+    ",:])*ADU_to_electron)])\n",
+    "t0.add_row([\"Upper Hemisphere: {:0.2f} ADU = {:0.2f} e-\".format(np.mean(noiseMap[x//2:,:]), np.mean(noiseMap[x//2:,:])*ADU_to_electron), \"Upper Hemisphere: {:0.2f} ADU = {:0.2f} e-\".format(np.mean(noiseMapCM[x//2:,:]), np.mean(noiseMapCM[x//2:,:])*ADU_to_electron), \"Upper Hemisphere: {:0.2f} ADU = {:0.2f} e-\".format(np.mean(noiseMapCM_2nd[x//2:,:]), np.mean(noiseMapCM_2nd[x//2:,:])*ADU_to_electron)])\n",
+    "print(t0,'\\n')\n",
+    "\n",
+    "t1 = PrettyTable()\n",
+    "t1.title = \"Comparison of Standard Deviations of Noise per Pixel\"\n",
+    "t1.field_names = [\"Initial Uncorrected Noise\",\"CM Corrected Noise, Bad Pixels Included\", \"CM Corrected Noise, No Bad Pixels\"]\n",
+    "t1.add_row([\"Entire Detector: {:0.2f} e-\".format(np.std(noiseMap)*ADU_to_electron), \"Entire Detector: {:0.2f} e-\".format(np.std(noiseMapCM)*ADU_to_electron), \"Entire Detector: {:0.2f} e-\".format(np.std(noiseMapCM_2nd)*ADU_to_electron)])\n",
+    "t1.add_row([\"Lower Hemisphere: {:0.2f} e-\".format(np.std(noiseMap[:x//2,:])*ADU_to_electron), \"Lower Hemisphere: {:0.2f} e-\".format(np.std(noiseMapCM[:x//2,:])*ADU_to_electron), \"Lower Hemisphere: {:0.2f} e-\".format(np.std(noiseMapCM_2nd[:x//2\n",
+    ",:])*ADU_to_electron)])\n",
+    "t1.add_row([\"Upper Hemisphere: {:0.2f} e-\".format(np.std(noiseMap[x//2:,:])*ADU_to_electron), \"Upper Hemisphere: {:0.2f} e-\".format(np.std(noiseMapCM[x//2:,:])*ADU_to_electron), \"Upper Hemisphere: {:0.2f} e-\".format(np.std(noiseMapCM_2nd[x//2:,:])*ADU_to_electron)])\n",
+    "print(t1)"
    ]
   },
   {
@@ -951,8 +1081,18 @@
     "        metadata.calibration_constant_version = Versions.Timespan(device=device, start=creation_time)\n",
     "    \n",
     "    if db_output:\n",
-    "        metadata.send(cal_db_interface, timeout=cal_db_timeout)    "
+    "        metadata.send(cal_db_interface, timeout=cal_db_timeout)    \n",
+    "        \n",
+    "print(\"Calibration constants (Offset, Noise and BadPixelsDark) are sent to the calibration database.\")\n",
+    "print(\"Creation time is: {}\".format(creation_time))"
    ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
   }
  ],
  "metadata": {
-- 
GitLab