Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
calng
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository 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
calng
Commits
a017449a
Commit
a017449a
authored
3 years ago
by
David Hammer
Browse files
Options
Downloads
Patches
Plain Diff
Allow overriding calibration constant ID
parent
beda6c41
No related branches found
No related tags found
2 merge requests
!12
Snapshot: field test deployed version as of end of run 202201
,
!3
Base correction device, CalCat interaction, DSSC and AGIPD devices
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/calng/base_correction.py
+17
-0
17 additions, 0 deletions
src/calng/base_correction.py
src/calng/calcat_utils.py
+64
-9
64 additions, 9 deletions
src/calng/calcat_utils.py
with
81 additions
and
9 deletions
src/calng/base_correction.py
+
17
−
0
View file @
a017449a
...
...
@@ -366,6 +366,23 @@ class BaseCorrection(PythonDevice):
self
.
_buffer_lock
=
threading
.
Lock
()
self
.
KARABO_SLOT
(
self
.
loadMostRecentConstants
)
self
.
KARABO_SLOT
(
self
.
requestScene
)
# TODO: the CalCatFriend could add these for us
# note: overly complicated slot function creation necessary for closure to work
def
make_wrapper_capturing_constant
(
constant
):
def
aux
():
self
.
calcat_friend
.
get_specific_constant_version_and_call_me_back
(
constant
,
self
.
_load_constant_to_gpu
)
return
aux
for
constant
in
self
.
_constant_enum_class
:
slot_name
=
f
"
foundConstants.
{
constant
.
name
}
.overrideConstantVersion
"
meth_name
=
slot_name
.
replace
(
"
.
"
,
"
_
"
)
self
.
KARABO_SLOT
(
make_wrapper_capturing_constant
(
constant
),
slotName
=
meth_name
,
)
def
preReconfigure
(
self
,
config
):
for
path
in
config
.
getPaths
():
...
...
This diff is collapsed.
Click to expand it.
src/calng/calcat_utils.py
+
64
−
9
View file @
a017449a
...
...
@@ -22,6 +22,7 @@ from karabo.bound import (
BOOL_ELEMENT
,
DOUBLE_ELEMENT
,
NODE_ELEMENT
,
SLOT_ELEMENT
,
STRING_ELEMENT
,
UINT32_ELEMENT
,
)
...
...
@@ -93,6 +94,22 @@ def _add_status_schema_from_enum(schema, prefix, enum_class):
.
readOnly
()
.
initialValue
(
""
)
.
commit
(),
STRING_ELEMENT
(
schema
)
.
key
(
f
"
{
constant_node
}
.constantVersionId
"
)
.
description
(
"
This field is editable - if for any reason a specific constant
"
"
version is desired, the constant version ID (as used in CalCat) can
"
"
be set here and the slot below can be called to load this particular
"
"
version, overriding the automatic loading of latest constants.
"
)
.
assignmentOptional
()
.
defaultValue
(
""
)
.
reconfigurable
()
.
commit
(),
SLOT_ELEMENT
(
schema
)
.
key
(
f
"
{
constant_node
}
.overrideConstantVersion
"
)
.
displayedName
(
"
Override constant version
"
)
.
commit
()
)
...
...
@@ -248,9 +265,9 @@ class BaseCalcatFriend:
"""
Helper to get value from attached device schema
"""
return
self
.
device
.
get
(
f
"
{
self
.
param_prefix
}
.
{
key
}
"
)
def
_set_status
(
self
,
key
,
value
):
def
_set_status
(
self
,
constant
,
key
,
value
):
"""
Helper to update information about found constants on device
"""
self
.
device
.
set
(
f
"
{
self
.
status_prefix
}
.
{
key
}
"
,
value
)
self
.
device
.
set
(
f
"
{
self
.
status_prefix
}
.
{
constant
.
name
}
.
{
key
}
"
,
value
)
@functools.cached_property
def
detector_id
(
self
):
...
...
@@ -328,18 +345,18 @@ class BaseCalcatFriend:
constant
=
self
.
_constant_enum_class
[
constant
]
calibration_id
=
self
.
calibration_id
(
constant
.
name
)
self
.
_set_status
(
f
"
{
constant
.
name
}
.
calibrationId
"
,
calibration_id
)
self
.
_set_status
(
constant
,
f
"
calibrationId
"
,
calibration_id
)
condition
=
self
.
_constants_need_conditions
[
constant
]()
condition_id
=
self
.
condition_id
(
self
.
_karabo_da_to_float_uuid
[
karabo_da
],
condition
)
self
.
_set_status
(
f
"
{
constant
.
name
}
.
conditionId
"
,
condition_id
)
self
.
_set_status
(
constant
,
f
"
conditionId
"
,
condition_id
)
constant_id
=
self
.
constant_id
(
calibration_id
=
calibration_id
,
condition_id
=
condition_id
)
self
.
_set_status
(
f
"
{
constant
.
name
}
.
constantId
"
,
constant_id
)
self
.
_set_status
(
constant
,
f
"
constantId
"
,
constant_id
)
resp
=
CalibrationConstantVersion
.
get_by_uk
(
self
.
client
,
...
...
@@ -352,7 +369,8 @@ class BaseCalcatFriend:
timestamp
=
resp
[
"
data
"
][
"
begin_at
"
]
# TODO: check which key we like (also has begin_validity_at)
self
.
_set_status
(
f
"
{
constant
.
name
}
.createdAt
"
,
timestamp
)
self
.
_set_status
(
constant
,
f
"
createdAt
"
,
timestamp
)
self
.
_set_status
(
constant
,
f
"
constantVersionId
"
,
resp
[
"
data
"
][
"
id
"
])
file_path
=
(
self
.
caldb_store
/
resp
[
"
data
"
][
"
path_to_file
"
]
/
resp
[
"
data
"
][
"
file_name
"
]
...
...
@@ -361,10 +379,34 @@ class BaseCalcatFriend:
with
h5py
.
File
(
file_path
,
"
r
"
)
as
fd
:
constant_data
=
np
.
array
(
fd
[
resp
[
"
data
"
][
"
data_set_name
"
]][
"
data
"
])
self
.
cached_constants
[
constant
]
=
constant_data
self
.
_set_status
(
f
"
{
constant
.
name
}
.
found
"
,
True
)
self
.
_set_status
(
constant
,
f
"
found
"
,
True
)
return
constant_data
def
get_specific_constant_version
(
self
,
constant
):
# TODO: warn if PDU or constant type does not match
# TODO: warn if result is list (happens for empty version ID)
constant_version_id
=
self
.
device
.
get
(
f
"
{
self
.
status_prefix
}
.
{
constant
.
name
}
.constantVersionId
"
)
resp
=
CalibrationConstantVersion
.
get_by_id
(
self
.
client
,
constant_version_id
)
_check_resp
(
resp
)
file_path
=
(
self
.
caldb_store
/
resp
[
"
data
"
][
"
path_to_file
"
]
/
resp
[
"
data
"
][
"
file_name
"
]
)
# TODO: handle FileNotFoundError if we are led astray
with
h5py
.
File
(
file_path
,
"
r
"
)
as
fd
:
constant_data
=
np
.
array
(
fd
[
resp
[
"
data
"
][
"
data_set_name
"
]][
"
data
"
])
self
.
cached_constants
[
constant
]
=
constant_data
self
.
_set_status
(
constant
,
f
"
createdAt
"
,
resp
[
"
data
"
][
"
begin_at
"
])
self
.
_set_status
(
constant
,
f
"
calibrationId
"
,
"
manual override
"
)
self
.
_set_status
(
constant
,
f
"
conditionId
"
,
"
manual override
"
)
self
.
_set_status
(
constant
,
f
"
constantId
"
,
"
manual override
"
)
self
.
_set_status
(
constant
,
f
"
constantVersionId
"
,
constant_version_id
)
self
.
_set_status
(
constant
,
f
"
found
"
,
True
)
return
constant_data
def
get_constant_version_and_call_me_back
(
self
,
constant
,
callback
,
snapshot_at
=
None
):
...
...
@@ -380,10 +422,23 @@ class BaseCalcatFriend:
thread
.
start
()
return
thread
def
get_specific_constant_version_and_call_me_back
(
self
,
constant
,
callback
):
"""
Blindly load whatever CalCat points to for CCV - user must be confident that
this CCV corresponds to correct kind of constant.
"""
# TODO: warn user about all the things that go wrong
def
aux
():
data
=
self
.
get_specific_constant_version
(
constant
)
callback
(
constant
,
data
)
thread
=
threading
.
Thread
(
target
=
aux
)
thread
.
start
()
return
thread
def
flush_constants
(
self
):
for
constant
in
self
.
_constant_enum_class
:
self
.
_set_status
(
f
"
{
constant
.
name
}
.
createdAt
"
,
""
)
self
.
_set_status
(
f
"
{
constant
.
name
}
.
found
"
,
False
)
self
.
_set_status
(
constant
,
f
"
createdAt
"
,
""
)
self
.
_set_status
(
constant
,
f
"
found
"
,
False
)
class
AgipdConstants
(
enum
.
Enum
):
...
...
This diff is collapsed.
Click to expand it.
David Hammer
@hammerd
mentioned in commit
3566342d
·
2 years ago
mentioned in commit
3566342d
mentioned in commit 3566342d031db1bb435b6430f100afdbaaa6c4bf
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