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
b3066fb1
Commit
b3066fb1
authored
1 year ago
by
Thomas Kluyver
Browse files
Options
Downloads
Patches
Plain Diff
Create MultiModuleConstant on demand
parent
68016f5c
No related branches found
No related tags found
1 merge request
!885
Revised CalCat API
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cal_tools/calcat_interface2.py
+29
-30
29 additions, 30 deletions
src/cal_tools/calcat_interface2.py
with
29 additions
and
30 deletions
src/cal_tools/calcat_interface2.py
+
29
−
30
View file @
b3066fb1
...
@@ -253,6 +253,7 @@ class MultiModuleConstant:
...
@@ -253,6 +253,7 @@ class MultiModuleConstant:
constants
:
Dict
[
str
,
SingleConstant
]
# Keys e.g. 'LPD00'
constants
:
Dict
[
str
,
SingleConstant
]
# Keys e.g. 'LPD00'
module_details
:
List
[
Dict
]
module_details
:
List
[
Dict
]
detector_name
:
str
# e.g. 'HED_DET_AGIPD500K2G'
def
select_modules
(
def
select_modules
(
self
,
module_nums
=
None
,
*
,
aggregator_names
=
None
,
qm_names
=
None
self
,
module_nums
=
None
,
*
,
aggregator_names
=
None
,
qm_names
=
None
...
@@ -262,7 +263,7 @@ class MultiModuleConstant:
...
@@ -262,7 +263,7 @@ class MultiModuleConstant:
)
)
d
=
{
aggr
:
scv
for
(
aggr
,
scv
)
in
self
.
constants
.
items
()
if
aggr
in
aggs
}
d
=
{
aggr
:
scv
for
(
aggr
,
scv
)
in
self
.
constants
.
items
()
if
aggr
in
aggs
}
mods
=
[
m
for
m
in
self
.
module_details
if
m
[
"
karabo_da
"
]
in
d
]
mods
=
[
m
for
m
in
self
.
module_details
if
m
[
"
karabo_da
"
]
in
d
]
return
MultiModuleConstant
(
d
,
mods
)
return
MultiModuleConstant
(
d
,
mods
,
self
.
detector_name
)
# These properties label only the modules we have constants for, which may
# These properties label only the modules we have constants for, which may
# be a subset of what's in module_details
# be a subset of what's in module_details
...
@@ -371,6 +372,7 @@ class CalibrationData(Mapping):
...
@@ -371,6 +372,7 @@ class CalibrationData(Mapping):
"""
Collected constants for a given detector
"""
"""
Collected constants for a given detector
"""
def
__init__
(
self
,
constant_groups
,
module_details
,
detector_name
):
def
__init__
(
self
,
constant_groups
,
module_details
,
detector_name
):
# {calibration: {karabo_da: SingleConstant}}
self
.
constant_groups
=
constant_groups
self
.
constant_groups
=
constant_groups
self
.
module_details
=
module_details
self
.
module_details
=
module_details
self
.
detector_name
=
detector_name
self
.
detector_name
=
detector_name
...
@@ -456,11 +458,7 @@ class CalibrationData(Mapping):
...
@@ -456,11 +458,7 @@ class CalibrationData(Mapping):
const_group
=
constant_groups
.
setdefault
(
cal_type
,
{})
const_group
=
constant_groups
.
setdefault
(
cal_type
,
{})
const_group
[
aggr
]
=
SingleConstant
.
from_response
(
ccv
)
const_group
[
aggr
]
=
SingleConstant
.
from_response
(
ccv
)
mmcs
=
{
return
cls
(
constant_groups
,
module_details
,
detector_name
)
const_type
:
MultiModuleConstant
(
d
,
module_details
)
for
const_type
,
d
in
constant_groups
.
items
()
}
return
cls
(
mmcs
,
module_details
,
detector_name
)
@classmethod
@classmethod
def
from_report
(
def
from_report
(
...
@@ -509,14 +507,12 @@ class CalibrationData(Mapping):
...
@@ -509,14 +507,12 @@ class CalibrationData(Mapping):
det_name
=
detector_id_to_name
(
det_ids
.
pop
(),
client
)
det_name
=
detector_id_to_name
(
det_ids
.
pop
(),
client
)
module_details
=
sorted
(
pdus
.
values
(),
key
=
lambda
d
:
d
[
"
karabo_da
"
])
module_details
=
sorted
(
pdus
.
values
(),
key
=
lambda
d
:
d
[
"
karabo_da
"
])
mmcs
=
{
return
cls
(
constant_groups
,
module_details
,
det_name
)
const_type
:
MultiModuleConstant
(
d
,
module_details
)
for
const_type
,
d
in
constant_groups
.
items
()
}
return
cls
(
mmcs
,
module_details
,
det_name
)
def
__getitem__
(
self
,
key
)
->
MultiModuleConstant
:
def
__getitem__
(
self
,
key
)
->
MultiModuleConstant
:
return
self
.
constant_groups
[
key
]
return
MultiModuleConstant
(
self
.
constant_groups
[
key
],
self
.
module_details
,
self
.
detector_name
)
def
__iter__
(
self
):
def
__iter__
(
self
):
return
iter
(
self
.
constant_groups
)
return
iter
(
self
.
constant_groups
)
...
@@ -564,25 +560,29 @@ class CalibrationData(Mapping):
...
@@ -564,25 +560,29 @@ class CalibrationData(Mapping):
aggs
=
prepare_selection
(
aggs
=
prepare_selection
(
self
.
module_details
,
module_nums
,
aggregator_names
,
qm_names
self
.
module_details
,
module_nums
,
aggregator_names
,
qm_names
)
)
mmcs
=
{
constant_groups
=
{}
cal_type
:
mmc
.
select_modules
(
matched_aggregators
=
set
()
aggregator_names
=
set
(
aggs
).
intersection
(
mmc
.
aggregator_names
)
for
cal_type
,
const_group
in
self
.
constant_groups
.
items
():
)
constant_groups
[
cal_type
]
=
d
=
{
for
(
cal_type
,
mmc
)
in
self
.
constant_groups
.
items
()
aggr
:
const
for
(
aggr
,
const
)
in
const_group
.
items
()
if
aggr
in
aggs
}
}
aggs
=
set
().
union
(
*
[
c
.
aggregator_names
for
c
in
mmcs
.
values
()])
matched_aggregators
.
update
(
d
.
keys
())
module_details
=
[
m
for
m
in
self
.
module_details
if
m
[
"
karabo_da
"
]
in
aggs
]
module_details
=
[
return
type
(
self
)(
mmcs
,
module_details
,
self
.
detector_name
)
m
for
m
in
self
.
module_details
if
m
[
"
karabo_da
"
]
in
matched_aggregators
]
return
type
(
self
)(
constant_groups
,
module_details
,
self
.
detector_name
)
def
select_calibrations
(
self
,
calibrations
)
->
"
CalibrationData
"
:
def
select_calibrations
(
self
,
calibrations
)
->
"
CalibrationData
"
:
mmc
s
=
{
c
:
self
.
constant_groups
[
c
]
for
c
in
calibrations
}
const_group
s
=
{
c
:
self
.
constant_groups
[
c
]
for
c
in
calibrations
}
return
type
(
self
)(
mmc
s
,
self
.
module_details
,
self
.
detector_name
)
return
type
(
self
)(
const_group
s
,
self
.
module_details
,
self
.
detector_name
)
def
merge
(
self
,
*
others
:
"
CalibrationData
"
)
->
"
CalibrationData
"
:
def
merge
(
self
,
*
others
:
"
CalibrationData
"
)
->
"
CalibrationData
"
:
det_names
=
set
(
cd
.
detector_name
for
cd
in
(
self
,)
+
others
)
det_names
=
set
(
cd
.
detector_name
for
cd
in
(
self
,)
+
others
)
if
len
(
det_names
)
>
1
:
if
len
(
det_names
)
>
1
:
raise
Exception
(
"
Cannot merge calibration data for different
"
raise
Exception
(
"
detectors:
"
+
"
,
"
.
join
(
sorted
(
det_names
)))
"
Cannot merge calibration data for different
"
"
detectors:
"
+
"
,
"
.
join
(
sorted
(
det_names
))
)
det_name
=
det_names
.
pop
()
det_name
=
det_names
.
pop
()
cal_types
=
set
(
self
.
constant_groups
)
cal_types
=
set
(
self
.
constant_groups
)
...
@@ -608,15 +608,14 @@ class CalibrationData(Mapping):
...
@@ -608,15 +608,14 @@ class CalibrationData(Mapping):
module_details
=
sorted
(
pdus_d
.
values
(),
key
=
lambda
d
:
d
[
"
karabo_da
"
])
module_details
=
sorted
(
pdus_d
.
values
(),
key
=
lambda
d
:
d
[
"
karabo_da
"
])
mmc
s
=
{}
constant_group
s
=
{}
for
cal_type
in
cal_types
:
for
cal_type
in
cal_types
:
d
=
{}
d
=
constant_groups
[
cal_type
]
=
{}
for
caldata
in
(
self
,)
+
others
:
for
caldata
in
(
self
,)
+
others
:
if
cal_type
in
caldata
:
if
cal_type
in
caldata
:
d
.
update
(
caldata
[
cal_type
].
constants
)
d
.
update
(
caldata
.
constant_groups
[
cal_type
])
mmcs
[
cal_type
]
=
MultiModuleConstant
(
d
,
module_details
)
return
type
(
self
)(
mmc
s
,
module_details
,
det_name
)
return
type
(
self
)(
constant_group
s
,
module_details
,
det_name
)
class
ConditionsBase
:
class
ConditionsBase
:
...
...
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