In this Notebook a number of test cases using the PIV sythetic image generator will be presented.
The three examples shown are:
In each of these cases the pattern to recieving the synthetic images is the same. The part that mostly varies is the data passed.
import synimagegen
import matplotlib.pyplot as plt
import numpy as np
import os
%matplotlib inline
In this case no data is passed to the function, so a random equation is invoked from the cff module. (line 46,52 in synimagegen.py)
This equation defines the velocities U,V for each point in the X,Y plane.
This equation is ment to be changed to suit the testing needs of each users system.
ground_truth,cv,x_1,y_1,U_par,V_par,par_diam1,par_int1,x_2,y_2,par_diam2,par_int2 = synimagegen.create_synimage_parameters(None,[0,1],[0,1],[256,256],dt=0.0025)
Requested pair loss: 10 Actual pair loss: 5
frame_a = synimagegen.generate_particle_image(256, 256, x_1, y_1, par_diam1, par_int1,16)
frame_b = synimagegen.generate_particle_image(256, 256, x_2, y_2, par_diam2, par_int2,16)
fig = plt.figure(figsize=(20,10))
a = fig.add_subplot(1, 2, 1,)
imgplot = plt.imshow(frame_a, cmap='gray')
a.set_title('frame_a')
a = fig.add_subplot(1, 2, 2)
imgplot = plt.imshow(frame_b, cmap='gray')
a.set_title('frame_b')
Text(0.5, 1.0, 'frame_b')
In this case experiment data is passed to the function, and the interpolation flag is enabled. Thus using the data to create a continous flow field by interpolation and then using the field to create the paramters.
data = np.load('PIV_experiment_data.npz')
data['Y']
array([[2080, 2080, 2080, ..., 2080, 2080, 2080], [2048, 2048, 2048, ..., 2048, 2048, 2048], [2016, 2016, 2016, ..., 2016, 2016, 2016], ..., [ 128, 128, 128, ..., 128, 128, 128], [ 96, 96, 96, ..., 96, 96, 96], [ 64, 64, 64, ..., 64, 64, 64]], dtype=int32)
plt.figure()
plt.quiver(data['X'], data['Y'], data['U'], data['V'])
<matplotlib.quiver.Quiver at 0x7f807e7cecb0>
cff = synimagegen.continuous_flow_field(None)
x = np.linspace(0, 20)
y = np.linspace(0, 20)
x, y = np.meshgrid(x, y)
u,v = cff.get_U_V(x,y)
plt.figure()
plt.quiver(x, y, u, v)
<matplotlib.quiver.Quiver at 0x7f807bd64dc0>
data = np.stack([data['X'], data['Y'],data['U'] ,data['V']], axis=2)
data.shape
(64, 50, 4)
ground_truth,cv,x_1,y_1,U_par,V_par,par_diam1,par_int1,x_2,y_2,par_diam2,par_int2 = synimagegen.create_synimage_parameters(data,[0,1],[0,1],[256,256],inter=True,dt=0.0025)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[7], line 1 ----> 1 ground_truth,cv,x_1,y_1,U_par,V_par,par_diam1,par_int1,x_2,y_2,par_diam2,par_int2 = synimagegen.create_synimage_parameters(data,[0,1],[0,1],[256,256],inter=True,dt=0.0025) File ~/Documents/repos/ErichZimmer/openpiv-python/synimage/synimagegen.py:205, in create_synimage_parameters(input_data, x_bound, y_bound, image_size, path, inter, den, per_loss_pairs, par_diam_mean, par_diam_std, par_int_std, dt) 202 data = input_data 204 if inter: --> 205 cff = continuous_flow_field(data, inter=True) 206 else: 207 cff = continuous_flow_field(None) File ~/Documents/repos/ErichZimmer/openpiv-python/synimage/synimagegen.py:36, in continuous_flow_field.__init__(self, data, inter) 34 self.inter = inter 35 if inter: ---> 36 self.f_U = scipy.interpolate.RectBivariateSpline(data[:, 0], data[:, 1], data[:, 2]) 37 self.f_V = scipy.interpolate.RectBivariateSpline(data[:, 0], data[:, 1], data[:, 3]) File ~/Documents/repos/openpiv-python-examples/.conda/lib/python3.10/site-packages/scipy/interpolate/_fitpack2.py:1586, in RectBivariateSpline.__init__(self, x, y, z, bbox, kx, ky, s) 1584 z = np.asarray(z) 1585 if not np.all(diff(x) > 0.0): -> 1586 raise ValueError('x must be strictly increasing') 1587 if not np.all(diff(y) > 0.0): 1588 raise ValueError('y must be strictly increasing') ValueError: x must be strictly increasing
frame_a = synimagegen.generate_particle_image(256, 256, x_1, y_1, par_diam1, par_int1,16)
frame_b = synimagegen.generate_particle_image(256, 256, x_2, y_2, par_diam2, par_int2,16)
fig = plt.figure(figsize=(20,10))
a = fig.add_subplot(1, 2, 1)
imgplot = plt.imshow(frame_a, cmap='gray')
a.set_title('frame_a')
a = fig.add_subplot(1, 2, 2)
imgplot = plt.imshow(frame_b, cmap='gray')
a.set_title('frame_b')
In this case flow simulation results are passed to the function, in the form of a tab-delimited text file. The file is parsed and the data is used in order to continous flow field by interpolation.
path_to_file = os.getcwd() + '/velocity_report.txt'
ground_truth,cv,x_1,y_1,U_par,V_par,par_diam1,par_int1,x_2,y_2,par_diam2,par_int2 = synimagegen.create_synimage_parameters(None,[0,1],[0,1],[256,256],path=path_to_file,inter=True,dt=0.0025)
frame_a = synimagegen.generate_particle_image(256, 256, x_1, y_1, par_diam1, par_int1,16)
frame_b = synimagegen.generate_particle_image(256, 256, x_2, y_2, par_diam2, par_int2,16)
fig = plt.figure(figsize=(20,10))
a = fig.add_subplot(1, 2, 1)
imgplot = plt.imshow(frame_a, cmap='gray')
a.set_title('frame_a')
a = fig.add_subplot(1, 2, 2)
imgplot = plt.imshow(frame_b, cmap='gray')
a.set_title('frame_b')