%23%20%2F%2F%2F%20script%0A%23%20requires-python%20%3D%20%22%3E%3D3.11%22%0A%23%20dependencies%20%3D%20%5B%0A%23%20%20%20%20%20%22marimo%22%2C%0A%23%20%20%20%20%20%22openpiv%3D%3D0.26.3%22%2C%0A%23%20%20%20%20%20%22numpy%22%2C%0A%23%20%20%20%20%20%22matplotlib%22%2C%0A%23%20%20%20%20%20%22scipy%22%2C%0A%23%20%20%20%20%20%22scikit-image%22%2C%0A%23%20%5D%0A%23%20%2F%2F%2F%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App(width%3D%22medium%22)%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%20%20%20%20mo.md(%22%23%20Educational%20PIV%20with%20OpenPIV%5Cn%5CnThis%20site%20teaches%20what%20PIV%20is%2C%20how%20to%20run%20it%2C%20and%20practical%20tips%20for%20good%20results.%22)%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%23%201.%20What%20is%20PIV%3F%0A%20%20%20%20Particle%20Image%20Velocimetry%20estimates%202D%20velocity%20fields%20by%20cross-correlating%20small%20interrogation%20windows%20between%20two%20images.%20Key%20ideas%3A%0A%20%20%20%20-%20Window%20size%20sets%20spatial%20resolution%20and%20accuracy.%0A%20%20%20%20-%20Overlap%20increases%20vector%20density%20but%20not%20independent%20information.%0A%20%20%20%20-%20Multi-pass%20with%20deformation%20improves%20accuracy%20on%20strong%20gradients.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%23%202.%20Generate%20synthetic%20images%0A%20%20%20%20We%20use%20OpenPIV's%20synthetic%20image%20generator%20to%20create%20a%20known%20flow%20for%20validation.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20from%20openpiv.tools%20import%20synimage%0A%20%20%20%20img_a%2C%20img_b%20%3D%20synimage.synimagegen(128)%0A%20%20%20%20print(%22images%22%2C%20img_a.shape%2C%20img_b.shape)%0A%20%20%20%20return%20img_a%2C%20img_b%0A%0A%0A%40app.cell%0Adef%20_(img_a%2C%20img_b)%3A%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt1%0A%20%20%20%20fig1%2C%20ax1%20%3D%20plt1.subplots(1%2C%202%2C%20figsize%3D(8%2C%204))%0A%20%20%20%20ax1%5B0%5D.imshow(img_a%2C%20cmap%3D%22gray%22)%0A%20%20%20%20ax1%5B0%5D.set_title(%22Image%20A%22)%0A%20%20%20%20ax1%5B1%5D.imshow(img_b%2C%20cmap%3D%22gray%22)%0A%20%20%20%20ax1%5B1%5D.set_title(%22Image%20B%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%23%203.%20Run%20PIV%0A%20%20%20%20Tip%3A%20start%20with%20window_size%3D32%2C%20overlap%3D50%25%2C%202-3%20passes.%20Use%20dt%20to%20convert%20to%20physical%20units.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(img_a%2C%20img_b)%3A%0A%20%20%20%20from%20openpiv%20import%20pyprocess%0A%20%20%20%20u%2C%20v%2C%20s2n%20%3D%20pyprocess.extended_search_area_piv(%0A%20%20%20%20%20%20%20%20img_a.astype(int)%2C%20img_b.astype(int)%2C%20window_size%3D32%2C%20overlap%3D16%2C%20dt%3D0.1%2C%20search_area_size%3D64%0A%20%20%20%20)%0A%20%20%20%20print(%22vectors%22%2C%20u.shape%2C%20%22finite%3A%22%2C%20(u%20%3D%3D%20u).sum())%0A%20%20%20%20return%20u%2C%20v%0A%0A%0A%40app.cell%0Adef%20_(u%2C%20v)%3A%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt2%0A%20%20%20%20fig2%2C%20ax2%20%3D%20plt2.subplots()%0A%20%20%20%20ax2.quiver(u%2C%20v)%0A%20%20%20%20ax2.set_title(%22Velocity%20field%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%23%204.%20Tips%20%26%20Tricks%0A%20%20%20%20-%20Use%20dynamic%20masking%20for%20objects%20in%20the%20flow.%0A%20%20%20%20-%20Apply%20validation%20(median%2C%20std)%20to%20remove%20outliers.%0A%20%20%20%20-%20Smooth%20with%20smoothn%20for%20presentation%2C%20not%20for%20validation.%0A%20%20%20%20-%20Check%20sig2noise%3B%20low%20values%20indicate%20poor%20correlation.%0A%20%20%20%20-%20Use%20Rust%20backend%20for%20speed%20on%20large%20datasets.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(%22%22%22%0A%20%20%20%20%23%23%205.%20Common%20pitfalls%0A%20%20%20%20-%20Too%20small%20windows%20%E2%86%92%20noise%3B%20too%20large%20%E2%86%92%20lose%20gradients.%0A%20%20%20%20-%20Insufficient%20overlap%20%E2%86%92%20coarse%20field.%0A%20%20%20%20-%20Not%20validating%20%E2%86%92%20false%20vectors.%0A%20%20%20%20-%20Ignoring%20dt%20%E2%86%92%20wrong%20units.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
289fa07d69dc07b935111ff3f4fc93c2