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
ba0bc2ca
Commit
ba0bc2ca
authored
5 years ago
by
Mikhail Karnevskiy
Browse files
Options
Downloads
Patches
Plain Diff
Small refactoring.
parent
b52a29c9
No related branches found
No related tags found
1 merge request
!92
Feat: update plotting notebooks
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cal_tools/cal_tools/ana_tools.py
+33
-22
33 additions, 22 deletions
cal_tools/cal_tools/ana_tools.py
notebooks/AGIPD/PlotFromCalDB_AGIPD_NBC.ipynb
+170
-32
170 additions, 32 deletions
notebooks/AGIPD/PlotFromCalDB_AGIPD_NBC.ipynb
with
203 additions
and
54 deletions
cal_tools/cal_tools/ana_tools.py
+
33
−
22
View file @
ba0bc2ca
import
h5py
import
numpy
as
np
import
matplotlib.pyplot
as
plt
from
enum
import
Enum
import
datetime
import
dateutil.parser
import
glob
import
dateutil.parser
import
h5py
import
matplotlib.pyplot
as
plt
import
numpy
as
np
def
save_dict_to_hdf5
(
dic
,
filename
):
"""
...
...
@@ -59,37 +61,36 @@ def load_data_from_hdf5(filelist):
# Load ndarray if they are there
item
=
f
.
get
(
"
/
"
.
join
((
cKey
,
mKey
,
tKey
)))
if
isinstance
(
item
,
h5py
.
_hl
.
dataset
.
Dataset
):
val
=
item
.
value
data
[
cKey
][
mKey
][
tKey
]
=
val
data
[
cKey
][
mKey
][
tKey
]
=
item
.
value
continue
# Loop over stored data
for
dK
a
y
in
f
.
get
(
"
/
"
.
join
((
cKey
,
mKey
,
tKey
))):
for
dK
e
y
in
f
.
get
(
"
/
"
.
join
((
cKey
,
mKey
,
tKey
))):
# Loop over metadata
if
dK
a
y
==
"
mdata
"
:
mdata
=
{}
if
dK
e
y
==
"
mdata
"
:
mdata
_d
=
{}
for
mdKey
in
f
.
get
(
"
/
"
.
join
((
cKey
,
mKey
,
tKey
,
'
mdata
'
))):
mdata
[
mdKey
]
=
f
.
get
(
mdata
_d
[
mdKey
]
=
f
.
get
(
"
/
"
.
join
(
(
cKey
,
mKey
,
tKey
,
'
mdata
'
,
mdKey
))).
value
mdata_l
=
data
[
cKey
][
mKey
].
get
(
"
mdata
"
,
[])
mdata_l
.
append
(
mdata
)
mdata_l
.
append
(
mdata
_d
)
data
[
cKey
][
mKey
][
"
mdata
"
]
=
mdata_l
continue
if
dK
a
y
not
in
data
[
cKey
][
mKey
]:
data
[
cKey
][
mKey
][
dK
a
y
]
=
[]
if
dK
e
y
not
in
data
[
cKey
][
mKey
]:
data
[
cKey
][
mKey
][
dK
e
y
]
=
[]
value
=
f
.
get
(
"
/
"
.
join
((
cKey
,
mKey
,
tKey
,
dK
a
y
))).
value
"
/
"
.
join
((
cKey
,
mKey
,
tKey
,
dK
e
y
))).
value
if
dK
a
y
==
"
ctime
"
:
if
dK
e
y
==
"
ctime
"
:
value
=
dateutil
.
parser
.
parse
(
value
)
data
[
cKey
][
mKey
][
dK
a
y
].
append
(
value
)
data
[
cKey
][
mKey
][
dK
e
y
].
append
(
value
)
return
data
...
...
@@ -303,10 +304,21 @@ def multi_intersect(a, b):
return
from_multiset
(
aa
&
bb
)
def
hm_combine
(
data
,
fname
=
None
,
type
=
1
,
**
kwargs
):
class
HMType
(
Enum
):
INSET_1D
=
1
INSET_AXIS
=
2
def
hm_combine
(
data
,
fname
=
None
,
htype
=
None
,
**
kwargs
):
"""
Plot heatmap for calibration report
Plotting is based on pyDetLib heatmapPlot with additional
insets depending on heatmap type.
HMType.INSET_1D insets additional 1D histogram for each line
of the heatmap
HMType.INSET_AXIS insets axis for memory cells
:param data: 2D numpy.array of data points to plot
:param fname: file name of output file
:param type: type of figure
...
...
@@ -319,7 +331,7 @@ def hm_combine(data, fname=None, type=1, **kwargs):
ax
=
fig
.
add_subplot
(
111
)
xana
.
heatmapPlot
(
data
,
add_panels
=
False
,
cmap
=
'
viridis
'
,
cb_pad
=
0.6
if
type
==
1
else
0.1
,
cb_pad
=
0.6
if
h
type
==
HMType
.
INSET_AXIS
else
0.1
,
use_axis
=
ax
,
**
kwargs
)
plt
.
setp
(
ax
.
yaxis
.
get_majorticklabels
(),
rotation
=
90
)
...
...
@@ -338,7 +350,7 @@ def hm_combine(data, fname=None, type=1, **kwargs):
h_frame
=
1
-
pad_b
-
pad_t
w_frame
=
1
-
pad_l
-
pad_r
if
type
==
2
:
if
h
type
==
HMType
.
INSET_1D
:
ax
.
tick_params
(
axis
=
'
y
'
,
which
=
'
major
'
,
pad
=
50
)
for
y
in
range
(
data
.
shape
[
0
]):
...
...
@@ -369,7 +381,6 @@ def hm_combine(data, fname=None, type=1, **kwargs):
'
drawstyle
'
:
'
steps-mid
'
,
'
linestyle
'
:
'
dotted
'
,
'
linewidth
'
:
2
,
'
color
'
:
'
white
'
,
},
{
'
x
'
:
np
.
array
([
0
,
data
.
shape
[
1
]
-
1
]),
...
...
@@ -391,7 +402,7 @@ def hm_combine(data, fname=None, type=1, **kwargs):
y_label
=
y_lab
,
use_axis
=
ax
,
y_log
=
False
)
if
type
==
1
:
if
h
type
==
HMType
.
INSET_AXIS
:
ax2
=
plt
.
axes
([
pad_l
,
pad_b
,
w_frame
,
h_frame
/
16.
],
frame_on
=
False
,
yticks
=
range
(
3
),
yticklabels
=
[
32
,
16
,
0
],
...
...
@@ -400,7 +411,7 @@ def hm_combine(data, fname=None, type=1, **kwargs):
ax2
.
yaxis
.
set_label_position
(
"
right
"
)
ax2
.
set_ylabel
(
'
Memory cell ID
'
,
color
=
'
r
'
)
ax2
.
tick_params
(
'
y
'
,
colors
=
'
r
'
,
right
=
True
,
left
=
False
,
labelright
=
True
,
labelleft
=
False
,
)
labelright
=
True
,
labelleft
=
False
)
if
fname
:
fig
.
savefig
(
fname
,
bbox_inches
=
'
tight
'
)
This diff is collapsed.
Click to expand it.
notebooks/AGIPD/PlotFromCalDB_AGIPD_NBC.ipynb
+
170
−
32
View file @
ba0bc2ca
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