OpenPIV examples that you can execute in your browser

Thanks to the great service of

Import what is necessary from OpenPIV

In [1]:
from openpiv import tools, validation, filters, scaling, pyprocess
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from IPython.display import display
from ipywidgets import interact_manual, interactive, fixed, IntSlider, HBox, VBox, Layout

Read a pair of PIV images

In [2]:
frame_a  = tools.imread( 'exp1_001_b.bmp' )
frame_b  = tools.imread( 'exp1_001_c.bmp' )

Show them using matplotlib

In [3]:
fig,ax = plt.subplots(1,2,figsize=(10,8))
<matplotlib.image.AxesImage at 0x7ff2f817bdf0>

Define the PIV analysis parameters

  1. Size of the interrogation window in frame A (winsize),
  2. Size of the search window in frame B (searchsize is larger or equal to winsize),
  3. overlap between the neighbouring windows (overlap),
  4. time interval of the PIV recording ($\Delta t$)
  5. type of the peak quality (signal-to-noise ratio)
In [4]:
winsize = 32 # pixels, interrogation window size in frame A
searchsize = 38  # pixels, search in image B
overlap = 12 # pixels, 50% overlap
dt = 0.02 # sec, time interval between pulses

Run the OpenPIV (fast code, precompiled in Cython)

In [5]:
u0, v0, sig2noise = pyprocess.extended_search_area_piv(frame_a.astype(np.int32), 

Get a list of coordinates for the vector field

In [6]:
x, y = pyprocess.get_coordinates( image_size=frame_a.shape, 
                                 overlap=overlap )

Clean the peaks that are below a quality threshold

In [7]:
u1, v1, mask = validation.sig2noise_val( u0, v0, 
                                        threshold = 1.05 )
# if you need more detailed look, first create a histogram of sig2noise
# plt.hist(sig2noise.flatten())
# to see where is a reasonable limit

Replace those that are masked as bad vectors with local interpolation

In [8]:
# filter out outliers that are very different from the
# neighbours

u2, v2 = filters.replace_outliers( u1, v1, 

Scale the results from pix/dt to mm/sec

In [9]:
# convert x,y to mm
# convert u,v to mm/sec

x, y, u3, v3 = scaling.uniform(x, y, u2, v2, 
                               scaling_factor = 96.52 ) # 96.52 microns/pixel

# 0,0 shall be bottom left, positive rotation rate is counterclockwise
x, y, u3, v3 = tools.transform_coordinates(x, y, u3, v3)

store the result in a text file

In [10]:
# save in the simple ASCII table format, y, u3, v3, mask, 'exp1_001.txt' )

plot the data stored in the text file

In [11]:
fig, ax = plt.subplots(figsize=(8,8))
                           ax=ax, scaling_factor=96.52, 
                           scale=50, # scale defines here the arrow length
                           width=0.0035, # width is the thickness of the arrow
                           on_img=True, # overlay on the image

Another example

Use any pair of images that you can access via URL

For instance we can use images from PIV Challenge

In [12]:
frame_a = tools.imread('')
frame_b = tools.imread('')
fig,ax = plt.subplots(1,2,figsize=(10,8))
<matplotlib.image.AxesImage at 0x7ff2f7ecb910>