Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F101329751
plot
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Feb 7, 20:11
Size
1 KB
Mime Type
text/x-python
Expires
Sun, Feb 9, 20:11 (2 d)
Engine
blob
Format
Raw Data
Handle
24135993
Attached To
rTAMAAS tamaas
plot
View Options
#!/usr/bin/env python3
# -*- mode: python; coding: utf-8 -*-
# vim: set ft=python:
"""
Read Numpy data from standard input, plot contact tractions and displacements.
"""
import
sys
import
io
import
matplotlib.pyplot
as
plt
import
numpy
as
np
__author__
=
"Lucas Frérot"
__copyright__
=
"""Copyright (©) 2019, EPFL (École Polytechnique Fédérale de Lausanne),
Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)"""
__license__
=
"AGPL"
__email__
=
"lucas.frerot@epfl.ch"
def
load_stream
(
stream
):
"""
Load numpy from binary stream (allows piping)
Code from
https://gist.github.com/CMCDragonkai/3c99fd4aabc8278b9e17f50494fcc30a
"""
np_magic
=
stream
.
read
(
6
)
# use the sys.stdin.buffer to read binary data
np_data
=
stream
.
read
()
# read it all into an io.BytesIO object
return
io
.
BytesIO
(
np_magic
+
np_data
)
fig
,
(
ax_traction
,
ax_displacement
)
=
plt
.
subplots
(
1
,
2
)
ax_traction
.
set_title
(
'Traction'
)
ax_displacement
.
set_title
(
'Displacement'
)
with
load_stream
(
sys
.
stdin
.
buffer
)
as
f_np
:
data
=
np
.
load
(
f_np
)
ax_traction
.
imshow
(
data
[
'traction'
])
ax_displacement
.
imshow
(
data
[
'displacement'
])
fig
.
set_size_inches
(
10
,
6
)
fig
.
tight_layout
()
plt
.
show
()
Event Timeline
Log In to Comment