1+ """ Testing basic PIV processes """
12import numpy as np
2- import matplotlib .pyplot as plt
33from skimage .util import random_noise
44from skimage import img_as_ubyte
55from scipy .ndimage import shift as shift_img
88from openpiv .pyprocess import extended_search_area_piv as piv
99from openpiv .pyprocess import fft_correlate_images , \
1010 correlation_to_displacement
11+ from openpiv import tools
1112
1213
13- threshold = 0.25
14+
15+ THRESHOLD = 0.25
1416
1517# define "PIV" shift, i.e. creating u,v values that we want to get
1618# -5.5 pixels to the left and 3.2 pixels upwards
1921# the second value is 1 pixel positive to the right
2022# shifted_digit_image=shift(some_digit_image,[2,1])
2123# so we expect to get later
22- # shift(image, [-1*shift_v, shift_u ])
24+ # shift(image, [-1*SHIFT_V, SHIFT_U ])
2325
2426
2527# <------
26- shift_u = - 3.5 # shift to the left, should be placed in columns, axis=1
28+ SHIFT_U = - 3.5 # shift to the left, should be placed in columns, axis=1
2729# ^
2830# |
2931# |
30- shift_v = 2.5 # shift upwards, should be placed in rows, axis=0
32+ SHIFT_V = 2.5 # shift upwards, should be placed in rows, axis=0
3133
3234
33- def create_pair (image_size = 32 , u = shift_u , v = shift_v ):
35+ def create_pair (image_size = 32 , u = SHIFT_U , v = SHIFT_V ):
3436 """ creates a pair of images with a roll/shift """
3537 frame_a = np .zeros ((image_size , image_size ))
3638 frame_a = random_noise (frame_a )
@@ -60,16 +62,16 @@ def test_piv():
6062 # extended_search_area_piv returns image based coordinate system
6163 u , v , _ = piv (frame_a , frame_b , window_size = 32 )
6264 print (u , v )
63- assert np .allclose (u , shift_u , atol = threshold )
64- assert np .allclose (v , shift_v , atol = threshold )
65+ assert np .allclose (u , SHIFT_U , atol = THRESHOLD )
66+ assert np .allclose (v , SHIFT_V , atol = THRESHOLD )
6567
6668
6769def test_piv_smaller_window ():
6870 """ test of the search area larger than the window """
6971 frame_a , frame_b = create_pair (image_size = 32 , u = - 3.5 , v = - 2.1 )
7072 u , v , _ = piv (frame_a , frame_b , window_size = 16 , search_area_size = 32 )
71- assert np .allclose (u , - 3.5 , atol = threshold )
72- assert np .allclose (v , - 2.1 , atol = threshold )
73+ assert np .allclose (u , - 3.5 , atol = THRESHOLD )
74+ assert np .allclose (v , - 2.1 , atol = THRESHOLD )
7375
7476
7577def test_extended_search_area ():
@@ -80,10 +82,10 @@ def test_extended_search_area():
8082 search_area_size = 32 ,
8183 overlap = 0 )
8284
83- assert np .allclose (u , - 3.5 , atol = threshold )
84- assert np .allclose (v , - 2.1 , atol = threshold )
85- # assert dist(u, shift_u ) < threshold
86- # assert dist(v, shift_v ) < threshold
85+ assert np .allclose (u , - 3.5 , atol = THRESHOLD )
86+ assert np .allclose (v , - 2.1 , atol = THRESHOLD )
87+ # assert dist(u, SHIFT_U ) < THRESHOLD
88+ # assert dist(v, SHIFT_V ) < THRESHOLD
8789
8890
8991def test_extended_search_area_overlap ():
@@ -94,8 +96,8 @@ def test_extended_search_area_overlap():
9496 search_area_size = 32 ,
9597 overlap = 8 )
9698 print (f"\n u={ u } \n v={ v } \n " )
97- assert np .allclose (u , shift_u , atol = threshold )
98- assert np .allclose (v , shift_v , atol = threshold )
99+ assert np .allclose (u , SHIFT_U , atol = THRESHOLD )
100+ assert np .allclose (v , SHIFT_V , atol = THRESHOLD )
99101
100102
101103def test_extended_search_area_sig2noise ():
@@ -110,8 +112,8 @@ def test_extended_search_area_sig2noise():
110112 subpixel_method = "gaussian"
111113 )
112114
113- assert np .allclose (u , - 3.5 , atol = threshold )
114- assert np .allclose (v , 2.1 , atol = threshold )
115+ assert np .allclose (u , - 3.5 , atol = THRESHOLD )
116+ assert np .allclose (v , 2.1 , atol = THRESHOLD )
115117
116118
117119def test_process_extended_search_area ():
@@ -120,13 +122,12 @@ def test_process_extended_search_area():
120122 u , v , _ = piv (frame_a , frame_b , window_size = 16 ,
121123 search_area_size = 32 , dt = 2. , overlap = 0 )
122124
123- assert np .allclose (u , shift_u / 2. , atol = threshold )
124- assert np .allclose (v , shift_v / 2. , atol = threshold )
125+ assert np .allclose (u , SHIFT_U / 2. , atol = THRESHOLD )
126+ assert np .allclose (v , SHIFT_V / 2. , atol = THRESHOLD )
125127
126128
127129def test_sig2noise_ratio ():
128130 """ s2n ratio test """
129- from openpiv import tools
130131 im1 = files ('openpiv.data' ).joinpath ('test1/exp1_001_a.bmp' )
131132 im2 = files ('openpiv.data' ).joinpath ('test1/exp1_001_b.bmp' )
132133
@@ -148,9 +149,10 @@ def test_sig2noise_ratio():
148149
149150
150151def test_fft_correlate ():
152+ """ test of the fft correlation """
151153 frame_a , frame_b = create_pair (image_size = 32 )
152154 corr = fft_correlate_images (frame_a , frame_b )
153155 u , v = correlation_to_displacement (corr [np .newaxis , ...], 1 , 1 )
154- assert np .allclose (u , shift_u , atol = threshold )
155- assert np .allclose (v , shift_v , atol = threshold )
156+ assert np .allclose (u , SHIFT_U , atol = THRESHOLD )
157+ assert np .allclose (v , SHIFT_V , atol = THRESHOLD )
156158
0 commit comments