Skip to content
Snippets Groups Projects
Commit ddec6595 authored by Mikhail Karnevskiy's avatar Mikhail Karnevskiy
Browse files

Get bias voltage as input paratemetr

parent 490b0a0e
No related branches found
No related tags found
1 merge request!53Add Dark Characterization for ePix100
%% Cell type:markdown id: tags:
# ePix100 Dark Characterization
Author: M. Karnevskiy, Version 1.0
The following notebook provides dark image analysis of the ePix100 detector.
Dark characterization evaluates offset and noise of the detector and gives information about bad pixels. Resulting maps are saved as .h5 files for a latter use and injected to calibration DB.
%% Cell type:code id: tags:
``` python
#in_folder = '/gpfs/exfel/d/raw/MID/201921/p002419' # input folder, required
in_folder = '/home/karnem/myscratch/dataTest/ePix'
in_folder = '/gpfs/exfel/d/raw/MID/201921/p002419' # input folder, required
out_folder = '/gpfs/exfel/data/scratch/karnem/test/' # output folder, required
path_template = 'RAW-R{:04d}-DA01-S{{:05d}}.h5' # the template to use to access data
run = 94 # which run to read data from, required
number_dark_frames = 0 # number of images to be used, if set to 0 all available images are used
cluster_profile = "noDB" # ipcluster profile to use
h5path = '/INSTRUMENT/MID_EXP_EPIX-1/DET/RECEIVER:daqOutput/data/image/pixels' # path in the HDF5 file to images
h5path_t = '/INSTRUMENT/MID_EXP_EPIX-1/DET/RECEIVER:daqOutput/data/backTemp' # path to find temperature at
h5path_cntrl = '/CONTROL/MID_EXP_EPIX-1/DET' # path to control data
cal_db_interface = "tcp://max-exfl016:8020" # calibration DB interface to use
local_output = False # output also in as H5 files
temp_limits = 5
temp_limits = 5 # limit for parameter Operational temperature
sequence = 0 # sequence file to use
use_dir_creation_date = True
use_dir_creation_date = False
detector_db = 'ePix100_M15' # detector instance
bias_voltage = 200 # bias voltage
in_vacuum = False # detector operated in vacuum
```
%% Cell type:code id: tags:
``` python
import XFELDetAna.xfelprofiler as xprof
profiler = xprof.Profiler()
profiler.disable()
from XFELDetAna.util import env
env.iprofile = cluster_profile
import warnings
warnings.filterwarnings('ignore')
from XFELDetAna import xfelpycaltools as xcal
from XFELDetAna import xfelpyanatools as xana
from XFELDetAna.plotting.util import prettyPlotting
prettyPlotting = True
from XFELDetAna.xfelreaders import ChunkReader
from XFELDetAna.detectors.fastccd import readerh5 as fastccdreaderh5
from cal_tools.tools import get_dir_creation_date
from iCalibrationDB import (ConstantMetaData, Constants, Conditions, Detectors,
Versions)
from iCalibrationDB.detectors import DetectorTypes
import numpy as np
import h5py
import matplotlib.pyplot as plt
% matplotlib inline
def nImagesOrLimit(nImages, limit):
if limit == 0:
return nImages
else:
return min(nImages, limit)
```
%% Output
Disabled GPU usage after pyCuda import failed!: libcuda.so.1: cannot open shared object file: No such file or directory
Using Cython were available
%% Cell type:code id: tags:
``` python
x = 708 # rows of the xPix100
y = 768 # columns of the xPix100
ped_dir = "{}/r{:04d}".format(in_folder, run)
fp_name = path_template.format(run).format(sequence)
filename = '{}/{}'.format(ped_dir, fp_name)
print("Reading data from: {}\n".format(filename))
print("Run number: {}".format(run))
print("HDF5 path: {}".format(h5path))
if use_dir_creation_date:
creation_time = get_dir_creation_date(in_folder, run)
print("Using {} as creation time".format(creation_time.isoformat()))
```
%% Output
Reading data from: /home/karnem/myscratch/dataTest/ePix/r0094/RAW-R0094-DA01-S00000.h5
Run number: 94
HDF5 path: /INSTRUMENT/MID_EXP_EPIX-1/DET/RECEIVER:daqOutput/data/image/pixels
Using 2019-03-28T13:42:56.588021 as creation time
%% Cell type:code id: tags:
``` python
sensorSize = [x, y]
chunkSize = 100 #Number of images to read per chunk
#Sensor area will be analysed according to blocksize
blockSize = [sensorSize[0] // 2, sensorSize[1] // 2]
xcal.defaultBlockSize = blockSize
cpuCores = 4 #Specifies the number of running cpu cores
memoryCells = 1 #No mamery cells
#Specifies total number of images to proceed
nImages = fastccdreaderh5.getDataSize(filename, h5path)[0]
nImages = nImagesOrLimit(nImages, number_dark_frames)
print("\nNumber of dark images to analyze: ", nImages)
run_parallel = False
with h5py.File(filename, 'r') as f:
#bias_voltage = int(f['{}/biasclock/bias/value'.format(h5path_cntrl)][0])
bias_voltage = 200
integration_time = int(f['{}/CONTROL/ePixBoard/DigFpga/AsicAcqWidth/value'.format(h5path_cntrl)][0])/1000.
temperature = np.mean(f[h5path_t])/100.
in_vacuum = False
temperature_k = temperature + 273.15
print("Bias voltage is {} V".format(bias_voltage))
print("Detector integration time is set to {}".format(integration_time))
print("Mean temperature was {:0.2f} °C / {:0.2f} K".format(temperature,
temperature_k))
print("Operated in vacuum: {} ".format(in_vacuum))
```
%% Output
Number of dark images to analyze: 500
Bias voltage is 200 V
Detector integration time is set to 5.0
Mean temperature was 14.16 °C / 287.31 K
Operated in vacuum: False
%% Cell type:code id: tags:
``` python
reader = ChunkReader(filename, fastccdreaderh5.readData,
nImages, chunkSize,
path=h5path,
pixels_x=sensorSize[0],
pixels_y=sensorSize[1], )
```
%% Cell type:code id: tags:
``` python
noiseCal = xcal.NoiseCalculator(sensorSize, memoryCells,
cores=cpuCores, blockSize=blockSize,
parallel=run_parallel)
histCalRaw = xcal.HistogramCalculator(sensorSize, bins=1000,
range=[0, 10000], parallel=False,
memoryCells=memoryCells,
cores=cpuCores, blockSize=blockSize)
```
%% Cell type:code id: tags:
``` python
for data in reader.readChunks():
dx = np.count_nonzero(data, axis=(0, 1))
data = data[:, :, dx != 0]
histCalRaw.fill(data)
noiseCal.fill(data) #Fill calculators with data
constant_maps = {}
constant_maps['Offset'] = noiseCal.getOffset() #Produce offset map
constant_maps['Noise'] = noiseCal.get() #Produce noise map
noiseCal.reset() #Reset noise calculator
print("Initial maps were created")
```
%% Output
Initial maps were created
%% Cell type:code id: tags:
``` python
#**************OFFSET MAP HISTOGRAM***********#
ho, co = np.histogram(constant_maps['Offset'].flatten(), bins=700)
do = {'x': co[:-1],
'y': ho,
'y_err': np.sqrt(ho[:]),
'drawstyle': 'bars',
'color': 'cornflowerblue',
}
fig = xana.simplePlot(do, figsize='1col', aspect=2,
x_label='Offset (ADU)',
y_label="Counts", y_log=True,
)
#*****NOISE MAP HISTOGRAM FROM THE OFFSET CORRECTED DATA*******#
hn, cn = np.histogram(constant_maps['Noise'].flatten(), bins=200)
dn = {'x': cn[:-1],
'y': hn,
'y_err': np.sqrt(hn[:]),
'drawstyle': 'bars',
'color': 'cornflowerblue',
}
fig = xana.simplePlot(dn, figsize='1col', aspect=2,
x_label='Noise (ADU)',
y_label="Counts",
y_log=True)
#**************HEAT MAPS*******************#
fig = xana.heatmapPlot(constant_maps['Offset'][:, :, 0],
x_label='Columns', y_label='Rows',
lut_label='Offset (ADU)',
x_range=(0, y),
y_range=(0, x), vmin=1000, vmax=4000)
fig = xana.heatmapPlot(constant_maps['Noise'][:, :, 0],
x_label='Columns', y_label='Rows',
lut_label='Noise (ADU)',
x_range=(0, y),
y_range=(0, x), vmax=2 * np.mean(constant_maps['Noise']))
```
%% Cell type:code id: tags:
``` python
# Save constants to DB
dclass="EPix100"
consts = ["Offset", "Noise"]
for const_name in consts:
metadata = ConstantMetaData()
det = getattr(Constants, dclass)
const = getattr(det, const_name)()
const.data = constant_maps[const_name].data
metadata.calibration_constant = const
# set the operating condition
dcond = Conditions.Dark
condition = getattr(dcond, dclass)(bias_voltage=bias_voltage,
integration_time=integration_time,
temperature=temperature_k,
in_vacuum=in_vacuum)
for parm in condition.parameters:
if parm.name == "Sensor Temperature":
parm.lower_deviation = temp_limits
parm.upper_deviation = temp_limits
device = getattr(Detectors, detector_db)
metadata.detector_condition = condition
# specify the a version for this constant
if use_dir_creation_date:
metadata.calibration_constant_version = Versions.FromFile(device=device,
file_path= filename)
else:
metadata.calibration_constant_version = Versions.Now(device=device)
#metadata.send(cal_db_interface)
print("Inject {} constants from {}".format(const_name,
metadata.calibration_constant_version.begin_at))
```
%% Output
Inject Offset constants from 2019-03-28 13:42:55.885900
Inject Noise constants from 2019-03-28 13:42:55.885900
%% Cell type:code id: tags:
``` python
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment