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
d2782da9
Commit
d2782da9
authored
10 months ago
by
Karim Ahmed
Browse files
Options
Downloads
Patches
Plain Diff
refactor: reduce MR diff by reverting some of function split
parent
5eee0511
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/cal_tools/constants.py
+64
-90
64 additions, 90 deletions
src/cal_tools/constants.py
with
64 additions
and
90 deletions
src/cal_tools/constants.py
+
64
−
90
View file @
d2782da9
...
...
@@ -106,28 +106,15 @@ def write_ccv(
return
ccv_group_name
def
_get_ccv_attributes
(
ccv_group
):
return
(
ccv_group
.
attrs
[
'
proposal
'
],
ccv_group
.
attrs
[
'
runs
'
],
ccv_group
.
attrs
[
'
begin_at
'
],
)
def
condition_parameters
(
condition_group
):
params
=
[]
# It's really not ideal we're mixing conditionS and condition now.
for
parameter
in
condition_group
:
param_dset
=
condition_group
[
parameter
]
params
.
append
({
'
parameter_name
'
:
param_dset
.
attrs
[
'
database_name
'
],
'
value
'
:
float
(
param_dset
[()]),
'
lower_deviation_value
'
:
param_dset
.
attrs
[
'
lower_deviation
'
],
'
upper_deviation_value
'
:
param_dset
.
attrs
[
'
upper_deviation
'
],
'
flg_available
'
:
True
})
return
params
def
get_condition_dict
(
name
,
value
,
lower_deviation
=
0.0
,
upper_deviation
=
0.0
):
return
{
'
parameter_name
'
:
name
,
'
value
'
:
value
,
'
lower_deviation_value
'
:
lower_deviation
,
'
upper_deviation_value
'
:
upper_deviation
,
'
flg_available
'
:
True
}
def
generate_unique_name
(
detector_type
,
pdu_name
,
pdu_uuid
,
cond_params
):
...
...
@@ -145,65 +132,12 @@ def generate_unique_name(detector_type, pdu_name, pdu_uuid, cond_params):
return
unique_name
[:
60
]
def
prepare_injection_payload
(
ccv_attrs
,
pdu_attrs
,
cond_params
,
const_filename
,
const_rel_path
,
unique_name
,
report_to
):
proposal
,
runs
,
begin_at_str
=
ccv_attrs
pdu_name
,
calibration
,
detector_type
,
pdu_uuid
=
pdu_attrs
def
get_raw_data_location
(
proposal
,
runs
):
if
proposal
and
len
(
runs
)
>
0
:
r
aw_data_location
=
(
r
eturn
(
f
'
proposal:
{
proposal
}
runs:
{
"
"
.
join
([
str
(
x
)
for
x
in
runs
])
}
'
)
else
:
pass
# Fallback for non-run based constants
# Add PDU "UUID" to parameters.
cond_params
.
append
({
'
parameter_name
'
:
'
Detector UUID
'
,
'
value
'
:
unpack
(
'
d
'
,
pack
(
'
q
'
,
pdu_uuid
))[
0
],
'
lower_deviation_value
'
:
0.0
,
'
upper_deviation_value
'
:
0.0
,
'
flg_available
'
:
True
})
inject_h
=
{
'
detector_condition
'
:
{
'
name
'
:
unique_name
,
'
parameters
'
:
cond_params
},
'
calibration_constant
'
:
{
'
calibration_name
'
:
calibration
,
'
detector_type_name
'
:
detector_type
,
'
flg_auto_approve
'
:
True
},
'
calibration_constant_version
'
:
{
'
raw_data_location
'
:
raw_data_location
,
'
file_name
'
:
const_filename
,
'
path_to_file
'
:
const_rel_path
,
'
data_set_name
'
:
f
'
{
pdu_name
}
/
{
calibration
}
/0
'
,
'
start_idx
'
:
'
0
'
,
'
end_idx
'
:
'
0
'
,
'
begin_validity_at
'
:
begin_at_str
,
'
end_validity_at
'
:
''
,
'
begin_at
'
:
begin_at_str
,
'
pdu_physical_name
'
:
pdu_name
,
'
flg_good_quality
'
:
True
}
}
if
report_to
:
report_path
=
Path
(
report_to
).
absolute
().
with_suffix
(
'
.pdf
'
)
inject_h
[
'
report
'
]
=
{
'
name
'
:
report_path
.
stem
,
'
file_path
'
:
str
(
report_path
)
}
return
inject_h
return
""
# Fallback for non-run based constants
def
inject_ccv
(
const_src
,
ccv_root
,
report_to
=
None
):
...
...
@@ -229,13 +163,23 @@ def inject_ccv(const_src, ccv_root, report_to=None):
detector_type
=
pdu_group
.
attrs
[
'
detector_type
'
]
ccv_group
=
const_file
[
ccv_root
]
ccv_attrs
=
_get_ccv_attributes
(
ccv_group
)
proposal
,
runs
=
ccv_group
.
attrs
[
'
proposal
'
],
ccv_group
.
attrs
[
'
runs
'
]
begin_at_str
=
ccv_group
.
attrs
[
'
begin_at
'
]
condition_group
=
ccv_group
[
'
operating_condition
'
]
cond_params
=
condition_parameters
(
condition_group
)
cond_params
=
[]
# It's really not ideal we're mixing conditionS and condition now.
for
parameter
in
condition_group
:
param_dset
=
condition_group
[
parameter
]
cond_params
.
append
(
get_condition_dict
(
param_dset
.
attrs
[
'
database_name
'
],
float
(
param_dset
[()]),
param_dset
.
attrs
[
'
lower_deviation
'
],
param_dset
.
attrs
[
'
upper_deviation
'
],
))
const_rel_path
=
f
'
xfel/cal/
{
detector_type
.
lower
()
}
/
{
pdu_name
.
lower
()
}
'
const_filename
=
f
'
cal.
{
time
.
time
()
}
.h5
'
...
...
@@ -243,16 +187,46 @@ def inject_ccv(const_src, ccv_root, report_to=None):
unique_name
=
generate_unique_name
(
detector_type
,
pdu_name
,
pdu_uuid
,
cond_params
)
pdu_attrs
=
(
pdu_name
,
calibration
,
detector_type
,
pdu_uuid
)
inject_h
=
prepare_injection_payload
(
ccv_attrs
,
pdu_attrs
,
cond_params
,
const_filename
,
const_rel_path
,
unique_name
,
report_to
)
raw_data_location
=
get_raw_data_location
(
proposal
,
runs
)
# Add PDU "UUID" to parameters.
cond_params
.
append
(
get_condition_dict
(
'
Detector UUID
'
,
unpack
(
'
d
'
,
pack
(
'
q
'
,
pdu_uuid
))[
0
]
))
inject_h
=
{
'
detector_condition
'
:
{
'
name
'
:
unique_name
,
'
parameters
'
:
cond_params
},
'
calibration_constant
'
:
{
'
calibration_name
'
:
calibration
,
'
detector_type_name
'
:
detector_type
,
'
flg_auto_approve
'
:
True
},
'
calibration_constant_version
'
:
{
'
raw_data_location
'
:
raw_data_location
,
'
file_name
'
:
const_filename
,
'
path_to_file
'
:
const_rel_path
,
'
data_set_name
'
:
f
'
{
pdu_name
}
/
{
calibration
}
/0
'
,
'
start_idx
'
:
'
0
'
,
'
end_idx
'
:
'
0
'
,
'
begin_validity_at
'
:
begin_at_str
,
'
end_validity_at
'
:
''
,
'
begin_at
'
:
begin_at_str
,
'
pdu_physical_name
'
:
pdu_name
,
'
flg_good_quality
'
:
True
}
}
if
report_to
:
report_path
=
Path
(
report_to
).
absolute
().
with_suffix
(
'
.pdf
'
)
inject_h
[
'
report
'
]
=
{
'
name
'
:
report_path
.
stem
,
'
file_path
'
:
str
(
report_path
)
}
const_dest
=
_get_default_caldb_root
()
/
const_rel_path
/
const_filename
const_dest
.
parent
.
mkdir
(
parents
=
True
,
exist_ok
=
True
)
copyfile
(
const_src
,
const_dest
)
...
...
This diff is collapsed.
Click to expand it.
Karim Ahmed
@ahmedk
mentioned in merge request
!1022 (merged)
·
7 months ago
mentioned in merge request
!1022 (merged)
mentioned in merge request !1022
Toggle commit list
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