# %loadpy tutorial-part1.py
import sys
sys.path.append('/Users/alex/Documents/OpenPIV/openpiv-python')
import openpiv.tools
import openpiv.process
import openpiv.scaling
frame_a = openpiv.tools.imread( 'exp1_001_a.bmp' )
frame_b = openpiv.tools.imread( 'exp1_001_b.bmp' )
winsize = 24 # pixels
searchsize = 64 # pixels, search in image B
overlap = 12 # pixels
dt = 0.02 # sec
u0, v0, sig2noise = openpiv.process.extended_search_area_piv( frame_a, frame_b, window_size=winsize, overlap=overlap, dt=dt, search_area_size=searchsize, sig2noise_method='peak2peak' )
x, y = openpiv.process.get_coordinates( image_size=frame_a.shape, window_size=winsize, overlap=overlap )
u1, v1, mask = openpiv.validation.sig2noise_val( u0, v0, sig2noise, threshold = 1.3 )
print nansum((u1 - u0)**2)
0.0
u2, v2 = openpiv.filters.replace_outliers( u1, v1, method='localmean', max_iter=10, kernel_size=2)
print nansum((u2 - u1)**2)
0.0
x, y, u3, v3 = openpiv.scaling.uniform(x, y, u2, v2, scaling_factor = 96.52 )
print nansum((u3 - u2)**2)
836665.088096
openpiv.tools.save(x, y, u3, v3, mask, 'exp1_001.txt' )
openpiv.tools.display_vector_field('exp1_001.txt', scale=100, width=0.0025)
# Small demonstration
x = np.array([1,2,3,4])
y = x # would preserve changes of x
z = x.copy() # would remain [1,2,3,4]
print 'x'; print x
print 'y'; print y
print 'z'; print z
# change x once:
x[0] = 10
print 'x'; print x
print 'y'; print y
print 'z'; print z
x [1 2 3 4] y [1 2 3 4] z [1 2 3 4] x [10 2 3 4] y [10 2 3 4] z [1 2 3 4]
# returns a view of the modified array
def test_change(x):
x[0] = 0
return x
# returns a copy of the modified array
def test_change_with_copy(x):
x[-1] = 25
return x.copy()
x_new_copy = test_change_with_copy(x)
x_new = test_change(x)
print 'x'; print x
print 'y'; print y
print 'z'; print z
print 'x_new'; print(x_new)
print 'x_copy'; print(x_new_copy)
x [ 0 2 3 25] y [ 0 2 3 25] z [1 2 3 4] x_new [ 0 2 3 25] x_copy [10 2 3 25]