Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jigyasa Watwani
/
growth-pattern-control
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
9ce31f90
authored
Nov 30, 2022
by
Jigyasa Watwani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1-D plotting with matplotlib
parent
dcc08e44
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
8 deletions
growing_domain/viz_growing_domains.py
growing_domain/viz_growing_domains.py
View file @
9ce31f90
...
@@ -3,6 +3,9 @@ import numpy as np
...
@@ -3,6 +3,9 @@ import numpy as np
import
vedo
as
vd
import
vedo
as
vd
import
os
import
os
import
h5py
import
h5py
from
matplotlib.widgets
import
Slider
import
matplotlib.pyplot
as
plt
from
tempfile
import
TemporaryDirectory
from
tempfile
import
TemporaryDirectory
def
get_data
(
params
,
DIR
=
''
):
def
get_data
(
params
,
DIR
=
''
):
...
@@ -19,6 +22,8 @@ def get_data(params, DIR=''):
...
@@ -19,6 +22,8 @@ def get_data(params, DIR=''):
geometry
.
append
(
np
.
array
(
h5
[
'
%
s/
%
s_
%
d/mesh/geometry'
%
(
var
,
var
,
i
)]))
geometry
.
append
(
np
.
array
(
h5
[
'
%
s/
%
s_
%
d/mesh/geometry'
%
(
var
,
var
,
i
)]))
h5
.
close
()
h5
.
close
()
geometry
=
np
.
array
(
geometry
)
geometry
=
np
.
array
(
geometry
)
if
params
[
'dimension'
]
==
1
:
geometry
,
zeros
=
np
.
dsplit
(
geometry
,
2
)
# create a mesh
# create a mesh
if
params
[
'dimension'
]
==
1
:
if
params
[
'dimension'
]
==
1
:
...
@@ -42,6 +47,7 @@ def get_data(params, DIR=''):
...
@@ -42,6 +47,7 @@ def get_data(params, DIR=''):
cFile
=
os
.
path
.
join
(
DIR
,
'
%
s_
%
s.xdmf'
%
(
params
[
'timestamp'
],
var
))
cFile
=
os
.
path
.
join
(
DIR
,
'
%
s_
%
s.xdmf'
%
(
params
[
'timestamp'
],
var
))
with
df
.
XDMFFile
(
cFile
)
as
cFile
:
with
df
.
XDMFFile
(
cFile
)
as
cFile
:
for
steps
in
range
(
savesteps
+
1
):
for
steps
in
range
(
savesteps
+
1
):
if
params
[
'dimension'
]
==
1
:
mesh
.
coordinates
()[:]
=
geometry
[
steps
]
mesh
.
coordinates
()[:]
=
geometry
[
steps
]
VFS
=
df
.
FunctionSpace
(
mesh
,
'P'
,
1
)
VFS
=
df
.
FunctionSpace
(
mesh
,
'P'
,
1
)
c
=
df
.
Function
(
VFS
)
c
=
df
.
Function
(
VFS
)
...
@@ -51,11 +57,36 @@ def get_data(params, DIR=''):
...
@@ -51,11 +57,36 @@ def get_data(params, DIR=''):
return
(
times
,
geometry
,
topology
,
concentration
)
return
(
times
,
geometry
,
topology
,
concentration
)
def
visualize
(
params
,
DIR
=
''
,
offscreen
=
False
):
def
visualize
(
params
,
DIR
=
''
,
offscreen
=
False
):
(
times
,
geometry
,
topology
,
concentration
)
=
get_data
(
params
,
DIR
)
radius
=
np
.
linalg
.
norm
(
geometry
,
axis
=
2
)
if
params
[
'dimension'
]
==
1
:
fig
,
axc
=
plt
.
subplots
(
1
,
1
,
figsize
=
(
8
,
8
))
axc
.
set_xlabel
(
r'$x$'
)
axc
.
set_xlim
(
np
.
min
(
radius
),
np
.
max
(
radius
))
axc
.
set_ylim
(
np
.
min
(
concentration
),
np
.
max
(
concentration
))
axc
.
set_ylabel
(
r'$c(x,t)$'
)
cplot
,
=
axc
.
plot
(
radius
[
0
],
concentration
[
0
])
def
update
(
value
):
ti
=
np
.
abs
(
times
-
value
)
.
argmin
()
cplot
.
set_ydata
(
concentration
[
ti
])
cplot
.
set_xdata
(
radius
[
ti
])
plt
.
draw
()
sax
=
plt
.
axes
([
0.1
,
0.92
,
0.7
,
0.02
])
slider
=
Slider
(
sax
,
r'$t/\tau$'
,
min
(
times
),
max
(
times
),
valinit
=
min
(
times
),
valfmt
=
'
%3.1
f'
,
fc
=
'#999999'
)
slider
.
drawon
=
False
slider
.
on_changed
(
update
)
plt
.
show
()
else
:
# heat map
n_cmap_vals
=
16
n_cmap_vals
=
16
scalar_cmap
=
'viridis'
scalar_cmap
=
'viridis'
(
times
,
geometry
,
topology
,
concentration
)
=
get_data
(
params
,
DIR
)
if
params
[
'dimension'
]
==
2
:
geometry
=
np
.
dstack
((
geometry
,
np
.
zeros
(
geometry
.
shape
[
0
:
2
])))
geometry
=
np
.
dstack
((
geometry
,
np
.
zeros
(
geometry
.
shape
[
0
:
2
])))
cmin
,
cmax
=
np
.
min
(
concentration
),
np
.
max
(
concentration
)
cmin
,
cmax
=
np
.
min
(
concentration
),
np
.
max
(
concentration
)
...
@@ -67,9 +98,10 @@ def visualize(params, DIR='', offscreen=False):
...
@@ -67,9 +98,10 @@ def visualize(params, DIR='', offscreen=False):
#scalar_actor.computeNormals(points=True, cells=True)
#scalar_actor.computeNormals(points=True, cells=True)
scalar_actor
.
pointdata
[
'concentration'
]
=
concentration
[
0
]
scalar_actor
.
pointdata
[
'concentration'
]
=
concentration
[
0
]
scalar_actor
.
cmap
(
scalar_cmap
,
concentration
[
0
],
vmin
=
cmin
,
vmax
=
cmax
,
n
=
n_cmap_vals
)
scalar_actor
.
cmap
(
scalar_cmap
,
concentration
[
0
],
vmin
=
cmin
,
vmax
=
cmax
,
n
=
n_cmap_vals
)
scalar_actor
.
addScalarB
ar
(
title
=
r'$c$'
,
scalar_actor
.
add_scalarb
ar
(
title
=
r'$c$'
,
pos
=
(
0.8
,
0.04
),
nlabels
=
2
,
pos
=
(
0.8
,
0.04
),
nlabels
=
2
,
titleYOffset
=
15
,
titleFontSize
=
28
,
size
=
(
100
,
600
))
# titleYOffset=15, titleFontSize=28, size=(100, 600)
)
plotter
+=
scalar_actor
plotter
+=
scalar_actor
def
update
(
idx
):
def
update
(
idx
):
...
@@ -81,12 +113,35 @@ def visualize(params, DIR='', offscreen=False):
...
@@ -81,12 +113,35 @@ def visualize(params, DIR='', offscreen=False):
idx
=
(
abs
(
times
-
value
))
.
argmin
()
idx
=
(
abs
(
times
-
value
))
.
argmin
()
update
(
idx
)
update
(
idx
)
slider
=
plotter
.
addSlider2D
(
slider_update
,
pos
=
[(
0.1
,
0.94
),
(
0.5
,
0.94
)],
slider
=
plotter
.
add_slider
(
slider_update
,
pos
=
[(
0.1
,
0.94
),
(
0.5
,
0.94
)],
xmin
=
times
[
0
],
xmax
=
times
.
max
(),
xmin
=
times
[
0
],
xmax
=
times
.
max
(),
value
=
times
[
0
],
title
=
r"$t/\tau$"
)
value
=
times
[
0
],
title
=
r"$t/\tau$"
)
vd
.
show
(
interactive
=
(
not
offscreen
),
zoom
=
0.8
)
vd
.
show
(
interactive
=
(
not
offscreen
),
zoom
=
0.8
)
# c(r,t) vs r
fig1
,
axc1
=
plt
.
subplots
(
1
,
1
,
figsize
=
(
8
,
8
))
axc1
.
set_xlabel
(
r'$r$'
)
axc1
.
set_xlim
(
np
.
min
(
radius
),
np
.
max
(
radius
))
axc1
.
set_ylim
(
np
.
min
(
concentration
),
np
.
max
(
concentration
))
axc1
.
set_ylabel
(
r'$c(r,t)$'
)
cplot
,
=
axc1
.
plot
(
radius
[
0
],
concentration
[
0
],
'o'
,
ms
=
3
)
def
update
(
value
):
ti
=
np
.
abs
(
times
-
value
)
.
argmin
()
cplot
.
set_ydata
(
concentration
[
ti
])
cplot
.
set_xdata
(
radius
[
ti
])
plt
.
draw
()
sax
=
plt
.
axes
([
0.1
,
0.92
,
0.7
,
0.02
])
slider
=
Slider
(
sax
,
r'$t/\tau$'
,
min
(
times
),
max
(
times
),
valinit
=
min
(
times
),
valfmt
=
'
%3.1
f'
,
fc
=
'#999999'
)
slider
.
drawon
=
False
slider
.
on_changed
(
update
)
plt
.
show
()
# make movie
# make movie
if
offscreen
:
if
offscreen
:
FPS
=
10
FPS
=
10
...
@@ -119,4 +174,3 @@ if __name__ == '__main__':
...
@@ -119,4 +174,3 @@ if __name__ == '__main__':
params
=
json
.
load
(
jsonFile
)
params
=
json
.
load
(
jsonFile
)
visualize
(
params
,
DIR
=
os
.
path
.
dirname
(
args
.
jsonfile
),
offscreen
=
(
not
args
.
onscreen
))
visualize
(
params
,
DIR
=
os
.
path
.
dirname
(
args
.
jsonfile
),
offscreen
=
(
not
args
.
onscreen
))
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment