diff --git a/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb b/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb index e7fb07b7434bae7dae6680aff38250382768d8ab..5351efbf9b5dfa074fda7f2748ed620905d17965 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 55978ac1ec6dcbd6dadf38671db8e338904ed0e6..88277c1449194bf6fdfd58d24d43e604879f92ea 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 59ca874d2c896224418347577f2a991789fb00b4..0147eb3e5116945567bd6e02e09d5b3e7fdf0d53 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: