Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F95671084
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
Wed, Dec 18, 05:48
Size
1 KB
Mime Type
text/x-python
Expires
Fri, Dec 20, 05:48 (1 d, 20 h)
Engine
blob
Format
Raw Data
Handle
23038372
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-2021, EPFL (École Polytechnique Fédérale de Lausanne),"
"
\n
Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)"
)
__license__
=
"AGPL"
__email__
=
"lucas.frerot@gmail.com"
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