From 61e5508440ee7b15c44cef88ad856f95597f2a6f Mon Sep 17 00:00:00 2001 From: Alex Liberzon Date: Sat, 23 Jul 2022 21:39:54 +0000 Subject: [PATCH] added simple_multiplass to windef, 0.24.2 --- openpiv/test/test_windef.py | 28 ++++++++++++--- openpiv/windef.py | 72 +++++++++++++++++++++++++++++++++++++ setup.py | 2 +- 3 files changed, 96 insertions(+), 6 deletions(-) diff --git a/openpiv/test/test_windef.py b/openpiv/test/test_windef.py index 3bde475c..2cb8e069 100644 --- a/openpiv/test/test_windef.py +++ b/openpiv/test/test_windef.py @@ -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, \ @@ -178,9 +175,30 @@ 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 """ + # windowsizes = (64, 32, 16) + x, y, u, v, s2n = windef.simple_multipass( + frame_a, + frame_b, + #windowsizes + ) + 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) + + # the second condition is to check if the multipass is done. + # It need's a little numerical inaccuracy. \ No newline at end of file diff --git a/openpiv/windef.py b/openpiv/windef.py index 8a599aeb..3033a6e7 100644 --- a/openpiv/windef.py +++ b/openpiv/windef.py @@ -21,6 +21,78 @@ from openpiv import smoothn from skimage.util import invert +def simple_multipass(frame_a, frame_b, windows = (64, 32, 16)): + """ Simple windows deformation multipass run with + default settings + """ + settings = Settings() + + settings.num_iterations = len(windows) + settings.windowsizes = 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, + method=settings.filter_method, + max_iter=settings.max_filter_iteration, + kernel_size=settings.filter_kernel_size + ) + + if settings.smoothn: + 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 + ) + # 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 """ diff --git a/setup.py b/setup.py index e6cc8f13..646988ae 100644 --- a/setup.py +++ b/setup.py @@ -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,