From 73ef8b0db19d9bd5315299aed107596b2b00bf84 Mon Sep 17 00:00:00 2001 From: ahmedk <karim.ahmed@xfel.eu> Date: Mon, 8 Jan 2024 12:53:02 +0100 Subject: [PATCH] remove gainCal_JF_Fit_sendDB_NBC after moving the code to creat_gain_map NB --- .../Jungfrau/gainCal_JF_Fit_sendDB_NBC.ipynb | 302 ------------------ 1 file changed, 302 deletions(-) delete mode 100755 notebooks/Jungfrau/gainCal_JF_Fit_sendDB_NBC.ipynb diff --git a/notebooks/Jungfrau/gainCal_JF_Fit_sendDB_NBC.ipynb b/notebooks/Jungfrau/gainCal_JF_Fit_sendDB_NBC.ipynb deleted file mode 100755 index b0f3f6d30..000000000 --- a/notebooks/Jungfrau/gainCal_JF_Fit_sendDB_NBC.ipynb +++ /dev/null @@ -1,302 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Send constants from file to the DB" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "in_folder = '/gpfs/exfel/exp/MID/202330/p900322/raw'\n", - "g_map_old_dir = '/gpfs/exfel/data/user/mramilli/jungfrau/module_PSI_gainmaps/M302'\n", - "gain_map_file = '/gainMaps_M109_Burst_Fix_20230523.h5' # path\n", - "out_folder = \"/gpfs/exfel/data/scratch/ahmedk/test/jf_ff/gain_maps\"\n", - "metadata_folder = '' # Directory containing calibration_metadata.yml when run by xfel-calibrate\n", - "\n", - "g0_runs = [94]\n", - "\n", - "# Detector module parameters.\n", - "karabo_id = 'MID_EXP_JF500K2'\n", - "karabo_da = ['JNGFR02']\n", - "\n", - "# Parameter conditions\n", - "bias_voltage = -1 # detector bias voltage\n", - "integration_time = -1 # the detector acquisition rate, use 0 to try to auto-determine\n", - "gain_setting = 0\n", - "gain_mode = 0\n", - "memory_cells = -1 # number of memory cells used, use 0 to auto-derive\n", - "\n", - "# Condition limits\n", - "bias_voltage_lims = [0, 200]\n", - "integration_time_lims = [0.1, 1000]\n", - "\n", - "gain_map_name = 'gain_map_g0'\n", - "db_output = False\n", - "send_bpix = False\n", - "\n", - "# CALCAT API parameters\n", - "cal_db_interface = \"tcp://max-exfl-cal-001:8020\" # the database interface to use\n", - "creation_time = \"\" # To overwrite the measured creation_time. Required Format: YYYY-MM-DD HR:MN:SC e.g. \"2022-06-28 13:00:00\"\\\n", - "cal_db_timeout = 180000" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# imports, usually no need to change anything here\n", - "from pathlib import Path\n", - "\n", - "import dateutil.parser\n", - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", - "from h5py import File as h5file\n", - "from iCalibrationDB import Conditions, Constants\n", - "from XFELDetAna.plotting.heatmap import heatmapPlot\n", - "\n", - "from cal_tools.calcat_interface import CalCatApi\n", - "from cal_tools.restful_config import calibration_client\n", - "from cal_tools.tools import calcat_creation_time, get_report, send_to_db\n", - "\n", - "%matplotlib inline" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "if gain_setting == 1:\n", - " gain_map_name = 'gain_map_hg0'\n", - "da_name = karabo_da[0]\n", - "g_map_old_dir = Path(g_map_old_dir)\n", - "in_folder = Path(in_folder)\n", - "out_folder = Path(out_folder)\n", - "gain_file = g_map_old_dir / gain_map_file\n", - "g0_run = g0_runs[0]\n", - "\n", - "# Run's creation time:\n", - "creation_time = calcat_creation_time(in_folder, g0_run, creation_time)\n", - "print(f\"Creation time: {creation_time}\")\n", - "\n", - "calcat_client = calibration_client()\n", - "calcat = CalCatApi(client=calcat_client)\n", - "\n", - "# Look up PDUs\n", - "detector_id = calcat.detector(karabo_id)['id']\n", - "pdus_by_da = calcat.physical_detector_units(\n", - " detector_id, pdu_snapshot_at=creation_time)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Read constants from file\n", - "constant_data = {}\n", - "\n", - "gain_map = None\n", - "bad_pixel_ff = None\n", - "pdu = pdus_by_da[da_name][\"physical_name\"]\n", - "with h5file(out_folder / f\"const_RelativeGain_{pdu}.h5\", 'r') as f:\n", - " gain_map = np.array(f[\"data\"])\n", - " \n", - " if memory_cells < 0:\n", - " memory_cells = int(gain_map.shape[-2])\n", - " # memory_cells = int(f[\"condition\"][\"Memory cells\"][\"value\"][()])\n", - " print(f'Memory Cells: {memory_cells}')\n", - "\n", - " if 'bad_pixel_fit' in f.keys():\n", - " bad_pixel_ff = np.array(f['bad_pixel_fit'])\n", - " print(bad_pixel_ff.shape)\n", - " else:\n", - " print('BadPixelsFF not found')\n", - " \n", - " if integration_time < 0:\n", - " integration_time = np.float32(f[\"condition\"][\"Integration Time\"][\"value\"][()])\n", - " print(f'Integration time: {integration_time} us')\n", - " else:\n", - " print(f'Using manual set integration_time {integration_time} us')\n", - "\n", - " if bias_voltage < 0:\n", - " bias_voltage = np.float32(f[\"condition\"][\"Sensor Bias Voltage\"][\"value\"][()])\n", - " print(f'Bias voltage: {bias_voltage} V')\n", - " else:\n", - " print(f'Using manual set bias_voltage: {bias_voltage} V')\n", - "\n", - " if 'creation_time' in f.keys():\n", - " creation_time = f['creation_time'][()].decode('utf-8')\n", - " creation_time = dateutil.parser.isoparse(creation_time)\n", - " print(f'Creation Time: {creation_time}')\n", - " else:\n", - " print(f'Using this date: {creation_time}')\n", - "\n", - " if 'file_loc' in f.keys():\n", - " file_loc = f['file_loc'][()].decode('utf-8')\n", - " print(f'file_loc: {file_loc}')\n", - " else:\n", - " proposal = list(filter(None, in_folder.strip('/').split('/')))[-2]\n", - " file_loc = f\"proposal:{proposal} runs:{g0_run}\"\n", - " print(f'Using this file_loc: {file_loc}')\n", - "\n", - " if 'report_path' in f.keys():\n", - " report_path = f['report_path'][()].decode('utf-8')\n", - " print(f'report_path: {report_path}')\n", - " else:\n", - " report_path = get_report(metadata_folder)\n", - " print(f'Using this report_path: {report_path}')\n", - " # if 'karabo_id' in f.attrs.keys():\n", - " # if isinstance(f.attrs['karabo_id'], str):\n", - " # karabo_id = str(f.attrs['karabo_id'])\n", - " # print(f'Karabo ID: {karabo_id}')\n", - " # else:\n", - " # print(f'karabo id not a string, using {karabo_id}')\n", - " # else:\n", - " # print(f'karabo id not found, using {karabo_id}')\n", - " \n", - " # if 'da_name' in f.attrs.keys():\n", - " # if isinstance(f.attrs['da_name'], str):\n", - " # da_name = str(f.attrs['da_name'])\n", - " # print(f'DA name: {da_name}')\n", - " # else:\n", - " # print(f'DA name not a string, using {da_name}')\n", - " # else:\n", - " # print(f'DA name not found, using {da_name}')\n", - "\n", - " if gain_mode < 0:\n", - " if \"gain_mode\" in f[\"condition\"].keys():\n", - " gain_mode = np.int(f[\"condition\"][\"Gain Mode\"][\"value\"][()])\n", - " else:\n", - " gain_mode = 0\n", - " print(f'Gain mode: {gain_mode}')\n", - " else:\n", - " print(f'Using manual set gain_mode {gain_mode}')\n", - "\n", - " f.close()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "gain = Constants.jungfrau.RelativeGain()\n", - "gain.data = gain_map\n", - "\n", - "condition = Conditions.Dark.jungfrau(\n", - " memory_cells=memory_cells, \n", - " bias_voltage=bias_voltage,\n", - " integration_time=integration_time,\n", - " gain_mode=gain_mode,\n", - " gain_setting=gain_setting)\n", - "\n", - "for parm in condition.parameters:\n", - " if parm.name == \"Integration Time\":\n", - " print('setting integration time limits')\n", - " parm.lower_deviation = integration_time - integration_time_lims[0]\n", - " parm.upper_deviation = integration_time_lims[1] - integration_time\n", - "\n", - "for parm in condition.parameters:\n", - " if parm.name == \"Sensor Bias Voltage\":\n", - " print('setting bias voltage limits')\n", - " parm.lower_deviation = bias_voltage - bias_voltage_lims[0]\n", - " parm.upper_deviation = bias_voltage_lims[1] - bias_voltage" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print('Creating time: ', creation_time)\n", - "\n", - "if db_output:\n", - " send_to_db(\n", - " db_module=pdu,\n", - " karabo_id=karabo_id, \n", - " constant=gain, \n", - " condition=condition, \n", - " file_loc=file_loc, \n", - " report_path='',\n", - " cal_db_interface=cal_db_interface,\n", - " creation_time=creation_time,\n", - " )\n", - "\n", - "if bad_pixel_ff is not None and send_bpix:\n", - " bpix_ff = Constants.jungfrau.BadPixelsFF()\n", - " # WHY CONDITION DEVIATIONS ARE NOT CONSIDERED FOR THE BADPIXELS\n", - " condition = Conditions.Dark.jungfrau(\n", - " memory_cells=memory_cells, \n", - " bias_voltage=bias_voltage,\n", - " integration_time=integration_time,\n", - " gain_setting=gain_setting,\n", - " )\n", - "\n", - " bpix_ff.data = bad_pixel_ff\n", - " send_to_db(\n", - " db_module=pdu,\n", - " karabo_id=karabo_id,\n", - " constant=bpix_ff, \n", - " condition=condition, \n", - " file_loc=file_loc,\n", - " report_path='',\n", - " cal_db_interface=cal_db_interface,\n", - " creation_time=creation_time,\n", - " )" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "for g in range(0, gain_map.shape[3]):\n", - " f_im = heatmapPlot(\n", - " np.swapaxes(gain_map[..., 0, g], 0, 1), \n", - " y_label=\"Row\",\n", - " x_label=\"Column\",\n", - " lut_label=\"G{:01d}[ADCu/keV]\".format(g),\n", - " aspect=1.,\n", - " vmin=np.min(gain_map[..., 0, g].ravel()),\n", - " vmax=np.max(gain_map[..., 0, g].ravel()),\n", - " )\n", - " plt.show()" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.8.11" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} -- GitLab