" if creation_time.replace(tzinfo=None) < dateutil.parser.parse('2020-01-31'):\n",
" print(\"Set gain-setting to None for runs taken before 2020-01-31\")\n",
...
...
%% Cell type:markdown id: tags:
# AGIPD Characterize Dark Images #
Author: S. Hauf, Version: 0.1
The following code analyzes a set of dark images taken with the AGIPD detector to deduce detector offsets , noise, bad-pixel maps and thresholding. All four types of constants are evaluated per-pixel and per-memory cell. Data for the detector's three gain stages needs to be present, separated into separate runs.
The evaluated calibration constants are stored locally and injected in the calibration data base.
%% Cell type:code id: tags:
``` python
in_folder="/gpfs/exfel/d/raw/CALLAB/202031/p900113"# path to input data, required
out_folder="/gpfs/exfel/data/scratch/hammerd/agipd-fixed-gain"# path to output to, required
sequences=[0]# sequence files to evaluate.
modules=[-1]# list of modules to evaluate, RANGE ALLOWED
run_high=9985# run number in which high gain data was recorded, required
run_med=9984# run number in which medium gain data was recorded, required
run_low=9983# run number in which low gain data was recorded, required
karabo_da=['-1']# a list of data aggregators names, Default [-1] for selecting all data aggregators
receiver_id="{}CH0"# inset for receiver devices
path_template='RAW-R{:04d}-{}-S{:05d}.h5'# the template to use to access data
h5path='/INSTRUMENT/{}/DET/{}:xtdf/image'# path in the HDF5 file to images
h5path_idx='/INDEX/{}/DET/{}:xtdf/image'# path in the HDF5 file to images
h5path_ctrl='/CONTROL/{}/MDL/FPGA_COMP'# path to control information
karabo_id_control="HED_EXP_AGIPD500K2G"# karabo-id for control device '
karabo_da_control="AGIPD500K2G00"# karabo DA for control infromation
use_dir_creation_date=True# use dir creation date as data production reference date
cal_db_interface="tcp://max-exfl016:8020"# the database interface to use
cal_db_timeout=3000000# timeout on caldb requests"
local_output=True# output constants locally
db_output=False# output constants to database
mem_cells=0# number of memory cells used, set to 0 to automatically infer
bias_voltage=0# detector bias voltage
gain_setting=0.1# the gain setting, use 0.1 to try to auto-determine
acq_rate=0.# the detector acquisition rate, use 0 to try to auto-determine
interlaced=False# assume interlaced data format, for data prior to Dec. 2017
rawversion=2# RAW file format version
thresholds_offset_sigma=3.# offset sigma thresholds for offset deduced bad pixels
thresholds_offset_hard=[0,0]# For setting the same threshold offset for the 3 gains. Left for backcompatability. Default [0, 0] to take the following parameters.
thresholds_offset_hard_hg=[3000,7000]# High-gain thresholds in absolute ADU terms for offset deduced bad pixels
thresholds_offset_hard_mg=[6000,10000]# Medium-gain thresholds in absolute ADU terms for offset deduced bad pixels
thresholds_offset_hard_lg=[6000,10000]# Low-gain thresholds in absolute ADU terms for offset deduced bad pixels
thresholds_noise_sigma=5.# noise sigma thresholds for offset deduced bad pixels
thresholds_noise_hard=[0,0]# For setting the same threshold noise for the 3 gains. Left for backcompatability. Default [0, 0] to take the following parameters.
thresholds_noise_hard_hg=[4,20]# High-gain thresholds in absolute ADU terms for offset deduced bad pixels
thresholds_noise_hard_mg=[4,20]# Medium-gain thresholds in absolute ADU terms for offset deduced bad pixels
thresholds_noise_hard_lg=[4,20]# Low-gain thresholds in absolute ADU terms for offset deduced bad pixels
thresholds_gain_sigma=5.# Gain separation sigma threshold
high_res_badpix_3d=False# set this to True if you need high-resolution 3d bad pixel plots. ~7mins extra time for 64 memory cells
```
%% Cell type:code id: tags:
``` python
# imports and things that do not usually need to be changed
print(f"Will process a total of {total_sequences} files.")
```
%% Cell type:code id: tags:
``` python
defindex_to_qm(i:int):
returnf"Q{i//4+1}M{i%4+1}"
```
%% Cell type:markdown id: tags:
## Calculate Offsets, Noise and Thresholds ##
The calculation is performed per-pixel and per-memory-cell. Offsets are simply the median value for a set of dark data taken at a given gain, noise the standard deviation, and gain-bit values the medians of the gain array.
The thresholds for gain switching are then defined as the mean value between in individual gain bit levels. Note that these thresholds need to be refined with charge induced thresholds, as the two are not the same.
Single cell overviews allow to identify potential effects on all memory cells, e.g. on sensor level. Additionally, they should serve as a first sanity check on expected behaviour, e.g. if structuring on the ASIC level is visible in the offsets, but otherwise no immediate artifacts are visible.
The following tables show summary information for the evaluated module. Values for currently evaluated constants are compared with values for pre-existing constants retrieved from the calibration database.