Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EXDF-tools
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
Package Registry
Model registry
Operate
Environments
Terraform modules
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
dataAnalysis
EXDF-tools
Commits
95ccc885
Commit
95ccc885
authored
1 year ago
by
Philipp Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
Properly copy attributes of CONTROL leafs and RUN-only keys
parent
ac5e32e5
No related branches found
No related tags found
1 merge request
!9
Properly copy attributes of CONTROL key leafs and RUN-only keys
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/exdf/write/sd_writer.py
+42
-12
42 additions, 12 deletions
src/exdf/write/sd_writer.py
with
42 additions
and
12 deletions
src/exdf/write/sd_writer.py
+
42
−
12
View file @
95ccc885
...
...
@@ -10,7 +10,7 @@ stricter validation when combining data from different locations.
from
functools
import
reduce
from
itertools
import
accumulate
from
itertools
import
accumulate
,
product
from
logging
import
getLogger
from
operator
import
or_
from
os.path
import
basename
...
...
@@ -207,22 +207,35 @@ class SourceDataWriter:
if
run_entry
:
run_entry
=
(
run_entry
[
'
value
'
],
run_entry
[
'
timestamp
'
])
ctrl_values
=
sd
[
f
'
{
key
}
.value
'
].
ndarray
()
ctrl_timestamps
=
sd
[
f
'
{
key
}
.timestamp
'
].
ndarray
()
value_key
=
f
'
{
key
}
.value
'
timestamp_key
=
f
'
{
key
}
.timestamp
'
ctrl_values
=
sd
[
value_key
].
ndarray
()
ctrl_timestamps
=
sd
[
timestamp_key
].
ndarray
()
h5source
.
create_key
(
key
,
values
=
ctrl_values
,
timestamps
=
ctrl_timestamps
,
run_entry
=
run_entry
,
attrs
=
attrs
.
pop
(
key
,
None
))
run_entry
=
run_entry
,
attrs
=
attrs
.
pop
(
key
,
None
),
attrs_value
=
attrs
.
pop
(
value_key
,
None
),
attrs_timestamp
=
attrs
.
pop
(
timestamp_key
,
None
))
# Write remaining RUN-only keys.
for
key
,
leafs
in
run_data_leafs
.
items
():
h5source
.
create_run_key
(
key
,
**
leafs
,
attrs
=
attrs
.
pop
(
key
,
None
))
key
,
**
leafs
,
attrs
=
attrs
.
pop
(
key
,
None
),
attrs_value
=
attrs
.
pop
(
f
'
{
key
}
.value
'
,
None
),
attrs_timestamp
=
attrs
.
pop
(
f
'
{
key
}
.timestamp
'
,
None
))
# Fill in the missing attributes for nodes.
for
path
,
attrs
in
attrs
.
items
():
h5source
.
run_key
[
path
].
attrs
.
update
(
attrs
)
h5source
.
key
[
path
].
attrs
.
update
(
attrs
)
try
:
grp
=
h5source
.
key
[
path
]
except
KeyError
:
pass
# May be RUN-only.
else
:
grp
.
attrs
.
update
(
attrs
)
def
write_instrument
(
self
,
f
,
sources
):
"""
Write INSTRUMENT data.
...
...
@@ -436,22 +449,39 @@ def build_sources_index(sources):
def
get_key_attributes
(
sd
):
if
sd
.
is_control
:
section
=
'
RUN
'
keys
=
{
key
[:
key
.
rfind
(
'
.
'
)]
for
key
in
sd
.
run_values
().
keys
()}
leaf_suffixes
=
[
''
,
'
.value
'
,
'
.timestamp
'
]
else
:
section
=
'
INSTRUMENT
'
keys
=
sd
.
keys
()
leaf_suffixes
=
[
''
]
source_attrs
=
dict
()
def
build_path
(
a
,
b
):
return
f
'
{
a
}
.
{
b
}
'
for
key
in
sd
.
keys
(
inc_timestamps
=
False
):
# Find the true files belonging to this source, assuming they're all
# in the same file via a random key. Importantly this will be a try
# CONTROL key in the case of CONTROL sources, not a RUN-only key.
files
=
[
FileAccess
(
f
)
for
f
in
sd
[
sd
.
one_key
()].
source_file_paths
]
for
key
in
keys
:
paths
=
accumulate
(
key
.
split
(
'
.
'
),
func
=
build_path
)
for
path
in
paths
:
if
path
in
source_attrs
:
for
base_
path
in
paths
:
if
base_
path
in
source_attrs
:
# Skip this path, already parent of some other key.
continue
for
source_file
in
sd
[
key
].
source_file_paths
:
fa
=
FileAccess
(
source_file
)
hdf_path
=
f
'
{
sd
.
section
}
/
{
sd
.
source
}
/
{
path
.
replace
(
"
.
"
,
"
/
"
)
}
'
for
fa
,
suffix
in
product
(
files
,
leaf_suffixes
if
base_path
==
key
else
[
''
]
):
path
=
base_path
+
suffix
hdf_path
=
f
'
{
section
}
/
{
sd
.
source
}
/
{
path
.
replace
(
"
.
"
,
"
/
"
)
}
'
path_attrs
=
dict
(
fa
.
file
[
hdf_path
].
attrs
)
existing_attrs
=
source_attrs
.
setdefault
(
path
,
path_attrs
)
...
...
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