Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
pygwinc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Lee McCuller
pygwinc
Commits
cace8e80
Commit
cace8e80
authored
4 years ago
by
Jameson Rollins
Browse files
Options
Downloads
Patches
Plain Diff
io: serialize 'ifo' objects in HDF5 IO
convert IFO Structs to yaml for HDF5 storage
parent
1b2462cd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gwinc/io.py
+21
-5
21 additions, 5 deletions
gwinc/io.py
with
21 additions
and
5 deletions
gwinc/io.py
+
21
−
5
View file @
cace8e80
import
h5py
import
datetime
from
.
import
Struct
SCHEMA
=
'
GWINC noise budget
'
SCHEMA_VERSION
=
1
...
...
@@ -19,7 +21,13 @@ def _write_trace_recursive(grp, traces):
def
save_hdf5
(
path
,
freq
,
traces
,
**
kwargs
):
"""
Save GWINC traces dict to HDF5 file.
"""
Save GWINC budget data to an HDF5 file.
The `freq` argument should be the frequency array, and `traces`
should be the traces (recursive) dictionary. Keyword arguments
are stored in the HDF5 top level
'
attrs
'
key-value store. If an
'
ifo
'
keyword arg is supplied, it is assumed to be a Struct and
will be serialized to YAML for storage.
See HDF5_SCHEMA.
...
...
@@ -30,7 +38,10 @@ def save_hdf5(path, freq, traces, **kwargs):
# FIXME: add budget code hash or something
f
.
attrs
[
'
date
'
]
=
datetime
.
datetime
.
now
().
isoformat
()
for
key
,
val
in
kwargs
.
items
():
f
.
attrs
[
key
]
=
val
if
key
==
'
ifo
'
:
f
.
attrs
[
'
ifo
'
]
=
val
.
to_yaml
()
else
:
f
.
attrs
[
key
]
=
val
f
.
create_dataset
(
'
Freq
'
,
data
=
freq
)
tgrp
=
f
.
create_group
(
'
traces
'
)
_write_trace_recursive
(
tgrp
,
traces
)
...
...
@@ -47,14 +58,19 @@ def _read_trace_recursive(element):
def
load_hdf5
(
path
):
"""
Load
traces
from HDF5 file.
"""
Load
GWINC budget data
from
an
HDF5 file.
Returns a recursive traces dictionary. See HDF5_SCHEMA.
Returns (freq, traces, attrs). An
'
ifo
'
attr will be
de-serialized from YAML into a Struct object.
See HDF5_SCHEMA.
"""
with
h5py
.
File
(
path
,
'
r
'
)
as
f
:
# FIXME: check SCHEMA name/version
freq
=
f
[
'
Freq
'
][:]
traces
=
_read_trace_recursive
(
f
[
'
/traces
'
])
attrs
=
dict
(
f
.
attrs
.
items
())
attrs
=
dict
(
f
.
attrs
)
if
'
ifo
'
in
attrs
:
attrs
[
'
ifo
'
]
=
Struct
.
from_yaml
(
attrs
[
'
ifo
'
])
return
freq
,
traces
,
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