# Offset, Noise and Dead Pixels Characterization #
Author: M. Karnevskiy, S. Hauf
This notebook performs re-characterize of dark images to derive offset, noise and bad-pixel maps. All three types of constants are evaluated per-pixel and per-memory cell.
The notebook will correctly handle veto settings, but note that if you veto cells you will not be able to use these offsets for runs with different veto settings - vetoed cells will have zero offset.
The evaluated calibration constants are stored locally and injected in the calibration data base.
**The offset** ($O$) is defined as the median ($M$) of the dark signal ($Ds$) over trains ($t$) for a given pixel ($x,y$) and memory cell ($c$).
**The noise** $N$ is the standard deviation $\sigma$ of the dark signal.
$$\mathrm{thresholds\_noise\_hard}_\mathrm{low} < N < \mathrm{thresholds\_noise\_hard}_\mathrm{high} $$
**"OFFSET_NOISE_EVAL_ERROR":**
Offset and Noise both not $nan$ values
Values: $\mathrm{thresholds\_offset\_sigma}$, $\mathrm{thresholds\_offset\_hard}$, $\mathrm{thresholds\_noise\_sigma}$, $\mathrm{thresholds\_noise\_hard}$ are given as parameters.
%% Cell type:code id: tags:
``` python
cluster_profile="noDB"# The ipcluster profile to use
in_folder="/gpfs/exfel/exp/FXE/201930/p900063/raw"# path to input data, required
in_folder="/gpfs/exfel/exp/FXE/201931/p900088/raw"# path to input data, required
out_folder="/gpfs/exfel/data/scratch/karnem/LPD/"# path to output to, required
sequences=[0]# sequence files to evaluate
modules=[-1]# list of modules to evaluate, RANGE ALLOWED
capacitor_setting=5# capacitor_setting for which data was taken, required
run_high=358# run number in which high gain data was recorded, required
run_med=359# run number in which medium gain data was recorded, required
run_low=360# run number in which low gain data was recorded, required
run_high=112# run number in which high gain data was recorded, required
run_med=113# run number in which medium gain data was recorded, required
run_low=114# run number in which low gain data was recorded, required
mem_cells=512# number of memory cells used
local_output=True# output constants locally
db_output=True# output constants to database
bias_voltage=250# detector bias voltage
cal_db_interface="tcp://max-exfl016:8015#8025"# the database interface to use
cal_db_timeout=300000# timeout on caldb requests"
thresholds_offset_sigma=3.# bad pixel relative threshold in terms of n sigma offset
thresholds_offset_hard=[400,1500]# bad pixel hard threshold
thresholds_noise_sigma=7.# bad pixel relative threshold in terms of n sigma noise
thresholds_noise_hard=[1,35]# bad pixel hard threshold
skip_first_ntrains=10# Number of first trains to skip
not_use_dir_creation_date=False# do not use the creation date of the directory for database time derivation
instrument="FXE"# instrument name
ntrains=300# number of trains to use
high_res_badpix_3d=False# plot bad-pixel summary in high resolution
Distribution of a pedestal (ADUs) over trains for the pixel (12,12), memory cell 12. A median of the distribution is shown in yellow. A standard deviation is shown in red. The green line shows average over all pixels for a given memory cell and gain stage.
Distributions of raw pedestal values have been tested if they are normally distributed. A normality test have been performed for each pixel and each memory cell. Plots below show histogram of p-Values and a 2D distribution for the memory cell 12.
%% Cell type:code id: tags:
``` python
# Loop over capacitor settings, modules, constants
Single cell overviews allow to identify potential effects on all memory cells, e.g. on a 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 plots shows the results of a bad pixel evaluation for all evaluated memory cells. Cells are stacked in the Z-dimension, while pixels values in x/y are re-binned with a factor of 2. This excludes single bad pixels present only in disconnected pixels. Hence, any bad pixels spanning at least 4 pixels in the x/y-plane, or across at least two memory cells are indicated. Colors encode the bad pixel type, or mixed type.
Plots give an overview of calibration constants averaged across tiles. A bad pixel mask is applied. Constants are compared with pre-existing constants retrieved from the calibration database. Differences $\Delta$ between the old and new constants is shown.
%% Cell type:code id: tags:
``` python
display(Markdown('The following pre-existing constants are used for comparison: \n'))
forkeyinold_mdata:
display(Markdown('**{}** at {}'.format(key,old_mdata[key])))
```
%% Cell type:code id: tags:
``` python
# Loop over capacitor settings, modules, constants
forcapinres:
forqminres[cap]:
forgaininrange(3):
display(Markdown('### Summary across tiles - {} gain'.format(gain_names[gain])))
## Variation of offset and noise across Tiles and ASICs ##
The following plots show a standard deviation $\sigma$ of the calibration constant. The plot of standard deviations across tiles show pixels of one tile ($128 \times 32$). Value for each pixel shows a standard deviation across 16 tiles. The standard deviation across ASICs are shown overall tiles. The plot shows pixels of one ASIC ($16 \times 32$), where the value shows a standard deviation across all ACIS of the module.
%% Cell type:code id: tags:
``` python
# Loop over capacitor settings, modules, constants
forcapinres:
forqminres[cap]:
forgaininrange(3):
display(Markdown('### Variation of offset and noise across ASICs - {} gain'.format(gain_names[gain])))
fig=plt.figure(figsize=(15,6))
foriconst,constinenumerate(['Offset','Noise']):
data=np.copy(res[cap][qm][const][:,:,:,gain])
data[badpix_g[cap][qm][:,:,:,gain]>0]=np.nan
label='$\sigma$ {} [ADU]'.format(const)
dataA=np.nanmean(data,axis=2)# average over cells
dataA=dataA.reshape(8,32,16,16)
dataA=np.nanstd(dataA,axis=(0,2))# average across ASICs
ax=fig.add_subplot(121+iconst)
_=heatmapPlot(dataA,add_panels=True,
y_label='rows',x_label='columns',
lut_label=label,use_axis=ax,
panel_y_label=label,panel_x_label=label,
cmap='viridis'
)
plt.show()
```
%% Cell type:code id: tags:
``` python
# Loop over capacitor settings, modules, constants
forcapinres:
forqminres[cap]:
forgaininrange(3):
display(Markdown('### Variation of offset and noise across tiles - {} gain'.format(gain_names[gain])))
fig=plt.figure(figsize=(15,6))
foriconst,constinenumerate(['Offset','Noise']):
data=np.copy(res[cap][qm][const][:,:,:,gain])
data[badpix_g[cap][qm][:,:,:,gain]>0]=np.nan
label='$\sigma$ {} [ADU]'.format(const)
dataT=data.reshape(
int(data.shape[0]/32),
32,
int(data.shape[1]/128),
128,
data.shape[2])
dataT=np.nanstd(dataT,axis=(0,2))
dataT=np.nanmean(dataT,axis=2)
ax=fig.add_subplot(121+iconst)
_=heatmapPlot(dataT,add_panels=True,
y_label='rows',x_label='columns',
lut_label=label,use_axis=ax,
panel_y_label=label,panel_x_label=label,
cmap='viridis')
plt.show()
```
%% Cell type:raw id: tags:
.. raw:: latex
\newpage
%% Cell type:markdown id: tags:
## Aggregate values and per cell behaviour ##
The following tables and plots give an overview of statistical aggregates for each constant, as well as per-cell behavior, averaged across pixels.
%% Cell type:code id: tags:
``` python
# Loop over capacitor settings, modules, constants
forcapinres:
forqminres[cap]:
forgaininrange(3):
display(Markdown('### Mean over pixels - {} gain'.format(gain_names[gain])))
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.