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
14018b95
Commit
14018b95
authored
2 years ago
by
Karim Ahmed
Browse files
Options
Downloads
Patches
Plain Diff
update da_to to module_naming
parent
b1ef743a
No related branches found
No related tags found
1 merge request
!738
New calcat interface
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cal_tools/calcat_interface.py
+61
-36
61 additions, 36 deletions
src/cal_tools/calcat_interface.py
with
61 additions
and
36 deletions
src/cal_tools/calcat_interface.py
+
61
−
36
View file @
14018b95
...
@@ -142,7 +142,12 @@ class CalCatApi(metaclass=ClientWrapper):
...
@@ -142,7 +142,12 @@ class CalCatApi(metaclass=ClientWrapper):
return
{
k
:
resp_detector
[
"
data
"
][
k
]
for
k
in
self
.
get_detector_keys
}
return
{
k
:
resp_detector
[
"
data
"
][
k
]
for
k
in
self
.
get_detector_keys
}
@lru_cache
()
@lru_cache
()
def
physical_detector_units
(
self
,
detector_id
,
snapshot_at
,
da_to
=
"
da
"
):
def
physical_detector_units
(
self
,
detector_id
,
snapshot_at
,
module_naming
=
"
da
"
,
):
"""
Physical detector unit metadata.
"""
"""
Physical detector unit metadata.
"""
resp_pdus
=
PhysicalDetectorUnit
.
get_all_by_detector
(
resp_pdus
=
PhysicalDetectorUnit
.
get_all_by_detector
(
...
@@ -154,19 +159,19 @@ class CalCatApi(metaclass=ClientWrapper):
...
@@ -154,19 +159,19 @@ class CalCatApi(metaclass=ClientWrapper):
# Create dict based on requested keys: karabo_da, module number,
# Create dict based on requested keys: karabo_da, module number,
# or QxMx naming convention.
# or QxMx naming convention.
if
da_to
==
"
da
"
:
if
module_naming
==
"
da
"
:
return
{
return
{
pdu
[
"
karabo_da
"
]:
{
k
:
pdu
[
k
]
for
k
in
self
.
get_pdu_keys
}
pdu
[
"
karabo_da
"
]:
{
k
:
pdu
[
k
]
for
k
in
self
.
get_pdu_keys
}
for
pdu
in
resp_pdus
[
"
data
"
]
for
pdu
in
resp_pdus
[
"
data
"
]
}
}
elif
da_to
==
"
modno
"
:
elif
module_naming
==
"
modno
"
:
return
{
return
{
int
(
pdu
[
"
karabo_da
"
][
-
2
:]):
{
int
(
pdu
[
"
karabo_da
"
][
-
2
:]):
{
k
:
pdu
[
k
]
for
k
in
self
.
get_pdu_keys
k
:
pdu
[
k
]
for
k
in
self
.
get_pdu_keys
}
}
for
pdu
in
resp_pdus
[
"
data
"
]
for
pdu
in
resp_pdus
[
"
data
"
]
}
}
elif
da_to
==
"
qm
"
:
elif
module_naming
==
"
qm
"
:
return
{
return
{
module_index_to_qm
(
int
(
pdu
[
"
karabo_da
"
][
-
2
:])):
{
module_index_to_qm
(
int
(
pdu
[
"
karabo_da
"
][
-
2
:])):
{
k
:
pdu
[
k
]
for
k
in
self
.
get_pdu_keys
k
:
pdu
[
k
]
for
k
in
self
.
get_pdu_keys
...
@@ -174,7 +179,7 @@ class CalCatApi(metaclass=ClientWrapper):
...
@@ -174,7 +179,7 @@ class CalCatApi(metaclass=ClientWrapper):
for
pdu
in
resp_pdus
[
"
data
"
]
for
pdu
in
resp_pdus
[
"
data
"
]
}
}
else
:
else
:
raise
ValueError
(
f
"
{
da_to
}
is unknown!
"
)
raise
ValueError
(
f
"
{
module_naming
}
is unknown!
"
)
@lru_cache
()
@lru_cache
()
def
calibration_id
(
self
,
calibration_name
):
def
calibration_id
(
self
,
calibration_name
):
...
@@ -209,7 +214,7 @@ class CalCatApi(metaclass=ClientWrapper):
...
@@ -209,7 +214,7 @@ class CalCatApi(metaclass=ClientWrapper):
event_at
=
None
,
event_at
=
None
,
snapshot_at
=
None
,
snapshot_at
=
None
,
metadata
=
None
,
metadata
=
None
,
da_to
=
"
da
"
,
module_naming
=
"
da
"
,
):
):
"""
Query bulk CCV metadata from CalCat.
"""
Query bulk CCV metadata from CalCat.
...
@@ -232,6 +237,13 @@ class CalCatApi(metaclass=ClientWrapper):
...
@@ -232,6 +237,13 @@ class CalCatApi(metaclass=ClientWrapper):
state to look at or None for now (default).
state to look at or None for now (default).
metadata (dict or None): Mapping to fill for results or
metadata (dict or None): Mapping to fill for results or
None for a new dictionary (default).
None for a new dictionary (default).
module_naming (str or None): Expected module name convention to be
used as metadata dict keys. Expected values are:
`da`: data aggregator name is used. Default.
`modno`: module index is used. Index is chosen based on last 2
integers in karabo_da.
`qm`: QxMx naming convention is used. Virtual names for
AGIPD, DSSC, and LPD.
Returns:
Returns:
(dict) Nested mapping of module number to calibrations to
(dict) Nested mapping of module number to calibrations to
...
@@ -282,16 +294,17 @@ class CalCatApi(metaclass=ClientWrapper):
...
@@ -282,16 +294,17 @@ class CalCatApi(metaclass=ClientWrapper):
for
ccv
in
resp_versions
[
"
data
"
]:
for
ccv
in
resp_versions
[
"
data
"
]:
try
:
try
:
if
da_to
==
"
da
"
:
if
module_naming
==
"
da
"
:
mod
=
ccv
[
"
physical_detector_unit
"
][
"
karabo_da
"
]
mod
=
ccv
[
"
physical_detector_unit
"
][
"
karabo_da
"
]
elif
da_to
==
"
qm
"
:
# Can be used for AGIPD, LPD, and DSSC.
# Can be used for AGIPD, LPD, and DSSC.
elif
module_naming
==
"
qm
"
:
mod
=
module_index_to_qm
(
mod
=
module_index_to_qm
(
int
(
ccv
[
"
physical_detector_unit
"
][
"
karabo_da
"
][
-
2
:])
int
(
ccv
[
"
physical_detector_unit
"
][
"
karabo_da
"
][
-
2
:])
)
)
elif
da_to
==
"
modno
"
:
elif
module_naming
==
"
modno
"
:
mod
=
int
(
ccv
[
"
physical_detector_unit
"
][
"
karabo_da
"
][
-
2
:])
mod
=
int
(
ccv
[
"
physical_detector_unit
"
][
"
karabo_da
"
][
-
2
:])
else
:
else
:
raise
ValueError
(
f
"
{
da_to
}
is unknown!
"
)
raise
ValueError
(
f
"
{
module_naming
}
is unknown!
"
)
except
KeyError
:
except
KeyError
:
# Not included in our modules
# Not included in our modules
continue
continue
...
@@ -364,7 +377,7 @@ class CalibrationData:
...
@@ -364,7 +377,7 @@ class CalibrationData:
client
=
None
,
client
=
None
,
event_at
=
None
,
event_at
=
None
,
snapshot_at
=
None
,
snapshot_at
=
None
,
da_to
=
"
da
"
,
module_naming
=
"
da
"
,
):
):
"""
Initialize a new CalibrationData object.
"""
Initialize a new CalibrationData object.
...
@@ -382,6 +395,13 @@ class CalibrationData:
...
@@ -382,6 +395,13 @@ class CalibrationData:
CCVs should have been valid, now if omitted
CCVs should have been valid, now if omitted
snapshot_at (datetime, date, str or None): Default time of
snapshot_at (datetime, date, str or None): Default time of
database state to look at, now if omitted.
database state to look at, now if omitted.
module_naming (str or None): Expected module name convention to be
used as metadata dict keys. Expected values are:
`da`: data aggregator name is used. Default.
`modno`: module index is used. Index is chosen based on last 2
integers in karabo_da.
`qm`: QxMx naming convention is used. Virtual names for
AGIPD, DSSC, and LPD.
**condition_params: Operating condition parameters defined
**condition_params: Operating condition parameters defined
on an instance level.
on an instance level.
"""
"""
...
@@ -390,7 +410,7 @@ class CalibrationData:
...
@@ -390,7 +410,7 @@ class CalibrationData:
self
.
modules
=
modules
self
.
modules
=
modules
self
.
event_at
=
event_at
self
.
event_at
=
event_at
self
.
snapshot_at
=
snapshot_at
self
.
snapshot_at
=
snapshot_at
self
.
da_to
=
da_to
self
.
module_naming
=
module_naming
if
client
is
None
:
if
client
is
None
:
client
=
(
client
=
(
...
@@ -505,7 +525,7 @@ class CalibrationData:
...
@@ -505,7 +525,7 @@ class CalibrationData:
@property
@property
def
physical_detector_units
(
self
):
def
physical_detector_units
(
self
):
return
self
.
_api
.
physical_detector_units
(
return
self
.
_api
.
physical_detector_units
(
self
.
detector
[
"
id
"
],
self
.
snapshot_at
,
self
.
da_to
self
.
detector
[
"
id
"
],
self
.
snapshot_at
,
self
.
module_naming
)
)
@property
@property
...
@@ -559,7 +579,7 @@ class CalibrationData:
...
@@ -559,7 +579,7 @@ class CalibrationData:
event_at
or
self
.
event_at
,
event_at
or
self
.
event_at
,
snapshot_at
or
self
.
snapshot_at
,
snapshot_at
or
self
.
snapshot_at
,
metadata
,
metadata
,
da_to
=
self
.
da_to
,
module_naming
=
self
.
module_naming
,
)
)
return
metadata
return
metadata
...
@@ -744,9 +764,9 @@ class CalibrationData:
...
@@ -744,9 +764,9 @@ class CalibrationData:
try
:
try
:
creation_date
=
data
.
files
[
0
].
metadata
()[
"
creationDate
"
]
creation_date
=
data
.
files
[
0
].
metadata
()[
"
creationDate
"
]
except
KeyError
:
except
KeyError
:
from
warnings
import
warn
from
warnings
import
warn
ing
warn
(
warn
ing
(
"
Last file modification time used as creation date for old
"
"
Last file modification time used as creation date for old
"
"
DAQ file format may be unreliable
"
"
DAQ file format may be unreliable
"
)
)
...
@@ -756,9 +776,9 @@ class CalibrationData:
...
@@ -756,9 +776,9 @@ class CalibrationData:
)
)
else
:
else
:
if
not
data
.
is_single_run
:
if
not
data
.
is_single_run
:
from
warnings
import
warn
from
warnings
import
warn
ing
warn
(
warn
ing
(
"
Sample file used to determine creation date for multi
"
"
Sample file used to determine creation date for multi
"
"
run data
"
"
run data
"
)
)
...
@@ -847,7 +867,10 @@ class SplitConditionCalibrationData(CalibrationData):
...
@@ -847,7 +867,10 @@ class SplitConditionCalibrationData(CalibrationData):
metadata
=
CCVMetadata
()
metadata
=
CCVMetadata
()
dark_calibrations
=
self
.
dark_calibrations
&
set
(
calibrations
)
# Calibrations are sorted to ensure using exactly the same query
# for multiple configuration. e.g. This is essential for calparrot.
dark_calibrations
=
sorted
(
self
.
dark_calibrations
&
set
(
calibrations
))
if
dark_calibrations
:
if
dark_calibrations
:
self
.
_api
.
closest_ccv_by_time_by_condition
(
self
.
_api
.
closest_ccv_by_time_by_condition
(
self
.
detector_name
,
self
.
detector_name
,
...
@@ -857,10 +880,11 @@ class SplitConditionCalibrationData(CalibrationData):
...
@@ -857,10 +880,11 @@ class SplitConditionCalibrationData(CalibrationData):
event_at
or
self
.
event_at
,
event_at
or
self
.
event_at
,
snapshot_at
or
self
.
snapshot_at
,
snapshot_at
or
self
.
snapshot_at
,
metadata
,
metadata
,
da_to
=
self
.
da_to
,
module_naming
=
self
.
module_naming
,
)
)
illum_calibrations
=
self
.
illuminated_calibrations
&
set
(
calibrations
)
illum_calibrations
=
sorted
(
self
.
illuminated_calibrations
&
set
(
calibrations
))
if
illum_calibrations
:
if
illum_calibrations
:
self
.
_api
.
closest_ccv_by_time_by_condition
(
self
.
_api
.
closest_ccv_by_time_by_condition
(
self
.
detector_name
,
self
.
detector_name
,
...
@@ -870,8 +894,9 @@ class SplitConditionCalibrationData(CalibrationData):
...
@@ -870,8 +894,9 @@ class SplitConditionCalibrationData(CalibrationData):
event_at
or
self
.
event_at
,
event_at
or
self
.
event_at
,
snapshot_at
or
self
.
snapshot_at
,
snapshot_at
or
self
.
snapshot_at
,
metadata
,
metadata
,
da_to
=
self
.
da_to
,
module_naming
=
self
.
module_naming
,
)
)
return
metadata
return
metadata
...
@@ -915,7 +940,7 @@ class AGIPD_CalibrationData(SplitConditionCalibrationData):
...
@@ -915,7 +940,7 @@ class AGIPD_CalibrationData(SplitConditionCalibrationData):
snapshot_at
=
None
,
snapshot_at
=
None
,
gain_setting
=
None
,
gain_setting
=
None
,
gain_mode
=
None
,
gain_mode
=
None
,
da_to
=
"
da
"
,
module_naming
=
"
da
"
,
integration_time
=
12
,
integration_time
=
12
,
source_energy
=
9.2
,
source_energy
=
9.2
,
pixels_x
=
512
,
pixels_x
=
512
,
...
@@ -927,7 +952,7 @@ class AGIPD_CalibrationData(SplitConditionCalibrationData):
...
@@ -927,7 +952,7 @@ class AGIPD_CalibrationData(SplitConditionCalibrationData):
client
,
client
,
event_at
,
event_at
,
snapshot_at
,
snapshot_at
,
da_to
,
module_naming
,
)
)
self
.
sensor_bias_voltage
=
sensor_bias_voltage
self
.
sensor_bias_voltage
=
sensor_bias_voltage
...
@@ -991,7 +1016,7 @@ class LPD_CalibrationData(SplitConditionCalibrationData):
...
@@ -991,7 +1016,7 @@ class LPD_CalibrationData(SplitConditionCalibrationData):
client
=
None
,
client
=
None
,
event_at
=
None
,
event_at
=
None
,
snapshot_at
=
None
,
snapshot_at
=
None
,
da_to
=
"
da
"
,
module_naming
=
"
da
"
,
):
):
super
().
__init__
(
super
().
__init__
(
detector_name
,
detector_name
,
...
@@ -999,7 +1024,7 @@ class LPD_CalibrationData(SplitConditionCalibrationData):
...
@@ -999,7 +1024,7 @@ class LPD_CalibrationData(SplitConditionCalibrationData):
client
,
client
,
event_at
,
event_at
,
snapshot_at
,
snapshot_at
,
da_to
,
module_naming
,
)
)
self
.
sensor_bias_voltage
=
sensor_bias_voltage
self
.
sensor_bias_voltage
=
sensor_bias_voltage
...
@@ -1044,7 +1069,7 @@ class DSSC_CalibrationData(CalibrationData):
...
@@ -1044,7 +1069,7 @@ class DSSC_CalibrationData(CalibrationData):
client
=
None
,
client
=
None
,
event_at
=
None
,
event_at
=
None
,
snapshot_at
=
None
,
snapshot_at
=
None
,
da_to
=
"
da
"
,
module_naming
=
"
da
"
,
):
):
super
().
__init__
(
super
().
__init__
(
detector_name
,
detector_name
,
...
@@ -1052,7 +1077,7 @@ class DSSC_CalibrationData(CalibrationData):
...
@@ -1052,7 +1077,7 @@ class DSSC_CalibrationData(CalibrationData):
client
,
client
,
event_at
,
event_at
,
snapshot_at
,
snapshot_at
,
da_to
,
module_naming
,
)
)
self
.
sensor_bias_voltage
=
sensor_bias_voltage
self
.
sensor_bias_voltage
=
sensor_bias_voltage
...
@@ -1100,7 +1125,7 @@ class JUNGFRAU_CalibrationData(CalibrationData):
...
@@ -1100,7 +1125,7 @@ class JUNGFRAU_CalibrationData(CalibrationData):
client
=
None
,
client
=
None
,
event_at
=
None
,
event_at
=
None
,
snapshot_at
=
None
,
snapshot_at
=
None
,
da_to
=
"
da
"
,
module_naming
=
"
da
"
,
):
):
super
().
__init__
(
super
().
__init__
(
detector_name
,
detector_name
,
...
@@ -1108,7 +1133,7 @@ class JUNGFRAU_CalibrationData(CalibrationData):
...
@@ -1108,7 +1133,7 @@ class JUNGFRAU_CalibrationData(CalibrationData):
client
,
client
,
event_at
,
event_at
,
snapshot_at
,
snapshot_at
,
da_to
,
module_naming
,
)
)
self
.
sensor_bias_voltage
=
sensor_bias_voltage
self
.
sensor_bias_voltage
=
sensor_bias_voltage
...
@@ -1160,7 +1185,7 @@ class PNCCD_CalibrationData(CalibrationData):
...
@@ -1160,7 +1185,7 @@ class PNCCD_CalibrationData(CalibrationData):
client
=
None
,
client
=
None
,
event_at
=
None
,
event_at
=
None
,
snapshot_at
=
None
,
snapshot_at
=
None
,
da_to
=
"
da
"
,
module_naming
=
"
da
"
,
):
):
# Ignore modules for this detector.
# Ignore modules for this detector.
super
().
__init__
(
super
().
__init__
(
...
@@ -1169,7 +1194,7 @@ class PNCCD_CalibrationData(CalibrationData):
...
@@ -1169,7 +1194,7 @@ class PNCCD_CalibrationData(CalibrationData):
client
,
client
,
event_at
,
event_at
,
snapshot_at
,
snapshot_at
,
da_to
,
module_naming
,
)
)
self
.
sensor_bias_voltage
=
sensor_bias_voltage
self
.
sensor_bias_voltage
=
sensor_bias_voltage
...
@@ -1215,7 +1240,7 @@ class EPIX100_CalibrationData(SplitConditionCalibrationData):
...
@@ -1215,7 +1240,7 @@ class EPIX100_CalibrationData(SplitConditionCalibrationData):
client
=
None
,
client
=
None
,
event_at
=
None
,
event_at
=
None
,
snapshot_at
=
None
,
snapshot_at
=
None
,
da_to
=
"
da
"
,
module_naming
=
"
da
"
,
):
):
# Ignore modules for this detector.
# Ignore modules for this detector.
super
().
__init__
(
super
().
__init__
(
...
@@ -1224,7 +1249,7 @@ class EPIX100_CalibrationData(SplitConditionCalibrationData):
...
@@ -1224,7 +1249,7 @@ class EPIX100_CalibrationData(SplitConditionCalibrationData):
client
,
client
,
event_at
,
event_at
,
snapshot_at
,
snapshot_at
,
da_to
,
module_naming
,
)
)
self
.
sensor_bias_voltage
=
sensor_bias_voltage
self
.
sensor_bias_voltage
=
sensor_bias_voltage
...
@@ -1264,7 +1289,7 @@ class GOTTHARD2_CalibrationData(CalibrationData):
...
@@ -1264,7 +1289,7 @@ class GOTTHARD2_CalibrationData(CalibrationData):
client
=
None
,
client
=
None
,
event_at
=
None
,
event_at
=
None
,
snapshot_at
=
None
,
snapshot_at
=
None
,
da_to
=
"
da
"
,
module_naming
=
"
da
"
,
):
):
# Ignore modules for this detector.
# Ignore modules for this detector.
super
().
__init__
(
super
().
__init__
(
...
@@ -1273,7 +1298,7 @@ class GOTTHARD2_CalibrationData(CalibrationData):
...
@@ -1273,7 +1298,7 @@ class GOTTHARD2_CalibrationData(CalibrationData):
client
,
client
,
event_at
,
event_at
,
snapshot_at
,
snapshot_at
,
da_to
,
module_naming
,
)
)
self
.
sensor_bias_voltage
=
sensor_bias_voltage
self
.
sensor_bias_voltage
=
sensor_bias_voltage
...
...
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