From 02a3f6c9d1ec0c4f75b669b173a338efc8b5bba7 Mon Sep 17 00:00:00 2001 From: ahmedk <karim.ahmed@xfel.eu> Date: Wed, 15 Nov 2023 17:37:58 +0100 Subject: [PATCH] Remove options check for num_cells and move it into dssclib and add deviation --- .../DSSC/Characterize_DSSC_Darks_NBC.ipynb | 21 +++++++------------ notebooks/DSSC/DSSC_Correct_and_Verify.ipynb | 15 +++++-------- src/cal_tools/dssclib.py | 10 +++++++++ 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb b/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb index e7fb07b74..5351efbf9 100644 --- a/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb +++ b/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb @@ -210,18 +210,7 @@ " import h5py\n", " import numpy as np\n", " from cal_tools.enums import BadPixels\n", - " \n", - " def get_num_cells(fname, h5path):\n", - " with h5py.File(fname, \"r\") as f:\n", - "\n", - " cells = f[f\"{h5path}/cellId\"][()]\n", - " if cells == []:\n", - " return\n", - " maxcell = np.max(cells)\n", - " options = [100, 200, 400, 500, 600, 700, 800, 900]\n", - " dists = np.array([(o-maxcell) for o in options])\n", - " dists[dists<0] = 10000 # assure to always go higher\n", - " return options[np.argmin(dists)]\n", + " from cal_tools.dssclib import get_num_cells\n", " \n", " filename, channel = inp\n", " \n", @@ -491,11 +480,15 @@ " acquisition_rate=opfreq, \n", " target_gain=targetgain,\n", " encoded_gain=encodedgain)\n", - " \n", + " for parm in condition.parameters:\n", + " if parm.name == \"Memory cells\":\n", + " parm.lower_deviation = mem_cells\n", + " parm.upper_deviation = 0\n", + "\n", " if db_output:\n", " md = send_to_db(db_module, karabo_id, dconst, condition, file_loc, report,\n", " cal_db_interface, creation_time=creation_time, timeout=cal_db_timeout)\n", - " \n", + "\n", " if local_output and dont_use_pulseIds: # Don't save constant localy two times.\n", " md = save_const_to_h5(db_module, karabo_id, dconst, condition,\n", " dconst.data, file_loc, report,\n", diff --git a/notebooks/DSSC/DSSC_Correct_and_Verify.ipynb b/notebooks/DSSC/DSSC_Correct_and_Verify.ipynb index 55978ac1e..88277c144 100644 --- a/notebooks/DSSC/DSSC_Correct_and_Verify.ipynb +++ b/notebooks/DSSC/DSSC_Correct_and_Verify.ipynb @@ -238,7 +238,11 @@ "\n", " import h5py\n", " import numpy as np\n", - " from cal_tools.dssclib import get_dssc_ctrl_data, get_pulseid_checksum\n", + " from cal_tools.dssclib import (\n", + " get_dssc_ctrl_data,\n", + " get_num_cells,\n", + " get_pulseid_checksum,\n", + " )\n", " from cal_tools.enums import BadPixels\n", " from cal_tools.tools import get_constant_from_db_and_time\n", " from iCalibrationDB import (\n", @@ -267,15 +271,6 @@ " pulse_edges = None\n", " err = None\n", " offset_not_found = False\n", - " def get_num_cells(fname, h5path):\n", - " with h5py.File(fname, \"r\") as f:\n", - "\n", - " cells = f[f\"{h5path}/cellId\"][()]\n", - " maxcell = np.max(cells)\n", - " options = [100, 200, 400, 500, 600, 700, 800]\n", - " dists = np.array([(o-maxcell) for o in options])\n", - " dists[dists<0] = 10000 # assure to always go higher\n", - " return options[np.argmin(dists)]\n", " \n", " if mem_cells == 0:\n", " mem_cells = get_num_cells(filename, h5path)\n", diff --git a/src/cal_tools/dssclib.py b/src/cal_tools/dssclib.py index 59ca874d2..0147eb3e5 100644 --- a/src/cal_tools/dssclib.py +++ b/src/cal_tools/dssclib.py @@ -9,6 +9,16 @@ import h5py import numpy as np +def get_num_cells(fname, h5path): + + with h5py.File(fname, "r") as f: + cells = f[f"{h5path}/cellId"][()] + if cells == []: + return + maxcell = np.max(cells) + return maxcell + + def get_pulseid_checksum(fname, h5path, h5path_idx): """generates hash value from pulse pattern (veto defined).""" with h5py.File(fname, "r") as infile: -- GitLab