Skip to content

Commit 991d83a

Browse files
authored
Merge pull request #247 from alexlib/simple_windef
added simple_multiplass to windef, 0.24.2
2 parents 4a035de + 05b557a commit 991d83a

File tree

3 files changed

+96
-6
lines changed

3 files changed

+96
-6
lines changed

openpiv/test/test_windef.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@
55
@author: Theo
66
"""
77

8-
8+
import pathlib
99
import numpy as np
1010
from openpiv import windef
1111
from openpiv.test import test_process
1212
from openpiv import preprocess
13-
import pathlib
14-
import os
15-
import matplotlib.pyplot as plt
1613

1714
frame_a, frame_b = test_process.create_pair(image_size=256)
1815
shift_u, shift_v, threshold = test_process.shift_u, test_process.shift_v, \
@@ -178,9 +175,38 @@ def test_multi_pass_lin():
178175
settings,
179176
)
180177
print(f"Iteration {i}")
181-
print("\n", x, y, u, v, s2n)
178+
print(u[:2,:2],v[:2,:2])
182179
assert np.allclose(u, shift_u, atol=threshold)
183180
assert np.allclose(v, shift_v, atol=threshold)
184181

185182
# the second condition is to check if the multipass is done.
186183
# It need's a little numerical inaccuracy.
184+
185+
def test_simple_multipass():
186+
""" Test simple multipass """
187+
x, y, u, v, s2n = windef.simple_multipass(
188+
frame_a,
189+
frame_b
190+
)
191+
print("simple multipass\n")
192+
print(u[:2,:2],v[:2,:2])
193+
194+
# note the -shift_v
195+
# the simple_multipass also transforms units, so
196+
# the plot is in the image-like space
197+
198+
assert np.allclose(u, shift_u, atol=threshold)
199+
assert np.allclose(v, -shift_v, atol=threshold)
200+
201+
202+
# windowsizes = (64, 32, 16)
203+
x, y, u, v, s2n = windef.simple_multipass(
204+
frame_a,
205+
frame_b,
206+
windows = (32,16)
207+
)
208+
assert np.allclose(u, shift_u, atol=threshold)
209+
assert np.allclose(v, -shift_v, atol=threshold)
210+
211+
# the second condition is to check if the multipass is done.
212+
# It need's a little numerical inaccuracy.

openpiv/windef.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,70 @@
2121
from openpiv import smoothn
2222
from skimage.util import invert
2323

24+
def simple_multipass(frame_a, frame_b, windows = None):
25+
""" Simple windows deformation multipass run with
26+
default settings
27+
"""
28+
settings = Settings() # default, see below
29+
30+
if windows is not None:
31+
settings.num_iterations = len(windows)
32+
settings.windowsizes = windows
33+
settings.overlap = [int(w/2) for w in windows]
34+
35+
x, y, u, v, s2n = first_pass(
36+
frame_a,
37+
frame_b,
38+
settings
39+
)
40+
41+
42+
u = np.ma.masked_array(u, mask=np.ma.nomask)
43+
v = np.ma.masked_array(v, mask=np.ma.nomask)
44+
45+
if settings.validation_first_pass:
46+
u, v, mask = validation.typical_validation(u, v, s2n, settings)
47+
48+
u, v = filters.replace_outliers(u, v)
49+
50+
if settings.smoothn:
51+
u,_,_,_ = smoothn.smoothn(u, s=settings.smoothn_p)
52+
v,_,_,_ = smoothn.smoothn(v, s=settings.smoothn_p)
53+
# multipass
54+
for i in range(1, settings.num_iterations):
55+
56+
x, y, u, v, s2n, mask = multipass_img_deform(
57+
frame_a,
58+
frame_b,
59+
i,
60+
x,
61+
y,
62+
u,
63+
v,
64+
settings
65+
)
66+
67+
# If the smoothing is active, we do it at each pass
68+
# but not the last one
69+
if settings.smoothn is True and i < settings.num_iterations-1:
70+
u, dummy_u1, dummy_u2, dummy_u3 = smoothn.smoothn(
71+
u, s=settings.smoothn_p
72+
)
73+
v, dummy_v1, dummy_v2, dummy_v3 = smoothn.smoothn(
74+
v, s=settings.smoothn_p
75+
)
76+
77+
# replance NaNs by zeros
78+
u = u.filled(0.)
79+
v = v.filled(0.)
80+
81+
# # "scales the results pixel-> meter"
82+
# x, y, u, v = scaling.uniform(x, y, u, v,
83+
# scaling_factor=settings.scaling_factor)
84+
85+
x, y, u, v = transform_coordinates(x, y, u, v)
86+
return (x,y,u,v,s2n)
87+
2488

2589
def piv(settings):
2690
""" the func fuction is the "frame" in which the PIV evaluation is done """

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
setup(
1212
name="OpenPIV",
13-
version='0.24.1',
13+
version='0.24.2',
1414
packages=find_packages(),
1515
include_package_data=True,
1616
long_description=long_description,

0 commit comments

Comments
 (0)