diff --git a/notebooks/ePix/Correction_ePix_NBC.ipynb b/notebooks/ePix/Correction_ePix_NBC.ipynb index 563a1af8e52885b5b1b17533919cc8dcbc44f161..fbf437b79267e09f108e48f2265ec70d0a09c354 100644 --- a/notebooks/ePix/Correction_ePix_NBC.ipynb +++ b/notebooks/ePix/Correction_ePix_NBC.ipynb @@ -18,13 +18,12 @@ "ExecuteTime": { "end_time": "2018-12-06T15:54:23.218849Z", "start_time": "2018-12-06T15:54:23.166497Z" - }, - "collapsed": false + } }, "outputs": [], "source": [ "in_folder = \"/gpfs/exfel/exp/MID/201930/p900071/raw\" # input folder, required\n", - "out_folder = '/gpfs/exfel/data/user/xcal/test/' # output folder, required\n", + "out_folder = '/gpfs/exfel/data/scratch/karnem/test/' # output folder, required\n", "path_template = 'RAW-R{:04d}-{}-S{{:05d}}.h5' # the template to use to access data\n", "run = 466 # which run to read data from, required\n", "h5path = '/INSTRUMENT/{}/DET/RECEIVER:daqOutput/data/image' # path in the HDF5 file to images\n", @@ -50,6 +49,9 @@ "bias_voltage = 200 # bias voltage\n", "in_vacuum = False # detector operated in vacuum\n", "fix_temperature = 290. # fix temperature to this value\n", + "gain_photon_energy = 9.0 # Photon energy used for gain calibration\n", + "photon_energy = 8.0 # Photon energy to calibrate in number of photons, 0 for calibration in keV \n", + "no_relative_gain = False # do not do gain correction\n", "split_evt_primary_threshold = 7. # primary threshold for split event correction\n", "split_evt_secondary_threshold = 5. # secondary threshold for split event correction\n", "split_evt_mip_threshold = 1000. # minimum ionizing particle threshold\n", @@ -82,8 +84,7 @@ "ExecuteTime": { "end_time": "2018-12-06T15:54:23.455376Z", "start_time": "2018-12-06T15:54:23.413579Z" - }, - "collapsed": false + } }, "outputs": [], "source": [ @@ -129,7 +130,13 @@ "\n", "h5path = h5path.format(instance)\n", "h5path_t = h5path_t.format(instance)\n", - "h5path_cntrl = h5path_cntrl.format(instance)" + "h5path_cntrl = h5path_cntrl.format(instance)\n", + "\n", + "plot_unit = 'ADU'\n", + "if not no_relative_gain:\n", + " plot_unit = 'keV'\n", + " if photon_energy>0:\n", + " plot_unit = '$\\gamma$'" ] }, { @@ -139,8 +146,7 @@ "ExecuteTime": { "end_time": "2018-12-06T15:54:23.679069Z", "start_time": "2018-12-06T15:54:23.662821Z" - }, - "collapsed": false + } }, "outputs": [], "source": [ @@ -173,7 +179,6 @@ "end_time": "2018-12-06T15:54:23.913269Z", "start_time": "2018-12-06T15:54:23.868910Z" }, - "collapsed": false, "scrolled": true }, "outputs": [], @@ -213,8 +218,7 @@ "ExecuteTime": { "end_time": "2018-12-06T15:54:24.088948Z", "start_time": "2018-12-06T15:54:24.059925Z" - }, - "collapsed": true + } }, "outputs": [], "source": [ @@ -252,8 +256,7 @@ "ExecuteTime": { "end_time": "2018-12-06T18:43:39.776018Z", "start_time": "2018-12-06T18:43:39.759185Z" - }, - "collapsed": false + } }, "outputs": [], "source": [ @@ -283,8 +286,7 @@ "ExecuteTime": { "end_time": "2018-12-06T15:54:28.254544Z", "start_time": "2018-12-06T15:54:24.709521Z" - }, - "collapsed": false + } }, "outputs": [], "source": [ @@ -293,7 +295,7 @@ "offsetMap = None\n", "temp_limits = 5.\n", "\n", - "## offset\n", + "# Offset\n", "det = getattr(Detectors, db_module)\n", "dconstants = getattr(Constants, dclass)\n", "\n", @@ -315,17 +317,52 @@ " None,\n", " cal_db_interface,\n", " creation_time=creation_time,\n", + " print_once=2,\n", " timeout=cal_db_timeout)\n", "\n", - "\n", + "# Noise\n", "const_name = \"Noise\"\n", + "condition = Conditions.Dark.ePix100(bias_voltage=bias_voltage,\n", + " integration_time=integration_time,\n", + " temperature=temperature_k,\n", + " in_vacuum=in_vacuum)\n", + "\n", "noiseMap = get_constant_from_db(det,\n", " getattr(dconstants, const_name)(),\n", " condition,\n", " None,\n", " cal_db_interface,\n", " creation_time=creation_time,\n", - " timeout=cal_db_timeout)\n" + " print_once=2,\n", + " timeout=cal_db_timeout)\n", + "\n", + "# Gain\n", + "if not no_relative_gain:\n", + " const_name = \"RelativeGain\"\n", + " condition = Conditions.Illuminated.ePix100(photon_energy=gain_photon_energy,\n", + " bias_voltage=bias_voltage,\n", + " integration_time=integration_time,\n", + " temperature=temperature_k,\n", + " in_vacuum=in_vacuum)\n", + "\n", + " gainMap = get_constant_from_db(det,\n", + " getattr(dconstants, const_name)(),\n", + " condition,\n", + " None,\n", + " cal_db_interface,\n", + " creation_time=creation_time,\n", + " print_once=2,\n", + " timeout=cal_db_timeout)\n", + " \n", + " if gainMap is None:\n", + " print(\"Gain map requisted, but not found\")\n", + " print(\"No gain correction will be applied\")\n", + " no_relative_gain = True\n", + " plot_unit = 'ADU'\n", + " gainMap = np.ones(sensorSize, np.float32)\n", + "\n", + "else:\n", + " gainMap = np.ones(sensorSize, np.float32)\n" ] }, { @@ -335,8 +372,7 @@ "ExecuteTime": { "end_time": "2018-12-06T15:54:28.771629Z", "start_time": "2018-12-06T15:54:28.346051Z" - }, - "collapsed": true + } }, "outputs": [], "source": [ @@ -347,7 +383,17 @@ " nCells = memoryCells, \n", " cores=cpuCores, gains=None,\n", " blockSize=blockSize,\n", - " parallel=run_parallel)\n" + " parallel=run_parallel)\n", + "\n", + "gainCorrection = xcal.RelativeGainCorrection(\n", + " sensorSize, \n", + " 1. / gainMap[..., None],\n", + " nCells=memoryCells,\n", + " parallel=run_parallel,\n", + " cores=cpuCores,\n", + " blockSize=blockSize,\n", + " gains=None)\n", + "\n" ] }, { @@ -357,8 +403,7 @@ "ExecuteTime": { "end_time": "2018-12-06T16:08:51.886343Z", "start_time": "2018-12-06T16:08:51.842837Z" - }, - "collapsed": true + } }, "outputs": [], "source": [ @@ -386,21 +431,19 @@ "ExecuteTime": { "end_time": "2018-12-06T16:08:53.042555Z", "start_time": "2018-12-06T16:08:53.034522Z" - }, - "collapsed": true + } }, "outputs": [], "source": [ "histCalOffsetCor.debug()\n", - "offsetCorrection.debug()" + "offsetCorrection.debug()\n", + "gainCorrection.debug()" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "#************************Calculators************************#\n", @@ -446,9 +489,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "cmCorrection.debug()\n", @@ -464,8 +505,7 @@ "ExecuteTime": { "end_time": "2018-12-06T16:08:53.551111Z", "start_time": "2018-12-06T16:08:53.531064Z" - }, - "collapsed": true + } }, "outputs": [], "source": [ @@ -498,8 +538,7 @@ "ExecuteTime": { "end_time": "2018-12-06T16:10:55.917179Z", "start_time": "2018-12-06T16:09:01.603633Z" - }, - "collapsed": true + } }, "outputs": [], "source": [ @@ -525,6 +564,11 @@ " dtype=np.float32)\n", "\n", " data = offsetCorrection.correct(data.astype(np.float32)) #correct for the offset\n", + " if not no_relative_gain:\n", + " data = gainCorrection.correct(data.astype(np.float32)) #correct for the gain\n", + " if photon_energy>0:\n", + " data /= photon_energy\n", + " \n", " histCalOffsetCor.fill(data)\n", " ddset[...] = np.moveaxis(data, 2, 0)\n", " except Exception as e:\n", @@ -575,8 +619,7 @@ "ExecuteTime": { "end_time": "2018-12-06T16:13:12.889583Z", "start_time": "2018-12-06T16:13:11.122653Z" - }, - "collapsed": false + } }, "outputs": [], "source": [ @@ -614,7 +657,7 @@ " })\n", "\n", "\n", - "fig = xana.simplePlot(d, aspect=1, x_label='Energy(ADU)', \n", + "fig = xana.simplePlot(d, aspect=1, x_label='Energy({})'.format(plot_unit), \n", " y_label='Number of occurrences', figsize='2col',\n", " y_log=True, x_range=(-50,500),\n", " legend='top-center-frame-2col')" @@ -634,14 +677,13 @@ "ExecuteTime": { "end_time": "2018-12-06T16:11:08.317130Z", "start_time": "2018-12-06T16:11:05.788655Z" - }, - "collapsed": false + } }, "outputs": [], "source": [ "fig = xana.heatmapPlot(np.nanmedian(data, axis=2),\n", " x_label='Columns', y_label='Rows',\n", - " lut_label='Signal (ADU)',\n", + " lut_label='Signal ({})'.format(plot_unit),\n", " x_range=(0,y),\n", " y_range=(0,x), vmin=-50, vmax=50)" ] @@ -662,14 +704,13 @@ "ExecuteTime": { "end_time": "2018-12-06T16:11:10.908912Z", "start_time": "2018-12-06T16:11:08.318486Z" - }, - "collapsed": false + } }, "outputs": [], "source": [ "fig = xana.heatmapPlot(data[...,0],\n", " x_label='Columns', y_label='Rows',\n", - " lut_label='Signal (ADU)',\n", + " lut_label='Signal ({})'.format(plot_unit),\n", " x_range=(0,y),\n", " y_range=(0,x), vmin=-50, vmax=50)" ] @@ -677,9 +718,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [] } @@ -700,7 +739,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.6" + "version": "3.6.7" }, "latex_envs": { "LaTeX_envs_menu_present": true,