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
281b5913
Commit
281b5913
authored
3 years ago
by
Karim Ahmed
Browse files
Options
Downloads
Patches
Plain Diff
expose the ccv_tag and expose it in agipdlib
parent
0561212a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!619
Feat: Expose the CCV `variant` to cal_tools sending and retrieving and expose it in agipdlib
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cal_tools/agipdlib.py
+33
-21
33 additions, 21 deletions
src/cal_tools/agipdlib.py
src/cal_tools/tools.py
+10
-4
10 additions, 4 deletions
src/cal_tools/tools.py
with
43 additions
and
25 deletions
src/cal_tools/agipdlib.py
+
33
−
21
View file @
281b5913
...
@@ -24,7 +24,7 @@ from cal_tools.agipdutils import (
...
@@ -24,7 +24,7 @@ from cal_tools.agipdutils import (
)
)
from
cal_tools.enums
import
AgipdGainMode
,
BadPixels
,
SnowResolution
from
cal_tools.enums
import
AgipdGainMode
,
BadPixels
,
SnowResolution
from
cal_tools.h5_copy_except
import
h5_copy_except_paths
from
cal_tools.h5_copy_except
import
h5_copy_except_paths
from
cal_tools.tools
import
get_
constant_from_db_and_time
from
cal_tools.tools
import
get_
from_db
class
AgipdCtrl
:
class
AgipdCtrl
:
def
__init__
(
def
__init__
(
...
@@ -1014,16 +1014,21 @@ class AgipdCorrections:
...
@@ -1014,16 +1014,21 @@ class AgipdCorrections:
when
=
{}
when
=
{}
cons_data
=
{}
cons_data
=
{}
for
cname
,
cval
in
const_dict
.
items
():
for
cname
,
cval
in
const_dict
.
items
():
condition
=
\
condition
=
getattr
(
getattr
(
Conditions
,
cval
[
2
][
0
]).
AGIPD
(
**
cval
[
2
][
1
])
Conditions
,
cval
[
2
][
0
]).
AGIPD
(
**
cval
[
2
][
1
])
cons_data
[
cname
],
when
[
cname
]
=
\
cons_data
[
cname
]
=
{}
get_constant_from_db_and_time
(
karabo_id
,
karabo_da
,
cons_data
[
cname
][
'
data
'
],
md
=
get_from_db
(
getattr
(
Constants
.
AGIPD
,
cname
)(),
# noqa
karabo_id
,
karabo_da
,
condition
,
getattr
(
Constants
.
AGIPD
,
cname
)(),
getattr
(
np
,
cval
[
0
])(
cval
[
1
]),
condition
,
cal_db_interface
,
getattr
(
np
,
cval
[
0
])(
cval
[
1
]),
creation_time
,
cal_db_interface
,
print_once
=
0
)
creation_time
,
print_once
=
0
,
)
cons_data
[
cname
][
"
version
"
]
=
md
.
calibration_constant_version
.
ccv_tag
when
[
cname
]
=
md
.
calibration_constant_version
.
begin_at
return
cons_data
,
when
return
cons_data
,
when
def
init_constants
(
self
,
cons_data
,
when
,
module_idx
):
def
init_constants
(
self
,
cons_data
,
when
,
module_idx
):
...
@@ -1075,11 +1080,11 @@ class AgipdCorrections:
...
@@ -1075,11 +1080,11 @@ class AgipdCorrections:
# assuming this method runs in parallel.
# assuming this method runs in parallel.
calgs_opts
=
dict
(
num_threads
=
os
.
cpu_count
()
//
len
(
self
.
offset
))
calgs_opts
=
dict
(
num_threads
=
os
.
cpu_count
()
//
len
(
self
.
offset
))
calgs
.
transpose_constant
(
self
.
offset
[
module_idx
],
cons_data
[
'
Offset
'
],
**
calgs_opts
)
calgs
.
transpose_constant
(
self
.
offset
[
module_idx
],
cons_data
[
'
data
'
][
'
Offset
'
],
**
calgs_opts
)
calgs
.
transpose_constant
(
self
.
noise
[
module_idx
],
cons_data
[
'
Noise
'
],
**
calgs_opts
)
calgs
.
transpose_constant
(
self
.
noise
[
module_idx
],
cons_data
[
'
data
'
][
'
Noise
'
],
**
calgs_opts
)
if
self
.
gain_mode
is
AgipdGainMode
.
ADAPTIVE_GAIN
:
if
self
.
gain_mode
is
AgipdGainMode
.
ADAPTIVE_GAIN
:
calgs
.
transpose_constant
(
self
.
thresholds
[
module_idx
],
calgs
.
transpose_constant
(
self
.
thresholds
[
module_idx
],
cons_data
[
'
ThresholdsDark
'
][...,
:
3
],
cons_data
[
'
data
'
][
'
ThresholdsDark
'
][...,
:
3
],
**
calgs_opts
)
**
calgs_opts
)
if
self
.
corr_bools
.
get
(
"
low_medium_gap
"
):
if
self
.
corr_bools
.
get
(
"
low_medium_gap
"
):
...
@@ -1087,17 +1092,17 @@ class AgipdCorrections:
...
@@ -1087,17 +1092,17 @@ class AgipdCorrections:
t1
=
self
.
thresholds
[
module_idx
][
1
]
t1
=
self
.
thresholds
[
module_idx
][
1
]
t1
[
t1
<=
1.05
*
t0
]
=
np
.
iinfo
(
np
.
uint16
).
max
t1
[
t1
<=
1.05
*
t0
]
=
np
.
iinfo
(
np
.
uint16
).
max
bpixels
=
cons_data
[
"
BadPixelsDark
"
].
astype
(
np
.
uint32
)
bpixels
=
cons_data
[
"
data
"
][
"
BadPixelsDark
"
].
astype
(
np
.
uint32
)
if
self
.
corr_bools
.
get
(
"
xray_corr
"
):
if
self
.
corr_bools
.
get
(
"
xray_corr
"
):
if
when
[
"
BadPixelsFF
"
]:
if
when
[
"
BadPixelsFF
"
]:
bpixels
|=
cons_data
[
"
BadPixelsFF
"
].
astype
(
np
.
uint32
)[...,
bpixels
|=
cons_data
[
"
data
"
][
"
BadPixelsFF
"
].
astype
(
np
.
uint32
)[...,
:
bpixels
.
shape
[
2
],
# noqa
:
bpixels
.
shape
[
2
],
# noqa
None
]
None
]
if
when
[
"
SlopesFF
"
]:
# Checking if constant was retrieved
if
when
[
"
SlopesFF
"
]:
# Checking if constant was retrieved
slopesFF
=
cons_data
[
"
SlopesFF
"
]
slopesFF
=
cons_data
[
"
data
"
][
"
SlopesFF
"
]
# This could be used for backward compatibility
# This could be used for backward compatibility
# for very old SlopesFF constants
# for very old SlopesFF constants
if
len
(
slopesFF
.
shape
)
==
4
:
if
len
(
slopesFF
.
shape
)
==
4
:
...
@@ -1134,7 +1139,7 @@ class AgipdCorrections:
...
@@ -1134,7 +1139,7 @@ class AgipdCorrections:
# add additional bad pixel information
# add additional bad pixel information
if
any
(
self
.
pc_bools
):
if
any
(
self
.
pc_bools
):
if
when
[
"
BadPixelsPC
"
]:
if
when
[
"
BadPixelsPC
"
]:
bppc
=
np
.
moveaxis
(
cons_data
[
"
BadPixelsPC
"
].
astype
(
np
.
uint32
),
bppc
=
np
.
moveaxis
(
cons_data
[
"
data
"
][
"
BadPixelsPC
"
].
astype
(
np
.
uint32
),
0
,
2
)
0
,
2
)
bpixels
|=
bppc
[...,
:
bpixels
.
shape
[
2
],
None
]
bpixels
|=
bppc
[...,
:
bpixels
.
shape
[
2
],
None
]
...
@@ -1142,7 +1147,7 @@ class AgipdCorrections:
...
@@ -1142,7 +1147,7 @@ class AgipdCorrections:
rel_gain
=
np
.
ones
((
128
,
512
,
self
.
max_cells
,
3
),
np
.
float32
)
rel_gain
=
np
.
ones
((
128
,
512
,
self
.
max_cells
,
3
),
np
.
float32
)
if
when
[
"
SlopesPC
"
]:
if
when
[
"
SlopesPC
"
]:
slopesPC
=
cons_data
[
"
SlopesPC
"
].
astype
(
np
.
float32
,
copy
=
False
)
slopesPC
=
cons_data
[
"
data
"
][
"
SlopesPC
"
].
astype
(
np
.
float32
,
copy
=
False
)
# This will handle some historical data in a different format
# This will handle some historical data in a different format
# constant dimension injected first
# constant dimension injected first
...
@@ -1243,13 +1248,20 @@ class AgipdCorrections:
...
@@ -1243,13 +1248,20 @@ class AgipdCorrections:
when
=
dict
()
when
=
dict
()
db_module
=
const_yaml
[
karabo_da
][
"
physical-detector-unit
"
]
db_module
=
const_yaml
[
karabo_da
][
"
physical-detector-unit
"
]
for
cname
,
mdata
in
const_yaml
[
karabo_da
][
"
constants
"
].
items
():
for
cname
,
mdata
in
const_yaml
[
karabo_da
][
"
constants
"
].
items
():
cons_data
[
cname
]
=
{}
when
[
cname
]
=
mdata
[
"
creation-time
"
]
when
[
cname
]
=
mdata
[
"
creation-time
"
]
if
when
[
cname
]:
if
when
[
cname
]:
with
h5py
.
File
(
mdata
[
"
file-path
"
],
"
r
"
)
as
cf
:
with
h5py
.
File
(
mdata
[
"
file-path
"
],
"
r
"
)
as
cf
:
cons_data
[
cname
]
=
np
.
copy
(
cf
[
f
"
{
db_module
}
/
{
cname
}
/0/data
"
])
# noqa
cons_data
[
cname
][
"
data
"
]
=
np
.
copy
(
cf
[
f
"
{
db_module
}
/
{
cname
}
/0/data
"
])
# TODO: choose an acceptable name.
if
f
"
{
db_module
}
/
{
cname
}
/0/version
"
in
cf
.
keys
():
cons_data
[
cname
][
"
version
"
]
=
cf
[
f
"
{
db_module
}
/
{
cname
}
/0/version
"
]
else
:
else
:
# Create empty constant using the list elements
# Create empty constant using the list elements
cons_data
[
cname
]
=
getattr
(
np
,
mdata
[
"
file-path
"
][
0
])(
mdata
[
"
file-path
"
][
1
])
# noqa
cons_data
[
cname
][
"
data
"
]
=
getattr
(
np
,
mdata
[
"
file-path
"
][
0
])(
mdata
[
"
file-path
"
][
1
])
self
.
init_constants
(
cons_data
,
when
,
module_idx
)
self
.
init_constants
(
cons_data
,
when
,
module_idx
)
...
...
This diff is collapsed.
Click to expand it.
src/cal_tools/tools.py
+
10
−
4
View file @
281b5913
...
@@ -603,7 +603,9 @@ def get_from_db(karabo_id: str, karabo_da: str,
...
@@ -603,7 +603,9 @@ def get_from_db(karabo_id: str, karabo_da: str,
)
)
with
h5py
.
File
(
Path
(
hdf5path
,
filename
),
"
r
"
)
as
f
:
with
h5py
.
File
(
Path
(
hdf5path
,
filename
),
"
r
"
)
as
f
:
arr
=
f
[
f
"
{
h5path
}
/data
"
][()]
arr
=
f
[
f
"
{
h5path
}
/data
"
][()]
version
=
f
[
f
"
{
h5path
}
/version
"
][()]
metadata
.
calibration_constant
.
data
=
arr
metadata
.
calibration_constant
.
data
=
arr
metadata
.
calibration_constant_version
.
ccv_tag
=
version
if
verbosity
>
0
:
if
verbosity
>
0
:
if
constant
.
name
not
in
already_printed
or
verbosity
>
1
:
if
constant
.
name
not
in
already_printed
or
verbosity
>
1
:
...
@@ -625,7 +627,8 @@ def send_to_db(db_module: str, karabo_id: str, constant, condition,
...
@@ -625,7 +627,8 @@ def send_to_db(db_module: str, karabo_id: str, constant, condition,
creation_time
:
Optional
[
datetime
.
datetime
]
=
None
,
creation_time
:
Optional
[
datetime
.
datetime
]
=
None
,
timeout
:
int
=
30000
,
timeout
:
int
=
30000
,
ntries
:
int
=
7
,
ntries
:
int
=
7
,
doraise
:
bool
=
False
):
doraise
:
bool
=
False
,
ccv_tag
:
Optional
[
int
]
=
None
):
"""
Return calibration constants and metadata requested from CalDB
"""
Return calibration constants and metadata requested from CalDB
:param db_module: database module (PDU/Physical Detector Unit)
:param db_module: database module (PDU/Physical Detector Unit)
...
@@ -634,14 +637,16 @@ def send_to_db(db_module: str, karabo_id: str, constant, condition,
...
@@ -634,14 +637,16 @@ def send_to_db(db_module: str, karabo_id: str, constant, condition,
:param condition: Calibration condition
:param condition: Calibration condition
:param file_loc: Location of raw data.
:param file_loc: Location of raw data.
:param report_path: xfel-calbrate report path to inject along with
:param report_path: xfel-calbrate report path to inject along with
the calibration constant versions to the database.
the calibration constant versions to the database.
:param cal_db_interface: Interface string, e.g.
"
tcp://max-exfl016:8015
"
:param cal_db_interface: Interface string, e.g.
"
tcp://max-exfl016:8015
"
:param creation_time: Latest time for constant to be created
:param creation_time: Latest time for constant to be created
:param timeout: Timeout for zmq request
:param timeout: Timeout for zmq request
:param ntries: number of tries to contact the database,
:param ntries: number of tries to contact the database,
ntries is set to 7 so that if the timeout started
ntries is set to 7 so that if the timeout started
at 30s last timeout will be ~ 1h.
at 30s last timeout will be ~ 1h.
:param doraise: if True raise errors during communication with DB
:param doraise: if True raise errors during communication with DB
:param ccv_tag: A calibration constant version tag to save in the
h5 file along with the constant data.
"""
"""
success
=
False
success
=
False
...
@@ -670,6 +675,7 @@ def send_to_db(db_module: str, karabo_id: str, constant, condition,
...
@@ -670,6 +675,7 @@ def send_to_db(db_module: str, karabo_id: str, constant, condition,
metadata
.
calibration_constant_version
.
device_name
=
db_module
metadata
.
calibration_constant_version
.
device_name
=
db_module
metadata
.
calibration_constant_version
.
karabo_da
=
None
metadata
.
calibration_constant_version
.
karabo_da
=
None
metadata
.
calibration_constant_version
.
raw_data_location
=
file_loc
metadata
.
calibration_constant_version
.
raw_data_location
=
file_loc
metadata
.
calibration_constant_version
.
ccv_tag
=
ccv_tag
if
constant
.
data
is
None
:
if
constant
.
data
is
None
:
raise
ValueError
(
raise
ValueError
(
"
There is no data available to
"
"
There is no data available to
"
...
...
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