Skip to content

Commit 836426b

Browse files
committed
tested simple_multipass, added display_vector_field_from_arrays
1 parent 7a0686f commit 836426b

File tree

3 files changed

+259
-103
lines changed

3 files changed

+259
-103
lines changed

openpiv/test/test_windef.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66

77
import pathlib
88
import numpy as np
9+
from importlib_resources import files
910
from openpiv import windef
1011
from openpiv.test import test_process
12+
from openpiv.tools import display_vector_field, display_vector_field_from_arrays, save
13+
from openpiv.tools import imread
1114

1215
frame_a, frame_b = test_process.create_pair(image_size=256)
1316
shift_u, shift_v, threshold = test_process.SHIFT_U, test_process.SHIFT_V, \
@@ -45,8 +48,11 @@ def test_first_pass_circ():
4548
settings
4649
)
4750
print("\n", x, y, u, v, s2n)
48-
assert np.mean(np.abs(u - shift_u)) < threshold
49-
assert np.mean(np.abs(v - shift_v)) < threshold
51+
assert np.allclose(u, shift_u, atol=threshold)
52+
assert np.allclose(v, shift_v, atol=threshold)
53+
54+
save('tmp.txt',x,y,u,v)
55+
display_vector_field('tmp.txt')
5056

5157

5258
def test_multi_pass_circ():
@@ -91,8 +97,8 @@ def test_multi_pass_circ():
9197
print(u)
9298
print(v)
9399
print(s2n)
94-
assert np.mean(np.abs(u - shift_u)) < threshold
95-
assert np.mean(np.abs(v - shift_v)) < threshold
100+
assert np.allclose(u, shift_u, atol=threshold)
101+
assert np.allclose(v, shift_v, atol=threshold)
96102
# the second condition is to check if the multipass is done.
97103
# It need's a little numerical inaccuracy.
98104

@@ -116,8 +122,8 @@ def test_first_pass_lin():
116122
settings,
117123
)
118124
print("\n", x, y, u, v, s2n)
119-
assert np.mean(np.abs(u - shift_u)) < threshold
120-
assert np.mean(np.abs(v - shift_v)) < threshold
125+
assert np.allclose(u, shift_u, atol=threshold)
126+
assert np.allclose(v, shift_v, atol=threshold)
121127

122128

123129
def test_save_plot():
@@ -185,11 +191,10 @@ def test_multi_pass_lin():
185191
)
186192

187193
print("\n", x, y, u, v, s2n)
188-
assert np.mean(np.abs(u - shift_u)) < threshold
189-
assert np.mean(np.abs(v - shift_v)) < threshold
194+
assert np.allclose(u, shift_u, atol=threshold)
195+
assert np.allclose(v, shift_v, atol=threshold)
190196

191197

192-
mask_coords = []
193198
u = np.ma.masked_array(u, mask=np.ma.nomask)
194199
v = np.ma.masked_array(v, mask=np.ma.nomask)
195200

@@ -228,6 +233,10 @@ def test_simple_multipass():
228233
frame_b,
229234
settings,
230235
)
236+
237+
save('tmp.txt', x, y, u, v)
238+
display_vector_field('tmp.txt')
239+
231240
# print("simple multipass\n")
232241
# print(x,y,u,v,mask)
233242
# print(u[:4,:4])
@@ -267,7 +276,7 @@ def test_simple_rectangular_window():
267276
settings = windef.PIVSettings()
268277

269278

270-
x, y, _,_,_ = windef.simple_multipass(
279+
x, y, u, v, _ = windef.simple_multipass(
271280
frame_a,
272281
frame_b,
273282
settings,
@@ -299,15 +308,27 @@ def test_simple_rectangular_window():
299308
settings.overlap = ((16, 32), (8, 16))
300309
settings.num_iterations = 2
301310

302-
x, y, _, _, _ = windef.simple_multipass(
311+
x, y, u, v, mask = windef.simple_multipass(
303312
frame_a,
304313
frame_b,
305314
settings,
306315
)
307316
assert np.diff(x[0,:2]) == 16
308-
assert np.diff(y[:2,0]) == -8
317+
assert np.diff(y[:2,0]) == -8
318+
319+
309320

310321
settings.show_all_plots = False
311322
settings.show_plot = True
312323

313324
windef.piv(settings)
325+
326+
im1 = imread(files('openpiv.data').joinpath('test1/exp1_001_a.bmp'))
327+
im2 = imread(files('openpiv.data').joinpath('test1/exp1_001_b.bmp'))
328+
x, y, u, v, mask = windef.simple_multipass(
329+
im1,
330+
im2,
331+
settings,
332+
)
333+
display_vector_field_from_arrays(x, y, u, v, 0*u, 0*v)
334+

0 commit comments

Comments
 (0)