Skip to content

Commit 975ed38

Browse files
committed
animation example
1 parent 9cdcd09 commit 975ed38

File tree

6 files changed

+81
-26
lines changed

6 files changed

+81
-26
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,8 @@ venv.bak/
102102

103103
# mypy
104104
.mypy_cache/
105+
106+
*.gif
107+
*.png
108+
*.mpg
109+
batch.log

hello-pytecplot.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import tecplot as tp
2+
3+
# connect to running instance of Tecplot 360 on port 7601
4+
tp.session.connect(port=7601)
5+
6+
# reset the layout. This will clear any previously loaded data
7+
tp.new_layout()
8+
9+
# get handle to the active frame
10+
frame = tp.active_frame()
11+
12+
# add a text box. The anchor will be in the center of the frame
13+
txt = frame.add_text('Hello, PyTecplot!', (50, 50))
14+
15+
# make text larger
16+
txt.size = 48
17+
18+
# center text by centering the anchor point
19+
txt.anchor = TextAnchor.MidCenter
20+
21+
# change the text color
22+
txt.color = Color.Blue
23+
File renamed without changes.

hello-world.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
frame = tp.active_frame()
55

66
# add a text box. The anchor will be in the center of the frame
7-
frame.add_text('Hello, World!', (50, 50))
7+
frame.add_text('Hello, World!', (50, 50), size=48)
88

99
# save an image of the frame
1010
tp.save_png('hello-world.png')
Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,44 @@
11
import glob
2-
import os
3-
import re
42
import sys
53

4+
import numpy as np
5+
66
import tecplot as tp
77
from tecplot.constant import *
88

9-
109
def plot_data(plot):
10+
"""Plot Isosurface of constant Pressure, contouring on Temperature"""
1111
T = plot.frame.dataset.variable('Temperature')
1212
P = plot.frame.dataset.variable('Pressure')
13-
14-
contour = plot.contour(0)
13+
plot = tp.active_frame().plot(PlotType.Cartesian3D)
14+
plot.show_shade = False
15+
plot.show_slices = True
16+
plot.show_isosurfaces = True
17+
contour = plot.slice(0).contour.flood_contour_group
1518
contour.variable = T
1619
contour.legend.auto_resize = True
17-
contour.colormap_filter.distribution = \
18-
ColorMapDistribution.Continuous
19-
contour.colormap_filter.continuous_min = 280
20-
contour.colormap_filter.continuous_max = 380
21-
22-
isosurf = tp.active_frame().plot().isosurface(0)
20+
contour.levels.reset_levels(np.linspace(280, 380, 201))
21+
isosurf = plot.isosurface(0)
2322
isosurf.definition_contour_group_index = 1
2423
isosurf.definition_contour_group.variable = P
25-
isosurf.contour.flood_contour_group = contour
2624
isosurf.isosurface_values = -6000
27-
25+
isosurf.contour.flood_contour_group = contour
2826
slice = tp.active_frame().plot().slice(0)
2927
slice.effects.use_translucency = True
3028
slice.effects.surface_translucency = 40
31-
32-
plot.show_shade = False
33-
plot.show_slices = True
34-
plot.show_isosurfaces = True
35-
3629
plot.view.psi = 68.2286
3730
plot.view.theta = -124.114
3831
plot.view.position = 2.95931, 2.15999, 1.45886
3932
plot.view.width = 0.339885
4033

41-
4234
if '-c' in sys.argv:
4335
tp.session.connect()
36+
tp.new_layout()
4437

4538
# sorting on filenames determines order of animation
46-
files = sorted(glob.glob('HotWaterMixing_Y05YT10*.plt'))
39+
files = sorted(glob.glob('hotwatermixing/HotWaterMixing_Y05YT10*.plt'))
4740

48-
# clear the layout, load the data and activate the 3D plot
49-
tp.new_layout()
41+
# load all data files and activate the 3D plot
5042
dataset = tp.data.load_tecplot(files)
5143
plot = tp.active_frame().plot(PlotType.Cartesian3D)
5244
plot.activate()
@@ -60,8 +52,20 @@ def plot_data(plot):
6052

6153
# Turn on one fieldmap at a time and save animation frame
6254
with tp.export.animation_mpeg4('hotwater-animation.mpg') as animation:
55+
56+
# for each zone named "fluid"
57+
# these will be in the order they were loaded
6358
for zone in dataset.zones('fluid'):
59+
60+
# get handle to fieldmap for this zone
6461
fmap = plot.fieldmap(zone)
62+
63+
# turn on this fieldmap
6564
fmap.show = True
65+
66+
# export a single animation frame
6667
animation.export_animation_frame()
68+
69+
# turn off this fieldmap
6770
fmap.show = False
71+

hotwater-isosurface.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,63 @@
11
import sys
2+
23
import numpy as np
4+
35
import tecplot as tp
46
from tecplot.exception import *
57
from tecplot.constant import *
68

9+
# if "-c" is passed as an argument from the
10+
# console conntect to Tecplot 360 on the
11+
# default port (7600) and clear the layout
712
if '-c' in sys.argv:
813
tp.session.connect()
914
tp.new_layout()
1015

16+
# load a single data file
1117
infile = 'hotwatermixing/HotWaterMixing.plt'
1218
dataset = tp.data.load_tecplot(infile)
19+
20+
# get handles to variables in the dataset
21+
T = dataset.variable('Temperature')
22+
P = dataset.variable('Pressure')
23+
24+
# get handle to 3D plot
1325
plot = tp.active_frame().plot(PlotType.Cartesian3D)
26+
27+
# turn on slices and isosurfaces, turn off shade
1428
plot.show_shade = False
1529
plot.show_slices = True
30+
plot.show_isosurfaces = True
31+
32+
# set slice flood contour to Temperature
33+
# and adjust contour levels
1634
contour = plot.slice(0).contour.flood_contour_group
17-
contour.variable = dataset.variable('Temperature')
35+
contour.variable = T
1836
contour.legend.auto_resize = True
1937
contour.levels.reset_levels(np.linspace(280, 380, 201))
2038

2139
# get handle to isosurface group
2240
isosurf = plot.isosurface(0)
2341

42+
# isosurface will be a constant value of Pressure
2443
isosurf.definition_contour_group_index = 1
2544
isosurf.definition_contour_group.variable = P
26-
isosurf.contour.flood_contour_group = contour
2745
isosurf.isosurface_values = -6000
2846

47+
# isosurface contoured by Temperature
48+
isosurf.contour.flood_contour_group = contour
49+
50+
# make slice translucent
2951
slice = tp.active_frame().plot().slice(0)
3052
slice.effects.use_translucency = True
3153
slice.effects.surface_translucency = 40
3254

33-
55+
# adjust the view
3456
plot.view.psi = 68.2286
3557
plot.view.theta = -124.114
3658
plot.view.position = 2.95931, 2.15999, 1.45886
3759
plot.view.width = 0.339885
3860

61+
# save image
3962
tp.save_png('hotwater-isosurface.png')
4063

0 commit comments

Comments
 (0)