Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SWIFTsim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
SWIFT
SWIFTsim
Commits
e7ede3af
Commit
e7ede3af
authored
6 years ago
by
Loic Hausammann
Browse files
Options
Downloads
Patches
Plain Diff
Logger: add a python example
parent
f653f041
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!685
Logger loader
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
logger/python/reader_example.py
+55
-0
55 additions, 0 deletions
logger/python/reader_example.py
with
55 additions
and
0 deletions
logger/python/reader_example.py
0 → 100644
+
55
−
0
View file @
e7ede3af
#!/usr/bin/env python3
"""
Read a logger file by using an index.
Example: ./reader_example.py ../../examples/SedovBlast_3D/index.dump ../../examples/SedovBlast_3D/index_0005.hdf5
"""
import
sys
from
h5py
import
File
import
numpy
as
np
import
matplotlib.pyplot
as
plt
sys
.
path
.
append
(
"
../.libs/
"
)
import
libswiftlogger
as
logger
# Get filenames
if
len
(
sys
.
argv
)
!=
3
:
print
(
"
WARNING missing arguments. Will use the default ones
"
)
index
=
"
../../examples/SedovBlast_3D/index_0005.hdf5
"
dump
=
"
../../examples/SedovBlast_3D/index.dump
"
else
:
index
=
sys
.
argv
[
-
1
]
dump
=
sys
.
argv
[
-
2
]
# constant
offset_name
=
"
PartType0/Offset
"
header
=
"
Header
"
time_name
=
"
Time Offset
"
# Read index file
with
File
(
index
,
"
r
"
)
as
f
:
if
offset_name
not
in
f
:
raise
Exception
(
"
Unable to find the offset dataset
"
)
offset
=
f
[
offset_name
][:]
if
header
not
in
f
:
raise
Exception
(
"
Unable to find the header
"
)
if
time_name
not
in
f
[
header
].
attrs
:
raise
Exception
(
"
Unable to find the time offset
"
)
time_offset
=
f
[
header
].
attrs
[
time_name
]
# read dump
data
=
logger
.
loadFromIndex
(
offset
,
dump
,
time_offset
)
# Compute distance from center
pos
=
data
[
"
position
"
]
center
=
pos
.
mean
()
r2
=
np
.
sum
((
pos
-
center
)
**
2
,
axis
=
1
)
# plot entropy vs distance
plt
.
plot
(
np
.
sqrt
(
r2
),
data
[
"
entropy
"
],
'
.
'
)
plt
.
xlim
(
0.
,
0.5
)
plt
.
ylim
(
-
5
,
50
)
plt
.
xlabel
(
"
Radius
"
)
plt
.
ylabel
(
"
Entropy
"
)
plt
.
show
()
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