diff --git a/cal_tools/cal_tools/agipdlib.py b/cal_tools/cal_tools/agipdlib.py index 598ab81be175bc6a2d62bb719a5a3be99ea3192d..f89f643fdd7c3d71ecd4c74e9825776bf1380b1f 100644 --- a/cal_tools/cal_tools/agipdlib.py +++ b/cal_tools/cal_tools/agipdlib.py @@ -840,10 +840,15 @@ class AgipdCorrections: # or with only simple pulse ranging. if pulse_step > 1 or \ allpulses[first_pulse] >= allpulses[last_pulse]: - can_calibrate = can_calibrate and np.isin(allpulses, cal_pulses) + can_calibrate = np.logical_and(can_calibrate, + np.isin(allpulses, cal_pulses)) else: - can_calibrate = can_calibrate and (allpulses <= np.min(cal_pulses)) # noqa - can_calibrate = can_calibrate and (allpulses >= np.max(cal_pulses)) # noqa + # Check interesection between array of booleans and + # array of pulses to calibrate. + can_calibrate = np.logical_and(can_calibrate, + (allpulses <= np.max(cal_pulses)), + (allpulses >= np.min(cal_pulses)) + ) return can_calibrate diff --git a/cal_tools/cal_tools/pnccdlib.py b/cal_tools/cal_tools/pnccdlib.py index da95ed28e5f0b09ec978bbada402138fb12a93c2..3d913a72a49dd6e436f924a648d8033415051784 100644 --- a/cal_tools/cal_tools/pnccdlib.py +++ b/cal_tools/cal_tools/pnccdlib.py @@ -6,6 +6,17 @@ from typing import Tuple import h5py +VALID_GAINS = { + "a" : 1.0, + "b" : 4.0, + "c" : 16.0, + "d" : 64.0, + "e" : 256.0, + "f" : 340.0, + "g" : 512.0 +} + + def extract_slow_data(karabo_id: str, karabo_da_control: str, ctrl_fname: str, ctrl_path: str, mdl_ctrl_path: str, @@ -30,7 +41,7 @@ def extract_slow_data(karabo_id: str, karabo_da_control: str, if fix_temperature_bot == 0.: fix_temperature_bot = f[os.path.join(ctrl_path, "inputB/krdg/value")][0] - except KeyError: + except IOError: print("Error during reading slow data," " please check the given h5 path for the control parameters") traceback.print_exc(limit=1) diff --git a/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb b/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb index 43d7d2437bda4400312d8ce0b4991f0473591a3a..7d4f3ecfd235c162fc9bfdd5f4ecc9b3c430c9b8 100644 --- a/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb +++ b/notebooks/DSSC/Characterize_DSSC_Darks_NBC.ipynb @@ -315,11 +315,14 @@ "all_cells = []\n", "checksums = {}\n", "\n", - "tGain, encodedGain, operatingFreq = get_dssc_ctrl_data(in_folder + f\"/r{:04d}/\".format(offset_runs[\"high\"]),\n", - " slow_data_pattern,\n", - " slow_data_aggregators,\n", - " offset_runs[\"high\"])\n", - "\n", + "try:\n", + " tGain, encodedGain, operatingFreq = get_dssc_ctrl_data(in_folder + \"/r{:04d}/\".format(offset_runs[\"high\"]),\n", + " slow_data_pattern,\n", + " slow_data_aggregators,\n", + " offset_runs[\"high\"])\n", + "except IOError:\n", + " print(\"ERROR: Couldn't access slow data to read tGain, encodedGain, and operatingFreq \\n\")\n", + " \n", "for gain, mapped_files in gain_mapped_files.items():\n", " inp = []\n", " dones = []\n", diff --git a/notebooks/pnCCD/Characterize_pnCCD_Dark_NBC.ipynb b/notebooks/pnCCD/Characterize_pnCCD_Dark_NBC.ipynb index 189a1b2b02c03004fc29ff75ba1ef07286423926..87030c5496f00cc71dbd92c8a83635e601a246ef 100644 --- a/notebooks/pnCCD/Characterize_pnCCD_Dark_NBC.ipynb +++ b/notebooks/pnCCD/Characterize_pnCCD_Dark_NBC.ipynb @@ -98,7 +98,7 @@ "from IPython.display import display, Markdown\n", "\n", "from cal_tools.enums import BadPixels\n", - "from cal_tools.pnccdlib import extract_slow_data\n", + "from cal_tools.pnccdlib import extract_slow_data, VALID_GAINS\n", "from cal_tools.tools import (get_dir_creation_date, save_const_to_h5,\n", " get_random_db_interface, send_to_db)\n", "from iCalibrationDB import (Conditions, Constants, Detectors, Versions)\n", @@ -359,17 +359,7 @@ "outputs": [], "source": [ "# pnCCD valid gains are 1, 1/4, 1/16, 1/64, 1/256, 1/340 and 1/512:\n", - "valid_gains = {\n", - " \"a\" : 1.0,\n", - " \"b\" : 4.0,\n", - " \"c\" : 16.0,\n", - " \"d\" : 64.0,\n", - " \"e\" : 256.0,\n", - " \"f\" : 340.0,\n", - " \"g\" : 512.0\n", - "}\n", - "\n", - "gain_k = [k for k, v in valid_gains.items() if v == gain][0]\n", + "gain_k = [k for k, v in VALID_GAINS.items() if v == gain][0]\n", "if gain_k == 'a' or gain_k == 'b':\n", " xrange = (0, 200) # x-axis range for the noise histogram plots\n", " bins = 2000 # number of bins for Histogram Calculators \n", diff --git a/notebooks/pnCCD/Characterize_pnCCD_Gain.ipynb b/notebooks/pnCCD/Characterize_pnCCD_Gain.ipynb index b88e2fdf9f71b94df1eefa85db3b7686246304b4..aab6f938d8149cae36c43d8217c60967f73544dd 100644 --- a/notebooks/pnCCD/Characterize_pnCCD_Gain.ipynb +++ b/notebooks/pnCCD/Characterize_pnCCD_Gain.ipynb @@ -100,7 +100,7 @@ "import numpy as np\n", "from prettytable import PrettyTable\n", "\n", - "from cal_tools.pnccdlib import extract_slow_data\n", + "from cal_tools.pnccdlib import extract_slow_data, VALID_GAINS\n", "from cal_tools.tools import get_dir_creation_date, save_const_to_h5, send_to_db\n", "from iCalibrationDB import (Conditions, ConstantMetaData,\n", " Constants, Detectors, Versions)\n", @@ -243,18 +243,7 @@ "source": [ "# The ADU values correspoding to the boundaries of the first peak region are used as cti_limit_low and \n", "# cti_limit_high:\n", - "\n", - "valid_gains = {\n", - " \"a\" : 1.0,\n", - " \"b\" : 4.0,\n", - " \"c\" : 16.0,\n", - " \"d\" : 64.0,\n", - " \"e\" : 256.0,\n", - " \"f\" : 340.0,\n", - " \"g\" : 512.0\n", - "}\n", - "\n", - "gain_k = [k for k, v in valid_gains.items() if v == gain][0]\n", + "gain_k = [k for k, v in VALID_GAINS.items() if v == gain][0]\n", "if gain_k == 'a':\n", " cti_limit_low = 300 # lower limit of cti\n", " cti_limit_high = 8200 # higher limit of cti\n", diff --git a/notebooks/pnCCD/Correct_pnCCD_NBC.ipynb b/notebooks/pnCCD/Correct_pnCCD_NBC.ipynb index 420047576a5363b9c011615a9df94963158c7b2e..e7436b99dc9d6f7cfcd64cf9eefbdfc513af933b 100644 --- a/notebooks/pnCCD/Correct_pnCCD_NBC.ipynb +++ b/notebooks/pnCCD/Correct_pnCCD_NBC.ipynb @@ -122,7 +122,7 @@ "import numpy as np\n", "from prettytable import PrettyTable\n", "\n", - "from cal_tools.pnccdlib import extract_slow_data\n", + "from cal_tools.pnccdlib import extract_slow_data, VALID_GAINS\n", "from cal_tools.tools import (get_constant_from_db_and_time,\n", " get_dir_creation_date,\n", " get_random_db_interface)\n", @@ -257,17 +257,7 @@ "metadata": {}, "outputs": [], "source": [ - "valid_gains = {\n", - " \"a\" : 1.0,\n", - " \"b\" : 4.0,\n", - " \"c\" : 16.0,\n", - " \"d\" : 64.0,\n", - " \"e\" : 256.0,\n", - " \"f\" : 340.0,\n", - " \"g\" : 512.0\n", - "}\n", - "\n", - "gain_k = [k for k, v in valid_gains.items() if v == gain][0]\n", + "gain_k = [k for k, v in VALID_GAINS.items() if v == gain][0]\n", "if gain_k == 'a':\n", " split_evt_mip_threshold = 1000. # MIP threshold in ADU for event classification (10 times average noise)\n", "\n", diff --git a/webservice/webservice.py b/webservice/webservice.py index 92053ecdae56f9cef42b83f27b9ff91665e746e8..3ec8b64fa50437e1828d6f4d153041c46ec2f426 100644 --- a/webservice/webservice.py +++ b/webservice/webservice.py @@ -753,7 +753,7 @@ async def server_runner(config, mode): # Read calibration configuration from yaml conf_file = Path(config['config-repo']['local-path'], - cycle, f'{proposal}.yml') + cycle, f'{proposal}.yaml') if not conf_file.exists(): conf_file = Path(config['config-repo']['local-path'], "default.yaml")