Skip to content

Commit

Permalink
Merge pull request #247 from alexlib/simple_windef
Browse files Browse the repository at this point in the history
added simple_multiplass to windef, 0.24.2
  • Loading branch information
alexlib authored Jul 23, 2022
2 parents 4a035de + 05b557a commit 991d83a
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 6 deletions.
36 changes: 31 additions & 5 deletions openpiv/test/test_windef.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@
@author: Theo
"""


import pathlib
import numpy as np
from openpiv import windef
from openpiv.test import test_process
from openpiv import preprocess
import pathlib
import os
import matplotlib.pyplot as plt

frame_a, frame_b = test_process.create_pair(image_size=256)
shift_u, shift_v, threshold = test_process.shift_u, test_process.shift_v, \
Expand Down Expand Up @@ -178,9 +175,38 @@ def test_multi_pass_lin():
settings,
)
print(f"Iteration {i}")
print("\n", x, y, u, v, s2n)
print(u[:2,:2],v[:2,:2])
assert np.allclose(u, shift_u, atol=threshold)
assert np.allclose(v, shift_v, atol=threshold)

# the second condition is to check if the multipass is done.
# It need's a little numerical inaccuracy.

def test_simple_multipass():
""" Test simple multipass """
x, y, u, v, s2n = windef.simple_multipass(
frame_a,
frame_b
)
print("simple multipass\n")
print(u[:2,:2],v[:2,:2])

# note the -shift_v
# the simple_multipass also transforms units, so
# the plot is in the image-like space

assert np.allclose(u, shift_u, atol=threshold)
assert np.allclose(v, -shift_v, atol=threshold)


# windowsizes = (64, 32, 16)
x, y, u, v, s2n = windef.simple_multipass(
frame_a,
frame_b,
windows = (32,16)
)
assert np.allclose(u, shift_u, atol=threshold)
assert np.allclose(v, -shift_v, atol=threshold)

# the second condition is to check if the multipass is done.
# It need's a little numerical inaccuracy.
64 changes: 64 additions & 0 deletions openpiv/windef.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,70 @@
from openpiv import smoothn
from skimage.util import invert

def simple_multipass(frame_a, frame_b, windows = None):
""" Simple windows deformation multipass run with
default settings
"""
settings = Settings() # default, see below

if windows is not None:
settings.num_iterations = len(windows)
settings.windowsizes = windows
settings.overlap = [int(w/2) for w in windows]

x, y, u, v, s2n = first_pass(
frame_a,
frame_b,
settings
)


u = np.ma.masked_array(u, mask=np.ma.nomask)
v = np.ma.masked_array(v, mask=np.ma.nomask)

if settings.validation_first_pass:
u, v, mask = validation.typical_validation(u, v, s2n, settings)

u, v = filters.replace_outliers(u, v)

if settings.smoothn:
u,_,_,_ = smoothn.smoothn(u, s=settings.smoothn_p)
v,_,_,_ = smoothn.smoothn(v, s=settings.smoothn_p)
# multipass
for i in range(1, settings.num_iterations):

x, y, u, v, s2n, mask = multipass_img_deform(
frame_a,
frame_b,
i,
x,
y,
u,
v,
settings
)

# If the smoothing is active, we do it at each pass
# but not the last one
if settings.smoothn is True and i < settings.num_iterations-1:
u, dummy_u1, dummy_u2, dummy_u3 = smoothn.smoothn(
u, s=settings.smoothn_p
)
v, dummy_v1, dummy_v2, dummy_v3 = smoothn.smoothn(
v, s=settings.smoothn_p
)

# replance NaNs by zeros
u = u.filled(0.)
v = v.filled(0.)

# # "scales the results pixel-> meter"
# x, y, u, v = scaling.uniform(x, y, u, v,
# scaling_factor=settings.scaling_factor)

x, y, u, v = transform_coordinates(x, y, u, v)
return (x,y,u,v,s2n)


def piv(settings):
""" the func fuction is the "frame" in which the PIV evaluation is done """
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="OpenPIV",
version='0.24.1',
version='0.24.2',
packages=find_packages(),
include_package_data=True,
long_description=long_description,
Expand Down

0 comments on commit 991d83a

Please sign in to comment.