#!/usr/bin/env python # coding: utf-8 # ## Synthetic Image Generation examples ## # In this Notebook a number of test cases using the PIV sythetic image generator will be presented. # # The three examples shown are: # 1. Using a fully synthetic flow field created by a random equation # 2. Using pre attained experimental data # 3. Using flow simulation results # # In each of these cases the pattern to recieving the synthetic images is the same. The part that mostly varies is the data passed. # # 1. Data is either syntheticly made or pass to the create_synimage_parameters function. # 2. The parameters for both images (frame_a, frame_b) are created # 3. The parameters are passed to the generate_particle_image function in order to create the image representation. # 4. Finally the images are shown on the screen as grayschale images. # In[1]: import synimagegen import matplotlib.pyplot as plt import numpy as np import os get_ipython().run_line_magic('matplotlib', 'inline') # ### Example 1: synthetic flow field created by a random equation ### # 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. # # In[2]: 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) # In[3]: 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) # In[4]: 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') # ### Example 2: pre attained experimental data ### # 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. # In[5]: data = np.load('PIV_experiment_data.npz') # In[6]: data = np.stack([data['X'], data['Y'],data['U'] ,data['V']], axis=2) # In[7]: 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) # In[8]: 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) # In[9]: 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') # ### Example 3: flow simulation results ### # 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. # # In[10]: 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) # In[11]: 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) # In[12]: 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')