forked from pyvista/pyvista
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_examples.py
180 lines (133 loc) · 4.58 KB
/
test_examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import os
from subprocess import PIPE, Popen
import numpy as np
import pytest
import vtk
import vtki
from vtki import examples
from vtki.plotting import running_xserver
TEST_DOWNLOADS = False
try:
if os.environ['TEST_DOWNLOADS'] == 'True':
TEST_DOWNLOADS = True
except KeyError:
pass
@pytest.mark.skipif(not running_xserver(), reason="Requires X11")
def test_docexample_advancedplottingwithnumpy():
import vtki
import numpy as np
# Make a grid
x, y, z = np.meshgrid(np.linspace(-5, 5, 20),
np.linspace(-5, 5, 20),
np.linspace(-5, 5, 5))
points = np.empty((x.size, 3))
points[:, 0] = x.ravel('F')
points[:, 1] = y.ravel('F')
points[:, 2] = z.ravel('F')
# Compute a direction for the vector field
direction = np.sin(points)**3
# plot using the plotting class
plotter = vtki.Plotter(off_screen=True)
plotter.add_arrows(points, direction, 0.5)
plotter.set_background([0, 0, 0]) # RGB set to black
plotter.plot(auto_close=False)
np.any(plotter.screenshot())
plotter.close()
@pytest.mark.skipif(not running_xserver(), reason="Requires X11")
def test_creatingagifmovie(tmpdir, off_screen=True):
if tmpdir:
filename = str(tmpdir.mkdir("tmpdir").join('wave.gif'))
else:
filename = '/tmp/wave.gif'
x = np.arange(-10, 10, 0.25)
y = np.arange(-10, 10, 0.25)
x, y = np.meshgrid(x, y)
r = np.sqrt(x**2 + y**2)
z = np.sin(r)
# Create and structured surface
grid = vtki.StructuredGrid(x, y, z)
# Make copy of points
pts = grid.points.copy()
# Start a plotter object and set the scalars to the Z height
plotter = vtki.Plotter(off_screen=off_screen)
plotter.add_mesh(grid, scalars=z.ravel())
plotter.plot(auto_close=False)
# Open a gif
plotter.open_gif(filename)
# Update Z and write a frame for each updated position
nframe = 5
for phase in np.linspace(0, 2*np.pi, nframe + 1)[:nframe]:
z = np.sin(r + phase)
pts[:, -1] = z.ravel()
plotter.update_coordinates(pts)
plotter.update_scalars(z.ravel())
plotter.write_frame()
# Close movie and delete object
plotter.close()
@pytest.mark.skipif(not running_xserver(), reason="Requires X11")
def test_plot_wave():
points = examples.plot_wave(wavetime=0.1, off_screen=True)
assert isinstance(points, np.ndarray)
@pytest.mark.skipif(not running_xserver(), reason="Requires X11")
def test_beam_example():
examples.beam_example(off_screen=True)
@pytest.mark.skipif(not running_xserver(), reason="Requires X11")
def test_plot_ants_plane():
examples.plot_ants_plane(off_screen=True)
def test_load_ant():
""" Load ply ant mesh """
mesh = examples.load_ant()
assert mesh.n_points
def test_load_airplane():
""" Load ply airplane mesh """
mesh = examples.load_airplane()
assert mesh.n_points
def test_load_sphere():
""" Loads sphere ply mesh """
mesh = examples.load_sphere()
assert mesh.n_points
def test_load_channels():
""" Loads geostat training image """
mesh = examples.load_channels()
assert mesh.n_points
if TEST_DOWNLOADS:
def test_download_masonry_texture():
data = examples.download_masonry_texture()
assert isinstance(data, vtk.vtkTexture)
def test_download_usa_texture():
data = examples.download_usa_texture()
assert isinstance(data, vtk.vtkTexture)
def test_download_usa():
data = examples.download_usa()
assert np.any(data.points)
def test_download_st_helens():
data = examples.download_st_helens()
assert data.n_points
def test_download_bunny():
data = examples.download_bunny()
assert data.n_points
def test_download_cow():
data = examples.download_cow()
assert data.n_points
def test_download_faults():
data = examples.download_faults()
assert data.n_points
def test_download_tensors():
data = examples.download_tensors()
assert data.n_points
def test_download_head():
data = examples.download_head()
assert data.n_points
def test_download_bolt_nut():
data = examples.download_bolt_nut()
assert isinstance(data, vtki.MultiBlock)
def test_download_clown():
data = examples.download_clown()
assert data.n_points
def test_download_exodus():
data = examples.download_exodus()
assert data.n_blocks
def test_download_nefertiti():
data = examples.download_nefertiti()
assert data.n_cells
# End of download tests