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
0e9b1ed5
Commit
0e9b1ed5
authored
1 year ago
by
Thomas Kluyver
Browse files
Options
Downloads
Patches
Plain Diff
Backport CalCat CCV metadata API from EXtra
parent
320b21f1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
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
+35
-1
35 additions, 1 deletion
src/cal_tools/calcat_interface2.py
with
35 additions
and
1 deletion
src/cal_tools/calcat_interface2.py
+
35
−
1
View file @
0e9b1ed5
import
json
import
re
from
collections.abc
import
Mapping
from
dataclasses
import
dataclass
,
replace
from
dataclasses
import
dataclass
,
field
,
replace
from
datetime
import
date
,
datetime
,
time
,
timezone
from
functools
import
lru_cache
from
pathlib
import
Path
...
...
@@ -244,6 +244,8 @@ class SingleConstant:
dataset
:
str
ccv_id
:
Optional
[
int
]
pdu_name
:
Optional
[
str
]
_metadata
:
dict
=
field
(
default_factory
=
dict
)
_have_calcat_metadata
:
bool
=
False
@classmethod
def
from_response
(
cls
,
ccv
:
dict
)
->
"
SingleConstant
"
:
...
...
@@ -252,6 +254,8 @@ class SingleConstant:
dataset
=
ccv
[
"
data_set_name
"
],
ccv_id
=
ccv
[
"
id
"
],
pdu_name
=
ccv
[
"
physical_detector_unit
"
][
"
physical_name
"
],
_metadata
=
ccv
,
_have_calcat_metadata
=
True
,
)
def
dataset_obj
(
self
,
caldb_root
=
None
)
->
h5py
.
Dataset
:
...
...
@@ -266,6 +270,36 @@ class SingleConstant:
def
ndarray
(
self
,
caldb_root
=
None
):
return
self
.
dataset_obj
(
caldb_root
)[:]
def
_load_calcat_metadata
(
self
,
client
=
None
):
client
=
client
or
get_client
()
calcat_meta
=
client
.
get
(
f
"
calibration_constant_versions/
{
self
.
ccv_id
}
"
)
# Any metadata we already have takes precedence over CalCat, so
# this can't change a value that was previously returned.
self
.
_metadata
=
calcat_meta
|
self
.
_metadata
self
.
_have_calcat_metadata
=
True
def
metadata
(
self
,
key
,
client
=
None
):
"""
Get a specific metadata field, e.g.
'
begin_validity_at
'
This may make a request to CalCat if the value is not already known.
"""
if
key
not
in
self
.
_metadata
and
not
self
.
_have_calcat_metadata
:
if
self
.
ccv_id
is
None
:
raise
KeyError
(
f
"
{
key
!r}
(no CCV ID to request data from CalCat
"
)
self
.
_load_calcat_metadata
(
client
)
return
self
.
_metadata
[
key
]
def
metadata_dict
(
self
,
client
=
None
):
"""
Get a dict of available metadata
If this constant didn
'
t come from CalCat but we have a CalCat CCV ID,
this will fetch metadata from CalCat.
"""
if
(
not
self
.
_have_calcat_metadata
)
and
(
self
.
ccv_id
is
not
None
):
self
.
_load_calcat_metadata
(
client
)
return
self
.
_metadata
.
copy
()
def
prepare_selection
(
module_details
,
module_nums
=
None
,
aggregator_names
=
None
,
qm_names
=
None
...
...
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