Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
ToolBox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
SCS
ToolBox
Merge requests
!186
Improved BOZ flat field
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Improved BOZ flat field
boz_flat_field
into
master
Overview
0
Commits
23
Pipelines
0
Changes
4
Merged
Loïc Le Guyader
requested to merge
boz_flat_field
into
master
2 years ago
Overview
0
Commits
23
Pipelines
0
Changes
6
Expand
adds low and high threshold on product and ratio of ROIs to calculate flat field correction
adds default flat field guess for the fit as parameters
implement hexagonal lattice for DSSC pixels
breaks left/right symmetry for flat field fitting since zone plate can be slightly rotated
implements a refine fit with regularization for flat field calculation
implements dask auto rechunking
Closes
#53 (closed)
#55 (closed)
Edited
2 years ago
by
Loïc Le Guyader
0
0
Merge request reports
Compare
version 8
version 21
9e9dfc4e
2 years ago
version 20
a92b3aae
2 years ago
version 19
3599f88c
2 years ago
version 18
e933e01d
2 years ago
version 17
b4eb414f
2 years ago
version 16
d4025d44
2 years ago
version 15
e790f635
2 years ago
version 14
81cf364a
2 years ago
version 13
0b06586f
2 years ago
version 12
46d7b773
2 years ago
version 11
a0996f77
2 years ago
version 10
5f83a338
2 years ago
version 9
1d8905f4
2 years ago
version 8
ca91ca0f
2 years ago
version 7
cce2870a
2 years ago
version 6
80080259
2 years ago
version 5
6cae94f2
2 years ago
version 4
e6cc785e
2 years ago
version 3
5312b270
2 years ago
version 2
f3b6ae69
2 years ago
version 1
2e65ab37
2 years ago
master (base)
and
version 17
latest version
b07442d9
23 commits,
2 years ago
version 21
9e9dfc4e
22 commits,
2 years ago
version 20
a92b3aae
21 commits,
2 years ago
version 19
3599f88c
20 commits,
2 years ago
version 18
e933e01d
19 commits,
2 years ago
version 17
b4eb414f
18 commits,
2 years ago
version 16
d4025d44
17 commits,
2 years ago
version 15
e790f635
16 commits,
2 years ago
version 14
81cf364a
15 commits,
2 years ago
version 13
0b06586f
14 commits,
2 years ago
version 12
46d7b773
13 commits,
2 years ago
version 11
a0996f77
16 commits,
2 years ago
version 10
5f83a338
15 commits,
2 years ago
version 9
1d8905f4
14 commits,
2 years ago
version 8
ca91ca0f
13 commits,
2 years ago
version 7
cce2870a
12 commits,
2 years ago
version 6
80080259
11 commits,
2 years ago
version 5
6cae94f2
10 commits,
2 years ago
version 4
e6cc785e
6 commits,
2 years ago
version 3
5312b270
4 commits,
2 years ago
version 2
f3b6ae69
3 commits,
2 years ago
version 1
2e65ab37
2 commits,
2 years ago
Show latest version
6 files
+
165
−
82
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
Search (e.g. *.vue) (Ctrl+P)
doc/Dask DSSC module binning.ipynb
+
3
−
2
Options
%% Cell type:code id: tags:
```
python
import
numpy
as
np
%
matplotlib
notebook
import
matplotlib.pyplot
as
plt
plt
.
rcParams
[
'
figure.constrained_layout.use
'
]
=
True
import
dask
print
(
f
'
dask:
{
dask
.
__version__
}
'
)
import
dask.array
as
da
da
.
config
.
set
({
'
array.chunk-size
'
:
'
512MiB
'
})
import
xarray
as
xr
```
%% Output
dask: 2.11.0
%% Cell type:code id: tags:
```
python
import
sys
print
(
sys
.
executable
)
```
%% Cell type:code id: tags:
```
python
from
psutil
import
virtual_memory
import
gc
# gc.collect() # run garbage collection to free possible memory
mem
=
virtual_memory
()
print
(
f
'
Physical memory:
{
mem
.
total
/
1024
/
1024
/
1024
:
.
0
f
}
Gb
'
)
# total physical memory available
```
%% Output
Physical memory: 504 Gb
%% Cell type:code id: tags:
```
python
import
logging
logging
.
basicConfig
(
filename
=
'
example.log
'
,
level
=
logging
.
DEBUG
)
```
%% Cell type:code id: tags:
```
python
%
load_ext
autoreload
%
autoreload
2
import
toolbox_scs
as
tb
print
(
tb
.
__file__
)
from
toolbox_scs.routines.boz
import
load_dssc_module
from
extra_data
import
open_run
```
%% Output
/home/lleguy/notebooks/ToolBox/src/toolbox_scs/__init__.py
%% Cell type:markdown id: tags:
# Parameters
%% Cell type:code id: tags:parameters
```
python
proposalNB
=
2719
dark_runNB
=
180
runNB
=
179
module_group
=
0
pulse_pattern
=
[
'
pumped
'
,
'
unpumped
'
]
xaxis
=
'
delay
'
# 'nrj'
bin_width
=
0.1
# [ps]
path
=
f
'
/gpfs/exfel/exp/SCS/202002/p002719/scratch/tests/r
{
runNB
}
/
'
```
%% Cell type:code id: tags:
```
python
moduleNB
=
list
(
range
(
module_group
*
4
,
(
module_group
+
1
)
*
4
))
```
%% Cell type:markdown id: tags:
# Processing function
%% Cell type:code id: tags:
```
python
def
process
(
module
):
# Load dark
arr_dark
,
tid_dark
=
load_dssc_module
(
proposalNB
,
dark_runNB
,
module
,
drop_intra_darks
=
False
)
arr_dark
=
arr_dark
.
rechunk
((
100
,
-
1
,
-
1
,
-
1
))
arr_dark
=
arr_dark
.
rechunk
((
'
auto
'
,
-
1
,
-
1
,
-
1
))
dark_img
=
arr_dark
.
mean
(
axis
=
0
).
compute
()
# Load module data
arr
,
tid
=
load_dssc_module
(
proposalNB
,
runNB
,
module
,
drop_intra_darks
=
False
)
arr
=
arr
.
rechunk
((
100
,
-
1
,
-
1
,
-
1
))
arr
=
arr
.
rechunk
((
'
auto
'
,
-
1
,
-
1
,
-
1
))
# dark and intra dark correction
arr
=
arr
-
dark_img
arr
=
arr
[:,
::
2
,
:,
:]
-
arr
[:,
1
::
2
,
:,
:]
# Load slow data against which to bin
if
xaxis
==
'
delay
'
:
run
,
v
=
tb
.
load
(
proposalNB
,
runNB
,
[
'
PP800_DelayLine
'
,
'
BAM1932M
'
,
'
SCS_XGM
'
])
else
:
run
,
v
=
tb
.
load
(
proposalNB
,
runNB
,
[
xaxis
,
'
SCS_XGM
'
])
# select part of the run
# v = v.isel({'trainId':slice(0,3000)})
# combine slow and DSSC module data
xr_data
=
xr
.
DataArray
(
arr
,
coords
=
{
'
trainId
'
:
tid
,
'
sa3_pId
'
:
v
[
'
sa3_pId
'
].
values
},
dims
=
[
'
trainId
'
,
'
sa3_pId
'
,
'
y
'
,
'
x
'
])
xr_data
=
xr_data
.
expand_dims
(
module
=
[
module
],
axis
=
2
)
r
=
xr
.
merge
([
xr_data
.
to_dataset
(
name
=
'
DSSC
'
),
v
],
join
=
'
inner
'
)
# calculate bins
if
xaxis
==
'
delay
'
:
r
[
'
delay
'
]
=
tb
.
misc
.
positionToDelay
(
r
[
'
PP800_DelayLine
'
])
bam
=
r
[
'
BAM1932M
'
]
-
r
[
'
BAM1932M
'
].
mean
()
r
[
'
bin_delay
'
]
=
((
r
[
'
delay
'
]
-
bam
)
/
bin_width
).
round
()
*
bin_width
else
:
r
[
'
bin_
'
+
xaxis
]
=
(
r
[
xaxis
]
/
bin_width
).
round
()
*
bin_width
# add the pulse pattern coordinates
Nrepeats
=
int
(
len
(
v
[
'
sa3_pId
'
].
values
)
/
len
(
pulse_pattern
))
pp
=
pulse_pattern
*
Nrepeats
pp
=
np
.
array
(
pp
)
r
=
r
.
assign_coords
(
pp
=
(
"
sa3_pId
"
,
pp
))
# select pattern and bin data
bin_data
=
None
for
p
in
np
.
unique
(
pp
):
# slice using non-index coordinates
# https://github.com/pydata/xarray/issues/2028
sub_r
=
r
.
sel
(
sa3_pId
=
(
r
.
pp
==
p
))
# calculate mean on bin, then mean to remove the dimension
res
=
sub_r
.
groupby
(
'
bin_
'
+
xaxis
).
mean
().
mean
([
'
sa3_pId
'
])
if
bin_data
is
None
:
bin_data
=
res
bin_data
[
'
DSSC
'
]
=
res
[
'
DSSC
'
].
expand_dims
(
pp
=
[
p
])
bin_data
[
'
SCS_SA3
'
]
=
res
[
'
SCS_SA3
'
].
expand_dims
(
pp
=
[
p
])
else
:
bin_data
=
xr
.
merge
([
bin_data
,
res
[
'
DSSC
'
].
expand_dims
(
pp
=
[
p
]),
res
[
'
SCS_SA3
'
].
expand_dims
(
pp
=
[
p
])])
# save the result
fname
=
path
+
f
'
run
{
runNB
}
-darkrun
{
dark_runNB
}
-module
{
module
}
.h5
'
print
(
fname
)
bin_data
.
to_netcdf
(
fname
,
format
=
'
NETCDF4
'
,
engine
=
'
h5netcdf
'
)
```
%% Cell type:markdown id: tags:
# Processing
%% Cell type:code id: tags:
```
python
for
m
in
moduleNB
:
process
(
m
)
```
Loading