This program implements the basic algorithms of the PIV method, such as an iterative cross-correlation method based on FFT with an integer and continuous displacement (DWS, CWS) of the interrogation windows, filtering and interpolation of the pair loss effect, and so on. At this stage, the graphical interface is available, the ability to select PIV hyperparameters. The key feature of the project is the use of GPU due to the torch library. PIV algorithm is completely vectorized, what results in a very high performance using the GPU, but still has a room for improvement.
Parameters of the program:
- Interrogation window size
- Window overlap size
- Coordinate scale
- Time between frames
- Selection of the device (CPU or any of your GPUs)
- Iteration method: DWS or CWS
- The number of iterations of the algorithm
- Interrogation window scale during iterations
- Supported image formats (bmp, jpg, tiff, ect.)
- Options for saving program results
Installation:
It is easier to use conda environment.
- Install nvidia CUDA Toolkit https://developer.nvidia.com/cuda-toolkit to ensure latest nvidia driver usage
- Install pytorch with GPU support https://pytorch.org/ . Matching your CUDA version is not critical since PyTorch installs it's own cudatoolkit.
- In your environment or command line
pip install TorchPIV
Usage:
Start GUI version from terminal
python
import torchPIV
torchPIV.runGUI()
Use as a part of the script
from torchPIV import OfflinePIV
piv_gen = OfflinePIV(
folder="test_images", # Path to experiment
device=torch.cuda.get_device_name(), # Device name
file_fmt="bmp",
wind_size=64,
overlap=32,
dt=12, # Time between frames, mcs
scale = 0.02, # mm/pix
multipass=2,
multipass_mode="CWS", # CWS or DWS
multipass_scale=2.0, # Window downscale on each pass
folder_mode="pairs" # Pairs or sequential frames
)
results = []
for out in piv_gen():
x, y, vx, vy = out
results.append(out)
Tested on Windows
Performance:
This method allows processing 4 thousand pairs of images with a size of 4 MP each with a search window of 64, overlap of 50%, two iterations with re-arranging (an increase in the number of vectors by 4 times) in less than 10 minutes. The first iteration of the algorithm (~[4000, 64, 64] subimage tensor) takes ~15 ms on a Geforce GTX 1660 Ti GPU.
Futhure plans: Creating a version of the program for processing data during their recording. The ability to process stereo PIV data.
You can cite this work with:
N. A. Nazarov and V. V Terekhov, “High level GPU-accelerated 2D PIV framework in Python,” Comput. Phys. Commun., p. 109009, 2023, doi: https://doi.org/10.1016/j.cpc.2023.109009.