Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pycalibration
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
calibration
pycalibration
Commits
0d4884ca
Commit
0d4884ca
authored
3 years ago
by
Karim Ahmed
Browse files
Options
Downloads
Patches
Plain Diff
use gain_photon_energy for gain calibration constants
parent
d72d7042
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!477
[ePix100][CORRECT] Cleanup and refactor ePix100 correction notebook
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
notebooks/ePix100/Correction_ePix100_NBC.ipynb
+1
-1
1 addition, 1 deletion
notebooks/ePix100/Correction_ePix100_NBC.ipynb
with
1 addition
and
1 deletion
notebooks/ePix100/Correction_ePix100_NBC.ipynb
+
1
−
1
View file @
0d4884ca
...
@@ -242,7 +242,7 @@
...
@@ -242,7 +242,7 @@
"\n",
"\n",
"# update conditions with illuminated conditins.\n",
"# update conditions with illuminated conditins.\n",
"cond_dict.update({\n",
"cond_dict.update({\n",
" \"photon_energy\": photon_energy\n",
" \"photon_energy\":
gain_
photon_energy\n",
" })\n",
" })\n",
"\n",
"\n",
"illum_condition = Conditions.Illuminated.ePix100(**cond_dict)\n",
"illum_condition = Conditions.Illuminated.ePix100(**cond_dict)\n",
...
...
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
# ePIX Data Correction ##
# ePIX Data Correction ##
Authors: Q. Tian S. Hauf, Version 1.0
Authors: Q. Tian S. Hauf, Version 1.0
The following notebook provides Offset correction of images acquired with the ePix100 detector.
The following notebook provides Offset correction of images acquired with the ePix100 detector.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
cluster_profile
=
"
noDB
"
# ipcluster profile to use
cluster_profile
=
"
noDB
"
# ipcluster profile to use
in_folder
=
"
/gpfs/exfel/exp/CALLAB/202031/p900113/raw
"
# input folder, required
in_folder
=
"
/gpfs/exfel/exp/CALLAB/202031/p900113/raw
"
# input folder, required
out_folder
=
""
# output folder, required
out_folder
=
""
# output folder, required
sequences
=
[
-
1
]
# sequences to correct, set to -1 for all, range allowed
sequences
=
[
-
1
]
# sequences to correct, set to -1 for all, range allowed
run
=
9988
# which run to read data from, required
run
=
9988
# which run to read data from, required
karabo_id
=
"
MID_EXP_EPIX-1
"
# karabo karabo_id
karabo_id
=
"
MID_EXP_EPIX-1
"
# karabo karabo_id
karabo_da
=
"
EPIX01
"
# data aggregators
karabo_da
=
"
EPIX01
"
# data aggregators
db_module
=
"
ePix100_M15
"
# module id in the database
db_module
=
"
ePix100_M15
"
# module id in the database
receiver_id
=
"
RECEIVER
"
# inset for receiver devices
receiver_id
=
"
RECEIVER
"
# inset for receiver devices
path_template
=
'
RAW-R{:04d}-{}-S{{:05d}}.h5
'
# the template to use to access data
path_template
=
'
RAW-R{:04d}-{}-S{{:05d}}.h5
'
# the template to use to access data
h5path
=
'
/INSTRUMENT/{}/DET/{}:daqOutput/data/image
'
# path in the HDF5 file to images
h5path
=
'
/INSTRUMENT/{}/DET/{}:daqOutput/data/image
'
# path in the HDF5 file to images
h5path_t
=
'
/INSTRUMENT/{}/DET/{}:daqOutput/data/backTemp
'
# path to find temperature at
h5path_t
=
'
/INSTRUMENT/{}/DET/{}:daqOutput/data/backTemp
'
# path to find temperature at
h5path_cntrl
=
'
/CONTROL/{}/DET
'
# path to control data
h5path_cntrl
=
'
/CONTROL/{}/DET
'
# path to control data
use_dir_creation_date
=
True
# date constants injected before directory creation time
use_dir_creation_date
=
True
# date constants injected before directory creation time
cal_db_interface
=
"
tcp://max-exfl016:8015#8025
"
# calibration DB interface to use
cal_db_interface
=
"
tcp://max-exfl016:8015#8025
"
# calibration DB interface to use
cal_db_timeout
=
300000
# timeout on caldb requests
cal_db_timeout
=
300000
# timeout on caldb requests
cpuCores
=
4
# Specifies the number of running cpu cores
cpuCores
=
4
# Specifies the number of running cpu cores
chunk_size_idim
=
1
# H5 chunking size of output data
chunk_size_idim
=
1
# H5 chunking size of output data
overwrite
=
True
# overwrite output folder
overwrite
=
True
# overwrite output folder
limit_images
=
0
# process only first N images, 0 - process all
limit_images
=
0
# process only first N images, 0 - process all
sequences_per_node
=
1
# number of sequence files per cluster node if run as slurm job, set to 0 to not run SLURM parallel
sequences_per_node
=
1
# number of sequence files per cluster node if run as slurm job, set to 0 to not run SLURM parallel
bias_voltage
=
200
# bias voltage
bias_voltage
=
200
# bias voltage
in_vacuum
=
False
# detector operated in vacuum
in_vacuum
=
False
# detector operated in vacuum
fix_temperature
=
290.
# fix temperature to this value
fix_temperature
=
290.
# fix temperature to this value
gain_photon_energy
=
9.0
# Photon energy used for gain calibration
gain_photon_energy
=
9.0
# Photon energy used for gain calibration
photon_energy
=
8.0
# Photon energy to calibrate in number of photons, 0 for calibration in keV
photon_energy
=
8.0
# Photon energy to calibrate in number of photons, 0 for calibration in keV
relative_gain
=
False
# Apply relative gain correction.
relative_gain
=
False
# Apply relative gain correction.
split_evt_primary_threshold
=
7.
# primary threshold for split event correction
split_evt_primary_threshold
=
7.
# primary threshold for split event correction
split_evt_secondary_threshold
=
5.
# secondary threshold for split event correction
split_evt_secondary_threshold
=
5.
# secondary threshold for split event correction
split_evt_mip_threshold
=
1000.
# minimum ionizing particle threshold
split_evt_mip_threshold
=
1000.
# minimum ionizing particle threshold
def
balance_sequences
(
in_folder
,
run
,
sequences
,
sequences_per_node
,
karabo_da
):
def
balance_sequences
(
in_folder
,
run
,
sequences
,
sequences_per_node
,
karabo_da
):
from
xfel_calibrate.calibrate
import
balance_sequences
as
bs
from
xfel_calibrate.calibrate
import
balance_sequences
as
bs
return
bs
(
in_folder
,
run
,
sequences
,
sequences_per_node
,
karabo_da
)
return
bs
(
in_folder
,
run
,
sequences
,
sequences_per_node
,
karabo_da
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
import
tabulate
import
tabulate
import
warnings
import
warnings
import
h5py
import
h5py
import
numpy
as
np
import
numpy
as
np
from
IPython.display
import
Latex
,
display
from
IPython.display
import
Latex
,
display
from
pathlib
import
Path
from
pathlib
import
Path
import
XFELDetAna.xfelprofiler
as
xprof
import
XFELDetAna.xfelprofiler
as
xprof
from
XFELDetAna
import
xfelpyanatools
as
xana
from
XFELDetAna
import
xfelpyanatools
as
xana
from
XFELDetAna
import
xfelpycaltools
as
xcal
from
XFELDetAna
import
xfelpycaltools
as
xcal
from
XFELDetAna.plotting.util
import
prettyPlotting
from
XFELDetAna.plotting.util
import
prettyPlotting
from
XFELDetAna.util
import
env
from
XFELDetAna.util
import
env
from
cal_tools.tools
import
(
from
cal_tools.tools
import
(
get_constant_from_db
,
get_constant_from_db
,
get_dir_creation_date
,
get_dir_creation_date
,
)
)
from
iCalibrationDB
import
(
from
iCalibrationDB
import
(
Conditions
,
Conditions
,
Constants
,
Constants
,
)
)
warnings
.
filterwarnings
(
'
ignore
'
)
warnings
.
filterwarnings
(
'
ignore
'
)
prettyPlotting
=
True
prettyPlotting
=
True
profiler
=
xprof
.
Profiler
()
profiler
=
xprof
.
Profiler
()
profiler
.
disable
()
profiler
.
disable
()
env
.
iprofile
=
cluster_profile
env
.
iprofile
=
cluster_profile
%
matplotlib
inline
%
matplotlib
inline
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# TODO: expose to first cell after fixing common mode correction.
# TODO: expose to first cell after fixing common mode correction.
common_mode
=
False
# Apply common mode correction.
common_mode
=
False
# Apply common mode correction.
h5path
=
h5path
.
format
(
karabo_id
,
receiver_id
)
h5path
=
h5path
.
format
(
karabo_id
,
receiver_id
)
h5path_t
=
h5path_t
.
format
(
karabo_id
,
receiver_id
)
h5path_t
=
h5path_t
.
format
(
karabo_id
,
receiver_id
)
h5path_cntrl
=
h5path_cntrl
.
format
(
karabo_id
)
h5path_cntrl
=
h5path_cntrl
.
format
(
karabo_id
)
plot_unit
=
'
ADU
'
plot_unit
=
'
ADU
'
if
relative_gain
:
if
relative_gain
:
plot_unit
=
'
keV
'
plot_unit
=
'
keV
'
if
photon_energy
>
0
:
if
photon_energy
>
0
:
plot_unit
=
'
$\gamma$
'
plot_unit
=
'
$\gamma$
'
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
x
=
708
# rows of the ePix100
x
=
708
# rows of the ePix100
y
=
768
# columns of the ePix100
y
=
768
# columns of the ePix100
in_folder
=
Path
(
in_folder
)
in_folder
=
Path
(
in_folder
)
ped_dir
=
in_folder
/
f
"
r
{
run
:
04
d
}
"
ped_dir
=
in_folder
/
f
"
r
{
run
:
04
d
}
"
fp_name
=
path_template
.
format
(
run
,
karabo_da
)
fp_name
=
path_template
.
format
(
run
,
karabo_da
)
print
(
f
"
Reading from:
{
ped_dir
/
fp_name
}
"
)
print
(
f
"
Reading from:
{
ped_dir
/
fp_name
}
"
)
print
(
f
"
Run is:
{
run
}
"
)
print
(
f
"
Run is:
{
run
}
"
)
print
(
f
"
HDF5 path:
{
h5path
}
"
)
print
(
f
"
HDF5 path:
{
h5path
}
"
)
print
(
f
"
Data is output to:
{
out_folder
}
"
)
print
(
f
"
Data is output to:
{
out_folder
}
"
)
creation_time
=
None
creation_time
=
None
if
use_dir_creation_date
:
if
use_dir_creation_date
:
creation_time
=
get_dir_creation_date
(
in_folder
,
run
)
creation_time
=
get_dir_creation_date
(
in_folder
,
run
)
if
creation_time
:
if
creation_time
:
print
(
f
"
Using
{
creation_time
.
isoformat
()
}
as creation time
"
)
print
(
f
"
Using
{
creation_time
.
isoformat
()
}
as creation time
"
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
sensorSize
=
[
x
,
y
]
sensorSize
=
[
x
,
y
]
chunkSize
=
100
# Number of images to read per chunk
chunkSize
=
100
# Number of images to read per chunk
# Sensor area will be analysed according to blocksize
# Sensor area will be analysed according to blocksize
blockSize
=
[
sensorSize
[
0
]
//
2
,
sensorSize
[
1
]
//
2
]
blockSize
=
[
sensorSize
[
0
]
//
2
,
sensorSize
[
1
]
//
2
]
xcal
.
defaultBlockSize
=
blockSize
xcal
.
defaultBlockSize
=
blockSize
memoryCells
=
1
# ePIX has no memory cells
memoryCells
=
1
# ePIX has no memory cells
run_parallel
=
True
run_parallel
=
True
# Read slow data from the first available sequence file.
# Read slow data from the first available sequence file.
filename
=
ped_dir
/
fp_name
.
format
(
sequences
[
0
]
if
sequences
[
0
]
!=
-
1
else
0
)
filename
=
ped_dir
/
fp_name
.
format
(
sequences
[
0
]
if
sequences
[
0
]
!=
-
1
else
0
)
with
h5py
.
File
(
filename
,
'
r
'
)
as
f
:
with
h5py
.
File
(
filename
,
'
r
'
)
as
f
:
integration_time
=
int
(
f
[
f
"
{
h5path_cntrl
}
/CONTROL/expTime/value
"
][
0
])
integration_time
=
int
(
f
[
f
"
{
h5path_cntrl
}
/CONTROL/expTime/value
"
][
0
])
temperature
=
np
.
mean
(
f
[
h5path_t
])
/
100.
temperature
=
np
.
mean
(
f
[
h5path_t
])
/
100.
temperature_k
=
temperature
+
273.15
temperature_k
=
temperature
+
273.15
if
fix_temperature
!=
0
:
if
fix_temperature
!=
0
:
temperature_k
=
fix_temperature
temperature_k
=
fix_temperature
print
(
"
Temperature is fixed!
"
)
print
(
"
Temperature is fixed!
"
)
print
(
f
"
Bias voltage is
{
bias_voltage
}
V
"
)
print
(
f
"
Bias voltage is
{
bias_voltage
}
V
"
)
print
(
f
"
Detector integration time is set to
{
integration_time
}
"
)
print
(
f
"
Detector integration time is set to
{
integration_time
}
"
)
print
(
print
(
f
"
Mean temperature was
{
temperature
:
0.2
f
}
°C
"
f
"
Mean temperature was
{
temperature
:
0.2
f
}
°C
"
f
"
/
{
temperature_k
:
0.2
f
}
K at beginning of run
"
f
"
/
{
temperature_k
:
0.2
f
}
K at beginning of run
"
)
)
print
(
f
"
Operated in vacuum:
{
in_vacuum
}
"
)
print
(
f
"
Operated in vacuum:
{
in_vacuum
}
"
)
out_folder
=
Path
(
out_folder
)
out_folder
=
Path
(
out_folder
)
if
out_folder
.
is_dir
()
and
not
overwrite
:
if
out_folder
.
is_dir
()
and
not
overwrite
:
raise
AttributeError
(
"
Output path exists! Exiting
"
)
raise
AttributeError
(
"
Output path exists! Exiting
"
)
out_folder
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
out_folder
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Glob the right *.h5 fast data files.
# Glob the right *.h5 fast data files.
seq_files
=
sorted
(
ped_dir
.
glob
(
f
"
*
{
karabo_da
}
*.h5
"
))
seq_files
=
sorted
(
ped_dir
.
glob
(
f
"
*
{
karabo_da
}
*.h5
"
))
# If a set of sequences requested to correct,
# If a set of sequences requested to correct,
# adapt seq_files list.
# adapt seq_files list.
if
sequences
!=
[
-
1
]:
if
sequences
!=
[
-
1
]:
seq_files
=
[
f
for
f
in
seq_files
seq_files
=
[
f
for
f
in
seq_files
if
any
(
f
.
match
(
f
"
*-S
{
s
:
05
d
}
.h5
"
)
for
s
in
sequences
)]
if
any
(
f
.
match
(
f
"
*-S
{
s
:
05
d
}
.h5
"
)
for
s
in
sequences
)]
print
(
f
"
Processing a total of
{
len
(
seq_files
)
}
sequence files
"
)
print
(
f
"
Processing a total of
{
len
(
seq_files
)
}
sequence files
"
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# Table of sequence files to process
# Table of sequence files to process
table
=
[(
k
,
f
)
for
k
,
f
in
enumerate
(
seq_files
)]
table
=
[(
k
,
f
)
for
k
,
f
in
enumerate
(
seq_files
)]
if
len
(
table
):
if
len
(
table
):
md
=
display
(
Latex
(
tabulate
.
tabulate
(
md
=
display
(
Latex
(
tabulate
.
tabulate
(
table
,
table
,
tablefmt
=
'
latex
'
,
tablefmt
=
'
latex
'
,
headers
=
[
"
#
"
,
"
file
"
]
headers
=
[
"
#
"
,
"
file
"
]
)))
)))
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
As a first step, dark maps have to be loaded.
As a first step, dark maps have to be loaded.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
temp_limits
=
5.
temp_limits
=
5.
cond_dict
=
{
cond_dict
=
{
"
bias_voltage
"
:
bias_voltage
,
"
bias_voltage
"
:
bias_voltage
,
"
integration_time
"
:
integration_time
,
"
integration_time
"
:
integration_time
,
"
temperature
"
:
temperature_k
,
"
temperature
"
:
temperature_k
,
"
in_vacuum
"
:
in_vacuum
,
"
in_vacuum
"
:
in_vacuum
,
}
}
dark_condition
=
Conditions
.
Dark
.
ePix100
(
**
cond_dict
)
dark_condition
=
Conditions
.
Dark
.
ePix100
(
**
cond_dict
)
# update conditions with illuminated conditins.
# update conditions with illuminated conditins.
cond_dict
.
update
({
cond_dict
.
update
({
"
photon_energy
"
:
photon_energy
"
photon_energy
"
:
gain_
photon_energy
})
})
illum_condition
=
Conditions
.
Illuminated
.
ePix100
(
**
cond_dict
)
illum_condition
=
Conditions
.
Illuminated
.
ePix100
(
**
cond_dict
)
const_cond
=
{
const_cond
=
{
"
Offset
"
:
dark_condition
,
"
Offset
"
:
dark_condition
,
"
Noise
"
:
dark_condition
,
"
Noise
"
:
dark_condition
,
"
RelativeGain
"
:
illum_condition
,
"
RelativeGain
"
:
illum_condition
,
}
}
const_data
=
dict
()
const_data
=
dict
()
for
cname
,
condition
in
const_cond
.
items
():
for
cname
,
condition
in
const_cond
.
items
():
if
cname
==
"
RelativeGain
"
and
not
relative_gain
:
if
cname
==
"
RelativeGain
"
and
not
relative_gain
:
continue
continue
# TODO: Fix this logic.
# TODO: Fix this logic.
for
parm
in
condition
.
parameters
:
for
parm
in
condition
.
parameters
:
if
parm
.
name
==
"
Sensor Temperature
"
:
if
parm
.
name
==
"
Sensor Temperature
"
:
parm
.
lower_deviation
=
temp_limits
parm
.
lower_deviation
=
temp_limits
parm
.
upper_deviation
=
temp_limits
parm
.
upper_deviation
=
temp_limits
const_data
[
cname
]
=
get_constant_from_db
(
const_data
[
cname
]
=
get_constant_from_db
(
karabo_id
=
karabo_id
,
karabo_id
=
karabo_id
,
karabo_da
=
karabo_da
,
karabo_da
=
karabo_da
,
constant
=
getattr
(
Constants
.
ePix100
,
cname
)(),
constant
=
getattr
(
Constants
.
ePix100
,
cname
)(),
condition
=
condition
,
condition
=
condition
,
empty_constant
=
None
,
empty_constant
=
None
,
cal_db_interface
=
cal_db_interface
,
cal_db_interface
=
cal_db_interface
,
creation_time
=
creation_time
,
creation_time
=
creation_time
,
print_once
=
2
,
print_once
=
2
,
timeout
=
cal_db_timeout
timeout
=
cal_db_timeout
)
)
if
relative_gain
and
const_data
[
"
RelativeGain
"
]
is
None
:
if
relative_gain
and
const_data
[
"
RelativeGain
"
]
is
None
:
print
(
print
(
"
WARNING: RelativeGain map is requested, but not found./n
"
"
WARNING: RelativeGain map is requested, but not found./n
"
"
No gain correction will be applied
"
"
No gain correction will be applied
"
)
)
relative_gain
=
False
relative_gain
=
False
plot_unit
=
'
ADU
'
plot_unit
=
'
ADU
'
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# ************************Calculators************************ #
# ************************Calculators************************ #
offsetCorrection
=
xcal
.
OffsetCorrection
(
offsetCorrection
=
xcal
.
OffsetCorrection
(
sensorSize
,
sensorSize
,
const_data
[
"
Offset
"
],
const_data
[
"
Offset
"
],
nCells
=
memoryCells
,
nCells
=
memoryCells
,
cores
=
cpuCores
,
cores
=
cpuCores
,
gains
=
None
,
gains
=
None
,
blockSize
=
blockSize
,
blockSize
=
blockSize
,
parallel
=
run_parallel
parallel
=
run_parallel
)
)
if
relative_gain
:
if
relative_gain
:
gainCorrection
=
xcal
.
RelativeGainCorrection
(
gainCorrection
=
xcal
.
RelativeGainCorrection
(
sensorSize
,
sensorSize
,
1.
/
const_data
[
"
RelativeGain
"
][...,
None
],
1.
/
const_data
[
"
RelativeGain
"
][...,
None
],
nCells
=
memoryCells
,
nCells
=
memoryCells
,
parallel
=
run_parallel
,
parallel
=
run_parallel
,
cores
=
cpuCores
,
cores
=
cpuCores
,
blockSize
=
blockSize
,
blockSize
=
blockSize
,
gains
=
None
,
gains
=
None
,
)
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# *****************Histogram Calculators****************** #
# *****************Histogram Calculators****************** #
histCalOffsetCor
=
xcal
.
HistogramCalculator
(
histCalOffsetCor
=
xcal
.
HistogramCalculator
(
sensorSize
,
sensorSize
,
bins
=
1050
,
bins
=
1050
,
range
=
[
-
50
,
1000
],
range
=
[
-
50
,
1000
],
parallel
=
run_parallel
,
parallel
=
run_parallel
,
nCells
=
memoryCells
,
nCells
=
memoryCells
,
cores
=
cpuCores
,
cores
=
cpuCores
,
blockSize
=
blockSize
blockSize
=
blockSize
)
)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Applying corrections
Applying corrections
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
histCalOffsetCor
.
debug
()
histCalOffsetCor
.
debug
()
offsetCorrection
.
debug
()
offsetCorrection
.
debug
()
if
relative_gain
:
if
relative_gain
:
gainCorrection
.
debug
()
gainCorrection
.
debug
()
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
# ************************Calculators************************ #
# ************************Calculators************************ #
if
common_mode
:
if
common_mode
:
commonModeBlockSize
=
[
x
//
2
,
y
//
2
]
commonModeBlockSize
=
[
x
//
2
,
y
//
2
]
commonModeAxisR
=
'
row
'
commonModeAxisR
=
'
row
'
cmCorrection
=
xcal
.
CommonModeCorrection
(
cmCorrection
=
xcal
.
CommonModeCorrection
(
[
x
,
y
],
[
x
,
y
],
commonModeBlockSize
,
commonModeBlockSize
,
commonModeAxisR
,
commonModeAxisR
,
nCells
=
memoryCells
,
nCells
=
memoryCells
,
noiseMap
=
const_data
[
"
Noise
"
],
noiseMap
=
const_data
[
"
Noise
"
],
runParallel
=
run_parallel
,
runParallel
=
run_parallel
,
stats
=
True
,
stats
=
True
,
)
)
histCalCMCor
=
xcal
.
HistogramCalculator
(
histCalCMCor
=
xcal
.
HistogramCalculator
(
sensorSize
,
sensorSize
,
bins
=
1050
,
bins
=
1050
,
range
=
[
-
50
,
1000
],
range
=
[
-
50
,
1000
],
parallel
=
run_parallel
,
parallel
=
run_parallel
,
nCells
=
memoryCells
,
nCells
=
memoryCells
,
cores
=
cpuCores
,
cores
=
cpuCores
,
blockSize
=
blockSize
,
blockSize
=
blockSize
,
)
)
patternClassifier
=
xcal
.
PatternClassifier
(
patternClassifier
=
xcal
.
PatternClassifier
(
[
x
,
y
],
[
x
,
y
],
const_data
[
"
Noise
"
],
const_data
[
"
Noise
"
],
split_evt_primary_threshold
,
split_evt_primary_threshold
,
split_evt_secondary_threshold
,
split_evt_secondary_threshold
,
split_evt_mip_threshold
,
split_evt_mip_threshold
,
tagFirstSingles
=
0
,
tagFirstSingles
=
0
,
nCells
=
memoryCells
,
nCells
=
memoryCells
,
cores
=
cpuCores
,
cores
=
cpuCores
,
allowElongated
=
False
,
allowElongated
=
False
,
blockSize
=
[
x
,
y
],
blockSize
=
[
x
,
y
],
runParallel
=
run_parallel
,
runParallel
=
run_parallel
,
)
)
histCalSECor
=
xcal
.
HistogramCalculator
(
histCalSECor
=
xcal
.
HistogramCalculator
(
sensorSize
,
sensorSize
,
bins
=
1050
,
bins
=
1050
,
range
=
[
-
50
,
1000
],
range
=
[
-
50
,
1000
],
parallel
=
run_parallel
,
parallel
=
run_parallel
,
nCells
=
memoryCells
,
nCells
=
memoryCells
,
cores
=
cpuCores
,
cores
=
cpuCores
,
blockSize
=
blockSize
,
blockSize
=
blockSize
,
)
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
if
common_mode
:
if
common_mode
:
cmCorrection
.
debug
()
cmCorrection
.
debug
()
histCalCMCor
.
debug
()
histCalCMCor
.
debug
()
patternClassifier
.
debug
()
patternClassifier
.
debug
()
histCalSECor
.
debug
()
histCalSECor
.
debug
()
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
def
copy_and_sanitize_non_cal_data
(
def
copy_and_sanitize_non_cal_data
(
infile
:
h5py
,
infile
:
h5py
,
outfile
:
h5py
,
outfile
:
h5py
,
h5base
:
str
h5base
:
str
):
):
"""
Copy and sanitize data in `infile`
"""
Copy and sanitize data in `infile`
that is not touched by `correctEPIX`.
"""
that is not touched by `correctEPIX`.
"""
if
h5base
.
startswith
(
"
/
"
):
if
h5base
.
startswith
(
"
/
"
):
h5base
=
h5base
[
1
:]
h5base
=
h5base
[
1
:]
dont_copy
=
[
h5base
+
"
/pixels
"
]
dont_copy
=
[
h5base
+
"
/pixels
"
]
def
visitor
(
k
,
item
):
def
visitor
(
k
,
item
):
if
k
not
in
dont_copy
:
if
k
not
in
dont_copy
:
if
isinstance
(
item
,
h5py
.
Group
):
if
isinstance
(
item
,
h5py
.
Group
):
outfile
.
create_group
(
k
)
outfile
.
create_group
(
k
)
elif
isinstance
(
item
,
h5py
.
Dataset
):
elif
isinstance
(
item
,
h5py
.
Dataset
):
group
=
str
(
k
).
split
(
"
/
"
)
group
=
str
(
k
).
split
(
"
/
"
)
group
=
"
/
"
.
join
(
group
[:
-
1
])
group
=
"
/
"
.
join
(
group
[:
-
1
])
infile
.
copy
(
k
,
outfile
[
group
])
infile
.
copy
(
k
,
outfile
[
group
])
infile
.
visititems
(
visitor
)
infile
.
visititems
(
visitor
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
for
f
in
seq_files
:
for
f
in
seq_files
:
data
=
None
data
=
None
out_file
=
out_folder
/
f
.
name
.
replace
(
"
RAW
"
,
"
CORR
"
)
out_file
=
out_folder
/
f
.
name
.
replace
(
"
RAW
"
,
"
CORR
"
)
with
h5py
.
File
(
f
,
"
r
"
)
as
infile
,
h5py
.
File
(
out_file
,
"
w
"
)
as
ofile
:
with
h5py
.
File
(
f
,
"
r
"
)
as
infile
,
h5py
.
File
(
out_file
,
"
w
"
)
as
ofile
:
try
:
try
:
copy_and_sanitize_non_cal_data
(
infile
,
ofile
,
h5path
)
copy_and_sanitize_non_cal_data
(
infile
,
ofile
,
h5path
)
data
=
infile
[
h5path
+
"
/pixels
"
][()]
data
=
infile
[
h5path
+
"
/pixels
"
][()]
data
=
np
.
compress
(
np
.
any
(
data
>
0
,
axis
=
(
1
,
2
)),
data
,
axis
=
0
)
data
=
np
.
compress
(
np
.
any
(
data
>
0
,
axis
=
(
1
,
2
)),
data
,
axis
=
0
)
if
limit_images
>
0
:
if
limit_images
>
0
:
data
=
data
[:
limit_images
,
...]
data
=
data
[:
limit_images
,
...]
oshape
=
data
.
shape
oshape
=
data
.
shape
data
=
np
.
moveaxis
(
data
,
0
,
2
)
data
=
np
.
moveaxis
(
data
,
0
,
2
)
ddset
=
ofile
.
create_dataset
(
ddset
=
ofile
.
create_dataset
(
h5path
+
"
/pixels
"
,
h5path
+
"
/pixels
"
,
oshape
,
oshape
,
chunks
=
(
chunk_size_idim
,
oshape
[
1
],
oshape
[
2
]),
chunks
=
(
chunk_size_idim
,
oshape
[
1
],
oshape
[
2
]),
dtype
=
np
.
float32
)
dtype
=
np
.
float32
)
# Offset correction.
# Offset correction.
data
=
offsetCorrection
.
correct
(
data
.
astype
(
np
.
float32
))
data
=
offsetCorrection
.
correct
(
data
.
astype
(
np
.
float32
))
# relative gain correction.
# relative gain correction.
if
relative_gain
:
if
relative_gain
:
data
=
gainCorrection
.
correct
(
data
.
astype
(
np
.
float32
))
data
=
gainCorrection
.
correct
(
data
.
astype
(
np
.
float32
))
if
photon_energy
>
0
:
if
photon_energy
>
0
:
data
/=
photon_energy
data
/=
photon_energy
histCalOffsetCor
.
fill
(
data
)
histCalOffsetCor
.
fill
(
data
)
ddset
[...]
=
np
.
moveaxis
(
data
,
2
,
0
)
ddset
[...]
=
np
.
moveaxis
(
data
,
2
,
0
)
# Common mode correction
# Common mode correction
# TODO: Fix conflict between common mode and relative gain.
# TODO: Fix conflict between common mode and relative gain.
"""
The gain correction is currently applying an absolute correction
"""
The gain correction is currently applying an absolute correction
(not a relative correction as the implied by the name);
(not a relative correction as the implied by the name);
it changes the scale (the unit of measurement) of the data from ADU
it changes the scale (the unit of measurement) of the data from ADU
to either keV or n_of_photons. But the common mode correction
to either keV or n_of_photons. But the common mode correction
relies on comparing data with the noise map, which is still in ADU.
relies on comparing data with the noise map, which is still in ADU.
The best solution is probably to do a relative gain correction first
The best solution is probably to do a relative gain correction first
(correct) and apply the global absolute gain to the data at the end,
(correct) and apply the global absolute gain to the data at the end,
after common mode and clustering.
after common mode and clustering.
"""
"""
if
common_mode
:
if
common_mode
:
ddsetcm
=
ofile
.
create_dataset
(
ddsetcm
=
ofile
.
create_dataset
(
h5path
+
"
/pixels_cm
"
,
h5path
+
"
/pixels_cm
"
,
oshape
,
oshape
,
chunks
=
(
chunk_size_idim
,
oshape
[
1
],
oshape
[
2
]),
chunks
=
(
chunk_size_idim
,
oshape
[
1
],
oshape
[
2
]),
dtype
=
np
.
float32
)
dtype
=
np
.
float32
)
ddsetc
=
ofile
.
create_dataset
(
ddsetc
=
ofile
.
create_dataset
(
h5path
+
"
/pixels_classified
"
,
h5path
+
"
/pixels_classified
"
,
oshape
,
oshape
,
chunks
=
(
chunk_size_idim
,
oshape
[
1
],
oshape
[
2
]),
chunks
=
(
chunk_size_idim
,
oshape
[
1
],
oshape
[
2
]),
dtype
=
np
.
float32
,
compression
=
"
gzip
"
)
dtype
=
np
.
float32
,
compression
=
"
gzip
"
)
ddsetp
=
ofile
.
create_dataset
(
ddsetp
=
ofile
.
create_dataset
(
h5path
+
"
/patterns
"
,
h5path
+
"
/patterns
"
,
oshape
,
oshape
,
chunks
=
(
chunk_size_idim
,
oshape
[
1
],
oshape
[
2
]),
chunks
=
(
chunk_size_idim
,
oshape
[
1
],
oshape
[
2
]),
dtype
=
np
.
int32
,
compression
=
"
gzip
"
)
dtype
=
np
.
int32
,
compression
=
"
gzip
"
)
# row common mode correction.
# row common mode correction.
data
=
cmCorrection
.
correct
(
data
)
data
=
cmCorrection
.
correct
(
data
)
histCalCMCor
.
fill
(
data
)
histCalCMCor
.
fill
(
data
)
ddsetcm
[...]
=
np
.
moveaxis
(
data
,
2
,
0
)
ddsetcm
[...]
=
np
.
moveaxis
(
data
,
2
,
0
)
data
,
patterns
=
patternClassifier
.
classify
(
data
)
data
,
patterns
=
patternClassifier
.
classify
(
data
)
data
[
data
<
(
split_evt_primary_threshold
*
const_data
[
"
Noise
"
])]
=
0
# noqa
data
[
data
<
(
split_evt_primary_threshold
*
const_data
[
"
Noise
"
])]
=
0
# noqa
ddsetc
[...]
=
np
.
moveaxis
(
data
,
2
,
0
)
ddsetc
[...]
=
np
.
moveaxis
(
data
,
2
,
0
)
ddsetp
[...]
=
np
.
moveaxis
(
patterns
,
2
,
0
)
ddsetp
[...]
=
np
.
moveaxis
(
patterns
,
2
,
0
)
data
[
patterns
!=
100
]
=
np
.
nan
data
[
patterns
!=
100
]
=
np
.
nan
histCalSECor
.
fill
(
data
)
histCalSECor
.
fill
(
data
)
except
Exception
as
e
:
except
Exception
as
e
:
print
(
f
"
ERROR applying common mode correction for
{
f
}
:
{
e
}
"
)
print
(
f
"
ERROR applying common mode correction for
{
f
}
:
{
e
}
"
)
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
ho
,
eo
,
co
,
so
=
histCalOffsetCor
.
get
()
ho
,
eo
,
co
,
so
=
histCalOffsetCor
.
get
()
d
=
[{
d
=
[{
'
x
'
:
co
,
'
x
'
:
co
,
'
y
'
:
ho
,
'
y
'
:
ho
,
'
y_err
'
:
np
.
sqrt
(
ho
[:]),
'
y_err
'
:
np
.
sqrt
(
ho
[:]),
'
drawstyle
'
:
'
steps-mid
'
,
'
drawstyle
'
:
'
steps-mid
'
,
'
errorstyle
'
:
'
bars
'
,
'
errorstyle
'
:
'
bars
'
,
'
errorcoarsing
'
:
2
,
'
errorcoarsing
'
:
2
,
'
label
'
:
'
Offset corr.
'
'
label
'
:
'
Offset corr.
'
}]
}]
if
common_mode
:
if
common_mode
:
ho
,
eo
,
co
,
so
=
histCalCMCor
.
get
()
ho
,
eo
,
co
,
so
=
histCalCMCor
.
get
()
d
.
append
({
d
.
append
({
'
x
'
:
co
,
'
x
'
:
co
,
'
y
'
:
ho
,
'
y
'
:
ho
,
'
y_err
'
:
np
.
sqrt
(
ho
[:]),
'
y_err
'
:
np
.
sqrt
(
ho
[:]),
'
drawstyle
'
:
'
steps-mid
'
,
'
drawstyle
'
:
'
steps-mid
'
,
'
errorstyle
'
:
'
bars
'
,
'
errorstyle
'
:
'
bars
'
,
'
errorcoarsing
'
:
2
,
'
errorcoarsing
'
:
2
,
'
label
'
:
'
CM corr.
'
'
label
'
:
'
CM corr.
'
})
})
ho
,
eo
,
co
,
so
=
histCalSECor
.
get
()
ho
,
eo
,
co
,
so
=
histCalSECor
.
get
()
d
.
append
({
d
.
append
({
'
x
'
:
co
,
'
x
'
:
co
,
'
y
'
:
ho
,
'
y
'
:
ho
,
'
y_err
'
:
np
.
sqrt
(
ho
[:]),
'
y_err
'
:
np
.
sqrt
(
ho
[:]),
'
drawstyle
'
:
'
steps-mid
'
,
'
drawstyle
'
:
'
steps-mid
'
,
'
errorstyle
'
:
'
bars
'
,
'
errorstyle
'
:
'
bars
'
,
'
errorcoarsing
'
:
2
,
'
errorcoarsing
'
:
2
,
'
label
'
:
'
Single split events
'
'
label
'
:
'
Single split events
'
})
})
fig
=
xana
.
simplePlot
(
fig
=
xana
.
simplePlot
(
d
,
aspect
=
1
,
x_label
=
f
'
Energy(
{
plot_unit
}
)
'
,
d
,
aspect
=
1
,
x_label
=
f
'
Energy(
{
plot_unit
}
)
'
,
y_label
=
'
Number of occurrences
'
,
figsize
=
'
2col
'
,
y_label
=
'
Number of occurrences
'
,
figsize
=
'
2col
'
,
y_log
=
True
,
x_range
=
(
-
50
,
500
),
y_log
=
True
,
x_range
=
(
-
50
,
500
),
legend
=
'
top-center-frame-2col
'
legend
=
'
top-center-frame-2col
'
)
)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Mean Image of last Sequence ##
## Mean Image of last Sequence ##
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
fig
=
xana
.
heatmapPlot
(
fig
=
xana
.
heatmapPlot
(
np
.
nanmedian
(
data
,
axis
=
2
),
np
.
nanmedian
(
data
,
axis
=
2
),
x_label
=
'
Columns
'
,
y_label
=
'
Rows
'
,
x_label
=
'
Columns
'
,
y_label
=
'
Rows
'
,
lut_label
=
f
'
Signal (
{
plot_unit
}
)
'
,
lut_label
=
f
'
Signal (
{
plot_unit
}
)
'
,
x_range
=
(
0
,
y
),
x_range
=
(
0
,
y
),
y_range
=
(
0
,
x
),
y_range
=
(
0
,
x
),
vmin
=-
50
,
vmax
=
50
)
vmin
=-
50
,
vmax
=
50
)
```
```
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Single Shot of last Sequence ##
## Single Shot of last Sequence ##
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
python
```
python
fig
=
xana
.
heatmapPlot
(
fig
=
xana
.
heatmapPlot
(
data
[...,
0
],
data
[...,
0
],
x_label
=
'
Columns
'
,
y_label
=
'
Rows
'
,
x_label
=
'
Columns
'
,
y_label
=
'
Rows
'
,
lut_label
=
f
'
Signal (
{
plot_unit
}
)
'
,
lut_label
=
f
'
Signal (
{
plot_unit
}
)
'
,
x_range
=
(
0
,
y
),
x_range
=
(
0
,
y
),
y_range
=
(
0
,
x
),
y_range
=
(
0
,
x
),
vmin
=-
50
,
vmax
=
50
)
vmin
=-
50
,
vmax
=
50
)
```
```
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment